Blame SOURCES/kvm-block-bdrv_reopen-with-backing-file-in-different-Aio.patch

902636
From 1e0582ad34e77a060e2067a35992979c9eae82c9 Mon Sep 17 00:00:00 2001
902636
From: Kevin Wolf <kwolf@redhat.com>
902636
Date: Fri, 13 Mar 2020 12:34:31 +0000
902636
Subject: [PATCH 11/20] block: bdrv_reopen() with backing file in different
902636
 AioContext
902636
902636
RH-Author: Kevin Wolf <kwolf@redhat.com>
902636
Message-id: <20200313123439.10548-6-kwolf@redhat.com>
902636
Patchwork-id: 94282
902636
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 05/13] block: bdrv_reopen() with backing file in different AioContext
902636
Bugzilla: 1790482 1805143
902636
RH-Acked-by: John Snow <jsnow@redhat.com>
902636
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
902636
RH-Acked-by: Peter Krempa <pkrempa@redhat.com>
902636
902636
This patch allows bdrv_reopen() (and therefore the x-blockdev-reopen QMP
902636
command) to attach a node as the new backing file even if the node is in
902636
a different AioContext than the parent if one of both nodes can be moved
902636
to the AioContext of the other node.
902636
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
Tested-by: Peter Krempa <pkrempa@redhat.com>
902636
Message-Id: <20200306141413.30705-3-kwolf@redhat.com>
902636
Reviewed-by: Alberto Garcia <berto@igalia.com>
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
(cherry picked from commit 1de6b45fb5c1489b450df7d1a4c692bba9678ce6)
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 block.c                | 32 ++++++++++++++++++++++++++------
902636
 tests/qemu-iotests/245 |  8 +++-----
902636
 2 files changed, 29 insertions(+), 11 deletions(-)
902636
902636
diff --git a/block.c b/block.c
902636
index a744bb5..39e4647 100644
902636
--- a/block.c
902636
+++ b/block.c
902636
@@ -3749,6 +3749,29 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs,
902636
     *shared = cumulative_shared_perms;
902636
 }
902636
 
902636
+static bool bdrv_reopen_can_attach(BlockDriverState *parent,
902636
+                                   BdrvChild *child,
902636
+                                   BlockDriverState *new_child,
902636
+                                   Error **errp)
902636
+{
902636
+    AioContext *parent_ctx = bdrv_get_aio_context(parent);
902636
+    AioContext *child_ctx = bdrv_get_aio_context(new_child);
902636
+    GSList *ignore;
902636
+    bool ret;
902636
+
902636
+    ignore = g_slist_prepend(NULL, child);
902636
+    ret = bdrv_can_set_aio_context(new_child, parent_ctx, &ignore, NULL);
902636
+    g_slist_free(ignore);
902636
+    if (ret) {
902636
+        return ret;
902636
+    }
902636
+
902636
+    ignore = g_slist_prepend(NULL, child);
902636
+    ret = bdrv_can_set_aio_context(parent, child_ctx, &ignore, errp);
902636
+    g_slist_free(ignore);
902636
+    return ret;
902636
+}
902636
+
902636
 /*
902636
  * Take a BDRVReopenState and check if the value of 'backing' in the
902636
  * reopen_state->options QDict is valid or not.
902636
@@ -3800,14 +3823,11 @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state,
902636
     }
902636
 
902636
     /*
902636
-     * TODO: before removing the x- prefix from x-blockdev-reopen we
902636
-     * should move the new backing file into the right AioContext
902636
-     * instead of returning an error.
902636
+     * Check AioContext compatibility so that the bdrv_set_backing_hd() call in
902636
+     * bdrv_reopen_commit() won't fail.
902636
      */
902636
     if (new_backing_bs) {
902636
-        if (bdrv_get_aio_context(new_backing_bs) != bdrv_get_aio_context(bs)) {
902636
-            error_setg(errp, "Cannot use a new backing file "
902636
-                       "with a different AioContext");
902636
+        if (!bdrv_reopen_can_attach(bs, bs->backing, new_backing_bs, errp)) {
902636
             return -EINVAL;
902636
         }
902636
     }
902636
diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245
902636
index f69c2fa..919131d 100644
902636
--- a/tests/qemu-iotests/245
902636
+++ b/tests/qemu-iotests/245
902636
@@ -1013,18 +1013,16 @@ class TestBlockdevReopen(iotests.QMPTestCase):
902636
     # neither of them can switch to the other AioContext
902636
     def test_iothreads_error(self):
902636
         self.run_test_iothreads('iothread0', 'iothread1',
902636
-                                "Cannot use a new backing file with a different AioContext")
902636
+                                "Cannot change iothread of active block backend")
902636
 
902636
     def test_iothreads_compatible_users(self):
902636
         self.run_test_iothreads('iothread0', 'iothread0')
902636
 
902636
     def test_iothreads_switch_backing(self):
902636
-        self.run_test_iothreads('iothread0', None,
902636
-                                "Cannot use a new backing file with a different AioContext")
902636
+        self.run_test_iothreads('iothread0', None)
902636
 
902636
     def test_iothreads_switch_overlay(self):
902636
-        self.run_test_iothreads(None, 'iothread0',
902636
-                                "Cannot use a new backing file with a different AioContext")
902636
+        self.run_test_iothreads(None, 'iothread0')
902636
 
902636
 if __name__ == '__main__':
902636
     iotests.main(supported_fmts=["qcow2"],
902636
-- 
902636
1.8.3.1
902636