block: move drain outside of bdrv_root_unref_child()
This is part of resolving the deadlock mentioned in commit "block: move draining out of bdrv_change_aio_context() and mark GRAPH_RDLOCK". bdrv_root_unref_child() is called by: 1. blk_remove_bs(), where a drained section is introduced. 2. bdrv_unref_child(), which runs under the graph lock, so the drain will be moved further up to its callers. 3. block_job_remove_all_bdrv(), where a drained section is introduced. For all callers of bdrv_unref_child() and its generated bdrv_co_unref_child() coroutine variant, a drained section is introduced, they are not explicilty listed here. The caller quorum_del_child() holds the graph lock, so it is not actually allowed to drain. This will be addressed in the next commit. Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Message-ID: <20250530151125.955508-16-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
0414930d3a
commit
b13f546545
11 changed files with 52 additions and 4 deletions
18
block.c
18
block.c
|
|
@ -1721,12 +1721,14 @@ bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, const char *node_name,
|
|||
open_failed:
|
||||
bs->drv = NULL;
|
||||
|
||||
bdrv_drain_all_begin();
|
||||
bdrv_graph_wrlock();
|
||||
if (bs->file != NULL) {
|
||||
bdrv_unref_child(bs, bs->file);
|
||||
assert(!bs->file);
|
||||
}
|
||||
bdrv_graph_wrunlock();
|
||||
bdrv_drain_all_end();
|
||||
|
||||
g_free(bs->opaque);
|
||||
bs->opaque = NULL;
|
||||
|
|
@ -3305,7 +3307,11 @@ out:
|
|||
return ret < 0 ? NULL : child;
|
||||
}
|
||||
|
||||
/* Callers must ensure that child->frozen is false. */
|
||||
/*
|
||||
* Callers must ensure that child->frozen is false.
|
||||
*
|
||||
* All block nodes must be drained.
|
||||
*/
|
||||
void bdrv_root_unref_child(BdrvChild *child)
|
||||
{
|
||||
BlockDriverState *child_bs = child->bs;
|
||||
|
|
@ -3326,10 +3332,8 @@ void bdrv_root_unref_child(BdrvChild *child)
|
|||
* When the parent requiring a non-default AioContext is removed, the
|
||||
* node moves back to the main AioContext
|
||||
*/
|
||||
bdrv_drain_all_begin();
|
||||
bdrv_try_change_aio_context_locked(child_bs, qemu_get_aio_context(),
|
||||
NULL, NULL);
|
||||
bdrv_drain_all_end();
|
||||
}
|
||||
|
||||
bdrv_schedule_unref(child_bs);
|
||||
|
|
@ -3402,7 +3406,11 @@ bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child,
|
|||
}
|
||||
}
|
||||
|
||||
/* Callers must ensure that child->frozen is false. */
|
||||
/*
|
||||
* Callers must ensure that child->frozen is false.
|
||||
*
|
||||
* All block nodes must be drained.
|
||||
*/
|
||||
void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child)
|
||||
{
|
||||
GLOBAL_STATE_CODE();
|
||||
|
|
@ -5172,6 +5180,7 @@ static void bdrv_close(BlockDriverState *bs)
|
|||
bs->drv = NULL;
|
||||
}
|
||||
|
||||
bdrv_drain_all_begin();
|
||||
bdrv_graph_wrlock();
|
||||
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
|
||||
bdrv_unref_child(bs, child);
|
||||
|
|
@ -5180,6 +5189,7 @@ static void bdrv_close(BlockDriverState *bs)
|
|||
assert(!bs->backing);
|
||||
assert(!bs->file);
|
||||
bdrv_graph_wrunlock();
|
||||
bdrv_drain_all_end();
|
||||
|
||||
g_free(bs->opaque);
|
||||
bs->opaque = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue