mirror of https://github.com/xemu-project/xemu.git
block: Fix AioContext locking in bdrv_open_child()
bdrv_attach_child() requires that the caller holds the AioContext lock for the new child node. Take it in bdrv_open_child() and document that the caller must not hold any AioContext apart from the main AioContext. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20230605085711.21261-5-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
2065cf6b23
commit
8394c35ee1
11
block.c
11
block.c
|
@ -3654,6 +3654,7 @@ done:
|
||||||
*
|
*
|
||||||
* The BlockdevRef will be removed from the options QDict.
|
* The BlockdevRef will be removed from the options QDict.
|
||||||
*
|
*
|
||||||
|
* The caller must hold the lock of the main AioContext and no other AioContext.
|
||||||
* @parent can move to a different AioContext in this function. Callers must
|
* @parent can move to a different AioContext in this function. Callers must
|
||||||
* make sure that their AioContext locking is still correct after this.
|
* make sure that their AioContext locking is still correct after this.
|
||||||
*/
|
*/
|
||||||
|
@ -3665,6 +3666,8 @@ BdrvChild *bdrv_open_child(const char *filename,
|
||||||
bool allow_none, Error **errp)
|
bool allow_none, Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
|
BdrvChild *child;
|
||||||
|
AioContext *ctx;
|
||||||
|
|
||||||
GLOBAL_STATE_CODE();
|
GLOBAL_STATE_CODE();
|
||||||
|
|
||||||
|
@ -3674,13 +3677,19 @@ BdrvChild *bdrv_open_child(const char *filename,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
|
ctx = bdrv_get_aio_context(bs);
|
||||||
|
aio_context_acquire(ctx);
|
||||||
|
child = bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
|
||||||
errp);
|
errp);
|
||||||
|
aio_context_release(ctx);
|
||||||
|
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrapper on bdrv_open_child() for most popular case: open primary child of bs.
|
* Wrapper on bdrv_open_child() for most popular case: open primary child of bs.
|
||||||
*
|
*
|
||||||
|
* The caller must hold the lock of the main AioContext and no other AioContext.
|
||||||
* @parent can move to a different AioContext in this function. Callers must
|
* @parent can move to a different AioContext in this function. Callers must
|
||||||
* make sure that their AioContext locking is still correct after this.
|
* make sure that their AioContext locking is still correct after this.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue