mirror of https://github.com/xemu-project/xemu.git
block: Fix AioContext locking in bdrv_insert_node()
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>
This commit is contained in:
parent
8dc8a60c9e
commit
8823407c06
11
block.c
11
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
|
* 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
|
* 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.
|
* 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,
|
BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
|
||||||
int flags, Error **errp)
|
int flags, Error **errp)
|
||||||
{
|
{
|
||||||
ERRP_GUARD();
|
ERRP_GUARD();
|
||||||
int ret;
|
int ret;
|
||||||
|
AioContext *ctx = bdrv_get_aio_context(bs);
|
||||||
BlockDriverState *new_node_bs = NULL;
|
BlockDriverState *new_node_bs = NULL;
|
||||||
const char *drvname, *node_name;
|
const char *drvname, *node_name;
|
||||||
BlockDriver *drv;
|
BlockDriver *drv;
|
||||||
|
@ -5425,8 +5430,14 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
|
||||||
|
|
||||||
GLOBAL_STATE_CODE();
|
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,
|
new_node_bs = bdrv_new_open_driver_opts(drv, node_name, options, flags,
|
||||||
errp);
|
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 */
|
options = NULL; /* bdrv_new_open_driver() eats options */
|
||||||
if (!new_node_bs) {
|
if (!new_node_bs) {
|
||||||
error_prepend(errp, "Could not create node: ");
|
error_prepend(errp, "Could not create node: ");
|
||||||
|
|
Loading…
Reference in New Issue