[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/28] block: Mark bdrv_root_unref_child() GRAPH_WRLOCK
From: |
Kevin Wolf |
Subject: |
[PULL 19/28] block: Mark bdrv_root_unref_child() GRAPH_WRLOCK |
Date: |
Fri, 15 Sep 2023 16:43:35 +0200 |
Instead of taking the writer lock internally, require callers to already
hold it when calling bdrv_root_unref_child(). These callers will
typically already hold the graph lock once the locking work is
completed, which means that they can't call functions that take it
internally.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20230911094620.45040-20-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block_int-global-state.h | 2 +-
block.c | 6 +++---
block/block-backend.c | 3 +++
blockjob.c | 2 ++
4 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/block/block_int-global-state.h
b/include/block/block_int-global-state.h
index e2304db58b..074b677838 100644
--- a/include/block/block_int-global-state.h
+++ b/include/block/block_int-global-state.h
@@ -202,7 +202,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState
*child_bs,
BdrvChildRole child_role,
uint64_t perm, uint64_t shared_perm,
void *opaque, Error **errp);
-void bdrv_root_unref_child(BdrvChild *child);
+void GRAPH_WRLOCK bdrv_root_unref_child(BdrvChild *child);
void GRAPH_RDLOCK bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t
*perm,
uint64_t *shared_perm);
diff --git a/block.c b/block.c
index 8e589bb2e4..9ea8333a28 100644
--- a/block.c
+++ b/block.c
@@ -3268,7 +3268,6 @@ void bdrv_root_unref_child(BdrvChild *child)
BlockDriverState *child_bs = child->bs;
GLOBAL_STATE_CODE();
- bdrv_graph_wrlock(NULL);
bdrv_replace_child_noperm(child, NULL);
bdrv_child_free(child);
@@ -3288,8 +3287,7 @@ void bdrv_root_unref_child(BdrvChild *child)
NULL);
}
- bdrv_graph_wrunlock();
- bdrv_unref(child_bs);
+ bdrv_schedule_unref(child_bs);
}
typedef struct BdrvSetInheritsFrom {
@@ -3366,8 +3364,10 @@ void bdrv_unref_child(BlockDriverState *parent,
BdrvChild *child)
return;
}
+ bdrv_graph_wrlock(NULL);
bdrv_unset_inherits_from(parent, child, NULL);
bdrv_root_unref_child(child);
+ bdrv_graph_wrunlock();
}
diff --git a/block/block-backend.c b/block/block-backend.c
index 8d0282a5d9..c2636f4351 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -915,7 +915,10 @@ void blk_remove_bs(BlockBackend *blk)
blk_drain(blk);
root = blk->root;
blk->root = NULL;
+
+ bdrv_graph_wrlock(NULL);
bdrv_root_unref_child(root);
+ bdrv_graph_wrunlock();
}
/*
diff --git a/blockjob.c b/blockjob.c
index 25fe8e625d..58c5d64539 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -198,6 +198,7 @@ void block_job_remove_all_bdrv(BlockJob *job)
* one to make sure that such a concurrent access does not attempt
* to process an already freed BdrvChild.
*/
+ bdrv_graph_wrlock(NULL);
while (job->nodes) {
GSList *l = job->nodes;
BdrvChild *c = l->data;
@@ -209,6 +210,7 @@ void block_job_remove_all_bdrv(BlockJob *job)
g_slist_free_1(l);
}
+ bdrv_graph_wrunlock();
}
bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs)
--
2.41.0
- [PULL 04/28] block: Take AioContext lock for bdrv_append() more consistently, (continued)
- [PULL 04/28] block: Take AioContext lock for bdrv_append() more consistently, Kevin Wolf, 2023/09/15
- [PULL 05/28] block: Introduce bdrv_schedule_unref(), Kevin Wolf, 2023/09/15
- [PULL 12/28] block: Mark bdrv_attach_child() GRAPH_WRLOCK, Kevin Wolf, 2023/09/15
- [PULL 08/28] block: Mark bdrv_replace_child_noperm() GRAPH_WRLOCK, Kevin Wolf, 2023/09/15
- [PULL 18/28] block: Take graph rdlock in bdrv_change_aio_context(), Kevin Wolf, 2023/09/15
- [PULL 17/28] block: Take graph rdlock in bdrv_drop_intermediate(), Kevin Wolf, 2023/09/15
- [PULL 16/28] block: Mark bdrv_parent_cb_change_media() GRAPH_RDLOCK, Kevin Wolf, 2023/09/15
- [PULL 22/28] block: add BDRV_BLOCK_COMPRESSED flag for bdrv_block_status(), Kevin Wolf, 2023/09/15
- [PULL 21/28] block: Mark bdrv_add/del_child() and caller GRAPH_WRLOCK, Kevin Wolf, 2023/09/15
- [PULL 23/28] qemu-img: map: report compressed data blocks, Kevin Wolf, 2023/09/15
- [PULL 19/28] block: Mark bdrv_root_unref_child() GRAPH_WRLOCK,
Kevin Wolf <=
- [PULL 20/28] block: Mark bdrv_unref_child() GRAPH_WRLOCK, Kevin Wolf, 2023/09/15
- [PULL 09/28] block: Mark bdrv_replace_child_tran() GRAPH_WRLOCK, Kevin Wolf, 2023/09/15
- [PULL 07/28] block-coroutine-wrapper: Allow arbitrary parameter names, Kevin Wolf, 2023/09/15
- [PULL 11/28] block: Call transaction callbacks with lock held, Kevin Wolf, 2023/09/15
- [PULL 14/28] block: Mark bdrv_get_cumulative_perm() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/15
- [PULL 15/28] block: Mark bdrv_child_perm() GRAPH_RDLOCK, Kevin Wolf, 2023/09/15
- [PULL 13/28] block: Mark bdrv_parent_perms_conflict() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/15
- [PULL 25/28] test-bdrv-drain: avoid race with BH in IOThread drain test, Kevin Wolf, 2023/09/15
- [PULL 26/28] block-backend: process I/O in the current AioContext, Kevin Wolf, 2023/09/15
- [PULL 24/28] block: remove AIOCBInfo->get_aio_context(), Kevin Wolf, 2023/09/15