Commit 458c5cd3 authored by Ankit Kumar's avatar Ankit Kumar Committed by Konrad Sztyber
Browse files

util: handle events for fd type eventfd



To clear interrupt events on file descriptors that are eventfds we have
to read them. This commit introduces a new fd type SPDK_FD_TYPE_EVENTFD
which does that.

Change-Id: Ida78e1a037097984fbdfac170478c41520822f93
Signed-off-by: default avatarAnkit Kumar <ankit.kumar@samsung.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/25171


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent 91e7a24c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@ extern "C" {
 */
enum spdk_fd_type {
	SPDK_FD_TYPE_DEFAULT		= 0x0,
	/**
	 * Event file descriptors. Once an event is generated on these file descriptors, event
	 * handler will perform a read operation on it to reset its internal eventfd object
	 * counter value to 0.
	 */
	SPDK_FD_TYPE_EVENTFD		= 0x1,
};

struct spdk_event_handler_opts {
+24 −0
Original line number Diff line number Diff line
@@ -559,8 +559,11 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout)
	uint32_t totalfds = fgrp->num_fds;
	struct epoll_event events[totalfds];
	struct event_handler *ehdlr;
	uint64_t count;
	int n;
	int nfds;
	int bytes_read;
	int read_errno;

	if (fgrp->parent != NULL) {
		if (timeout < 0) {
@@ -617,6 +620,27 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout)
		}

		g_event = &events[n];

		/* read fd to reset the internal eventfd object counter value to 0 */
		if (ehdlr->fd_type == SPDK_FD_TYPE_EVENTFD) {
			bytes_read = read(ehdlr->fd, &count, sizeof(count));
			if (bytes_read < 0) {
				g_event = NULL;
				if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) {
					continue;
				}
				read_errno = errno;
				/* TODO: Device is buggy. Handle this properly */
				SPDK_ERRLOG("Failed to read fd (%d) %s\n",
					    ehdlr->fd, strerror(errno));
				return -read_errno;
			} else if (bytes_read == 0) {
				SPDK_ERRLOG("Read nothing from fd (%d)\n", ehdlr->fd);
				g_event = NULL;
				return -EINVAL;
			}
		}

		/* call the interrupt response function */
		ehdlr->fn(ehdlr->fn_arg);
		g_event = NULL;