7f1c5b
From 1808e560396872173f787f8e338e9837a4c3d626 Mon Sep 17 00:00:00 2001
7f1c5b
From: Kevin Wolf <kwolf@redhat.com>
7f1c5b
Date: Fri, 18 Nov 2022 18:41:00 +0100
7f1c5b
Subject: [PATCH 18/31] block: Inline bdrv_drain_invoke()
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: [6/16] 2c7473a36360eb43d94b967deb12308cb5ea0d3b (sgarzarella/qemu-kvm-c-9-s)
7f1c5b
7f1c5b
bdrv_drain_invoke() has now two entirely separate cases that share no
7f1c5b
code any more and are selected depending on a bool parameter. Each case
7f1c5b
has only one caller. Just inline the function.
7f1c5b
7f1c5b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
7f1c5b
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7f1c5b
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
7f1c5b
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
7f1c5b
Message-Id: <20221118174110.55183-6-kwolf@redhat.com>
7f1c5b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
(cherry picked from commit c7bc05f78ab31fb02fc9635f60b9bd22efc8d121)
7f1c5b
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
7f1c5b
---
7f1c5b
 block/io.c | 23 ++++++-----------------
7f1c5b
 1 file changed, 6 insertions(+), 17 deletions(-)
7f1c5b
7f1c5b
diff --git a/block/io.c b/block/io.c
7f1c5b
index f4ca62b034..a25103be6f 100644
7f1c5b
--- a/block/io.c
7f1c5b
+++ b/block/io.c
7f1c5b
@@ -242,21 +242,6 @@ typedef struct {
7f1c5b
     bool ignore_bds_parents;
7f1c5b
 } BdrvCoDrainData;
7f1c5b
 
7f1c5b
-/* Recursively call BlockDriver.bdrv_drain_begin/end callbacks */
7f1c5b
-static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
7f1c5b
-{
7f1c5b
-    if (!bs->drv || (begin && !bs->drv->bdrv_drain_begin) ||
7f1c5b
-            (!begin && !bs->drv->bdrv_drain_end)) {
7f1c5b
-        return;
7f1c5b
-    }
7f1c5b
-
7f1c5b
-    if (begin) {
7f1c5b
-        bs->drv->bdrv_drain_begin(bs);
7f1c5b
-    } else {
7f1c5b
-        bs->drv->bdrv_drain_end(bs);
7f1c5b
-    }
7f1c5b
-}
7f1c5b
-
7f1c5b
 /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() */
7f1c5b
 bool bdrv_drain_poll(BlockDriverState *bs, bool recursive,
7f1c5b
                      BdrvChild *ignore_parent, bool ignore_bds_parents)
7f1c5b
@@ -390,7 +375,9 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs,
7f1c5b
     }
7f1c5b
 
7f1c5b
     bdrv_parent_drained_begin(bs, parent, ignore_bds_parents);
7f1c5b
-    bdrv_drain_invoke(bs, true);
7f1c5b
+    if (bs->drv && bs->drv->bdrv_drain_begin) {
7f1c5b
+        bs->drv->bdrv_drain_begin(bs);
7f1c5b
+    }
7f1c5b
 }
7f1c5b
 
7f1c5b
 static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
7f1c5b
@@ -461,7 +448,9 @@ static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
7f1c5b
     assert(bs->quiesce_counter > 0);
7f1c5b
 
7f1c5b
     /* Re-enable things in child-to-parent order */
7f1c5b
-    bdrv_drain_invoke(bs, false);
7f1c5b
+    if (bs->drv && bs->drv->bdrv_drain_end) {
7f1c5b
+        bs->drv->bdrv_drain_end(bs);
7f1c5b
+    }
7f1c5b
     bdrv_parent_drained_end(bs, parent, ignore_bds_parents);
7f1c5b
 
7f1c5b
     old_quiesce_counter = qatomic_fetch_dec(&bs->quiesce_counter);
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b