432cb7
From ea4d8424fb2053b1cbb9538190b2b06351054125 Mon Sep 17 00:00:00 2001
432cb7
From: Kevin Wolf <kwolf@redhat.com>
432cb7
Date: Thu, 3 Feb 2022 15:05:34 +0100
432cb7
Subject: [PATCH 3/5] iotests: Test blockdev-reopen with iothreads and
432cb7
 throttling
432cb7
432cb7
RH-Author: Kevin Wolf <kwolf@redhat.com>
432cb7
RH-MergeRequest: 142: block: Lock AioContext for drain_end in blockdev-reopen
432cb7
RH-Commit: [2/2] 91d365864c391ca7db7db13260913fb61987b833
432cb7
RH-Bugzilla: 2067118
432cb7
RH-Acked-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
432cb7
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
432cb7
RH-Acked-by: Hanna Reitz <hreitz@redhat.com>
432cb7
432cb7
The 'throttle' block driver implements .bdrv_co_drain_end, so
432cb7
blockdev-reopen will have to wait for it to complete in the polling
432cb7
loop at the end of qmp_blockdev_reopen(). This makes AIO_WAIT_WHILE()
432cb7
release the AioContext lock, which causes a crash if the lock hasn't
432cb7
correctly been taken.
432cb7
432cb7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
432cb7
Message-Id: <20220203140534.36522-3-kwolf@redhat.com>
432cb7
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
432cb7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
432cb7
(cherry picked from commit ee810602376125ca0e0afd6b7c715e13740978ea)
432cb7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
432cb7
---
432cb7
 tests/qemu-iotests/245     | 36 +++++++++++++++++++++++++++++++++---
432cb7
 tests/qemu-iotests/245.out |  4 ++--
432cb7
 2 files changed, 35 insertions(+), 5 deletions(-)
432cb7
432cb7
diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245
432cb7
index 24ac43f70e..8cbed7821b 100755
432cb7
--- a/tests/qemu-iotests/245
432cb7
+++ b/tests/qemu-iotests/245
432cb7
@@ -1138,12 +1138,13 @@ class TestBlockdevReopen(iotests.QMPTestCase):
432cb7
         self.assertEqual(self.get_node('hd1'), None)
432cb7
         self.assert_qmp(self.get_node('hd2'), 'ro', True)
432cb7
 
432cb7
-    def run_test_iothreads(self, iothread_a, iothread_b, errmsg = None):
432cb7
-        opts = hd_opts(0)
432cb7
+    def run_test_iothreads(self, iothread_a, iothread_b, errmsg = None,
432cb7
+                           opts_a = None, opts_b = None):
432cb7
+        opts = opts_a or hd_opts(0)
432cb7
         result = self.vm.qmp('blockdev-add', conv_keys = False, **opts)
432cb7
         self.assert_qmp(result, 'return', {})
432cb7
 
432cb7
-        opts2 = hd_opts(2)
432cb7
+        opts2 = opts_b or hd_opts(2)
432cb7
         result = self.vm.qmp('blockdev-add', conv_keys = False, **opts2)
432cb7
         self.assert_qmp(result, 'return', {})
432cb7
 
432cb7
@@ -1194,6 +1195,35 @@ class TestBlockdevReopen(iotests.QMPTestCase):
432cb7
     def test_iothreads_switch_overlay(self):
432cb7
         self.run_test_iothreads('', 'iothread0')
432cb7
 
432cb7
+    def test_iothreads_with_throttling(self):
432cb7
+        # Create a throttle-group object
432cb7
+        opts = { 'qom-type': 'throttle-group', 'id': 'group0',
432cb7
+                 'limits': { 'iops-total': 1000 } }
432cb7
+        result = self.vm.qmp('object-add', conv_keys = False, **opts)
432cb7
+        self.assert_qmp(result, 'return', {})
432cb7
+
432cb7
+        # Options with a throttle filter between format and protocol
432cb7
+        opts = [
432cb7
+            {
432cb7
+                'driver': iotests.imgfmt,
432cb7
+                'node-name': f'hd{idx}',
432cb7
+                'file' : {
432cb7
+                    'node-name': f'hd{idx}-throttle',
432cb7
+                    'driver': 'throttle',
432cb7
+                    'throttle-group': 'group0',
432cb7
+                    'file': {
432cb7
+                        'driver': 'file',
432cb7
+                        'node-name': f'hd{idx}-file',
432cb7
+                        'filename': hd_path[idx],
432cb7
+                    },
432cb7
+                },
432cb7
+            }
432cb7
+            for idx in (0, 2)
432cb7
+        ]
432cb7
+
432cb7
+        self.run_test_iothreads('iothread0', 'iothread0', None,
432cb7
+                                opts[0], opts[1])
432cb7
+
432cb7
 if __name__ == '__main__':
432cb7
     iotests.activate_logging()
432cb7
     iotests.main(supported_fmts=["qcow2"],
432cb7
diff --git a/tests/qemu-iotests/245.out b/tests/qemu-iotests/245.out
432cb7
index 4eced19294..a4e04a3266 100644
432cb7
--- a/tests/qemu-iotests/245.out
432cb7
+++ b/tests/qemu-iotests/245.out
432cb7
@@ -17,8 +17,8 @@ read 1/1 bytes at offset 262152
432cb7
 read 1/1 bytes at offset 262160
432cb7
 1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
432cb7
 
432cb7
-...............
432cb7
+................
432cb7
 ----------------------------------------------------------------------
432cb7
-Ran 25 tests
432cb7
+Ran 26 tests
432cb7
 
432cb7
 OK
432cb7
-- 
432cb7
2.27.0
432cb7