block: Mark bdrv_primary_child() and callers GRAPH_RDLOCK
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_primary_child() need to hold a reader lock for the graph because it accesses the children list of a node. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20230929145157.45443-12-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
b7cfc7d58e
commit
c0fc5123ad
11
block.c
11
block.c
@ -6692,7 +6692,8 @@ void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent event)
|
|||||||
bs->drv->bdrv_co_debug_event(bs, event);
|
bs->drv->bdrv_co_debug_event(bs, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockDriverState *bdrv_find_debug_node(BlockDriverState *bs)
|
static BlockDriverState * GRAPH_RDLOCK
|
||||||
|
bdrv_find_debug_node(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
GLOBAL_STATE_CODE();
|
GLOBAL_STATE_CODE();
|
||||||
while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) {
|
while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) {
|
||||||
@ -6711,6 +6712,8 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
|
|||||||
const char *tag)
|
const char *tag)
|
||||||
{
|
{
|
||||||
GLOBAL_STATE_CODE();
|
GLOBAL_STATE_CODE();
|
||||||
|
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||||
|
|
||||||
bs = bdrv_find_debug_node(bs);
|
bs = bdrv_find_debug_node(bs);
|
||||||
if (bs) {
|
if (bs) {
|
||||||
return bs->drv->bdrv_debug_breakpoint(bs, event, tag);
|
return bs->drv->bdrv_debug_breakpoint(bs, event, tag);
|
||||||
@ -6722,6 +6725,8 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
|
|||||||
int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag)
|
int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag)
|
||||||
{
|
{
|
||||||
GLOBAL_STATE_CODE();
|
GLOBAL_STATE_CODE();
|
||||||
|
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||||
|
|
||||||
bs = bdrv_find_debug_node(bs);
|
bs = bdrv_find_debug_node(bs);
|
||||||
if (bs) {
|
if (bs) {
|
||||||
return bs->drv->bdrv_debug_remove_breakpoint(bs, tag);
|
return bs->drv->bdrv_debug_remove_breakpoint(bs, tag);
|
||||||
@ -6733,6 +6738,8 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag)
|
|||||||
int bdrv_debug_resume(BlockDriverState *bs, const char *tag)
|
int bdrv_debug_resume(BlockDriverState *bs, const char *tag)
|
||||||
{
|
{
|
||||||
GLOBAL_STATE_CODE();
|
GLOBAL_STATE_CODE();
|
||||||
|
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||||
|
|
||||||
while (bs && (!bs->drv || !bs->drv->bdrv_debug_resume)) {
|
while (bs && (!bs->drv || !bs->drv->bdrv_debug_resume)) {
|
||||||
bs = bdrv_primary_bs(bs);
|
bs = bdrv_primary_bs(bs);
|
||||||
}
|
}
|
||||||
@ -6747,6 +6754,8 @@ int bdrv_debug_resume(BlockDriverState *bs, const char *tag)
|
|||||||
bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
||||||
{
|
{
|
||||||
GLOBAL_STATE_CODE();
|
GLOBAL_STATE_CODE();
|
||||||
|
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||||
|
|
||||||
while (bs && bs->drv && !bs->drv->bdrv_debug_is_suspended) {
|
while (bs && bs->drv && !bs->drv->bdrv_debug_is_suspended) {
|
||||||
bs = bdrv_primary_bs(bs);
|
bs = bdrv_primary_bs(bs);
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,10 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
|
|||||||
* respective option (with the qdict_put_str() call above).
|
* respective option (with the qdict_put_str() call above).
|
||||||
* Assert that .bdrv_open() has attached the right BDS as primary child.
|
* Assert that .bdrv_open() has attached the right BDS as primary child.
|
||||||
*/
|
*/
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
assert(bdrv_primary_bs(bs) == fallback_bs);
|
assert(bdrv_primary_bs(bs) == fallback_bs);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
|
|
||||||
bdrv_unref(fallback_bs);
|
bdrv_unref(fallback_bs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
|
|||||||
BdrvChild *bdrv_cow_child(BlockDriverState *bs);
|
BdrvChild *bdrv_cow_child(BlockDriverState *bs);
|
||||||
BdrvChild *bdrv_filter_child(BlockDriverState *bs);
|
BdrvChild *bdrv_filter_child(BlockDriverState *bs);
|
||||||
BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs);
|
BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs);
|
||||||
BdrvChild *bdrv_primary_child(BlockDriverState *bs);
|
BdrvChild * GRAPH_RDLOCK bdrv_primary_child(BlockDriverState *bs);
|
||||||
BlockDriverState *bdrv_skip_filters(BlockDriverState *bs);
|
BlockDriverState *bdrv_skip_filters(BlockDriverState *bs);
|
||||||
BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs);
|
BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs);
|
||||||
|
|
||||||
@ -155,7 +155,8 @@ static inline BlockDriverState *bdrv_filter_or_cow_bs(BlockDriverState *bs)
|
|||||||
return child_bs(bdrv_filter_or_cow_child(bs));
|
return child_bs(bdrv_filter_or_cow_child(bs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BlockDriverState *bdrv_primary_bs(BlockDriverState *bs)
|
static inline BlockDriverState * GRAPH_RDLOCK
|
||||||
|
bdrv_primary_bs(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
IO_CODE();
|
IO_CODE();
|
||||||
return child_bs(bdrv_primary_child(bs));
|
return child_bs(bdrv_primary_child(bs));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user