thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-iotests-Test-handling-of-AioContexts-with-some-block.patch

22c213
From 6b9a6ba9ed753ad7aa714b35de938ebeeb4fa6cb Mon Sep 17 00:00:00 2001
22c213
From: Sergio Lopez Pascual <slp@redhat.com>
22c213
Date: Fri, 7 Feb 2020 10:27:49 +0000
22c213
Subject: [PATCH 16/18] iotests: Test handling of AioContexts with some
22c213
 blockdev actions
22c213
22c213
RH-Author: Sergio Lopez Pascual <slp@redhat.com>
22c213
Message-id: <20200207112749.25073-10-slp@redhat.com>
22c213
Patchwork-id: 93762
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 9/9] iotests: Test handling of AioContexts with some blockdev actions
22c213
Bugzilla: 1745606 1746217 1773517 1779036 1782111 1782175 1783965
22c213
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
22c213
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
Includes the following tests:
22c213
22c213
 - Adding a dirty bitmap.
22c213
   * RHBZ: 1782175
22c213
22c213
 - Starting a drive-mirror to an NBD-backed target.
22c213
   * RHBZ: 1746217, 1773517
22c213
22c213
 - Aborting an external snapshot transaction.
22c213
   * RHBZ: 1779036
22c213
22c213
 - Aborting a blockdev backup transaction.
22c213
   * RHBZ: 1782111
22c213
22c213
For each one of them, a VM with a number of disks running in an
22c213
IOThread AioContext is used.
22c213
22c213
Signed-off-by: Sergio Lopez <slp@redhat.com>
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
(cherry picked from commit 9b8c59e7610b9c5315ef093d801843dbe8debfac)
22c213
Signed-off-by: Sergio Lopez <slp@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 tests/qemu-iotests/281     | 247 +++++++++++++++++++++++++++++++++++++++++++++
22c213
 tests/qemu-iotests/281.out |   5 +
22c213
 tests/qemu-iotests/group   |   1 +
22c213
 3 files changed, 253 insertions(+)
22c213
 create mode 100755 tests/qemu-iotests/281
22c213
 create mode 100644 tests/qemu-iotests/281.out
22c213
22c213
diff --git a/tests/qemu-iotests/281 b/tests/qemu-iotests/281
22c213
new file mode 100755
22c213
index 0000000..269d583
22c213
--- /dev/null
22c213
+++ b/tests/qemu-iotests/281
22c213
@@ -0,0 +1,247 @@
22c213
+#!/usr/bin/env python
22c213
+#
22c213
+# Test cases for blockdev + IOThread interactions
22c213
+#
22c213
+# Copyright (C) 2019 Red Hat, Inc.
22c213
+#
22c213
+# This program is free software; you can redistribute it and/or modify
22c213
+# it under the terms of the GNU General Public License as published by
22c213
+# the Free Software Foundation; either version 2 of the License, or
22c213
+# (at your option) any later version.
22c213
+#
22c213
+# This program is distributed in the hope that it will be useful,
22c213
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
22c213
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22c213
+# GNU General Public License for more details.
22c213
+#
22c213
+# You should have received a copy of the GNU General Public License
22c213
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22c213
+#
22c213
+
22c213
+import os
22c213
+import iotests
22c213
+from iotests import qemu_img
22c213
+
22c213
+image_len = 64 * 1024 * 1024
22c213
+
22c213
+# Test for RHBZ#1782175
22c213
+class TestDirtyBitmapIOThread(iotests.QMPTestCase):
22c213
+    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
22c213
+    images = { 'drive0': drive0_img }
22c213
+
22c213
+    def setUp(self):
22c213
+        for name in self.images:
22c213
+            qemu_img('create', '-f', iotests.imgfmt,
22c213
+                     self.images[name], str(image_len))
22c213
+
22c213
+        self.vm = iotests.VM()
22c213
+        self.vm.add_object('iothread,id=iothread0')
22c213
+
22c213
+        for name in self.images:
22c213
+            self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
22c213
+                                 % (self.images[name], name))
22c213
+            self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
22c213
+                                 % (name, name))
22c213
+
22c213
+        self.vm.launch()
22c213
+        self.vm.qmp('x-blockdev-set-iothread',
22c213
+                    node_name='drive0', iothread='iothread0',
22c213
+                    force=True)
22c213
+
22c213
+    def tearDown(self):
22c213
+        self.vm.shutdown()
22c213
+        for name in self.images:
22c213
+            os.remove(self.images[name])
22c213
+
22c213
+    def test_add_dirty_bitmap(self):
22c213
+        result = self.vm.qmp(
22c213
+            'block-dirty-bitmap-add',
22c213
+            node='drive0',
22c213
+            name='bitmap1',
22c213
+            persistent=True,
22c213
+        )
22c213
+
22c213
+        self.assert_qmp(result, 'return', {})
22c213
+
22c213
+
22c213
+# Test for RHBZ#1746217 & RHBZ#1773517
22c213
+class TestNBDMirrorIOThread(iotests.QMPTestCase):
22c213
+    nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
22c213
+    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
22c213
+    mirror_img = os.path.join(iotests.test_dir, 'mirror.img')
22c213
+    images = { 'drive0': drive0_img, 'mirror': mirror_img }
22c213
+
22c213
+    def setUp(self):
22c213
+        for name in self.images:
22c213
+            qemu_img('create', '-f', iotests.imgfmt,
22c213
+                     self.images[name], str(image_len))
22c213
+
22c213
+        self.vm_src = iotests.VM(path_suffix='src')
22c213
+        self.vm_src.add_object('iothread,id=iothread0')
22c213
+        self.vm_src.add_blockdev('driver=file,filename=%s,node-name=file0'
22c213
+                          % (self.drive0_img))
22c213
+        self.vm_src.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
22c213
+        self.vm_src.launch()
22c213
+        self.vm_src.qmp('x-blockdev-set-iothread',
22c213
+                        node_name='drive0', iothread='iothread0',
22c213
+                        force=True)
22c213
+
22c213
+        self.vm_tgt = iotests.VM(path_suffix='tgt')
22c213
+        self.vm_tgt.add_object('iothread,id=iothread0')
22c213
+        self.vm_tgt.add_blockdev('driver=file,filename=%s,node-name=file0'
22c213
+                          % (self.mirror_img))
22c213
+        self.vm_tgt.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
22c213
+        self.vm_tgt.launch()
22c213
+        self.vm_tgt.qmp('x-blockdev-set-iothread',
22c213
+                        node_name='drive0', iothread='iothread0',
22c213
+                        force=True)
22c213
+
22c213
+    def tearDown(self):
22c213
+        self.vm_src.shutdown()
22c213
+        self.vm_tgt.shutdown()
22c213
+        for name in self.images:
22c213
+            os.remove(self.images[name])
22c213
+
22c213
+    def test_nbd_mirror(self):
22c213
+        result = self.vm_tgt.qmp(
22c213
+            'nbd-server-start',
22c213
+            addr={
22c213
+                'type': 'unix',
22c213
+                'data': { 'path': self.nbd_sock }
22c213
+            }
22c213
+        )
22c213
+        self.assert_qmp(result, 'return', {})
22c213
+
22c213
+        result = self.vm_tgt.qmp(
22c213
+            'nbd-server-add',
22c213
+            device='drive0',
22c213
+            writable=True
22c213
+        )
22c213
+        self.assert_qmp(result, 'return', {})
22c213
+
22c213
+        result = self.vm_src.qmp(
22c213
+            'drive-mirror',
22c213
+            device='drive0',
22c213
+            target='nbd+unix:///drive0?socket=' + self.nbd_sock,
22c213
+            sync='full',
22c213
+            mode='existing',
22c213
+            speed=64*1024*1024,
22c213
+            job_id='j1'
22c213
+        )
22c213
+        self.assert_qmp(result, 'return', {})
22c213
+
22c213
+        self.vm_src.event_wait(name="BLOCK_JOB_READY")
22c213
+
22c213
+
22c213
+# Test for RHBZ#1779036
22c213
+class TestExternalSnapshotAbort(iotests.QMPTestCase):
22c213
+    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
22c213
+    snapshot_img = os.path.join(iotests.test_dir, 'snapshot.img')
22c213
+    images = { 'drive0': drive0_img, 'snapshot': snapshot_img }
22c213
+
22c213
+    def setUp(self):
22c213
+        for name in self.images:
22c213
+            qemu_img('create', '-f', iotests.imgfmt,
22c213
+                     self.images[name], str(image_len))
22c213
+
22c213
+        self.vm = iotests.VM()
22c213
+        self.vm.add_object('iothread,id=iothread0')
22c213
+        self.vm.add_blockdev('driver=file,filename=%s,node-name=file0'
22c213
+                          % (self.drive0_img))
22c213
+        self.vm.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
22c213
+        self.vm.launch()
22c213
+        self.vm.qmp('x-blockdev-set-iothread',
22c213
+                    node_name='drive0', iothread='iothread0',
22c213
+                    force=True)
22c213
+
22c213
+    def tearDown(self):
22c213
+        self.vm.shutdown()
22c213
+        for name in self.images:
22c213
+            os.remove(self.images[name])
22c213
+
22c213
+    def test_external_snapshot_abort(self):
22c213
+        # Use a two actions transaction with a bogus values on the second
22c213
+        # one to trigger an abort of the transaction.
22c213
+        result = self.vm.qmp('transaction', actions=[
22c213
+            {
22c213
+                'type': 'blockdev-snapshot-sync',
22c213
+                'data': { 'node-name': 'drive0',
22c213
+                          'snapshot-file': self.snapshot_img,
22c213
+                          'snapshot-node-name': 'snap1',
22c213
+                          'mode': 'absolute-paths',
22c213
+                          'format': 'qcow2' }
22c213
+            },
22c213
+            {
22c213
+                'type': 'blockdev-snapshot-sync',
22c213
+                'data': { 'node-name': 'drive0',
22c213
+                          'snapshot-file': '/fakesnapshot',
22c213
+                          'snapshot-node-name': 'snap2',
22c213
+                          'mode': 'absolute-paths',
22c213
+                          'format': 'qcow2' }
22c213
+            },
22c213
+        ])
22c213
+
22c213
+        # Crashes on failure, we expect this error.
22c213
+        self.assert_qmp(result, 'error/class', 'GenericError')
22c213
+
22c213
+
22c213
+# Test for RHBZ#1782111
22c213
+class TestBlockdevBackupAbort(iotests.QMPTestCase):
22c213
+    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
22c213
+    drive1_img = os.path.join(iotests.test_dir, 'drive1.img')
22c213
+    snap0_img = os.path.join(iotests.test_dir, 'snap0.img')
22c213
+    snap1_img = os.path.join(iotests.test_dir, 'snap1.img')
22c213
+    images = { 'drive0': drive0_img,
22c213
+               'drive1': drive1_img,
22c213
+               'snap0': snap0_img,
22c213
+               'snap1': snap1_img }
22c213
+
22c213
+    def setUp(self):
22c213
+        for name in self.images:
22c213
+            qemu_img('create', '-f', iotests.imgfmt,
22c213
+                     self.images[name], str(image_len))
22c213
+
22c213
+        self.vm = iotests.VM()
22c213
+        self.vm.add_object('iothread,id=iothread0')
22c213
+        self.vm.add_device('virtio-scsi,iothread=iothread0')
22c213
+
22c213
+        for name in self.images:
22c213
+            self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
22c213
+                                 % (self.images[name], name))
22c213
+            self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
22c213
+                                 % (name, name))
22c213
+
22c213
+        self.vm.add_device('scsi-hd,drive=drive0')
22c213
+        self.vm.add_device('scsi-hd,drive=drive1')
22c213
+        self.vm.launch()
22c213
+
22c213
+    def tearDown(self):
22c213
+        self.vm.shutdown()
22c213
+        for name in self.images:
22c213
+            os.remove(self.images[name])
22c213
+
22c213
+    def test_blockdev_backup_abort(self):
22c213
+        # Use a two actions transaction with a bogus values on the second
22c213
+        # one to trigger an abort of the transaction.
22c213
+        result = self.vm.qmp('transaction', actions=[
22c213
+            {
22c213
+                'type': 'blockdev-backup',
22c213
+                'data': { 'device': 'drive0',
22c213
+                          'target': 'snap0',
22c213
+                          'sync': 'full',
22c213
+                          'job-id': 'j1' }
22c213
+            },
22c213
+            {
22c213
+                'type': 'blockdev-backup',
22c213
+                'data': { 'device': 'drive1',
22c213
+                          'target': 'snap1',
22c213
+                          'sync': 'full' }
22c213
+            },
22c213
+        ])
22c213
+
22c213
+        # Hangs on failure, we expect this error.
22c213
+        self.assert_qmp(result, 'error/class', 'GenericError')
22c213
+
22c213
+if __name__ == '__main__':
22c213
+    iotests.main(supported_fmts=['qcow2'],
22c213
+                 supported_protocols=['file'])
22c213
diff --git a/tests/qemu-iotests/281.out b/tests/qemu-iotests/281.out
22c213
new file mode 100644
22c213
index 0000000..89968f3
22c213
--- /dev/null
22c213
+++ b/tests/qemu-iotests/281.out
22c213
@@ -0,0 +1,5 @@
22c213
+....
22c213
+----------------------------------------------------------------------
22c213
+Ran 4 tests
22c213
+
22c213
+OK
22c213
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
22c213
index 01301cd..c0e8197 100644
22c213
--- a/tests/qemu-iotests/group
22c213
+++ b/tests/qemu-iotests/group
22c213
@@ -287,3 +287,4 @@
22c213
 273 backing quick
22c213
 277 rw quick
22c213
 280 rw migration quick
22c213
+281 rw quick
22c213
-- 
22c213
1.8.3.1
22c213