From 7f6afb7bc01e1e3ee4713dbeab2fdb0f4f887dbf Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Sat, 2 Jan 2021 15:53:21 -0500 Subject: [PATCH] bdev_aio: allow value of efd to be 0 Previously, value '0' is used to reflect efd's invalidation. But it is possible that efd is 0 if STDIN is closed. So change related condition checking, and assign efd to be '-1' in initializing Change-Id: Iffea09b1f094617ab2edd3fe3b98336ec9084b8a Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5781 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- module/bdev/aio/bdev_aio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/module/bdev/aio/bdev_aio.c b/module/bdev/aio/bdev_aio.c index 4fd83ffa7..f2c4814ca 100644 --- a/module/bdev/aio/bdev_aio.c +++ b/module/bdev/aio/bdev_aio.c @@ -59,6 +59,9 @@ struct bdev_aio_io_channel { }; struct bdev_aio_group_channel { + /* eventfd for io completion notification in interrupt mode. + * Negative value like '-1' indicates it is invalid or unused. + */ int efd; struct spdk_interrupt *intr; struct spdk_poller *poller; @@ -173,7 +176,7 @@ bdev_aio_readv(struct file_disk *fdisk, struct spdk_io_channel *ch, int rc; io_prep_preadv(iocb, fdisk->fd, iov, iovcnt, offset); - if (aio_ch->group_ch->efd) { + if (aio_ch->group_ch->efd >= 0) { io_set_eventfd(iocb, aio_ch->group_ch->efd); } iocb->data = aio_task; @@ -207,7 +210,7 @@ bdev_aio_writev(struct file_disk *fdisk, struct spdk_io_channel *ch, int rc; io_prep_pwritev(iocb, fdisk->fd, iov, iovcnt, offset); - if (aio_ch->group_ch->efd) { + if (aio_ch->group_ch->efd >= 0) { io_set_eventfd(iocb, aio_ch->group_ch->efd); } iocb->data = aio_task; @@ -369,7 +372,7 @@ bdev_aio_group_interrupt(void *arg) int rc; uint64_t num_events; - assert(group_ch->efd); + assert(group_ch->efd >= 0); /* if completed IO number is larger than SPDK_AIO_QUEUE_DEPTH, * io_getevent should be called again to ensure all completed IO are processed. @@ -642,7 +645,7 @@ bdev_aio_unregister_interrupt(struct bdev_aio_group_channel *ch) { spdk_interrupt_unregister(&ch->intr); close(ch->efd); - ch->efd = 0; + ch->efd = -1; } static int @@ -651,6 +654,8 @@ bdev_aio_group_create_cb(void *io_device, void *ctx_buf) struct bdev_aio_group_channel *ch = ctx_buf; TAILQ_INIT(&ch->io_ch_head); + /* Initialize ch->efd to be invalid and unused. */ + ch->efd = -1; if (spdk_interrupt_mode_is_enabled()) { return bdev_aio_register_interrupt(ch);