qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	qemu-devel@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [RFC PATCH 4/6] block.c: add subtree_drains where needed
Date: Mon, 13 Dec 2021 05:40:12 -0500	[thread overview]
Message-ID: <20211213104014.69858-5-eesposit@redhat.com> (raw)
In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com>

Protect bdrv_replace_child_noperm, as it modifies the
graph by adding/removing elements to .children and .parents
list of a bs.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 block.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/block.c b/block.c
index 3c3c90704c..1aa9e51a98 100644
--- a/block.c
+++ b/block.c
@@ -2369,7 +2369,11 @@ static void bdrv_replace_child_abort(void *opaque)
      * So whether new_bs was NULL or not, we cannot pass s->childp here; and in
      * any case, there is no reason to pass it anyway.
      */
+    bdrv_subtree_drained_begin_unlocked(s->child->bs);
+    bdrv_subtree_drained_begin_unlocked(s->old_bs);
     bdrv_replace_child_noperm(&s->child, s->old_bs, true);
+    bdrv_subtree_drained_end_unlocked(s->old_bs);
+    bdrv_subtree_drained_end_unlocked(s->child->bs);
     /*
      * The child was pre-existing, so s->old_bs must be non-NULL, and
      * s->child thus must not have been freed
@@ -2427,13 +2431,20 @@ static void bdrv_replace_child_tran(BdrvChild **childp,
 
     if (new_bs) {
         bdrv_ref(new_bs);
+        bdrv_subtree_drained_begin_unlocked(new_bs);
     }
     /*
      * Pass free_empty_child=false, we will free the child (if
      * necessary) in bdrv_replace_child_commit() (if our
      * @free_empty_child parameter was true).
      */
+    bdrv_subtree_drained_begin_unlocked(s->old_bs);
     bdrv_replace_child_noperm(childp, new_bs, false);
+    bdrv_subtree_drained_end_unlocked(s->old_bs);
+
+    if (new_bs) {
+        bdrv_subtree_drained_end_unlocked(new_bs);
+    }
     /* old_bs reference is transparently moved from *childp to @s */
 }
 
@@ -2951,7 +2962,9 @@ static void bdrv_attach_child_common_abort(void *opaque)
      * need to keep it as an empty shell (after this function, it will
      * not be attached to any parent, and it will not have a .bs).
      */
+    bdrv_subtree_drained_begin_unlocked(bs);
     bdrv_replace_child_noperm(s->child, NULL, false);
+    bdrv_subtree_drained_end_unlocked(bs);
 
     if (bdrv_get_aio_context(bs) != s->old_child_ctx) {
         bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort);
@@ -3051,7 +3064,10 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs,
     }
 
     bdrv_ref(child_bs);
+
+    bdrv_subtree_drained_begin_unlocked(child_bs);
     bdrv_replace_child_noperm(&new_child, child_bs, true);
+    bdrv_subtree_drained_end_unlocked(child_bs);
     /* child_bs was non-NULL, so new_child must not have been freed */
     assert(new_child != NULL);
 
@@ -3114,8 +3130,16 @@ static void bdrv_detach_child(BdrvChild **childp)
     BlockDriverState *old_bs = (*childp)->bs;
 
     assert(qemu_in_main_thread());
+    if (old_bs) {
+        bdrv_subtree_drained_begin(old_bs);
+    }
+
     bdrv_replace_child_noperm(childp, NULL, true);
 
+    if (old_bs) {
+        bdrv_subtree_drained_end(old_bs);
+    }
+
     if (old_bs) {
         /*
          * Update permissions for old node. We're just taking a parent away, so
-- 
2.31.1



  parent reply	other threads:[~2021-12-13 10:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13 10:40 [RFC PATCH 0/6] Removal of Aiocontext lock and usage of subtree drains in aborted transactions Emanuele Giuseppe Esposito
2021-12-13 10:40 ` [RFC PATCH 1/6] tests/unit/test-bdrv-drain.c: graph setup functions can't run in coroutines Emanuele Giuseppe Esposito
2021-12-13 10:40 ` [RFC PATCH 2/6] introduce BDRV_POLL_WHILE_UNLOCKED Emanuele Giuseppe Esposito
2021-12-13 10:40 ` [RFC PATCH 3/6] block/io.c: introduce bdrv_subtree_drained_{begin/end}_unlocked Emanuele Giuseppe Esposito
2021-12-13 10:40 ` Emanuele Giuseppe Esposito [this message]
2021-12-13 10:40 ` [RFC PATCH 5/6] test-bdrv-drain.c: adapt test to the new subtree drains Emanuele Giuseppe Esposito
2021-12-13 10:40 ` [RFC PATCH 6/6] block/io.c: enable assert_bdrv_graph_writable Emanuele Giuseppe Esposito
2021-12-13 14:52 ` [RFC PATCH 0/6] Removal of Aiocontext lock and usage of subtree drains in aborted transactions Stefan Hajnoczi
2021-12-14 18:10   ` Emanuele Giuseppe Esposito
2021-12-15 12:34     ` Hanna Reitz
2021-12-16 10:37       ` Kevin Wolf
2021-12-14 16:47 ` 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=20211213104014.69858-5-eesposit@redhat.com \
    --to=eesposit@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).