Skip to content

Commit

Permalink
block: Protect bs->parents with graph_lock
Browse files Browse the repository at this point in the history
Almost all functions that access the parent link already take the graph
lock now. Add locking to the remaining user in a test case and finally
annotate the struct field itself as protected by the graph lock.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20230929145157.45443-21-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 3574499 commit b59b466
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/block/block_int-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ struct BdrvChild {
bool quiesced_parent;

QLIST_ENTRY(BdrvChild) next;
QLIST_ENTRY(BdrvChild) next_parent;
QLIST_ENTRY(BdrvChild GRAPH_RDLOCK_PTR) next_parent;
};

/*
Expand Down Expand Up @@ -1180,7 +1180,7 @@ struct BlockDriverState {
BdrvChild *backing;
BdrvChild *file;

QLIST_HEAD(, BdrvChild) parents;
QLIST_HEAD(, BdrvChild GRAPH_RDLOCK_PTR) parents;

QDict *options;
QDict *explicit_options;
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test-block-iothread.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,16 @@ static void test_sync_op(const void *opaque)
BlockDriverState *bs;
BdrvChild *c;

GLOBAL_STATE_CODE();

blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL);
bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
bs->total_sectors = 65536 / BDRV_SECTOR_SIZE;
blk_insert_bs(blk, bs, &error_abort);

bdrv_graph_rdlock_main_loop();
c = QLIST_FIRST(&bs->parents);
bdrv_graph_rdunlock_main_loop();

blk_set_aio_context(blk, ctx, &error_abort);
aio_context_acquire(ctx);
Expand Down

0 comments on commit b59b466

Please sign in to comment.