From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkbUy-0006K4-U0 for qemu-devel@nongnu.org; Mon, 17 Dec 2012 09:16:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkbUr-0007Vp-Hc for qemu-devel@nongnu.org; Mon, 17 Dec 2012 09:16:52 -0500 Received: from 212-4-128-36.cust.selfnet.cz ([212.4.128.36]:46974 helo=lws-ntb.brq.redhat.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkbUp-0007T3-Qx for qemu-devel@nongnu.org; Mon, 17 Dec 2012 09:16:45 -0500 From: mrezanin@redhat.com Date: Mon, 17 Dec 2012 14:39:50 +0100 Message-Id: <1355751593-31535-2-git-send-email-mrezanin@redhat.com> In-Reply-To: <1355751593-31535-1-git-send-email-mrezanin@redhat.com> References: <1355751593-31535-1-git-send-email-mrezanin@redhat.com> Subject: [Qemu-devel] [PATCH v7 1/4] block: Add synchronous wrapper for bdrv_co_is_allocated_above List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, Miroslav Rezanina , stefanha@redhat.com From: Miroslav Rezanina There's no synchronous wrapper for bdrv_co_is_allocated_above function so it's not possible to check for sector allocation in image with backing file. This patch add missing synchronous wrapper. Signed-off-by: Miroslav Rezanina --- block.c | 39 +++++++++++++++++++++++++++++++++++++++ block.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/block.c b/block.c index c05875f..24c06ab 100644 --- a/block.c +++ b/block.c @@ -2699,6 +2699,7 @@ int bdrv_has_zero_init(BlockDriverState *bs) typedef struct BdrvCoIsAllocatedData { BlockDriverState *bs; + BlockDriverState *base; int64_t sector_num; int nb_sectors; int *pnum; @@ -2829,6 +2830,44 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, return 0; } +/* Coroutine wrapper for bdrv_is_allocated_above() */ +static void coroutine_fn bdrv_is_allocated_above_co_entry(void *opaque) +{ + BdrvCoIsAllocatedData *data = opaque; + BlockDriverState *top = data->bs; + BlockDriverState *base = data->base; + + data->ret = bdrv_co_is_allocated_above(top, base, data->sector_num, + data->nb_sectors, data->pnum); + data->done = true; +} + +/* + * Synchronous wrapper around bdrv_co_is_allocated_above(). + * + * See bdrv_co_is_allocated_above() for details. + */ +int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + int64_t sector_num, int nb_sectors, int *pnum) +{ + Coroutine *co; + BdrvCoIsAllocatedData data = { + .bs = top, + .base = base, + .sector_num = sector_num, + .nb_sectors = nb_sectors, + .pnum = pnum, + .done = false, + }; + + co = qemu_coroutine_create(bdrv_is_allocated_above_co_entry); + qemu_coroutine_enter(co, &data); + while (!data.done) { + qemu_aio_wait(); + } + return data.ret; +} + BlockInfo *bdrv_query_info(BlockDriverState *bs) { BlockInfo *info = g_malloc0(sizeof(*info)); diff --git a/block.h b/block.h index 722c620..2cb8d71 100644 --- a/block.h +++ b/block.h @@ -278,6 +278,8 @@ int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_has_zero_init(BlockDriverState *bs); int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); +int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + int64_t sector_num, int nb_sectors, int *pnum); void bdrv_set_on_error(BlockDriverState *bs, BlockdevOnError on_read_error, BlockdevOnError on_write_error); -- 1.7.11.7