From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROuGR-0007hQ-0D for qemu-devel@nongnu.org; Fri, 11 Nov 2011 11:47:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROuGO-0000p7-2L for qemu-devel@nongnu.org; Fri, 11 Nov 2011 11:47:38 -0500 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:33853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROuGN-0000oK-RR for qemu-devel@nongnu.org; Fri, 11 Nov 2011 11:47:36 -0500 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pABGlXRK029826 for ; Fri, 11 Nov 2011 16:47:33 GMT Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pABGlXfb2494684 for ; Fri, 11 Nov 2011 16:47:33 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost.localdomain [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pABGlXsa009533 for ; Fri, 11 Nov 2011 09:47:33 -0700 From: Stefan Hajnoczi Date: Fri, 11 Nov 2011 16:47:14 +0000 Message-Id: <1321030042-20446-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1321030042-20446-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1321030042-20446-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 02/10] block: add .bdrv_co_is_allocated() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Marcelo Tosatti , Stefan Hajnoczi This patch adds the .bdrv_co_is_allocated() interface which is identical to .bdrv_is_allocated() but runs in coroutine context. Running in coroutine context implies that other coroutines might be performing I/O at the same time. Therefore it must be safe to run while the following BlockDriver functions are in-flight: .bdrv_co_readv() .bdrv_co_writev() .bdrv_co_flush() .bdrv_co_is_allocated() The new .bdrv_co_is_allocated() interface is useful because it can be used when a VM is running, whereas .bdrv_is_allocated() is a synchronous interface that does not cope with parallel requests. Signed-off-by: Stefan Hajnoczi --- block.c | 37 +++++++++++++++++++++++++++++++++++++ block_int.h | 2 ++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index e6ac6d3..f8705b7 100644 --- a/block.c +++ b/block.c @@ -1771,6 +1771,26 @@ int bdrv_has_zero_init(BlockDriverState *bs) return 1; } +typedef struct BdrvCoIsAllocatedData { + BlockDriverState *bs; + int64_t sector_num; + int nb_sectors; + int *pnum; + int ret; + bool done; +} BdrvCoIsAllocatedData; + +/* Coroutine wrapper for bdrv_is_allocated() */ +static void coroutine_fn bdrv_is_allocated_co_entry(void *opaque) +{ + BdrvCoIsAllocatedData *data = opaque; + BlockDriverState *bs = data->bs; + + data->ret = bs->drv->bdrv_co_is_allocated(bs, data->sector_num, + data->nb_sectors, data->pnum); + data->done = true; +} + /* * Returns true iff the specified sector is present in the disk image. Drivers * not implementing the functionality are assumed to not support backing files, @@ -1786,6 +1806,23 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { int64_t n; + if (bs->drv->bdrv_co_is_allocated) { + Coroutine *co; + BdrvCoIsAllocatedData data = { + .bs = bs, + .sector_num = sector_num, + .nb_sectors = nb_sectors, + .pnum = pnum, + .done = false, + }; + + co = qemu_coroutine_create(bdrv_is_allocated_co_entry); + qemu_coroutine_enter(co, &data); + while (!data.done) { + qemu_aio_wait(); + } + return data.ret; + } if (!bs->drv->bdrv_is_allocated) { if (sector_num >= bs->total_sectors) { *pnum = 0; diff --git a/block_int.h b/block_int.h index f4547f6..1c1351c 100644 --- a/block_int.h +++ b/block_int.h @@ -87,6 +87,8 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); + int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum); int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs, int num_reqs); -- 1.7.7.1