Commit 7f236385 authored by Thanos Makatos's avatar Thanos Makatos Committed by Tomasz Zawadzki
Browse files

util: add function spdk_fd_group_get_epoll_event



This patch introduces function spdk_fd_group_get_epoll_event, which
returns the epoll(7) event that caused the file descriptor group
callback function to execute. Rather than changing the signature of
spdk_fd_fn in order to pass the struct epoll_event, which would result
in a gigantic patch where there vast majority of users would simply have
to ignore the new argument, we introduce this new API that allows to
return the epoll_event only when really needed.

Signed-off-by: default avatarThanos Makatos <thanos.makatos@nutanix.com>
Suggested-by: default avatarJohn Levon <john.levon@nutanix.com>
Change-Id: I3debe1382d1c2bfec6ae4fea274ee38ed0b135fe
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14935


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJohn Levon <levon@movementarian.org>
parent 5f8c0566
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -55,6 +55,11 @@ Added spdk_rpc_set_allowlist to restrict allowed RPCs to the specified list.
Promoted the application to example to match similar programs: fio_plugin and perf.
It can now be found inside `examples/bdev/bdevperf`.

### util

New API `spdk_fd_group_get_epoll_event` that returns the epoll(7) event that
caused a function callback in file descriptor group to execute.

## v22.09

### accel
+16 −0
Original line number Diff line number Diff line
@@ -118,6 +118,22 @@ void spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd);
int spdk_fd_group_event_modify(struct spdk_fd_group *fgrp,
			       int efd, int event_types);

/*
 * Forward declaration of epoll_event to avoid having to conditionally compile
 * spdk_fd_group_get_epoll_event on non-Linux systems.
 */
struct epoll_event;

/**
 * Copies the epoll(7) event that caused a callback function to execute.
 * This function can only be called by the callback function, doing otherwise
 * results in undefined behavior.
 *
 * \param event pointer to an epoll(7) event to copy to
 * \return 0 on success, -errno on error
 */
int spdk_fd_group_get_epoll_event(struct epoll_event *event);

#ifdef __cplusplus
}
#endif
+20 −0
Original line number Diff line number Diff line
@@ -60,6 +60,18 @@ spdk_fd_group_get_fd(struct spdk_fd_group *fgrp)

#ifdef __linux__

static __thread struct epoll_event *g_event = NULL;

int
spdk_fd_group_get_epoll_event(struct epoll_event *event)
{
	if (g_event == NULL) {
		return -EINVAL;
	}
	*event = *g_event;
	return 0;
}

int
spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd, spdk_fd_fn fn,
		  void *arg, const char *name)
@@ -277,8 +289,10 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout)
		SPDK_DTRACE_PROBE4(interrupt_fd_process, ehdlr->name, ehdlr->fd,
				   ehdlr->fn, ehdlr->fn_arg);

		g_event = &events[n];
		/* call the interrupt response function */
		ehdlr->fn(ehdlr->fn_arg);
		g_event = NULL;

		/* It is possible that the ehdlr was removed
		 * during this wait loop when it get executed.
@@ -295,6 +309,12 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout)

#else

int
spdk_fd_group_get_epoll_event(struct epoll_event *event)
{
	return -ENOTSUP;
}

int
spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd, spdk_fd_fn fn,
		  void *arg, const char *name)
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@
	# public functions in fd_group.h
	spdk_fd_group_create;
	spdk_fd_group_destroy;
	spdk_fd_group_get_epoll_event;
	spdk_fd_group_wait;
	spdk_fd_group_add;
	spdk_fd_group_remove;