Skip to content

Commit

Permalink
graph-lock: remove AioContext locking
Browse files Browse the repository at this point in the history
Stop acquiring/releasing the AioContext lock in
bdrv_graph_wrlock()/bdrv_graph_unlock() since the lock no longer has any
effect.

The distinction between bdrv_graph_wrunlock() and
bdrv_graph_wrunlock_ctx() becomes meaningless and they can be collapsed
into one function.

Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
stefanhaRH authored and kevmw committed Dec 21, 2023
1 parent b5f4fda commit 6bc30f1
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 193 deletions.
50 changes: 25 additions & 25 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -1708,12 +1708,12 @@ bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, const char *node_name,
open_failed:
bs->drv = NULL;

bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
if (bs->file != NULL) {
bdrv_unref_child(bs, bs->file);
assert(!bs->file);
}
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();

g_free(bs->opaque);
bs->opaque = NULL;
Expand Down Expand Up @@ -3575,9 +3575,9 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,

bdrv_ref(drain_bs);
bdrv_drained_begin(drain_bs);
bdrv_graph_wrlock(backing_hd);
bdrv_graph_wrlock();
ret = bdrv_set_backing_hd_drained(bs, backing_hd, errp);
bdrv_graph_wrunlock(backing_hd);
bdrv_graph_wrunlock();
bdrv_drained_end(drain_bs);
bdrv_unref(drain_bs);

Expand Down Expand Up @@ -3790,13 +3790,13 @@ BdrvChild *bdrv_open_child(const char *filename,
return NULL;
}

bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
ctx = bdrv_get_aio_context(bs);
aio_context_acquire(ctx);
child = bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
errp);
aio_context_release(ctx);
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();

return child;
}
Expand Down Expand Up @@ -4650,9 +4650,9 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
aio_context_release(ctx);
}

bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
tran_commit(tran);
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();

QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) {
BlockDriverState *bs = bs_entry->state.bs;
Expand All @@ -4669,9 +4669,9 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
goto cleanup;

abort:
bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
tran_abort(tran);
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();

QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
if (bs_entry->prepared) {
Expand Down Expand Up @@ -4852,12 +4852,12 @@ bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
}

bdrv_graph_rdunlock_main_loop();
bdrv_graph_wrlock(new_child_bs);
bdrv_graph_wrlock();

ret = bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing,
tran, errp);

bdrv_graph_wrunlock_ctx(ctx);
bdrv_graph_wrunlock();

if (old_ctx != ctx) {
aio_context_release(ctx);
Expand Down Expand Up @@ -5209,14 +5209,14 @@ static void bdrv_close(BlockDriverState *bs)
bs->drv = NULL;
}

bdrv_graph_wrlock(bs);
bdrv_graph_wrlock();
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
bdrv_unref_child(bs, child);
}

assert(!bs->backing);
assert(!bs->file);
bdrv_graph_wrunlock(bs);
bdrv_graph_wrunlock();

g_free(bs->opaque);
bs->opaque = NULL;
Expand Down Expand Up @@ -5509,9 +5509,9 @@ int bdrv_drop_filter(BlockDriverState *bs, Error **errp)
bdrv_graph_rdunlock_main_loop();

bdrv_drained_begin(child_bs);
bdrv_graph_wrlock(bs);
bdrv_graph_wrlock();
ret = bdrv_replace_node_common(bs, child_bs, true, true, errp);
bdrv_graph_wrunlock(bs);
bdrv_graph_wrunlock();
bdrv_drained_end(child_bs);

return ret;
Expand Down Expand Up @@ -5561,7 +5561,7 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
aio_context_acquire(old_context);
new_context = NULL;

bdrv_graph_wrlock(bs_top);
bdrv_graph_wrlock();

child = bdrv_attach_child_noperm(bs_new, bs_top, "backing",
&child_of_bds, bdrv_backing_role(bs_new),
Expand Down Expand Up @@ -5593,7 +5593,7 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
tran_finalize(tran, ret);

bdrv_refresh_limits(bs_top, NULL, NULL);
bdrv_graph_wrunlock(bs_top);
bdrv_graph_wrunlock();

bdrv_drained_end(bs_top);
bdrv_drained_end(bs_new);
Expand All @@ -5620,7 +5620,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,
bdrv_ref(old_bs);
bdrv_drained_begin(old_bs);
bdrv_drained_begin(new_bs);
bdrv_graph_wrlock(new_bs);
bdrv_graph_wrlock();

bdrv_replace_child_tran(child, new_bs, tran);

Expand All @@ -5631,7 +5631,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,

tran_finalize(tran, ret);

bdrv_graph_wrunlock(new_bs);
bdrv_graph_wrunlock();
bdrv_drained_end(old_bs);
bdrv_drained_end(new_bs);
bdrv_unref(old_bs);
Expand Down Expand Up @@ -5718,9 +5718,9 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
bdrv_ref(bs);
bdrv_drained_begin(bs);
bdrv_drained_begin(new_node_bs);
bdrv_graph_wrlock(new_node_bs);
bdrv_graph_wrlock();
ret = bdrv_replace_node(bs, new_node_bs, errp);
bdrv_graph_wrunlock(new_node_bs);
bdrv_graph_wrunlock();
bdrv_drained_end(new_node_bs);
bdrv_drained_end(bs);
bdrv_unref(bs);
Expand Down Expand Up @@ -5975,7 +5975,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base,

bdrv_ref(top);
bdrv_drained_begin(base);
bdrv_graph_wrlock(base);
bdrv_graph_wrlock();

if (!top->drv || !base->drv) {
goto exit_wrlock;
Expand Down Expand Up @@ -6015,7 +6015,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base,
* That's a FIXME.
*/
bdrv_replace_node_common(top, base, false, false, &local_err);
bdrv_graph_wrunlock(base);
bdrv_graph_wrunlock();

if (local_err) {
error_report_err(local_err);
Expand Down Expand Up @@ -6052,7 +6052,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base,
goto exit;

exit_wrlock:
bdrv_graph_wrunlock(base);
bdrv_graph_wrunlock();
exit:
bdrv_drained_end(base);
bdrv_unref(top);
Expand Down
4 changes: 2 additions & 2 deletions block/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
block_copy_set_speed(bcs, speed);

/* Required permissions are taken by copy-before-write filter target */
bdrv_graph_wrlock(target);
bdrv_graph_wrlock();
block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
&error_abort);
bdrv_graph_wrunlock(target);
bdrv_graph_wrunlock();

return &job->common;

Expand Down
8 changes: 4 additions & 4 deletions block/blklogwrites.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
ret = 0;
fail_log:
if (ret < 0) {
bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
bdrv_unref_child(bs, s->log_file);
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();
s->log_file = NULL;
}
fail:
Expand All @@ -265,10 +265,10 @@ static void blk_log_writes_close(BlockDriverState *bs)
{
BDRVBlkLogWritesState *s = bs->opaque;

bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
bdrv_unref_child(bs, s->log_file);
s->log_file = NULL;
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();
}

static int64_t coroutine_fn GRAPH_RDLOCK
Expand Down
4 changes: 2 additions & 2 deletions block/blkverify.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ static void blkverify_close(BlockDriverState *bs)
{
BDRVBlkverifyState *s = bs->opaque;

bdrv_graph_wrlock(NULL);
bdrv_graph_wrlock();
bdrv_unref_child(bs, s->test_file);
s->test_file = NULL;
bdrv_graph_wrunlock(NULL);
bdrv_graph_wrunlock();
}

static int64_t coroutine_fn GRAPH_RDLOCK
Expand Down
11 changes: 4 additions & 7 deletions block/block-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,6 @@ void blk_remove_bs(BlockBackend *blk)
{
ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
BdrvChild *root;
AioContext *ctx;

GLOBAL_STATE_CODE();

Expand Down Expand Up @@ -919,10 +918,9 @@ void blk_remove_bs(BlockBackend *blk)
root = blk->root;
blk->root = NULL;

ctx = bdrv_get_aio_context(root->bs);
bdrv_graph_wrlock(root->bs);
bdrv_graph_wrlock();
bdrv_root_unref_child(root);
bdrv_graph_wrunlock_ctx(ctx);
bdrv_graph_wrunlock();
}

/*
Expand All @@ -933,16 +931,15 @@ void blk_remove_bs(BlockBackend *blk)
int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp)
{
ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
AioContext *ctx = bdrv_get_aio_context(bs);

GLOBAL_STATE_CODE();
bdrv_ref(bs);
bdrv_graph_wrlock(bs);
bdrv_graph_wrlock();
blk->root = bdrv_root_attach_child(bs, "root", &child_root,
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
blk->perm, blk->shared_perm,
blk, errp);
bdrv_graph_wrunlock_ctx(ctx);
bdrv_graph_wrunlock();
if (blk->root == NULL) {
return -EPERM;
}
Expand Down
16 changes: 8 additions & 8 deletions block/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ static void commit_abort(Job *job)
bdrv_graph_rdunlock_main_loop();

bdrv_drained_begin(commit_top_backing_bs);
bdrv_graph_wrlock(commit_top_backing_bs);
bdrv_graph_wrlock();
bdrv_replace_node(s->commit_top_bs, commit_top_backing_bs, &error_abort);
bdrv_graph_wrunlock(commit_top_backing_bs);
bdrv_graph_wrunlock();
bdrv_drained_end(commit_top_backing_bs);

bdrv_unref(s->commit_top_bs);
Expand Down Expand Up @@ -339,7 +339,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,
* this is the responsibility of the interface (i.e. whoever calls
* commit_start()).
*/
bdrv_graph_wrlock(top);
bdrv_graph_wrlock();
s->base_overlay = bdrv_find_overlay(top, base);
assert(s->base_overlay);

Expand Down Expand Up @@ -370,19 +370,19 @@ void commit_start(const char *job_id, BlockDriverState *bs,
ret = block_job_add_bdrv(&s->common, "intermediate node", iter, 0,
iter_shared_perms, errp);
if (ret < 0) {
bdrv_graph_wrunlock(top);
bdrv_graph_wrunlock();
goto fail;
}
}

if (bdrv_freeze_backing_chain(commit_top_bs, base, errp) < 0) {
bdrv_graph_wrunlock(top);
bdrv_graph_wrunlock();
goto fail;
}
s->chain_frozen = true;

ret = block_job_add_bdrv(&s->common, "base", base, 0, BLK_PERM_ALL, errp);
bdrv_graph_wrunlock(top);
bdrv_graph_wrunlock();

if (ret < 0) {
goto fail;
Expand Down Expand Up @@ -434,9 +434,9 @@ void commit_start(const char *job_id, BlockDriverState *bs,
* otherwise this would fail because of lack of permissions. */
if (commit_top_bs) {
bdrv_drained_begin(top);
bdrv_graph_wrlock(top);
bdrv_graph_wrlock();
bdrv_replace_node(commit_top_bs, top, &error_abort);
bdrv_graph_wrunlock(top);
bdrv_graph_wrunlock();
bdrv_drained_end(top);
}
}
Expand Down
Loading

0 comments on commit 6bc30f1

Please sign in to comment.