Skip to content

Commit

Permalink
block: Fix locking in media change monitor commands
Browse files Browse the repository at this point in the history
blk_insert_bs() requires that the caller holds the AioContext lock for
the node to be inserted. Since commit c066e80, 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: c066e80
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231013153302.39234-2-kwolf@redhat.com>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed Oct 31, 2023
1 parent 87fe52c commit fed8245
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions block/qapi-sysemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down

0 comments on commit fed8245

Please sign in to comment.