[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 34/35] qcow2: Always execute preallocate() in a corou
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 34/35] qcow2: Always execute preallocate() in a coroutine |
Date: |
Thu, 26 Oct 2017 15:17:40 +0200 |
From: Max Reitz <address@hidden>
Some qcow2 functions (at least perform_cow()) expect s->lock to be
taken. Therefore, if we want to make use of them, we should execute
preallocate() (as "preallocate_co") in a coroutine so that we can use
the qemu_co_mutex_* functions.
Signed-off-by: Max Reitz <address@hidden>
Message-id: address@hidden
Cc: address@hidden
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 1ea763126d..92cb9f9bfa 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2460,6 +2460,14 @@ static int qcow2_set_up_encryption(BlockDriverState *bs,
const char *encryptfmt,
}
+typedef struct PreallocCo {
+ BlockDriverState *bs;
+ uint64_t offset;
+ uint64_t new_length;
+
+ int ret;
+} PreallocCo;
+
/**
* Preallocates metadata structures for data clusters between @offset (in the
* guest disk) and @new_length (which is thus generally the new guest disk
@@ -2467,9 +2475,12 @@ static int qcow2_set_up_encryption(BlockDriverState *bs,
const char *encryptfmt,
*
* Returns: 0 on success, -errno on failure.
*/
-static int preallocate(BlockDriverState *bs,
- uint64_t offset, uint64_t new_length)
+static void coroutine_fn preallocate_co(void *opaque)
{
+ PreallocCo *params = opaque;
+ BlockDriverState *bs = params->bs;
+ uint64_t offset = params->offset;
+ uint64_t new_length = params->new_length;
BDRVQcow2State *s = bs->opaque;
uint64_t bytes;
uint64_t host_offset = 0;
@@ -2477,9 +2488,7 @@ static int preallocate(BlockDriverState *bs,
int ret;
QCowL2Meta *meta;
- if (qemu_in_coroutine()) {
- qemu_co_mutex_lock(&s->lock);
- }
+ qemu_co_mutex_lock(&s->lock);
assert(offset <= new_length);
bytes = new_length - offset;
@@ -2533,10 +2542,28 @@ static int preallocate(BlockDriverState *bs,
ret = 0;
done:
+ qemu_co_mutex_unlock(&s->lock);
+ params->ret = ret;
+}
+
+static int preallocate(BlockDriverState *bs,
+ uint64_t offset, uint64_t new_length)
+{
+ PreallocCo params = {
+ .bs = bs,
+ .offset = offset,
+ .new_length = new_length,
+ .ret = -EINPROGRESS,
+ };
+
if (qemu_in_coroutine()) {
- qemu_co_mutex_unlock(&s->lock);
+ preallocate_co(¶ms);
+ } else {
+ Coroutine *co = qemu_coroutine_create(preallocate_co, ¶ms);
+ bdrv_coroutine_enter(bs, co);
+ BDRV_POLL_WHILE(bs, params.ret == -EINPROGRESS);
}
- return ret;
+ return params.ret;
}
/* qcow2_refcount_metadata_size:
--
2.13.6
- [Qemu-block] [PULL 21/35] qemu-img: Change img_rebase() to be byte-based, (continued)
- [Qemu-block] [PULL 21/35] qemu-img: Change img_rebase() to be byte-based, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 25/35] qcow2: Reduce is_zero() rounding, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 27/35] qemu-img.1: Image invalidation on qemu-img commit, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 28/35] qcow2: Use BDRV_SECTOR_BITS instead of its literal value, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 26/35] qemu-io: Relax 'alloc' now that block-status doesn't assert, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 30/35] iotests: Pull _filter_actual_image_size from 67/87, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 31/35] iotests: Filter actual image size in 184 and 191, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 29/35] iotests: Add test for dataplane mirroring, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 32/35] qcow2: Emit errp when truncating the image tail, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 33/35] qcow2: Fix unaligned preallocated truncation, Kevin Wolf, 2017/10/26
- [Qemu-block] [PULL 34/35] qcow2: Always execute preallocate() in a coroutine,
Kevin Wolf <=
- [Qemu-block] [PULL 35/35] iotests: Add cluster_size=64k to 125, Kevin Wolf, 2017/10/26
- Re: [Qemu-block] [Qemu-devel] [PULL 00/35] Block layer patches, Peter Maydell, 2017/10/27