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

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