qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [PULL 15/26] block: Mark bdrv_primary_child() and callers GRAPH_RDLOCK
Date: Thu, 12 Oct 2023 18:22:13 +0200	[thread overview]
Message-ID: <20231012162224.240535-16-kwolf@redhat.com> (raw)
In-Reply-To: <20231012162224.240535-1-kwolf@redhat.com>

This adds GRAPH_RDLOCK annotations to declare that callers of
bdrv_primary_child() need to hold a reader lock for the graph
because it accesses the children list of a node.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20230929145157.45443-12-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/block/block_int-io.h |  5 +++--
 block.c                      | 11 ++++++++++-
 block/snapshot.c             |  3 +++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h
index eb0da7232e..2b6004ab93 100644
--- a/include/block/block_int-io.h
+++ b/include/block/block_int-io.h
@@ -133,7 +133,7 @@ bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
 BdrvChild *bdrv_cow_child(BlockDriverState *bs);
 BdrvChild *bdrv_filter_child(BlockDriverState *bs);
 BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs);
-BdrvChild *bdrv_primary_child(BlockDriverState *bs);
+BdrvChild * GRAPH_RDLOCK bdrv_primary_child(BlockDriverState *bs);
 BlockDriverState *bdrv_skip_filters(BlockDriverState *bs);
 BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs);
 
@@ -155,7 +155,8 @@ static inline BlockDriverState *bdrv_filter_or_cow_bs(BlockDriverState *bs)
     return child_bs(bdrv_filter_or_cow_child(bs));
 }
 
-static inline BlockDriverState *bdrv_primary_bs(BlockDriverState *bs)
+static inline BlockDriverState * GRAPH_RDLOCK
+bdrv_primary_bs(BlockDriverState *bs)
 {
     IO_CODE();
     return child_bs(bdrv_primary_child(bs));
diff --git a/block.c b/block.c
index 142e1d5e2b..6ce3e2ad7a 100644
--- a/block.c
+++ b/block.c
@@ -6692,7 +6692,8 @@ void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent event)
     bs->drv->bdrv_co_debug_event(bs, event);
 }
 
-static BlockDriverState *bdrv_find_debug_node(BlockDriverState *bs)
+static BlockDriverState * GRAPH_RDLOCK
+bdrv_find_debug_node(BlockDriverState *bs)
 {
     GLOBAL_STATE_CODE();
     while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) {
@@ -6711,6 +6712,8 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
                           const char *tag)
 {
     GLOBAL_STATE_CODE();
+    GRAPH_RDLOCK_GUARD_MAINLOOP();
+
     bs = bdrv_find_debug_node(bs);
     if (bs) {
         return bs->drv->bdrv_debug_breakpoint(bs, event, tag);
@@ -6722,6 +6725,8 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
 int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag)
 {
     GLOBAL_STATE_CODE();
+    GRAPH_RDLOCK_GUARD_MAINLOOP();
+
     bs = bdrv_find_debug_node(bs);
     if (bs) {
         return bs->drv->bdrv_debug_remove_breakpoint(bs, tag);
@@ -6733,6 +6738,8 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag)
 int bdrv_debug_resume(BlockDriverState *bs, const char *tag)
 {
     GLOBAL_STATE_CODE();
+    GRAPH_RDLOCK_GUARD_MAINLOOP();
+
     while (bs && (!bs->drv || !bs->drv->bdrv_debug_resume)) {
         bs = bdrv_primary_bs(bs);
     }
@@ -6747,6 +6754,8 @@ int bdrv_debug_resume(BlockDriverState *bs, const char *tag)
 bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag)
 {
     GLOBAL_STATE_CODE();
+    GRAPH_RDLOCK_GUARD_MAINLOOP();
+
     while (bs && bs->drv && !bs->drv->bdrv_debug_is_suspended) {
         bs = bdrv_primary_bs(bs);
     }
diff --git a/block/snapshot.c b/block/snapshot.c
index 554065578b..ad2bf6e068 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -311,7 +311,10 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
          * respective option (with the qdict_put_str() call above).
          * Assert that .bdrv_open() has attached the right BDS as primary child.
          */
+        bdrv_graph_rdlock_main_loop();
         assert(bdrv_primary_bs(bs) == fallback_bs);
+        bdrv_graph_rdunlock_main_loop();
+
         bdrv_unref(fallback_bs);
         return ret;
     }
-- 
2.41.0



  parent reply	other threads:[~2023-10-12 16:29 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 16:21 [PULL 00/26] Block layer patches Kevin Wolf
2023-10-12 16:21 ` [PULL 01/26] block: rename the bdrv_co_block_status static function Kevin Wolf
2023-10-12 16:22 ` [PULL 02/26] block: complete public block status API Kevin Wolf
2023-10-12 16:22 ` [PULL 03/26] block: switch to co_wrapper for bdrv_is_allocated_* Kevin Wolf
2023-10-12 16:22 ` [PULL 04/26] block: convert more bdrv_is_allocated* and bdrv_block_status* calls to coroutine versions Kevin Wolf
2023-10-12 16:22 ` [PULL 05/26] test-bdrv-drain: Don't call bdrv_graph_wrlock() in coroutine context Kevin Wolf
2023-10-12 16:22 ` [PULL 06/26] block-coroutine-wrapper: Add no_co_wrapper_bdrv_rdlock functions Kevin Wolf
2023-10-12 16:22 ` [PULL 07/26] block: Take graph rdlock in bdrv_inactivate_all() Kevin Wolf
2023-10-12 16:22 ` [PULL 08/26] block: Mark bdrv_first_blk() and bdrv_is_root_node() GRAPH_RDLOCK Kevin Wolf
2023-10-12 16:22 ` [PULL 09/26] block: Mark drain related functions GRAPH_RDLOCK Kevin Wolf
2023-10-12 16:22 ` [PULL 10/26] block: Mark bdrv_parent_cb_resize() and callers GRAPH_RDLOCK Kevin Wolf
2023-10-12 16:22 ` [PULL 11/26] block: Mark bdrv_snapshot_fallback() " Kevin Wolf
2023-10-12 16:22 ` [PULL 12/26] block: Take graph rdlock in parts of reopen Kevin Wolf
2023-10-12 16:22 ` [PULL 13/26] block: Mark bdrv_get_xdbg_block_graph() and callers GRAPH_RDLOCK Kevin Wolf
2023-10-12 16:22 ` [PULL 14/26] block: Mark bdrv_refresh_filename() " Kevin Wolf
2023-10-12 16:22 ` Kevin Wolf [this message]
2023-10-12 16:22 ` [PULL 16/26] block: Mark bdrv_get_parent_name() " Kevin Wolf
2023-10-12 16:22 ` [PULL 17/26] block: Mark bdrv_amend_options() " Kevin Wolf
2023-10-12 16:22 ` [PULL 18/26] qcow2: Mark qcow2_signal_corruption() " Kevin Wolf
2023-10-12 16:22 ` [PULL 19/26] qcow2: Mark qcow2_inactivate() " Kevin Wolf
2023-10-12 16:22 ` [PULL 20/26] qcow2: Mark check_constraints_on_bitmap() GRAPH_RDLOCK Kevin Wolf
2023-10-12 16:22 ` [PULL 21/26] block: Mark bdrv_op_is_blocked() and callers GRAPH_RDLOCK Kevin Wolf
2023-10-12 16:22 ` [PULL 22/26] block: Mark bdrv_apply_auto_read_only() " Kevin Wolf
2023-10-12 16:22 ` [PULL 23/26] block: Mark bdrv_get_specific_info() " Kevin Wolf
2023-10-12 16:22 ` [PULL 24/26] block: Protect bs->parents with graph_lock Kevin Wolf
2023-10-12 16:22 ` [PULL 25/26] block: Protect bs->children " Kevin Wolf
2023-10-12 16:22 ` [PULL 26/26] block: Add assertion for bdrv_graph_wrlock() Kevin Wolf
2023-10-16 19:20 ` [PULL 00/26] Block layer patches Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231012162224.240535-16-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).