thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-iotests-Test-mirror-with-temporarily-disabled-target.patch

ddf19c
From 239f7bdeef48a3c0b07098617371b9955dc55348 Mon Sep 17 00:00:00 2001
ddf19c
From: Kevin Wolf <kwolf@redhat.com>
ddf19c
Date: Fri, 13 Mar 2020 12:34:36 +0000
ddf19c
Subject: [PATCH 16/20] iotests: Test mirror with temporarily disabled target
ddf19c
 backing file
ddf19c
ddf19c
RH-Author: Kevin Wolf <kwolf@redhat.com>
ddf19c
Message-id: <20200313123439.10548-11-kwolf@redhat.com>
ddf19c
Patchwork-id: 94288
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 10/13] iotests: Test mirror with temporarily disabled target backing file
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
The newly tested scenario is a common live storage migration scenario:
ddf19c
The target node is opened without a backing file so that the active
ddf19c
layer is mirrored while its backing chain can be copied in the
ddf19c
background.
ddf19c
ddf19c
The backing chain should be attached to the mirror target node when
ddf19c
finalising the job, just before switching the users of the source node
ddf19c
to the new copy (at which point the mirror job still has a reference to
ddf19c
the node). drive-mirror did this automatically, but with blockdev-mirror
ddf19c
this is the job of the QMP client.
ddf19c
ddf19c
This patch adds test cases for two ways to achieve the desired result,
ddf19c
using either x-blockdev-reopen or blockdev-snapshot.
ddf19c
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Message-Id: <20200310113831.27293-5-kwolf@redhat.com>
ddf19c
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit 8bdee9f10eac2aefdcc5095feef756354c87bdec)
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 tests/qemu-iotests/155     | 56 +++++++++++++++++++++++++++++++++++++++++-----
ddf19c
 tests/qemu-iotests/155.out |  4 ++--
ddf19c
 2 files changed, 53 insertions(+), 7 deletions(-)
ddf19c
ddf19c
diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
ddf19c
index d7ef257..3053e50 100755
ddf19c
--- a/tests/qemu-iotests/155
ddf19c
+++ b/tests/qemu-iotests/155
ddf19c
@@ -45,10 +45,15 @@ target_img = os.path.join(iotests.test_dir, 'target.' + iotests.imgfmt)
ddf19c
 #                      image during runtime, only makes sense if
ddf19c
 #                      target_blockdev_backing is not None
ddf19c
 #                      (None: same as target_backing)
ddf19c
+# target_open_with_backing: If True, the target image is added with its backing
ddf19c
+#                           chain opened right away. If False, blockdev-add
ddf19c
+#                           opens it without a backing file and job completion
ddf19c
+#                           is supposed to open the backing chain.
ddf19c
 
ddf19c
 class BaseClass(iotests.QMPTestCase):
ddf19c
     target_blockdev_backing = None
ddf19c
     target_real_backing = None
ddf19c
+    target_open_with_backing = True
ddf19c
 
ddf19c
     def setUp(self):
ddf19c
         qemu_img('create', '-f', iotests.imgfmt, back0_img, '1440K')
ddf19c
@@ -80,9 +85,13 @@ class BaseClass(iotests.QMPTestCase):
ddf19c
                 options = { 'node-name': 'target',
ddf19c
                             'driver': iotests.imgfmt,
ddf19c
                             'file': { 'driver': 'file',
ddf19c
+                                      'node-name': 'target-file',
ddf19c
                                       'filename': target_img } }
ddf19c
-                if self.target_blockdev_backing:
ddf19c
-                    options['backing'] = self.target_blockdev_backing
ddf19c
+
ddf19c
+                if not self.target_open_with_backing:
ddf19c
+                        options['backing'] = None
ddf19c
+                elif self.target_blockdev_backing:
ddf19c
+                        options['backing'] = self.target_blockdev_backing
ddf19c
 
ddf19c
                 result = self.vm.qmp('blockdev-add', **options)
ddf19c
                 self.assert_qmp(result, 'return', {})
ddf19c
@@ -147,10 +156,14 @@ class BaseClass(iotests.QMPTestCase):
ddf19c
 # cmd: Mirroring command to execute, either drive-mirror or blockdev-mirror
ddf19c
 
ddf19c
 class MirrorBaseClass(BaseClass):
ddf19c
+    def openBacking(self):
ddf19c
+        pass
ddf19c
+
ddf19c
     def runMirror(self, sync):
ddf19c
         if self.cmd == 'blockdev-mirror':
ddf19c
             result = self.vm.qmp(self.cmd, job_id='mirror-job', device='source',
ddf19c
-                                 sync=sync, target='target')
ddf19c
+                                 sync=sync, target='target',
ddf19c
+                                 auto_finalize=False)
ddf19c
         else:
ddf19c
             if self.existing:
ddf19c
                 mode = 'existing'
ddf19c
@@ -159,11 +172,12 @@ class MirrorBaseClass(BaseClass):
ddf19c
             result = self.vm.qmp(self.cmd, job_id='mirror-job', device='source',
ddf19c
                                  sync=sync, target=target_img,
ddf19c
                                  format=iotests.imgfmt, mode=mode,
ddf19c
-                                 node_name='target')
ddf19c
+                                 node_name='target', auto_finalize=False)
ddf19c
 
ddf19c
         self.assert_qmp(result, 'return', {})
ddf19c
 
ddf19c
-        self.complete_and_wait('mirror-job')
ddf19c
+        self.vm.run_job('mirror-job', use_log=False, auto_finalize=False,
ddf19c
+                        pre_finalize=self.openBacking, auto_dismiss=True)
ddf19c
 
ddf19c
     def testFull(self):
ddf19c
         self.runMirror('full')
ddf19c
@@ -221,6 +235,38 @@ class TestBlockdevMirrorForcedBacking(MirrorBaseClass):
ddf19c
     target_blockdev_backing = { 'driver': 'null-co' }
ddf19c
     target_real_backing = 'null-co://'
ddf19c
 
ddf19c
+# Attach the backing chain only during completion, with blockdev-reopen
ddf19c
+class TestBlockdevMirrorReopen(MirrorBaseClass):
ddf19c
+    cmd = 'blockdev-mirror'
ddf19c
+    existing = True
ddf19c
+    target_backing = 'null-co://'
ddf19c
+    target_open_with_backing = False
ddf19c
+
ddf19c
+    def openBacking(self):
ddf19c
+        if not self.target_open_with_backing:
ddf19c
+            result = self.vm.qmp('blockdev-add', node_name="backing",
ddf19c
+                                 driver="null-co")
ddf19c
+            self.assert_qmp(result, 'return', {})
ddf19c
+            result = self.vm.qmp('x-blockdev-reopen', node_name="target",
ddf19c
+                                 driver=iotests.imgfmt, file="target-file",
ddf19c
+                                 backing="backing")
ddf19c
+            self.assert_qmp(result, 'return', {})
ddf19c
+
ddf19c
+# Attach the backing chain only during completion, with blockdev-snapshot
ddf19c
+class TestBlockdevMirrorSnapshot(MirrorBaseClass):
ddf19c
+    cmd = 'blockdev-mirror'
ddf19c
+    existing = True
ddf19c
+    target_backing = 'null-co://'
ddf19c
+    target_open_with_backing = False
ddf19c
+
ddf19c
+    def openBacking(self):
ddf19c
+        if not self.target_open_with_backing:
ddf19c
+            result = self.vm.qmp('blockdev-add', node_name="backing",
ddf19c
+                                 driver="null-co")
ddf19c
+            self.assert_qmp(result, 'return', {})
ddf19c
+            result = self.vm.qmp('blockdev-snapshot', node="backing",
ddf19c
+                                 overlay="target")
ddf19c
+            self.assert_qmp(result, 'return', {})
ddf19c
 
ddf19c
 class TestCommit(BaseClass):
ddf19c
     existing = False
ddf19c
diff --git a/tests/qemu-iotests/155.out b/tests/qemu-iotests/155.out
ddf19c
index 4176bb9..4fd1c2d 100644
ddf19c
--- a/tests/qemu-iotests/155.out
ddf19c
+++ b/tests/qemu-iotests/155.out
ddf19c
@@ -1,5 +1,5 @@
ddf19c
-...................
ddf19c
+.........................
ddf19c
 ----------------------------------------------------------------------
ddf19c
-Ran 19 tests
ddf19c
+Ran 25 tests
ddf19c
 
ddf19c
 OK
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c