[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 15/22] qcow2: Mark qcow2_inactivate() and callers GRAPH_RDLOCK
From: |
Kevin Wolf |
Subject: |
[PATCH 15/22] qcow2: Mark qcow2_inactivate() and callers GRAPH_RDLOCK |
Date: |
Fri, 29 Sep 2023 16:51:50 +0200 |
This adds GRAPH_RDLOCK annotations to declare that callers of
qcow2_inactivate() need to hold a reader lock for the graph because it
calls bdrv_get_device_or_node_name(), which accesses the parents list of
a node.
qcow2_do_close() is a bit strange because it is called from different
contexts. If close_data_file = true, we know that we were called from
non-coroutine main loop context (more specifically, we're coming from
qcow2_close()) and can safely drop the reader lock temporarily with
bdrv_graph_rdunlock_main_loop() and acquire the writer lock.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/qcow2.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 1c01de95af..490b763f57 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2737,14 +2737,12 @@ fail_nometa:
return ret;
}
-static int qcow2_inactivate(BlockDriverState *bs)
+static int GRAPH_RDLOCK qcow2_inactivate(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
int ret, result = 0;
Error *local_err = NULL;
- assume_graph_lock(); /* FIXME */
-
qcow2_store_persistent_dirty_bitmaps(bs, true, &local_err);
if (local_err != NULL) {
result = -EINVAL;
@@ -2774,7 +2772,8 @@ static int qcow2_inactivate(BlockDriverState *bs)
return result;
}
-static void qcow2_do_close(BlockDriverState *bs, bool close_data_file)
+static void coroutine_mixed_fn GRAPH_RDLOCK
+qcow2_do_close(BlockDriverState *bs, bool close_data_file)
{
BDRVQcow2State *s = bs->opaque;
qemu_vfree(s->l1_table);
@@ -2801,18 +2800,24 @@ static void qcow2_do_close(BlockDriverState *bs, bool
close_data_file)
g_free(s->image_backing_format);
if (close_data_file && has_data_file(bs)) {
+ GLOBAL_STATE_CODE();
+ bdrv_graph_rdunlock_main_loop();
bdrv_graph_wrlock(NULL);
bdrv_unref_child(bs, s->data_file);
bdrv_graph_wrunlock();
s->data_file = NULL;
+ bdrv_graph_rdlock_main_loop();
}
qcow2_refcount_close(bs);
qcow2_free_snapshots(bs);
}
-static void qcow2_close(BlockDriverState *bs)
+static void GRAPH_UNLOCKED qcow2_close(BlockDriverState *bs)
{
+ GLOBAL_STATE_CODE();
+ GRAPH_RDLOCK_GUARD_MAINLOOP();
+
qcow2_do_close(bs, true);
}
--
2.41.0
- [PATCH 01/22] test-bdrv-drain: Don't call bdrv_graph_wrlock() in coroutine context, (continued)
- [PATCH 01/22] test-bdrv-drain: Don't call bdrv_graph_wrlock() in coroutine context, Kevin Wolf, 2023/09/29
- [PATCH 05/22] block: Mark drain related functions GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 04/22] block: Mark bdrv_first_blk() and bdrv_is_root_node() GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 07/22] block: Mark bdrv_snapshot_fallback() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 06/22] block: Mark bdrv_parent_cb_resize() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 08/22] block: Take graph rdlock in parts of reopen, Kevin Wolf, 2023/09/29
- [PATCH 09/22] block: Mark bdrv_get_xdbg_block_graph() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 10/22] block: Mark bdrv_refresh_filename() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 12/22] block: Mark bdrv_get_parent_name() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 13/22] block: Mark bdrv_amend_options() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 15/22] qcow2: Mark qcow2_inactivate() and callers GRAPH_RDLOCK,
Kevin Wolf <=
- [PATCH 14/22] qcow2: Mark qcow2_signal_corruption() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 17/22] block: Mark bdrv_op_is_blocked() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 16/22] qcow2: Mark check_constraints_on_bitmap() GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 11/22] block: Mark bdrv_primary_child() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 18/22] block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 21/22] block: Protect bs->children with graph_lock, Kevin Wolf, 2023/09/29
- [PATCH 19/22] block: Mark bdrv_get_specific_info() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/29
- [PATCH 20/22] block: Protect bs->parents with graph_lock, Kevin Wolf, 2023/09/29
- [PATCH 22/22] block: Add assertion for bdrv_graph_wrlock(), Kevin Wolf, 2023/09/29