From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8gG-0005NH-Sj for qemu-devel@nongnu.org; Wed, 03 Sep 2014 07:24:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XP8g9-0006Sg-9z for qemu-devel@nongnu.org; Wed, 03 Sep 2014 07:24:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8g9-0006Rm-2r for qemu-devel@nongnu.org; Wed, 03 Sep 2014 07:24:45 -0400 From: Fam Zheng Date: Wed, 3 Sep 2014 19:23:37 +0800 Message-Id: <1409743435-21155-3-git-send-email-famz@redhat.com> In-Reply-To: <1409743435-21155-1-git-send-email-famz@redhat.com> References: <1409743435-21155-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v4 02/20] block: Add bdrv_aio_cancel_async List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Chrysostomos Nanakos , Stefan Hajnoczi , Liu Yuan , Peter Lieven , Ronnie Sahlberg , Josh Durgin , Paolo Bonzini , MORITA Kazutaka , Benoit Canet This is the async version of bdrv_aio_cancel, which doesn't block the caller. It guarantees that the cb is called either before returning or some time later. bdrv_aio_cancel can base on bdrv_aio_cancel_async, later we can convert all .io_cancel implementations to .io_cancel_async, and the aio_poll is the common logic. In the end, .io_cancel can be dropped. Signed-off-by: Fam Zheng --- block.c | 27 ++++++++++++++++++++++++++- include/block/aio.h | 2 ++ include/block/block.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 78d68cb..2dfd1be 100644 --- a/block.c +++ b/block.c @@ -4634,7 +4634,32 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs) void bdrv_aio_cancel(BlockDriverAIOCB *acb) { - acb->aiocb_info->cancel(acb); + if (acb->aiocb_info->cancel) { + acb->aiocb_info->cancel(acb); + } else { + qemu_aio_ref(acb); + bdrv_aio_cancel_async(acb); + while (acb->refcnt > 1) { + if (acb->aiocb_info->get_aio_context) { + aio_poll(acb->aiocb_info->get_aio_context(acb), true); + } else if (acb->bs) { + aio_poll(bdrv_get_aio_context(acb->bs), true); + } else { + abort(); + } + } + qemu_aio_release(acb); + } +} + +/* Async version of aio cancel. The caller is not blocked if the acb implements + * cancel_async, otherwise we do nothing and let the request normally complete. + * In either case the completion callback must be called. */ +void bdrv_aio_cancel_async(BlockDriverAIOCB *acb) +{ + if (acb->aiocb_info->cancel_async) { + acb->aiocb_info->cancel_async(acb); + } } /**************************************************************/ diff --git a/include/block/aio.h b/include/block/aio.h index 2626fc7..ad361e3 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -27,6 +27,8 @@ typedef void BlockDriverCompletionFunc(void *opaque, int ret); typedef struct AIOCBInfo { void (*cancel)(BlockDriverAIOCB *acb); + void (*cancel_async)(BlockDriverAIOCB *acb); + AioContext *(*get_aio_context)(BlockDriverAIOCB *acb); size_t aiocb_size; } AIOCBInfo; diff --git a/include/block/block.h b/include/block/block.h index 8f4ad16..35a2448 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -336,6 +336,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); void bdrv_aio_cancel(BlockDriverAIOCB *acb); +void bdrv_aio_cancel_async(BlockDriverAIOCB *acb); typedef struct BlockRequest { /* Fields to be filled by multiwrite caller */ -- 2.1.0.27.g96db324