Skip to content

Commit

Permalink
block: Add assertion for bdrv_graph_wrlock()
Browse files Browse the repository at this point in the history
bdrv_graph_wrlock() can't run in a coroutine (because it polls) and
requires holding the BQL. We already have GLOBAL_STATE_CODE() to assert
the latter. Assert the former as well and add a no_coroutine_fn marker.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20230929145157.45443-23-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed Oct 12, 2023
1 parent 680e0cc commit e6e964b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion block/graph-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ static uint32_t reader_count(void)
return rd;
}

void bdrv_graph_wrlock(BlockDriverState *bs)
void no_coroutine_fn bdrv_graph_wrlock(BlockDriverState *bs)
{
AioContext *ctx = NULL;

GLOBAL_STATE_CODE();
assert(!qatomic_read(&has_writer));
assert(!qemu_in_coroutine());

/*
* Release only non-mainloop AioContext. The mainloop often relies on the
Expand Down
3 changes: 2 additions & 1 deletion include/block/graph-lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ void unregister_aiocontext(AioContext *ctx);
* This function polls. Callers must not hold the lock of any AioContext other
* than the current one and the one of @bs.
*/
void bdrv_graph_wrlock(BlockDriverState *bs) TSA_ACQUIRE(graph_lock) TSA_NO_TSA;
void no_coroutine_fn TSA_ACQUIRE(graph_lock) TSA_NO_TSA
bdrv_graph_wrlock(BlockDriverState *bs);

/*
* bdrv_graph_wrunlock:
Expand Down

0 comments on commit e6e964b

Please sign in to comment.