Skip to contentSkip to conversation

blockdev: mirror: do not require a root block node

PATCH Superseded Fiona Ebner 1 participant 6 messages Jun 11 – Jul 10

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover blockdev: mirror: do not require a root block node

The mirror block job currently only operates on a root block node. It might be desired to use a throttle node as the root node for limiting the guest IO, without also limiting mirror operations.

There is no obvious reason why mirror should only be able to operate on a root block node.

For a related discussion see here:
https://lore.kernel.org/qemu-devel/[email protected]/

Fiona Ebner (3):
iotests/041: add test for mirror with throttle node as source
blockdev: mirror: do not require a root block node iotests/041: add tests for mirroring below throttle node

 blockdev.c                 |  20 +++++-
 tests/qemu-iotests/041     | 128 +++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/041.out |   4 +-
 3 files changed, 147 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/3 iotests/041: add test for mirror with throttle node as source

Mostly in preparation for commit "iotests/041: add tests for mirroring below throttle node" which adds test cases for commit "blockdev:
mirror: do not require a root block node".

---
 tests/qemu-iotests/041     | 88 ++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/041.out |  4 +-
 2 files changed, 90 insertions(+), 2 deletions(-)
tests/qemu-iotests/041 +88 -0
index 8452845f44..3eda59db8e 100755
@@ -1373,6 +1373,94 @@ class TestFilters(iotests.QMPTestCase):
 
         self.complete_and_wait('mirror')
 
+class TestThrottle(iotests.QMPTestCase):
+    image_len = 3 * 1024 * 1024
+    attachTargetImage = True
+
+    def mirror_command(self, device):
+        self.vm.cmd('blockdev-mirror',
+                    job_id='mirror',
+                    device=device,
+                    target='target',
+                    sync='full')
+
+    def setUp(self):
+        qemu_img('create', '-f', iotests.imgfmt,
+                 test_img, str(self.image_len));
+        qemu_img('create', '-f', iotests.imgfmt,
+                 target_img, str(self.image_len));
+        qemu_io('-c', 'write -P 23 0 3M', test_img)
+
+        self.vm = iotests.VM().add_device('virtio-scsi,id=vio-scsi')
+        self.vm.launch()
+
+        self.vm.cmd('object-add', {
+                        'id': 'thrgr0',
+                        'qom-type': 'throttle-group',
+                        'limits': {
+                            'bps-total': 1 * 1024
+                        }
+                    })
+
+        if self.attachTargetImage:
+            self.vm.cmd('blockdev-add', {
+                            'node-name': 'target',
+                            'driver': iotests.imgfmt,
+                            'file': {
+                                'driver': 'file',
+                                'filename': target_img
+                            },
+                        })
+
+        source = {
+            'node-name': 'source',
+            'driver': iotests.imgfmt,
+            'file': {
+                'driver': 'file',
+                'filename': test_img
+            },
+        }
+
+        self.vm.cmd('blockdev-add', {
+                        'node-name': 'throttle',
+                        'driver': 'throttle',
+                        'throttle-group': 'thrgr0',
+                        'file': source,
+                    })
+
+        self.vm.cmd('device_add',
+                    driver='scsi-hd',
+                    id='virtio',
+                    bus='vio-scsi.0',
+                    drive='throttle')
+
+    def tearDown(self):
+        os.remove(test_img)
+        os.remove(target_img)
+
+    def test_throttled(self):
+        self.mirror_command('throttle')
+
+        time.sleep(1)
+        result = self.vm.qmp('query-block-jobs')
+        self.assert_qmp(result, 'return[0]/ready', False)
+
+        self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000 * 1000}')
+        self.complete_and_wait('mirror')
+        self.vm.shutdown()
+        self.assertTrue(iotests.compare_images(test_img, target_img),
+                        'target image does not match source after mirroring')
+
+class TestThrottleDriveMirror(TestThrottle):
+    attachTargetImage = False
+
+    def mirror_command(self, device):
+        self.vm.cmd('drive-mirror',
+                    job_id='mirror',
+                    device=device,
+                    target=target_img,
+                    sync='full',
+                    mode='existing')
 
 if __name__ == '__main__':
     iotests.main(supported_fmts=['qcow2', 'qed'],
tests/qemu-iotests/041.out +2 -2
index 46651953e8..96a0752f44 100644
@@ -1,5 +1,5 @@
-...........................................................................................................
+.............................................................................................................
 ----------------------------------------------------------------------
-Ran 107 tests
+Ran 109 tests
 
 OK
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/3 blockdev: mirror: do not require a root block node

In reply to Fiona Ebner

The mirror block job currently only operates on a root block node. It might be desired to use a throttle node as the root node for limiting the guest IO, without also limiting mirror operations.

There is no obvious reason why mirror should only be able to operate on a root block node.

When there is no explicit @replaces argument, implicit filters on top are skipped. Allowing mirror to operate on non-root nodes does not change that fact and keeps the behavior consistent with the documentation for @replaces.

---
 blockdev.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
blockdev.c +17 -3
index 6e86c6262f..0f70973326 100644
@@ -2987,13 +2987,19 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
     bool target_is_zero;
     int ret;
 
-    bs = qmp_get_root_bs(arg->device, errp);
+    bdrv_graph_rdlock_main_loop();
+    bs = bdrv_lookup_bs(arg->device, arg->device, errp);
     if (!bs) {
+        bdrv_graph_rdunlock_main_loop();
+        return;
+    }
+    if (!bdrv_is_inserted(bs)) {
+        error_setg(errp, "Device has no medium");
+        bdrv_graph_rdunlock_main_loop();
         return;
     }
 
     /* Early check to avoid creating target */
-    bdrv_graph_rdlock_main_loop();
     if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_MIRROR_SOURCE, errp)) {
         bdrv_graph_rdunlock_main_loop();
         return;
@@ -3150,10 +3156,18 @@ void qmp_blockdev_mirror(const char *job_id,
     BlockMirrorBackingMode backing_mode = MIRROR_LEAVE_BACKING_CHAIN;
     int ret;
 
-    bs = qmp_get_root_bs(device, errp);
+    bdrv_graph_rdlock_main_loop();
+    bs = bdrv_lookup_bs(device, device, errp);
     if (!bs) {
+        bdrv_graph_rdunlock_main_loop();
         return;
     }
+    if (!bdrv_is_inserted(bs)) {
+        error_setg(errp, "Device has no medium");
+        bdrv_graph_rdunlock_main_loop();
+        return;
+    }
+    bdrv_graph_rdunlock_main_loop();
 
     target_bs = bdrv_lookup_bs(target, target, errp);
     if (!target_bs) {
Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/3 iotests/041: add tests for mirroring below throttle node

In reply to Fiona Ebner

Test mirror with a non-root node as a source. This restriction was dropped with commit "blockdev: mirror: do not require a root block node".

---
 tests/qemu-iotests/041     | 40 ++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/041.out |  4 ++--
 2 files changed, 42 insertions(+), 2 deletions(-)
tests/qemu-iotests/041 +40 -0
index 3eda59db8e..38a207a724 100755
@@ -1434,10 +1434,19 @@ class TestThrottle(iotests.QMPTestCase):
                     bus='vio-scsi.0',
                     drive='throttle')
 
+        self.drive_qdev = '/machine/peripheral/virtio'
+
     def tearDown(self):
         os.remove(test_img)
         os.remove(target_img)
 
+    def blockstats(self, device):
+        result = self.vm.qmp("query-blockstats")
+        for r in result['return']:
+            if r['node-name'] == device:
+                return r['stats']
+        raise Exception(f'Device {device} not found when querying blockstats')
+
     def test_throttled(self):
         self.mirror_command('throttle')
 
@@ -1451,6 +1460,37 @@ class TestThrottle(iotests.QMPTestCase):
         self.assertTrue(iotests.compare_images(test_img, target_img),
                         'target image does not match source after mirroring')
 
+    def test_below_throttle(self):
+        self.mirror_command('source')
+
+        # The throttling above should not block the mirror from completing.
+        self.complete_and_wait('mirror')
+        self.vm.shutdown()
+        self.assertTrue(iotests.compare_images(test_img, target_img),
+                        'target image does not match source after mirroring')
+
+    def test_below_throttle_with_io_on_throttle(self):
+        self.mirror_command('source')
+
+        reqs = 3
+        req_len = 1 * 1024
+
+        for i in range(0, reqs):
+            req = f'aio_write -P 7 {i}M {req_len}'
+            self.vm.hmp_qemu_io(self.drive_qdev, req, qdev=True)
+
+        self.wait_ready('mirror')
+        # The throttle node above should still have in-flight requests.
+        assert self.blockstats('throttle')['wr_bytes'] <= 1 * req_len
+
+        self.complete_and_wait('mirror', wait_ready=False)
+        assert self.blockstats('throttle')['wr_bytes'] == reqs * req_len
+        self.vm.shutdown()
+        # The throttle node above is drained too when the mirror finishes, so
+        # the images should match.
+        self.assertTrue(iotests.compare_images(test_img, target_img),
+                        'target image does not match source after mirroring')
+
 class TestThrottleDriveMirror(TestThrottle):
     attachTargetImage = False
 
tests/qemu-iotests/041.out +2 -2
index 96a0752f44..ec055a9915 100644
@@ -1,5 +1,5 @@
-.............................................................................................................
+.................................................................................................................
 ----------------------------------------------------------------------
-Ran 109 tests
+Ran 113 tests
 
 OK
Signature · 1 line
2.47.3
#4 lore raw
In reply to Fiona Ebner

Ping

Am 11.06.26 um 5:35 PM schrieb Fiona Ebner:

Quoted 20 lines

The mirror block job currently only operates on a root block node. It might be desired to use a throttle node as the root node for limiting the guest IO, without also limiting mirror operations.

There is no obvious reason why mirror should only be able to operate on a root block node.

For a related discussion see here:
https://lore.kernel.org/qemu-devel/[email protected]/

Fiona Ebner (3):
iotests/041: add test for mirror with throttle node as source
blockdev: mirror: do not require a root block node iotests/041: add tests for mirroring below throttle node

 blockdev.c                 |  20 +++++-
 tests/qemu-iotests/041     | 128 +++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/041.out |   4 +-
 3 files changed, 147 insertions(+), 5 deletions(-)
#5 lore raw

Ping

Am 29.06.26 um 3:29 PM schrieb Fiona Ebner:

Quoted 27 lines

Ping

Am 11.06.26 um 5:35 PM schrieb Fiona Ebner:

Quoted 20 lines

The mirror block job currently only operates on a root block node. It might be desired to use a throttle node as the root node for limiting the guest IO, without also limiting mirror operations.

There is no obvious reason why mirror should only be able to operate on a root block node.

For a related discussion see here:
https://lore.kernel.org/qemu-devel/[email protected]/

Fiona Ebner (3):
iotests/041: add test for mirror with throttle node as source
blockdev: mirror: do not require a root block node iotests/041: add tests for mirroring below throttle node

 blockdev.c                 |  20 +++++-
 tests/qemu-iotests/041     | 128 +++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/041.out |   4 +-
 3 files changed, 147 insertions(+), 5 deletions(-)