[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 30/55] qcow2: Always execute preallocate() in a coro
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 30/55] qcow2: Always execute preallocate() in a coroutine |
Date: |
Wed, 6 Dec 2017 13:16:23 -0600 |
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>
(cherry picked from commit 572b07bea1d1a0f7726fd95c2613c76002a379bc)
Signed-off-by: Michael Roth <address@hidden>
---
block/qcow2.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 10e38074ad..668665ea8d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2476,6 +2476,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
@@ -2483,9 +2491,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;
@@ -2493,9 +2504,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;
@@ -2549,10 +2558,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.11.0
- [Qemu-devel] [PATCH 24/55] memory: Share special empty FlatView, (continued)
- [Qemu-devel] [PATCH 24/55] memory: Share special empty FlatView, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 27/55] memory: fix off-by-one error in memory_region_notify_one(), Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 29/55] qcow2: Fix unaligned preallocated truncation, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 25/55] exec: add page_mask for flatview_do_translate, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 26/55] exec: simplify address_space_get_iotlb_entry, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 02/55] hw/usb/bus: Remove bad object_unparent() from usb_try_create_simple(), Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 32/55] nios2: define tcg_env, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 33/55] io: monitor encoutput buffer size from websocket GSource, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 34/55] ppc: fix setting of compat mode, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 28/55] hw/sd: fix out-of-bounds check for multi block reads, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 30/55] qcow2: Always execute preallocate() in a coroutine,
Michael Roth <=
- [Qemu-devel] [PATCH 31/55] iotests: Add cluster_size=64k to 125, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 36/55] hw/intc/arm_gicv3_its: Don't abort on table save failure, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 40/55] util/stats64: Fix min/max comparisons, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 38/55] net: fix check for number of parameters to -netdev socket, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 37/55] net/socket: fix coverity issue, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 35/55] translate.c: Fix usermode big-endian AArch32 LDREXD and STREXD, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 39/55] nbd/client: Use error_prepend() correctly, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 03/55] block/mirror: check backing in bdrv_mirror_top_flush, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 41/55] virtio: Add queue interface to restore avail index from vring used index, Michael Roth, 2017/12/06
- [Qemu-devel] [PATCH 47/55] virtio-net: don't touch virtqueue if vm is stopped, Michael Roth, 2017/12/06