Received: from eggs.gnu.org ([208.118.235.92]:57124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULKkb-00012Q-15 for qemu-devel@nongnu.org; Thu, 28 Mar 2013 17:52:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULKkX-0003C5-SJ for qemu-devel@nongnu.org; Thu, 28 Mar 2013 17:52:48 -0400 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:36173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULKkX-0003Bd-9f for qemu-devel@nongnu.org; Thu, 28 Mar 2013 17:52:45 -0400 Received: from /spool/local by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 29 Mar 2013 07:45:35 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 85FB62CE804C for ; Fri, 29 Mar 2013 08:52:40 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2SLdSxC65929222 for ; Fri, 29 Mar 2013 08:39:28 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2SLqdsW002127 for ; Fri, 29 Mar 2013 08:52:40 +1100 From: Anthony Liguori Date: Thu, 28 Mar 2013 16:52:30 -0500 Message-Id: <1364507550-25093-4-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1364507550-25093-1-git-send-email-aliguori@us.ibm.com> References: <1364507550-25093-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [RFC PATCH 3/3] rbd: remove aio handler when no requests are pending List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Anthony Liguori , Mike Roth This allows us to pass NULL for io_flush by removing the aio event when no requests are pending. Signed-off-by: Anthony Liguori --- block/rbd.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 1a8ea6d..a7c3645 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -407,6 +407,18 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) g_free(rcb); } +static void qemu_rbd_aio_event_reader(void *opaque); + +static void qemu_rbd_update_aio_handler(BDRVRBDState *s) +{ + if (s->qemu_aio_count > 0) { + qemu_aio_set_fd_handler(s->fds[RBD_FD_READ], qemu_rbd_aio_event_reader, + NULL, NULL, s); + } else { + qemu_aio_set_fd_handler(s->fds[RBD_FD_READ], NULL, NULL, NULL, NULL); + } +} + /* * aio fd read handler. It runs in the qemu context and calls the * completion handling of completed rados aio operations. @@ -429,18 +441,12 @@ static void qemu_rbd_aio_event_reader(void *opaque) s->event_reader_pos = 0; qemu_rbd_complete_aio(s->event_rcb); s->qemu_aio_count--; + qemu_rbd_update_aio_handler(s); } } } while (ret < 0 && errno == EINTR); } -static int qemu_rbd_aio_flush_cb(void *opaque) -{ - BDRVRBDState *s = opaque; - - return (s->qemu_aio_count > 0); -} - static int qemu_rbd_open(BlockDriverState *bs, const char *filename, QDict *options, int flags) { @@ -525,9 +531,8 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, } fcntl(s->fds[0], F_SETFL, O_NONBLOCK); fcntl(s->fds[1], F_SETFL, O_NONBLOCK); - qemu_aio_set_fd_handler(s->fds[RBD_FD_READ], qemu_rbd_aio_event_reader, - NULL, qemu_rbd_aio_flush_cb, s); + qemu_rbd_update_aio_handler(s); return 0; @@ -701,6 +706,7 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs, size = nb_sectors * BDRV_SECTOR_SIZE; s->qemu_aio_count++; /* All the RADOSCB */ + qemu_rbd_update_aio_handler(s); rcb = g_malloc(sizeof(RADOSCB)); rcb->done = 0; @@ -736,6 +742,7 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs, failed: g_free(rcb); s->qemu_aio_count--; + qemu_rbd_update_aio_handler(s); qemu_aio_release(acb); return NULL; } -- 1.8.0