Commit 872a40a0 authored by Ankit Kumar's avatar Ankit Kumar Committed by Konrad Sztyber
Browse files

util/fd_group: improve logs and documentation



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


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent f01c6f2d
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ struct spdk_fd_group;
 *
 * \param fgrp A pointer to return the initialized fgrp.
 *
 * \return 0 if success or -errno if failed
 * \return 0 on success, negated errno on failure.
 */
int spdk_fd_group_create(struct spdk_fd_group **fgrp);

@@ -61,8 +61,7 @@ void spdk_fd_group_destroy(struct spdk_fd_group *fgrp);
 * \param timeout Specifies the number of milliseconds that will block.
 * -1 causes indefinitely blocking; 0 causes immediately return.
 *
 * \return the number of processed events
 * or -errno if failed
 * \return the number of events processed on success, negated errno on failure.
 */
int spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout);

@@ -110,7 +109,7 @@ int spdk_fd_group_unnest(struct spdk_fd_group *parent, struct spdk_fd_group *chi
 * \param arg Function argument for fn.
 * \param name Name of the event source.
 *
 * \return 0 if success or -errno if failed
 * \return 0 on success, negated errno on failure.
 */
int spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd,
		      spdk_fd_fn fn, void *arg, const char *name);
@@ -128,7 +127,7 @@ int spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd,
 * \param arg Function argument for fn.
 * \param name Name of the event source.
 *
 * \return 0 if success or -errno if failed
 * \return 0 on success, negated errno on failure.
 */
int spdk_fd_group_add_for_events(struct spdk_fd_group *fgrp, int efd, uint32_t events,
				 spdk_fd_fn fn, void *arg,  const char *name);
@@ -157,7 +156,7 @@ void spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd);
 * \param efd File descriptor of the event source.
 * \param event_types The event notification types.
 *
 * \return 0 if success or -errno if failed
 * \return 0 on success, negated errno on failure.
 */
int spdk_fd_group_event_modify(struct spdk_fd_group *fgrp,
			       int efd, int event_types);
@@ -173,8 +172,8 @@ struct epoll_event;
 * 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
 * \param event pointer to an epoll(7) event to copy to.
 * \return 0 on success, negated errno on failure.
 */
int spdk_fd_group_get_epoll_event(struct epoll_event *event);

+21 −12
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ enum event_handler_state {
	EVENT_HANDLER_STATE_REMOVED,
};

/* file descriptor of the interrupt event */

/* Taking "ehdlr" as short name for file descriptor handler of the interrupt event. */
struct event_handler {
	TAILQ_ENTRY(event_handler)	next;
@@ -94,7 +92,8 @@ _fd_group_del_all(int epfd, struct spdk_fd_group *grp)
			}

			ret = -errno;
			SPDK_ERRLOG("Failed to remove fd %d from group: %s\n", ehdlr->fd, strerror(errno));
			SPDK_ERRLOG("Failed to remove fd: %d from group: %s\n",
				    ehdlr->fd, strerror(errno));
			goto recover;
		}
	}
@@ -102,7 +101,7 @@ _fd_group_del_all(int epfd, struct spdk_fd_group *grp)
	return 0;

recover:
	/* We failed to remove everything. Let's try to get everything put back into
	/* We failed to remove everything. Let's try to put everything back into
	 * the original group. */
	TAILQ_FOREACH(ehdlr, &grp->event_handlers, next) {
		epevent.events = ehdlr->events;
@@ -144,7 +143,8 @@ _fd_group_add_all(int epfd, struct spdk_fd_group *grp)
			}

			ret = -errno;
			SPDK_ERRLOG("Failed to add fd to fd group: %s\n", strerror(errno));
			SPDK_ERRLOG("Failed to add fd: %d to fd group: %s\n",
				    ehdlr->fd, strerror(errno));
			goto recover;
		}
	}
@@ -209,7 +209,7 @@ spdk_fd_group_nest(struct spdk_fd_group *parent, struct spdk_fd_group *child)
	}

	if (parent->parent) {
		/* More than one layer of nesting is not currently supported */
		/* More than one layer of nesting is currently not supported */
		assert(false);
		return -ENOTSUP;
	}
@@ -275,6 +275,8 @@ spdk_fd_group_add_for_events(struct spdk_fd_group *fgrp, int efd, uint32_t event
	epevent.data.ptr = ehdlr;
	rc = epoll_ctl(epfd, EPOLL_CTL_ADD, efd, &epevent);
	if (rc < 0) {
		SPDK_ERRLOG("Failed to add fd: %d to fd group(%p): %s\n",
			    efd, fgrp, strerror(errno));
		free(ehdlr);
		return -errno;
	}
@@ -293,7 +295,7 @@ spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd)
	int epfd;

	if (fgrp == NULL || efd < 0) {
		SPDK_ERRLOG("Invalid to remove efd(%d) from fd_group(%p).\n", efd, fgrp);
		SPDK_ERRLOG("Cannot remove fd: %d from fd group(%p)\n", efd, fgrp);
		assert(0);
		return;
	}
@@ -306,7 +308,7 @@ spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd)
	}

	if (ehdlr == NULL) {
		SPDK_ERRLOG("efd(%d) is not existed in fgrp(%p)\n", efd, fgrp);
		SPDK_ERRLOG("fd: %d doesn't exist in fd group(%p)\n", efd, fgrp);
		return;
	}

@@ -320,7 +322,8 @@ spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd)

	rc = epoll_ctl(epfd, EPOLL_CTL_DEL, ehdlr->fd, NULL);
	if (rc < 0) {
		SPDK_ERRLOG("Failed to delete the fd(%d) from the epoll group(%p)\n", efd, fgrp);
		SPDK_ERRLOG("Failed to remove fd: %d from fd group(%p): %s\n",
			    ehdlr->fd, fgrp, strerror(errno));
		return;
	}

@@ -407,7 +410,12 @@ void
spdk_fd_group_destroy(struct spdk_fd_group *fgrp)
{
	if (fgrp == NULL || fgrp->num_fds > 0) {
		SPDK_ERRLOG("Invalid fd_group(%p) to destroy.\n", fgrp);
		if (!fgrp) {
			SPDK_ERRLOG("fd_group doesn't exist.\n");
		} else {
			SPDK_ERRLOG("Cannot delete fd group(%p) as (%d) fds still registered to it.\n",
				    fgrp, fgrp->num_fds);
		}
		assert(0);
		return;
	}
@@ -433,7 +441,7 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout)
			assert(false);
			return -EINVAL;
		} else {
			SPDK_WARNLOG("Calling spdk_fd_group_wait on a group nested in another group will never find any events\n");
			SPDK_WARNLOG("Calling spdk_fd_group_wait on a group nested in another group will never find any events.\n");
			return 0;
		}
	}
@@ -441,7 +449,8 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout)
	nfds = epoll_wait(fgrp->epfd, events, totalfds, timeout);
	if (nfds < 0) {
		if (errno != EINTR) {
			SPDK_ERRLOG("fgrp epoll_wait returns with fail. errno is %d\n", errno);
			SPDK_ERRLOG("fd group(%p) epoll_wait failed: %s\n",
				    fgrp, strerror(errno));
		}

		return -errno;