mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
block: Mark bdrv_add/del_child() and caller GRAPH_WRLOCK
The functions read the parents list in the generic block layer, so we need to hold the graph lock already there. The BlockDriver implementations actually modify the graph, so it has to be a writer lock. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-ID: <20230911094620.45040-22-kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
32a8aba37e
commit
9def6082cf
4 changed files with 27 additions and 30 deletions
17
blockdev.c
17
blockdev.c
|
@ -3545,8 +3545,8 @@ out:
|
|||
aio_context_release(aio_context);
|
||||
}
|
||||
|
||||
static BdrvChild *bdrv_find_child(BlockDriverState *parent_bs,
|
||||
const char *child_name)
|
||||
static BdrvChild * GRAPH_RDLOCK
|
||||
bdrv_find_child(BlockDriverState *parent_bs, const char *child_name)
|
||||
{
|
||||
BdrvChild *child;
|
||||
|
||||
|
@ -3565,9 +3565,11 @@ void qmp_x_blockdev_change(const char *parent, const char *child,
|
|||
BlockDriverState *parent_bs, *new_bs = NULL;
|
||||
BdrvChild *p_child;
|
||||
|
||||
bdrv_graph_wrlock(NULL);
|
||||
|
||||
parent_bs = bdrv_lookup_bs(parent, parent, errp);
|
||||
if (!parent_bs) {
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!child == !node) {
|
||||
|
@ -3576,7 +3578,7 @@ void qmp_x_blockdev_change(const char *parent, const char *child,
|
|||
} else {
|
||||
error_setg(errp, "Either child or node must be specified");
|
||||
}
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (child) {
|
||||
|
@ -3584,7 +3586,7 @@ void qmp_x_blockdev_change(const char *parent, const char *child,
|
|||
if (!p_child) {
|
||||
error_setg(errp, "Node '%s' does not have child '%s'",
|
||||
parent, child);
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
bdrv_del_child(parent_bs, p_child, errp);
|
||||
}
|
||||
|
@ -3593,10 +3595,13 @@ void qmp_x_blockdev_change(const char *parent, const char *child,
|
|||
new_bs = bdrv_find_node(node);
|
||||
if (!new_bs) {
|
||||
error_setg(errp, "Node '%s' not found", node);
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
bdrv_add_child(parent_bs, new_bs, errp);
|
||||
}
|
||||
|
||||
out:
|
||||
bdrv_graph_wrunlock();
|
||||
}
|
||||
|
||||
BlockJobInfoList *qmp_query_block_jobs(Error **errp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue