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

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