From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XM9vV-0006nM-SN for qemu-devel@nongnu.org; Tue, 26 Aug 2014 02:08:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XM9vP-0003Id-Hn for qemu-devel@nongnu.org; Tue, 26 Aug 2014 02:08:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53296) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XM9vP-0003IY-9Y for qemu-devel@nongnu.org; Tue, 26 Aug 2014 02:08:11 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7Q68AUp005395 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 26 Aug 2014 02:08:10 -0400 From: Fam Zheng Date: Tue, 26 Aug 2014 14:08:12 +0800 Message-Id: <1409033298-5720-3-git-send-email-famz@redhat.com> In-Reply-To: <1409033298-5720-1-git-send-email-famz@redhat.com> References: <1409033298-5720-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [RFC PATCH v2 2/8] 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 , Paolo Bonzini , Stefan Hajnoczi 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. Signed-off-by: Fam Zheng --- block.c | 26 ++++++++++++++++++++++++++ include/block/aio.h | 1 + include/block/block.h | 1 + 3 files changed, 28 insertions(+) diff --git a/block.c b/block.c index f8e342f..f4c77ec 100644 --- a/block.c +++ b/block.c @@ -4612,6 +4612,32 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb) acb->aiocb_info->cancel(acb); } +static void bdrv_aio_cancel_cb_nop(void *opaque, int ret) +{ + /* nop */ +} + +/* Async version of aio cancel. The caller is not blocked if the acb implements + * cancel_async, otherwise fall back to bdrv_aio_cancel. In both cases, acb->cb + * is guarenteed to be called, before or after function returns. */ +void bdrv_aio_cancel_async(BlockDriverAIOCB *acb) +{ + if (acb->aiocb_info->cancel_async) { + acb->aiocb_info->cancel_async(acb); + } else { + /* Mask the cb and cancel, we'll call it manually once the synchronous + * cancel is done. */ + BlockDriverCompletionFunc *cb = acb->cb; + void *opaque = acb->opaque; + acb->cb = bdrv_aio_cancel_cb_nop; + acb->opaque = NULL; + qemu_aio_ref(acb); + acb->aiocb_info->cancel(acb); + cb(opaque, -ECANCELED); + qemu_aio_release(acb); + } +} + /**************************************************************/ /* async block device emulation */ diff --git a/include/block/aio.h b/include/block/aio.h index 8c216f6..c434466 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -27,6 +27,7 @@ typedef void BlockDriverCompletionFunc(void *opaque, int ret); typedef struct AIOCBInfo { void (*cancel)(BlockDriverAIOCB *acb); + void (*cancel_async)(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