[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] block: Fix locking in media change monitor commands
From: |
Kevin Wolf |
Subject: |
[PATCH 1/2] block: Fix locking in media change monitor commands |
Date: |
Fri, 13 Oct 2023 17:33:01 +0200 |
blk_insert_bs() requires that the caller holds the AioContext lock for
the node to be inserted. Since commit c066e808e11, neglecting to do so
causes a crash when the child has to be moved to a different AioContext
to attach it to the BlockBackend.
This fixes qmp_blockdev_insert_anon_medium(), which is called for the
QMP commands 'blockdev-insert-medium' and 'blockdev-change-medium', to
correctly take the lock.
Cc: qemu-stable@nongnu.org
Fixes: https://issues.redhat.com/browse/RHEL-3922
Fixes: c066e808e11a5c181b625537b6c78e0de27a4801
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/qapi-sysemu.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
index 3f614cbc04..1618cd225a 100644
--- a/block/qapi-sysemu.c
+++ b/block/qapi-sysemu.c
@@ -237,6 +237,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend
*blk,
BlockDriverState *bs, Error **errp)
{
Error *local_err = NULL;
+ AioContext *ctx;
bool has_device;
int ret;
@@ -258,7 +259,11 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend
*blk,
return;
}
+ ctx = bdrv_get_aio_context(bs);
+ aio_context_acquire(ctx);
ret = blk_insert_bs(blk, bs, errp);
+ aio_context_release(ctx);
+
if (ret < 0) {
return;
}
--
2.41.0