cryptospore / rpms / qemu-kvm

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