cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
495e37
From 06583ce33fab2976157461ac4503d6f8eeb59e75 Mon Sep 17 00:00:00 2001
495e37
From: Hanna Reitz <hreitz@redhat.com>
495e37
Date: Fri, 4 Feb 2022 12:10:12 +0100
495e37
Subject: [PATCH 8/8] iotests/281: Let NBD connection yield in iothread
495e37
495e37
RH-Author: Hanna Reitz <hreitz@redhat.com>
495e37
RH-MergeRequest: 74: block/nbd: Handle AioContext changes
495e37
RH-Commit: [6/6] 632b9ef5177a80d1c0c00121e1acc37272076d3e (hreitz/qemu-kvm-c-9-s)
495e37
RH-Bugzilla: 2033626
495e37
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
495e37
RH-Acked-by: Eric Blake <eblake@redhat.com>
495e37
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
495e37
495e37
Put an NBD block device into an I/O thread, and then read data from it,
495e37
hoping that the NBD connection will yield during that read.  When it
495e37
does, the coroutine must be reentered in the block device's I/O thread,
495e37
which will only happen if the NBD block driver attaches the connection's
495e37
QIOChannel to the new AioContext.  It did not do that after 4ddb5d2fde
495e37
("block/nbd: drop connection_co") and prior to "block/nbd: Move s->ioc
495e37
on AioContext change", which would cause an assertion failure.
495e37
495e37
To improve our chances of yielding, the NBD server is throttled to
495e37
reading 64 kB/s, and the NBD client reads 128 kB, so it should yield at
495e37
some point.
495e37
495e37
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
495e37
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
495e37
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
495e37
(cherry picked from commit 8cfbe929e8c26050f0a4580a1606a370a947d4ce)
495e37
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
495e37
---
495e37
 tests/qemu-iotests/281     | 28 +++++++++++++++++++++++++---
495e37
 tests/qemu-iotests/281.out |  4 ++--
495e37
 2 files changed, 27 insertions(+), 5 deletions(-)
495e37
495e37
diff --git a/tests/qemu-iotests/281 b/tests/qemu-iotests/281
495e37
index 13c588be75..b2ead7f388 100755
495e37
--- a/tests/qemu-iotests/281
495e37
+++ b/tests/qemu-iotests/281
495e37
@@ -253,8 +253,9 @@ class TestYieldingAndTimers(iotests.QMPTestCase):
495e37
         self.create_nbd_export()
495e37
 
495e37
         # Simple VM with an NBD block device connected to the NBD export
495e37
-        # provided by the QSD
495e37
+        # provided by the QSD, and an (initially unused) iothread
495e37
         self.vm = iotests.VM()
495e37
+        self.vm.add_object('iothread,id=iothr')
495e37
         self.vm.add_blockdev('nbd,node-name=nbd,server.type=unix,' +
495e37
                              f'server.path={self.sock},export=exp,' +
495e37
                              'reconnect-delay=1')
495e37
@@ -293,19 +294,40 @@ class TestYieldingAndTimers(iotests.QMPTestCase):
495e37
         # thus not see the error, and so the test will pass.)
495e37
         time.sleep(2)
495e37
 
495e37
+    def test_yield_in_iothread(self):
495e37
+        # Move the NBD node to the I/O thread; the NBD block driver should
495e37
+        # attach the connection's QIOChannel to that thread's AioContext, too
495e37
+        result = self.vm.qmp('x-blockdev-set-iothread',
495e37
+                             node_name='nbd', iothread='iothr')
495e37
+        self.assert_qmp(result, 'return', {})
495e37
+
495e37
+        # Do some I/O that will be throttled by the QSD, so that the network
495e37
+        # connection hopefully will yield here.  When it is resumed, it must
495e37
+        # then be resumed in the I/O thread's AioContext.
495e37
+        result = self.vm.qmp('human-monitor-command',
495e37
+                             command_line='qemu-io nbd "read 0 128K"')
495e37
+        self.assert_qmp(result, 'return', '')
495e37
+
495e37
     def create_nbd_export(self):
495e37
         assert self.qsd is None
495e37
 
495e37
-        # Simple NBD export of a null-co BDS
495e37
+        # Export a throttled null-co BDS: Reads are throttled (max 64 kB/s),
495e37
+        # writes are not.
495e37
         self.qsd = QemuStorageDaemon(
495e37
+            '--object',
495e37
+            'throttle-group,id=thrgr,x-bps-read=65536,x-bps-read-max=65536',
495e37
+
495e37
             '--blockdev',
495e37
             'null-co,node-name=null,read-zeroes=true',
495e37
 
495e37
+            '--blockdev',
495e37
+            'throttle,node-name=thr,file=null,throttle-group=thrgr',
495e37
+
495e37
             '--nbd-server',
495e37
             f'addr.type=unix,addr.path={self.sock}',
495e37
 
495e37
             '--export',
495e37
-            'nbd,id=exp,node-name=null,name=exp,writable=true'
495e37
+            'nbd,id=exp,node-name=thr,name=exp,writable=true'
495e37
         )
495e37
 
495e37
     def stop_nbd_export(self):
495e37
diff --git a/tests/qemu-iotests/281.out b/tests/qemu-iotests/281.out
495e37
index 914e3737bd..3f8a935a08 100644
495e37
--- a/tests/qemu-iotests/281.out
495e37
+++ b/tests/qemu-iotests/281.out
495e37
@@ -1,5 +1,5 @@
495e37
-.....
495e37
+......
495e37
 ----------------------------------------------------------------------
495e37
-Ran 5 tests
495e37
+Ran 6 tests
495e37
 
495e37
 OK
495e37
-- 
495e37
2.27.0
495e37