[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/32] block: Fix AioContext locking in bdrv_insert_node()
From: |
Kevin Wolf |
Subject: |
[PULL 10/32] block: Fix AioContext locking in bdrv_insert_node() |
Date: |
Tue, 30 May 2023 18:32:17 +0200 |
While calling bdrv_new_open_driver_opts(), the main AioContext lock must
be held, not the lock of the AioContext of the block subtree it will be
added to afterwards.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230525124713.401149-11-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/block.c b/block.c
index 29dea3a6a1..ec65fcf732 100644
--- a/block.c
+++ b/block.c
@@ -5399,12 +5399,17 @@ static void bdrv_delete(BlockDriverState *bs)
* empty set of options. The reference to the QDict belongs to the block layer
* after the call (even on failure), so if the caller intends to reuse the
* dictionary, it needs to use qobject_ref() before calling bdrv_open.
+ *
+ * The caller holds the AioContext lock for @bs. It must make sure that @bs
+ * stays in the same AioContext, i.e. @options must not refer to nodes in a
+ * different AioContext.
*/
BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
int flags, Error **errp)
{
ERRP_GUARD();
int ret;
+ AioContext *ctx = bdrv_get_aio_context(bs);
BlockDriverState *new_node_bs = NULL;
const char *drvname, *node_name;
BlockDriver *drv;
@@ -5425,8 +5430,14 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs,
QDict *options,
GLOBAL_STATE_CODE();
+ aio_context_release(ctx);
+ aio_context_acquire(qemu_get_aio_context());
new_node_bs = bdrv_new_open_driver_opts(drv, node_name, options, flags,
errp);
+ aio_context_release(qemu_get_aio_context());
+ aio_context_acquire(ctx);
+ assert(bdrv_get_aio_context(bs) == ctx);
+
options = NULL; /* bdrv_new_open_driver() eats options */
if (!new_node_bs) {
error_prepend(errp, "Could not create node: ");
--
2.40.1
- [PULL 18/32] block/export: wait for vhost-user-blk requests when draining, (continued)
- [PULL 18/32] block/export: wait for vhost-user-blk requests when draining, 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 26/32] block/export: don't require AioContext lock around blk_exp_ref/unref(), 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 30/32] virtio-scsi: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 07/32] raw-format: Fix open with 'file' in iothread, Kevin Wolf, 2023/05/30
- [PULL 11/32] iotests: Make verify_virtio_scsi_pci_or_ccw() public, Kevin Wolf, 2023/05/30
- [PULL 09/32] block: Take AioContext lock in bdrv_open_driver(), Kevin Wolf, 2023/05/30
- [PULL 14/32] hw/qdev: introduce qdev_is_realized() helper, Kevin Wolf, 2023/05/30
- [PULL 12/32] iotests: Test blockdev-create in iothread, Kevin Wolf, 2023/05/30
- [PULL 10/32] block: Fix AioContext locking in bdrv_insert_node(),
Kevin Wolf <=
- [PULL 23/32] xen-block: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 21/32] block: add blk_in_drain() API, Kevin Wolf, 2023/05/30
- [PULL 13/32] block-backend: split blk_do_set_aio_context(), Kevin Wolf, 2023/05/30
- [PULL 20/32] hw/xen: do not use aio_set_fd_handler(is_external=true) in xen_xenstore, Kevin Wolf, 2023/05/30
- [PULL 25/32] block/export: rewrite vduse-blk drain code, 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 28/32] virtio: make it possible to detach host notifier from any thread, Kevin Wolf, 2023/05/30
- [PULL 31/32] virtio: do not set is_external=true on host notifiers, Kevin Wolf, 2023/05/30
- [PULL 29/32] virtio-blk: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 32/32] aio: remove aio_disable_external() API, Kevin Wolf, 2023/05/30