[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/32] copy-before-write: Fix open with child in iothread
|
From: |
Kevin Wolf |
|
Subject: |
[PULL 08/32] copy-before-write: Fix open with child in iothread |
|
Date: |
Tue, 30 May 2023 18:32:15 +0200 |
The AioContext lock must not be held for bdrv_open_child(), but it is
necessary for the following operations, in particular those using nested
event loops in coroutine wrappers.
Temporarily dropping the main AioContext lock is not necessary because
we know we run in the main thread.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230525124713.401149-9-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/copy-before-write.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 646d8227a4..b866e42271 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -412,6 +412,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
int64_t cluster_size;
g_autoptr(BlockdevOptions) full_opts = NULL;
BlockdevOptionsCbw *opts;
+ AioContext *ctx;
int ret;
full_opts = cbw_parse_options(options, errp);
@@ -432,11 +433,15 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
return -EINVAL;
}
+ ctx = bdrv_get_aio_context(bs);
+ aio_context_acquire(ctx);
+
if (opts->bitmap) {
bitmap = block_dirty_bitmap_lookup(opts->bitmap->node,
opts->bitmap->name, NULL, errp);
if (!bitmap) {
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
}
s->on_cbw_error = opts->has_on_cbw_error ? opts->on_cbw_error :
@@ -454,21 +459,24 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
s->bcs = block_copy_state_new(bs->file, s->target, bitmap, errp);
if (!s->bcs) {
error_prepend(errp, "Cannot create block-copy-state: ");
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
cluster_size = block_copy_cluster_size(s->bcs);
s->done_bitmap = bdrv_create_dirty_bitmap(bs, cluster_size, NULL, errp);
if (!s->done_bitmap) {
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
bdrv_disable_dirty_bitmap(s->done_bitmap);
/* s->access_bitmap starts equal to bcs bitmap */
s->access_bitmap = bdrv_create_dirty_bitmap(bs, cluster_size, NULL, errp);
if (!s->access_bitmap) {
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
bdrv_disable_dirty_bitmap(s->access_bitmap);
bdrv_dirty_bitmap_merge_internal(s->access_bitmap,
@@ -478,7 +486,10 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
qemu_co_mutex_init(&s->lock);
QLIST_INIT(&s->frozen_read_reqs);
- return 0;
+ ret = 0;
+out:
+ aio_context_release(ctx);
+ return ret;
}
static void cbw_close(BlockDriverState *bs)
--
2.40.1
- [PULL 02/32] block: Clarify locking rules for bdrv_open(_inherit)(), (continued)
- [PULL 02/32] block: Clarify locking rules for bdrv_open(_inherit)(), Kevin Wolf, 2023/05/30
- [PULL 13/32] block-backend: split blk_do_set_aio_context(), Kevin Wolf, 2023/05/30
- [PULL 26/32] block/export: don't require AioContext lock around blk_exp_ref/unref(), Kevin Wolf, 2023/05/30
- [PULL 12/32] iotests: Test blockdev-create in iothread, Kevin Wolf, 2023/05/30
- [PULL 31/32] virtio: do not set is_external=true on host notifiers, Kevin Wolf, 2023/05/30
- [PULL 22/32] block: drain from main loop thread in bdrv_co_yield_to_drain(), Kevin Wolf, 2023/05/30
- [PULL 32/32] aio: remove aio_disable_external() API, Kevin Wolf, 2023/05/30
- [PULL 23/32] xen-block: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 27/32] block/fuse: do not set is_external=true on FUSE fd, Kevin Wolf, 2023/05/30
- [PULL 06/32] qcow2: Fix open with 'file' in iothread, Kevin Wolf, 2023/05/30
- [PULL 08/32] copy-before-write: Fix open with child in iothread,
Kevin Wolf <=
- [PULL 14/32] hw/qdev: introduce qdev_is_realized() helper, Kevin Wolf, 2023/05/30
- [PULL 11/32] iotests: Make verify_virtio_scsi_pci_or_ccw() public, Kevin Wolf, 2023/05/30
- [PULL 15/32] virtio-scsi: avoid race between unplug and transport event, Kevin Wolf, 2023/05/30
- [PULL 16/32] virtio-scsi: stop using aio_disable_external() during unplug, Kevin Wolf, 2023/05/30
- [PULL 10/32] block: Fix AioContext locking in bdrv_insert_node(), Kevin Wolf, 2023/05/30
- [PULL 21/32] block: add blk_in_drain() API, Kevin Wolf, 2023/05/30
- [PULL 19/32] block/export: stop using is_external in vhost-user-blk server, Kevin Wolf, 2023/05/30
- [PULL 24/32] hw/xen: do not set is_external=true on evtchn fds, Kevin Wolf, 2023/05/30
- [PULL 25/32] block/export: rewrite vduse-blk drain code, Kevin Wolf, 2023/05/30
- [PULL 17/32] util/vhost-user-server: rename refcount to in_flight counter, Kevin Wolf, 2023/05/30