fd_group.h File Reference

File descriptor group utility functions. More...

Macros

#define SPDK_FD_GROUP_ADD(fgrp, efd, fn, arg)    spdk_fd_group_add(fgrp, efd, fn, arg, #fn)
 

Typedefs

typedef int(* spdk_fd_fn) (void *ctx)
 Callback function registered for the event source file descriptor. More...
 

Functions

int spdk_fd_group_create (struct spdk_fd_group **fgrp)
 Initialize one fd_group. More...
 
void spdk_fd_group_destroy (struct spdk_fd_group *fgrp)
 Release all resources associated with this fgrp. More...
 
int spdk_fd_group_wait (struct spdk_fd_group *fgrp, int timeout)
 Wait for new events generated inside fgrp, and process them with their registered spdk_fd_fn. More...
 
int spdk_fd_group_get_fd (struct spdk_fd_group *fgrp)
 Return the internal epoll_fd of specific fd_group. More...
 
int spdk_fd_group_add (struct spdk_fd_group *fgrp, int efd, spdk_fd_fn fn, void *arg, const char *name)
 Register one event source to specified fgrp. More...
 
void spdk_fd_group_remove (struct spdk_fd_group *fgrp, int efd)
 Unregister one event source from one fgrp. More...
 
int spdk_fd_group_event_modify (struct spdk_fd_group *fgrp, int efd, int event_types)
 Change the event notification types associated with the event source. More...
 

Detailed Description

File descriptor group utility functions.

Typedef Documentation

◆ spdk_fd_fn

typedef int(* spdk_fd_fn) (void *ctx)

Callback function registered for the event source file descriptor.

Parameters
ctxContext passed as arg to spdk_fd_group_add().
Returns
0 to indicate that event notification took place but no events were found; positive to indicate that event notification took place and some events were processed; negative if no event information is provided.

Function Documentation

◆ spdk_fd_group_add()

int spdk_fd_group_add ( struct spdk_fd_group *  fgrp,
int  efd,
spdk_fd_fn  fn,
void *  arg,
const char *  name 
)

Register one event source to specified fgrp.

Parameters
fgrpThe fgrp registered to.
efdFile descriptor of the event source.
fnCalled each time there are events in event source.
argFunction argument for fn.
nameName of the event source.
Returns
0 if success or -errno if failed

◆ spdk_fd_group_create()

int spdk_fd_group_create ( struct spdk_fd_group **  fgrp)

Initialize one fd_group.

Parameters
fgrpA pointer to return the initialized fgrp.
Returns
0 if success or -errno if failed

◆ spdk_fd_group_destroy()

void spdk_fd_group_destroy ( struct spdk_fd_group *  fgrp)

Release all resources associated with this fgrp.

Users need to remove all event sources from the fgrp before destroying it.

Parameters
fgrpThe fgrp to destroy.

◆ spdk_fd_group_event_modify()

int spdk_fd_group_event_modify ( struct spdk_fd_group *  fgrp,
int  efd,
int  event_types 
)

Change the event notification types associated with the event source.

Modules like nbd, need this api to add EPOLLOUT when having data to send, and remove EPOLLOUT if no data to send.

Parameters
fgrpThe fgrp registered to.
efdFile descriptor of the event source.
event_typesThe event notification types.
Returns
0 if success or -errno if failed

◆ spdk_fd_group_get_fd()

int spdk_fd_group_get_fd ( struct spdk_fd_group *  fgrp)

Return the internal epoll_fd of specific fd_group.

Parameters
fgrpThe pointer of specified fgrp.
Returns
The epoll_fd of specific fgrp.

◆ spdk_fd_group_remove()

void spdk_fd_group_remove ( struct spdk_fd_group *  fgrp,
int  efd 
)

Unregister one event source from one fgrp.

Parameters
fgrpThe fgrp registered to.
efdFile descriptor of the event source.

◆ spdk_fd_group_wait()

int spdk_fd_group_wait ( struct spdk_fd_group *  fgrp,
int  timeout 
)

Wait for new events generated inside fgrp, and process them with their registered spdk_fd_fn.

Parameters
fgrpThe fgrp to wait and process.
timeoutSpecifies the number of milliseconds that will block. -1 causes indefinitely blocking; 0 causes immediately return.
Returns
the number of processed events or -errno if failed