|
|
9bac43 |
From 98ebc4e55985747726bbcbedecbe06fed8d7ea0a Mon Sep 17 00:00:00 2001
|
|
|
9bac43 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9bac43 |
Date: Mon, 27 Nov 2017 16:19:58 +0100
|
|
|
9bac43 |
Subject: [PATCH 03/21] qcow2: Always execute preallocate() in a coroutine
|
|
|
9bac43 |
|
|
|
9bac43 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9bac43 |
Message-id: <20171127161959.13234-4-mreitz@redhat.com>
|
|
|
9bac43 |
Patchwork-id: 77913
|
|
|
9bac43 |
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH 3/4] qcow2: Always execute preallocate() in a coroutine
|
|
|
9bac43 |
Bugzilla: 1414049
|
|
|
9bac43 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
Some qcow2 functions (at least perform_cow()) expect s->lock to be
|
|
|
9bac43 |
taken. Therefore, if we want to make use of them, we should execute
|
|
|
9bac43 |
preallocate() (as "preallocate_co") in a coroutine so that we can use
|
|
|
9bac43 |
the qemu_co_mutex_* functions.
|
|
|
9bac43 |
|
|
|
9bac43 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9bac43 |
Message-id: 20171009215533.12530-3-mreitz@redhat.com
|
|
|
9bac43 |
Cc: qemu-stable@nongnu.org
|
|
|
9bac43 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9bac43 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
9bac43 |
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9bac43 |
(cherry picked from commit 572b07bea1d1a0f7726fd95c2613c76002a379bc)
|
|
|
9bac43 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
---
|
|
|
9bac43 |
block/qcow2.c | 41 ++++++++++++++++++++++++++++++++++-------
|
|
|
9bac43 |
1 file changed, 34 insertions(+), 7 deletions(-)
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
9bac43 |
index 2cfe706..b26cbbf 100644
|
|
|
9bac43 |
--- a/block/qcow2.c
|
|
|
9bac43 |
+++ b/block/qcow2.c
|
|
|
9bac43 |
@@ -2476,6 +2476,14 @@ static int qcow2_set_up_encryption(BlockDriverState *bs, const char *encryptfmt,
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
|
|
|
9bac43 |
+typedef struct PreallocCo {
|
|
|
9bac43 |
+ BlockDriverState *bs;
|
|
|
9bac43 |
+ uint64_t offset;
|
|
|
9bac43 |
+ uint64_t new_length;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ int ret;
|
|
|
9bac43 |
+} PreallocCo;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
/**
|
|
|
9bac43 |
* Preallocates metadata structures for data clusters between @offset (in the
|
|
|
9bac43 |
* guest disk) and @new_length (which is thus generally the new guest disk
|
|
|
9bac43 |
@@ -2483,9 +2491,12 @@ static int qcow2_set_up_encryption(BlockDriverState *bs, const char *encryptfmt,
|
|
|
9bac43 |
*
|
|
|
9bac43 |
* Returns: 0 on success, -errno on failure.
|
|
|
9bac43 |
*/
|
|
|
9bac43 |
-static int preallocate(BlockDriverState *bs,
|
|
|
9bac43 |
- uint64_t offset, uint64_t new_length)
|
|
|
9bac43 |
+static void coroutine_fn preallocate_co(void *opaque)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
+ PreallocCo *params = opaque;
|
|
|
9bac43 |
+ BlockDriverState *bs = params->bs;
|
|
|
9bac43 |
+ uint64_t offset = params->offset;
|
|
|
9bac43 |
+ uint64_t new_length = params->new_length;
|
|
|
9bac43 |
BDRVQcow2State *s = bs->opaque;
|
|
|
9bac43 |
uint64_t bytes;
|
|
|
9bac43 |
uint64_t host_offset = 0;
|
|
|
9bac43 |
@@ -2493,9 +2504,7 @@ static int preallocate(BlockDriverState *bs,
|
|
|
9bac43 |
int ret;
|
|
|
9bac43 |
QCowL2Meta *meta;
|
|
|
9bac43 |
|
|
|
9bac43 |
- if (qemu_in_coroutine()) {
|
|
|
9bac43 |
- qemu_co_mutex_lock(&s->lock);
|
|
|
9bac43 |
- }
|
|
|
9bac43 |
+ qemu_co_mutex_lock(&s->lock);
|
|
|
9bac43 |
|
|
|
9bac43 |
assert(offset <= new_length);
|
|
|
9bac43 |
bytes = new_length - offset;
|
|
|
9bac43 |
@@ -2549,10 +2558,28 @@ static int preallocate(BlockDriverState *bs,
|
|
|
9bac43 |
ret = 0;
|
|
|
9bac43 |
|
|
|
9bac43 |
done:
|
|
|
9bac43 |
+ qemu_co_mutex_unlock(&s->lock);
|
|
|
9bac43 |
+ params->ret = ret;
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static int preallocate(BlockDriverState *bs,
|
|
|
9bac43 |
+ uint64_t offset, uint64_t new_length)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ PreallocCo params = {
|
|
|
9bac43 |
+ .bs = bs,
|
|
|
9bac43 |
+ .offset = offset,
|
|
|
9bac43 |
+ .new_length = new_length,
|
|
|
9bac43 |
+ .ret = -EINPROGRESS,
|
|
|
9bac43 |
+ };
|
|
|
9bac43 |
+
|
|
|
9bac43 |
if (qemu_in_coroutine()) {
|
|
|
9bac43 |
- qemu_co_mutex_unlock(&s->lock);
|
|
|
9bac43 |
+ preallocate_co(¶ms);
|
|
|
9bac43 |
+ } else {
|
|
|
9bac43 |
+ Coroutine *co = qemu_coroutine_create(preallocate_co, ¶ms);
|
|
|
9bac43 |
+ bdrv_coroutine_enter(bs, co);
|
|
|
9bac43 |
+ BDRV_POLL_WHILE(bs, params.ret == -EINPROGRESS);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
- return ret;
|
|
|
9bac43 |
+ return params.ret;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
/* qcow2_refcount_metadata_size:
|
|
|
9bac43 |
--
|
|
|
9bac43 |
1.8.3.1
|
|
|
9bac43 |
|