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

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