[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 23/41] block: convert qcow2, qcow2, and vmdk to .bdr
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 23/41] block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated() |
Date: |
Mon, 5 Dec 2011 15:21:00 +0100 |
From: Stefan Hajnoczi <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow.c | 8 +++++---
block/qcow2.c | 13 ++++++++-----
block/vmdk.c | 8 +++++---
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/block/qcow.c b/block/qcow.c
index 326ef87..b16955d 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -368,14 +368,16 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
return cluster_offset;
}
-static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, int *pnum)
+static int coroutine_fn qcow_co_is_allocated(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, int *pnum)
{
BDRVQcowState *s = bs->opaque;
int index_in_cluster, n;
uint64_t cluster_offset;
+ qemu_co_mutex_lock(&s->lock);
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
+ qemu_co_mutex_unlock(&s->lock);
index_in_cluster = sector_num & (s->cluster_sectors - 1);
n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors)
@@ -844,7 +846,7 @@ static BlockDriver bdrv_qcow = {
.bdrv_co_readv = qcow_co_readv,
.bdrv_co_writev = qcow_co_writev,
.bdrv_co_flush_to_disk = qcow_co_flush,
- .bdrv_is_allocated = qcow_is_allocated,
+ .bdrv_co_is_allocated = qcow_co_is_allocated,
.bdrv_set_key = qcow_set_key,
.bdrv_make_empty = qcow_make_empty,
diff --git a/block/qcow2.c b/block/qcow2.c
index 3f8a128..5ac9fb4 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -344,16 +344,19 @@ static int qcow2_set_key(BlockDriverState *bs, const char
*key)
return 0;
}
-static int qcow2_is_allocated(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, int *pnum)
+static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, int *pnum)
{
+ BDRVQcowState *s = bs->opaque;
uint64_t cluster_offset;
int ret;
*pnum = nb_sectors;
- /* FIXME We can get errors here, but the bdrv_is_allocated interface can't
- * pass them on today */
+ /* FIXME We can get errors here, but the bdrv_co_is_allocated interface
+ * can't pass them on today */
+ qemu_co_mutex_lock(&s->lock);
ret = qcow2_get_cluster_offset(bs, sector_num << 9, pnum, &cluster_offset);
+ qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
*pnum = 0;
}
@@ -1277,7 +1280,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_open = qcow2_open,
.bdrv_close = qcow2_close,
.bdrv_create = qcow2_create,
- .bdrv_is_allocated = qcow2_is_allocated,
+ .bdrv_co_is_allocated = qcow2_co_is_allocated,
.bdrv_set_key = qcow2_set_key,
.bdrv_make_empty = qcow2_make_empty,
diff --git a/block/vmdk.c b/block/vmdk.c
index f544159..5623ac1 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,
--
1.7.6.4
- [Qemu-devel] [PATCH 14/41] qcow2: Cleanups and memleak fix in qcow2_snapshot_create, (continued)
- [Qemu-devel] [PATCH 14/41] qcow2: Cleanups and memleak fix in qcow2_snapshot_create, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 16/41] qcow2: Return real error in qcow2_snapshot_goto, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 19/41] qcow2: Fix error path in qcow2_snapshot_load_tmp, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 18/41] qcow2: Fix order in qcow2_snapshot_delete, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 17/41] qcow2: Fix order of refcount updates in qcow2_snapshot_goto, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 22/41] qed: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 26/41] cow: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 27/41] block: drop .bdrv_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 24/41] vvfat: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 20/41] block: use public bdrv_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 23/41] block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 21/41] block: add .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 25/41] vdi: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 29/41] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 31/41] block: add request tracking, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 30/41] coroutine: add qemu_co_queue_restart_all(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 28/41] block: add bdrv_co_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 32/41] block: add interface to toggle copy-on-read, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 39/41] block: implement bdrv_co_is_allocated() boundary cases, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 37/41] cow: use bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 35/41] block: core copy-on-read logic, Kevin Wolf, 2011/12/05