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

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