Blame SOURCES/kvm-iotests-281-Let-NBD-connection-yield-in-iothread.patch

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