From 43607106b168996b4b13a220947edd7815891525 Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Wed, 28 Oct 2020 05:52:10 -0400 Subject: [PATCH] intr: allow operations on fd=0 It is possible that STDIN_FILENO is registered as one interrupt source. So fd_group and spdk_thread should accept fd whose value is "0". Change-Id: I96c7e0d6dc1dfa10b42b59aadfa6dc159c133519 Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5161 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- lib/thread/thread.c | 8 +++++--- lib/util/fd_group.c | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index ed00407d5..a336bb44f 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1098,6 +1098,7 @@ poller_register(spdk_poller_fn fn, if (thread->interrupt_mode && period_microseconds != 0) { int rc; + poller->timerfd = -1; rc = thread_interrupt_register_timerfd(thread->fgrp, period_microseconds, poller); if (rc < 0) { SPDK_ERRLOG("Failed to register timerfd for periodic poller: %s\n", spdk_strerror(-rc)); @@ -1154,10 +1155,10 @@ spdk_poller_unregister(struct spdk_poller **ppoller) return; } - if (thread->interrupt_mode && poller->timerfd) { + if (thread->interrupt_mode && poller->timerfd >= 0) { spdk_fd_group_remove(thread->fgrp, poller->timerfd); close(poller->timerfd); - poller->timerfd = 0; + poller->timerfd = -1; } /* If the poller was paused, put it on the active_pollers list so that @@ -1825,12 +1826,13 @@ thread_interrupt_destroy(struct spdk_thread *thread) SPDK_INFOLOG(thread, "destroy fgrp for thread (%s)\n", thread->name); - if (thread->msg_fd <= 0) { + if (thread->msg_fd < 0) { return; } spdk_fd_group_remove(fgrp, thread->msg_fd); close(thread->msg_fd); + thread->msg_fd = -1; spdk_fd_group_destroy(fgrp); thread->fgrp = NULL; diff --git a/lib/util/fd_group.c b/lib/util/fd_group.c index c16e3d66c..d3f910467 100644 --- a/lib/util/fd_group.c +++ b/lib/util/fd_group.c @@ -90,7 +90,7 @@ spdk_fd_group_add(struct spdk_fd_group *fgrp, int rc; /* parameter checking */ - if (fgrp == NULL || efd <= 0 || fn == NULL) { + if (fgrp == NULL || efd < 0 || fn == NULL) { return -EINVAL; } @@ -132,7 +132,7 @@ spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd) struct event_handler *ehdlr; int rc; - if (fgrp == NULL || efd <= 0) { + if (fgrp == NULL || efd < 0) { SPDK_ERRLOG("Invalid to remvoe efd(%d) from fd_group(%p).\n", efd, fgrp); assert(0); return; @@ -177,7 +177,7 @@ spdk_fd_group_event_modify(struct spdk_fd_group *fgrp, struct epoll_event epevent; struct event_handler *ehdlr; - if (fgrp == NULL || efd <= 0) { + if (fgrp == NULL || efd < 0) { return -EINVAL; }