From nobody Fri Apr 3 03:01:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774437169821119.01825837460626; Wed, 25 Mar 2026 04:12:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5M9j-0002RQ-4y; Wed, 25 Mar 2026 07:12:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5M9R-0002Mg-VI; Wed, 25 Mar 2026 07:11:54 -0400 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5M9O-0003Ob-UM; Wed, 25 Mar 2026 07:11:53 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CCD7F49019; Wed, 25 Mar 2026 12:11:48 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com Subject: [PATCH v3 1/2] iotests/041: add test for mirror with throttled NBD export as target Date: Wed, 25 Mar 2026 12:11:03 +0100 Message-ID: <20260325111140.347421-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260325111140.347421-1-f.ebner@proxmox.com> References: <20260325111140.347421-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774437060106 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1774437173374154100 Content-Type: text/plain; charset="utf-8" Mostly in preparation for commit "iotests/041: add test for duplicate job-complete with throttled target". Use a second VM instance for providing the NBD export rather than qemu-storage-daemon, because the latter does not support qtest for stepping the clock. Use copy_mode=3D'write-blocking' for easy checking how many bytes were written in a given time. In the job's offset, the numbers are inflated, since a 1 KiB write will mean copying a full cluster of 64 KiB. Signed-off-by: Fiona Ebner --- Changes in v3: * In the first test, avoid testing that all requests complete in a given time. This is prone to flakiness. Instead, complete the job under throttle. tests/qemu-iotests/041 | 146 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- 2 files changed, 148 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 8452845f44..976a12a6f2 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1373,6 +1373,152 @@ class TestFilters(iotests.QMPTestCase): =20 self.complete_and_wait('mirror') =20 +# Tests for mirror where the target is a throttled NBD export. +class TestThrottledNBDTarget(iotests.QMPTestCase): + image_len =3D 32 * 1024 * 1024 + reqs =3D 20 + req_len =3D 1024 + + def setUp(self): + iotests.create_image(backing_img, self.image_len) + iotests.create_image(target_backing_img, self.image_len) + qemu_img('create', '-f', iotests.imgfmt, + '-o', f'backing_file=3D{backing_img}', '-F', 'raw', test_= img) + qemu_img('create', '-f', iotests.imgfmt, + '-o', f'backing_file=3D{target_backing_img}', '-F', 'raw', + target_img) + qemu_io('-c', f'write -P 23 0 {self.image_len}', test_img) + + self.target_vm =3D iotests.VM() + self.target_vm.launch() + + self.target_vm.cmd('nbd-server-start', { + 'addr': { + 'type': 'unix', + 'data': { + 'path': nbd_sock_path + } + } + }) + + self.target_vm.cmd('object-add', { + 'qom-type': 'throttle-group', + 'id': 'thrgr-target', + 'limits': {} # limits are set by the individual tests + }) + + self.target_vm.cmd('blockdev-add', { + 'node-name': 'target', + 'driver': 'throttle', + 'throttle-group': 'thrgr-target', + 'file': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + } + } + }) + + self.target_vm.cmd('block-export-add', { + 'id': 'exp0', + 'type': 'nbd', + 'node-name': 'target', + 'writable': True + }) + + self.vm =3D iotests.VM().add_device('virtio-scsi,id=3Dvio-scsi') + self.vm.launch() + + self.vm.cmd('blockdev-add',{ + 'node-name': 'source', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + }, + 'backing': { + 'node-name': 'backing', + 'driver': 'raw', + 'file': { + 'driver': 'file', + 'filename': backing_img + } + } + }) + + self.vm.cmd('device_add', + driver=3D'scsi-hd', + id=3D'virtio', + bus=3D'vio-scsi.0', + drive=3D'source') + + self.vm.cmd('blockdev-add', { + 'node-name': 'target', + 'driver': 'nbd', + 'export': 'target', + 'server': { + 'type': 'unix', + 'path': nbd_sock_path + } + }) + + self.drive_qdev =3D '/machine/peripheral/virtio' + + def set_throttle_limits(self, limits): + self.target_vm.cmd('qom-set', { + 'path': 'thrgr-target', + 'property': 'limits', + 'value': limits + }) + + def disable_throttling(self): + if self.target_vm.is_running(): + self.set_throttle_limits({}) + for i in range(0, self.reqs): + self.target_vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}= ') + + def tearDown(self): + if self.target_vm.is_running(): + self.disable_throttling() + self.target_vm.shutdown() + self.vm.shutdown() + os.remove(test_img) + os.remove(target_img) + os.remove(backing_img) + os.remove(target_backing_img) + + def test_throttled(self): + self.vm.cmd('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'full', + copy_mode=3D'write-blocking') + + self.wait_ready('mirror') + + self.set_throttle_limits({'iops-write': 1}) + + # Issue requests that will be throttled. + for i in range(0, self.reqs): + req =3D f'aio_write -P 7 {i}M {self.req_len}' + self.vm.hmp_qemu_io(self.drive_qdev, req, qdev=3DTrue) + + # Check that requests do not complete faster than 1 per second. Th= ey + # might complete in batches, so do not check for exactly 1 per sec= ond. + for i in range(0, self.reqs): + result =3D self.vm.cmd('query-blockstats') + assert result[0]['stats']['wr_bytes'] <=3D (i + 1) * self.req_= len + + self.target_vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}') + time.sleep(0.1) + + self.complete_and_wait('mirror', wait_ready=3DFalse) + self.target_vm.shutdown() + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirrorin= g') =20 if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed'], diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 46651953e8..5273ce86c3 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= ................................. +..........................................................................= .................................. ---------------------------------------------------------------------- -Ran 107 tests +Ran 108 tests =20 OK --=20 2.47.3