From f8a2e5e3ca6146d4cc66a4750daf44a0cf043319 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 14 Nov 2011 12:44:21 +0000 Subject: block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated() The qcow2, qcow, and vmdk block drivers are based on coroutines. They have a coroutine mutex which protects internal state. We can convert the .bdrv_is_allocated() function to .bdrv_co_is_allocated() by holding the mutex around the cluster lookup operation. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/vmdk.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'block/vmdk.c') diff --git a/block/vmdk.c b/block/vmdk.c index f5441591d7..5623ac10cd 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -861,8 +861,8 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, return NULL; } -static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn vmdk_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum) { BDRVVmdkState *s = bs->opaque; int64_t index_in_cluster, n, ret; @@ -873,8 +873,10 @@ static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num, if (!extent) { return 0; } + qemu_co_mutex_lock(&s->lock); ret = get_cluster_offset(bs, extent, NULL, sector_num * 512, 0, &offset); + qemu_co_mutex_unlock(&s->lock); /* get_cluster_offset returning 0 means success */ ret = !ret; @@ -1596,7 +1598,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_close = vmdk_close, .bdrv_create = vmdk_create, .bdrv_co_flush_to_disk = vmdk_co_flush, - .bdrv_is_allocated = vmdk_is_allocated, + .bdrv_co_is_allocated = vmdk_co_is_allocated, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, .create_options = vmdk_create_options, -- cgit v1.2.1