thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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