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 <xiaodong.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5161
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Liu Xiaodong 2020-10-28 05:52:10 -04:00 committed by Jim Harris
parent add8fc1575
commit 43607106b1
2 changed files with 8 additions and 6 deletions

View File

@ -1098,6 +1098,7 @@ poller_register(spdk_poller_fn fn,
if (thread->interrupt_mode && period_microseconds != 0) { if (thread->interrupt_mode && period_microseconds != 0) {
int rc; int rc;
poller->timerfd = -1;
rc = thread_interrupt_register_timerfd(thread->fgrp, period_microseconds, poller); rc = thread_interrupt_register_timerfd(thread->fgrp, period_microseconds, poller);
if (rc < 0) { if (rc < 0) {
SPDK_ERRLOG("Failed to register timerfd for periodic poller: %s\n", spdk_strerror(-rc)); 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; return;
} }
if (thread->interrupt_mode && poller->timerfd) { if (thread->interrupt_mode && poller->timerfd >= 0) {
spdk_fd_group_remove(thread->fgrp, poller->timerfd); spdk_fd_group_remove(thread->fgrp, poller->timerfd);
close(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 /* 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); SPDK_INFOLOG(thread, "destroy fgrp for thread (%s)\n", thread->name);
if (thread->msg_fd <= 0) { if (thread->msg_fd < 0) {
return; return;
} }
spdk_fd_group_remove(fgrp, thread->msg_fd); spdk_fd_group_remove(fgrp, thread->msg_fd);
close(thread->msg_fd); close(thread->msg_fd);
thread->msg_fd = -1;
spdk_fd_group_destroy(fgrp); spdk_fd_group_destroy(fgrp);
thread->fgrp = NULL; thread->fgrp = NULL;

View File

@ -90,7 +90,7 @@ spdk_fd_group_add(struct spdk_fd_group *fgrp,
int rc; int rc;
/* parameter checking */ /* parameter checking */
if (fgrp == NULL || efd <= 0 || fn == NULL) { if (fgrp == NULL || efd < 0 || fn == NULL) {
return -EINVAL; return -EINVAL;
} }
@ -132,7 +132,7 @@ spdk_fd_group_remove(struct spdk_fd_group *fgrp, int efd)
struct event_handler *ehdlr; struct event_handler *ehdlr;
int rc; 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); SPDK_ERRLOG("Invalid to remvoe efd(%d) from fd_group(%p).\n", efd, fgrp);
assert(0); assert(0);
return; return;
@ -177,7 +177,7 @@ spdk_fd_group_event_modify(struct spdk_fd_group *fgrp,
struct epoll_event epevent; struct epoll_event epevent;
struct event_handler *ehdlr; struct event_handler *ehdlr;
if (fgrp == NULL || efd <= 0) { if (fgrp == NULL || efd < 0) {
return -EINVAL; return -EINVAL;
} }