block: Protect bs->backing with graph_lock

Almost all functions that access bs->backing already take the graph
lock now. Add locking to the remaining users and finally annotate the
struct field itself as protected by the graph lock.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231027155333.420094-18-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2023-10-27 17:53:26 +02:00
parent ccd6a37947
commit 004915a96a
9 changed files with 70 additions and 27 deletions

View file

@ -218,8 +218,14 @@ static void do_drain_end_unlocked(enum drain_type drain_type, BlockDriverState *
}
}
static void test_drv_cb_common(BlockBackend *blk, enum drain_type drain_type,
bool recursive)
/*
* Locking the block graph would be a bit cumbersome here because this function
* is called both in coroutine and non-coroutine context. We know this is a test
* and nothing else is running, so don't bother with TSA.
*/
static void coroutine_mixed_fn TSA_NO_TSA
test_drv_cb_common(BlockBackend *blk, enum drain_type drain_type,
bool recursive)
{
BlockDriverState *bs = blk_bs(blk);
BlockDriverState *backing = bs->backing->bs;
@ -307,8 +313,14 @@ static void test_drv_cb_co_drain(void)
blk_unref(blk);
}
static void test_quiesce_common(BlockBackend *blk, enum drain_type drain_type,
bool recursive)
/*
* Locking the block graph would be a bit cumbersome here because this function
* is called both in coroutine and non-coroutine context. We know this is a test
* and nothing else is running, so don't bother with TSA.
*/
static void coroutine_mixed_fn TSA_NO_TSA
test_quiesce_common(BlockBackend *blk, enum drain_type drain_type,
bool recursive)
{
BlockDriverState *bs = blk_bs(blk);
BlockDriverState *backing = bs->backing->bs;
@ -1868,6 +1880,8 @@ static void bdrv_replace_test_drain_end(BlockDriverState *bs)
{
BDRVReplaceTestState *s = bs->opaque;
GRAPH_RDLOCK_GUARD_MAINLOOP();
if (!s->setup_completed) {
return;
}

View file

@ -206,15 +206,18 @@ static void test_should_update_child(void)
bdrv_set_backing_hd(target, bs, &error_abort);
g_assert(target->backing->bs == bs);
bdrv_graph_wrlock(NULL);
g_assert(target->backing->bs == bs);
bdrv_attach_child(filter, target, "target", &child_of_bds,
BDRV_CHILD_DATA, &error_abort);
bdrv_graph_wrunlock();
aio_context_acquire(qemu_get_aio_context());
bdrv_append(filter, bs, &error_abort);
aio_context_release(qemu_get_aio_context());
bdrv_graph_rdlock_main_loop();
g_assert(target->backing->bs == bs);
bdrv_graph_rdunlock_main_loop();
bdrv_unref(filter);
bdrv_unref(bs);