7f1c5b
From 0dc7990533cef41e58579ee96315aca1fdc44ea1 Mon Sep 17 00:00:00 2001
7f1c5b
From: Kevin Wolf <kwolf@redhat.com>
7f1c5b
Date: Fri, 18 Nov 2022 18:41:07 +0100
7f1c5b
Subject: [PATCH 25/31] block: Remove ignore_bds_parents parameter from
7f1c5b
 drain_begin/end.
7f1c5b
7f1c5b
RH-Author: Stefano Garzarella <sgarzare@redhat.com>
7f1c5b
RH-MergeRequest: 135: block: Simplify drain to prevent QEMU from crashing during snapshot
7f1c5b
RH-Bugzilla: 2155112
7f1c5b
RH-Acked-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
7f1c5b
RH-Acked-by: Hanna Czenczek <hreitz@redhat.com>
7f1c5b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
RH-Commit: [13/16] 1ed88d975a9569bffeb33ad847874417780ce408 (sgarzarella/qemu-kvm-c-9-s)
7f1c5b
7f1c5b
ignore_bds_parents is now ignored during drain_begin and drain_end, so
7f1c5b
we can just remove it there. It is still a valid optimisation for
7f1c5b
drain_all in bdrv_drained_poll(), so leave it around there.
7f1c5b
7f1c5b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
Message-Id: <20221118174110.55183-13-kwolf@redhat.com>
7f1c5b
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
7f1c5b
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
7f1c5b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
(cherry picked from commit a82a3bd135078d14f1bb4b5e50f51e77d3748270)
7f1c5b
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
7f1c5b
---
7f1c5b
 block.c                  |  2 +-
7f1c5b
 block/io.c               | 58 +++++++++++++++-------------------------
7f1c5b
 include/block/block-io.h |  3 +--
7f1c5b
 3 files changed, 24 insertions(+), 39 deletions(-)
7f1c5b
7f1c5b
diff --git a/block.c b/block.c
7f1c5b
index 5a583e260d..af31a94863 100644
7f1c5b
--- a/block.c
7f1c5b
+++ b/block.c
7f1c5b
@@ -1226,7 +1226,7 @@ static char *bdrv_child_get_parent_desc(BdrvChild *c)
7f1c5b
 static void bdrv_child_cb_drained_begin(BdrvChild *child)
7f1c5b
 {
7f1c5b
     BlockDriverState *bs = child->opaque;
7f1c5b
-    bdrv_do_drained_begin_quiesce(bs, NULL, false);
7f1c5b
+    bdrv_do_drained_begin_quiesce(bs, NULL);
7f1c5b
 }
7f1c5b
 
7f1c5b
 static bool bdrv_child_cb_drained_poll(BdrvChild *child)
7f1c5b
diff --git a/block/io.c b/block/io.c
7f1c5b
index 87d6f22ec4..2e9503df6a 100644
7f1c5b
--- a/block/io.c
7f1c5b
+++ b/block/io.c
7f1c5b
@@ -45,13 +45,12 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs);
7f1c5b
 static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
7f1c5b
     int64_t offset, int64_t bytes, BdrvRequestFlags flags);
7f1c5b
 
7f1c5b
-static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore,
7f1c5b
-                                      bool ignore_bds_parents)
7f1c5b
+static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore)
7f1c5b
 {
7f1c5b
     BdrvChild *c, *next;
7f1c5b
 
7f1c5b
     QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) {
7f1c5b
-        if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {
7f1c5b
+        if (c == ignore) {
7f1c5b
             continue;
7f1c5b
         }
7f1c5b
         bdrv_parent_drained_begin_single(c, false);
7f1c5b
@@ -70,13 +69,12 @@ void bdrv_parent_drained_end_single(BdrvChild *c)
7f1c5b
     }
7f1c5b
 }
7f1c5b
 
7f1c5b
-static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,
7f1c5b
-                                    bool ignore_bds_parents)
7f1c5b
+static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore)
7f1c5b
 {
7f1c5b
     BdrvChild *c;
7f1c5b
 
7f1c5b
     QLIST_FOREACH(c, &bs->parents, next_parent) {
7f1c5b
-        if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {
7f1c5b
+        if (c == ignore) {
7f1c5b
             continue;
7f1c5b
         }
7f1c5b
         bdrv_parent_drained_end_single(c);
7f1c5b
@@ -242,7 +240,6 @@ typedef struct {
7f1c5b
     bool begin;
7f1c5b
     bool poll;
7f1c5b
     BdrvChild *parent;
7f1c5b
-    bool ignore_bds_parents;
7f1c5b
 } BdrvCoDrainData;
7f1c5b
 
7f1c5b
 /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() */
7f1c5b
@@ -269,9 +266,8 @@ static bool bdrv_drain_poll_top_level(BlockDriverState *bs,
7f1c5b
 }
7f1c5b
 
7f1c5b
 static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
-                                  bool ignore_bds_parents, bool poll);
7f1c5b
-static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
-                                bool ignore_bds_parents);
7f1c5b
+                                  bool poll);
7f1c5b
+static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent);
7f1c5b
 
7f1c5b
 static void bdrv_co_drain_bh_cb(void *opaque)
7f1c5b
 {
7f1c5b
@@ -284,11 +280,10 @@ static void bdrv_co_drain_bh_cb(void *opaque)
7f1c5b
         aio_context_acquire(ctx);
7f1c5b
         bdrv_dec_in_flight(bs);
7f1c5b
         if (data->begin) {
7f1c5b
-            bdrv_do_drained_begin(bs, data->parent, data->ignore_bds_parents,
7f1c5b
-                                  data->poll);
7f1c5b
+            bdrv_do_drained_begin(bs, data->parent, data->poll);
7f1c5b
         } else {
7f1c5b
             assert(!data->poll);
7f1c5b
-            bdrv_do_drained_end(bs, data->parent, data->ignore_bds_parents);
7f1c5b
+            bdrv_do_drained_end(bs, data->parent);
7f1c5b
         }
7f1c5b
         aio_context_release(ctx);
7f1c5b
     } else {
7f1c5b
@@ -303,7 +298,6 @@ static void bdrv_co_drain_bh_cb(void *opaque)
7f1c5b
 static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
7f1c5b
                                                 bool begin,
7f1c5b
                                                 BdrvChild *parent,
7f1c5b
-                                                bool ignore_bds_parents,
7f1c5b
                                                 bool poll)
7f1c5b
 {
7f1c5b
     BdrvCoDrainData data;
7f1c5b
@@ -321,7 +315,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
7f1c5b
         .done = false,
7f1c5b
         .begin = begin,
7f1c5b
         .parent = parent,
7f1c5b
-        .ignore_bds_parents = ignore_bds_parents,
7f1c5b
         .poll = poll,
7f1c5b
     };
7f1c5b
 
7f1c5b
@@ -353,8 +346,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
7f1c5b
     }
7f1c5b
 }
7f1c5b
 
7f1c5b
-void bdrv_do_drained_begin_quiesce(BlockDriverState *bs,
7f1c5b
-                                   BdrvChild *parent, bool ignore_bds_parents)
7f1c5b
+void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent)
7f1c5b
 {
7f1c5b
     IO_OR_GS_CODE();
7f1c5b
     assert(!qemu_in_coroutine());
7f1c5b
@@ -362,9 +354,7 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs,
7f1c5b
     /* Stop things in parent-to-child order */
7f1c5b
     if (qatomic_fetch_inc(&bs->quiesce_counter) == 0) {
7f1c5b
         aio_disable_external(bdrv_get_aio_context(bs));
7f1c5b
-
7f1c5b
-        /* TODO Remove ignore_bds_parents, we don't consider it any more */
7f1c5b
-        bdrv_parent_drained_begin(bs, parent, false);
7f1c5b
+        bdrv_parent_drained_begin(bs, parent);
7f1c5b
         if (bs->drv && bs->drv->bdrv_drain_begin) {
7f1c5b
             bs->drv->bdrv_drain_begin(bs);
7f1c5b
         }
7f1c5b
@@ -372,14 +362,14 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs,
7f1c5b
 }
7f1c5b
 
7f1c5b
 static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
-                                  bool ignore_bds_parents, bool poll)
7f1c5b
+                                  bool poll)
7f1c5b
 {
7f1c5b
     if (qemu_in_coroutine()) {
7f1c5b
-        bdrv_co_yield_to_drain(bs, true, parent, ignore_bds_parents, poll);
7f1c5b
+        bdrv_co_yield_to_drain(bs, true, parent, poll);
7f1c5b
         return;
7f1c5b
     }
7f1c5b
 
7f1c5b
-    bdrv_do_drained_begin_quiesce(bs, parent, ignore_bds_parents);
7f1c5b
+    bdrv_do_drained_begin_quiesce(bs, parent);
7f1c5b
 
7f1c5b
     /*
7f1c5b
      * Wait for drained requests to finish.
7f1c5b
@@ -391,7 +381,6 @@ static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
      * nodes.
7f1c5b
      */
7f1c5b
     if (poll) {
7f1c5b
-        assert(!ignore_bds_parents);
7f1c5b
         BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, parent));
7f1c5b
     }
7f1c5b
 }
7f1c5b
@@ -399,20 +388,19 @@ static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
 void bdrv_drained_begin(BlockDriverState *bs)
7f1c5b
 {
7f1c5b
     IO_OR_GS_CODE();
7f1c5b
-    bdrv_do_drained_begin(bs, NULL, false, true);
7f1c5b
+    bdrv_do_drained_begin(bs, NULL, true);
7f1c5b
 }
7f1c5b
 
7f1c5b
 /**
7f1c5b
  * This function does not poll, nor must any of its recursively called
7f1c5b
  * functions.
7f1c5b
  */
7f1c5b
-static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
-                                bool ignore_bds_parents)
7f1c5b
+static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent)
7f1c5b
 {
7f1c5b
     int old_quiesce_counter;
7f1c5b
 
7f1c5b
     if (qemu_in_coroutine()) {
7f1c5b
-        bdrv_co_yield_to_drain(bs, false, parent, ignore_bds_parents, false);
7f1c5b
+        bdrv_co_yield_to_drain(bs, false, parent, false);
7f1c5b
         return;
7f1c5b
     }
7f1c5b
     assert(bs->quiesce_counter > 0);
7f1c5b
@@ -423,9 +411,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
         if (bs->drv && bs->drv->bdrv_drain_end) {
7f1c5b
             bs->drv->bdrv_drain_end(bs);
7f1c5b
         }
7f1c5b
-        /* TODO Remove ignore_bds_parents, we don't consider it any more */
7f1c5b
-        bdrv_parent_drained_end(bs, parent, false);
7f1c5b
-
7f1c5b
+        bdrv_parent_drained_end(bs, parent);
7f1c5b
         aio_enable_external(bdrv_get_aio_context(bs));
7f1c5b
     }
7f1c5b
 }
7f1c5b
@@ -433,7 +419,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent,
7f1c5b
 void bdrv_drained_end(BlockDriverState *bs)
7f1c5b
 {
7f1c5b
     IO_OR_GS_CODE();
7f1c5b
-    bdrv_do_drained_end(bs, NULL, false);
7f1c5b
+    bdrv_do_drained_end(bs, NULL);
7f1c5b
 }
7f1c5b
 
7f1c5b
 void bdrv_drain(BlockDriverState *bs)
7f1c5b
@@ -491,7 +477,7 @@ void bdrv_drain_all_begin(void)
7f1c5b
     GLOBAL_STATE_CODE();
7f1c5b
 
7f1c5b
     if (qemu_in_coroutine()) {
7f1c5b
-        bdrv_co_yield_to_drain(NULL, true, NULL, true, true);
7f1c5b
+        bdrv_co_yield_to_drain(NULL, true, NULL, true);
7f1c5b
         return;
7f1c5b
     }
7f1c5b
 
7f1c5b
@@ -516,7 +502,7 @@ void bdrv_drain_all_begin(void)
7f1c5b
         AioContext *aio_context = bdrv_get_aio_context(bs);
7f1c5b
 
7f1c5b
         aio_context_acquire(aio_context);
7f1c5b
-        bdrv_do_drained_begin(bs, NULL, true, false);
7f1c5b
+        bdrv_do_drained_begin(bs, NULL, false);
7f1c5b
         aio_context_release(aio_context);
7f1c5b
     }
7f1c5b
 
7f1c5b
@@ -536,7 +522,7 @@ void bdrv_drain_all_end_quiesce(BlockDriverState *bs)
7f1c5b
     g_assert(!bs->refcnt);
7f1c5b
 
7f1c5b
     while (bs->quiesce_counter) {
7f1c5b
-        bdrv_do_drained_end(bs, NULL, true);
7f1c5b
+        bdrv_do_drained_end(bs, NULL);
7f1c5b
     }
7f1c5b
 }
7f1c5b
 
7f1c5b
@@ -558,7 +544,7 @@ void bdrv_drain_all_end(void)
7f1c5b
         AioContext *aio_context = bdrv_get_aio_context(bs);
7f1c5b
 
7f1c5b
         aio_context_acquire(aio_context);
7f1c5b
-        bdrv_do_drained_end(bs, NULL, true);
7f1c5b
+        bdrv_do_drained_end(bs, NULL);
7f1c5b
         aio_context_release(aio_context);
7f1c5b
     }
7f1c5b
 
7f1c5b
diff --git a/include/block/block-io.h b/include/block/block-io.h
7f1c5b
index 9c36a16a1f..8f5e75756a 100644
7f1c5b
--- a/include/block/block-io.h
7f1c5b
+++ b/include/block/block-io.h
7f1c5b
@@ -329,8 +329,7 @@ void bdrv_drained_begin(BlockDriverState *bs);
7f1c5b
  * Quiesces a BDS like bdrv_drained_begin(), but does not wait for already
7f1c5b
  * running requests to complete.
7f1c5b
  */
7f1c5b
-void bdrv_do_drained_begin_quiesce(BlockDriverState *bs,
7f1c5b
-                                   BdrvChild *parent, bool ignore_bds_parents);
7f1c5b
+void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent);
7f1c5b
 
7f1c5b
 /**
7f1c5b
  * bdrv_drained_end:
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b