From nobody Tue Apr 7 22:04:14 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 1773241158545951.5298737575864; Wed, 11 Mar 2026 07:59:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0L0E-0001OG-83; Wed, 11 Mar 2026 10:57:38 -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 1w0L0C-0001NE-Ot; Wed, 11 Mar 2026 10:57:36 -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 1w0L0A-0002oN-Tv; Wed, 11 Mar 2026 10:57:36 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id BC3D0874AF; Wed, 11 Mar 2026 15:57:25 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, jsnow@redhat.com, qemu-stable@nongnu.org Subject: [PATCH 1/3] block/mirror: fix assertion failure upon duplicate complete for job using 'replaces' Date: Wed, 11 Mar 2026 15:54:25 +0100 Message-ID: <20260311145717.668492-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260311145717.668492-1-f.ebner@proxmox.com> References: <20260311145717.668492-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: 1773241010274 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: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1773241160647158500 Content-Type: text/plain; charset="utf-8" If s->replace_blocker was already set by an earlier invocation of mirror_complete(), then there will be an assertion failure when error_setg() is called for it a second time. The bdrv_op_block_all() and bdrv_ref() operations should only be done a single time too. Signed-off-by: Fiona Ebner Reviewed-by: Hanna Czenczek --- block/mirror.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index fa1d975eb9..2fcded9e93 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1276,23 +1276,25 @@ static void mirror_complete(Job *job, Error **errp) return; } =20 - /* block all operations on to_replace bs */ - if (s->replaces) { - s->to_replace =3D bdrv_find_node(s->replaces); - if (!s->to_replace) { - error_setg(errp, "Node name '%s' not found", s->replaces); - return; + if (!s->should_complete) { + /* block all operations on to_replace bs */ + if (s->replaces) { + s->to_replace =3D bdrv_find_node(s->replaces); + if (!s->to_replace) { + error_setg(errp, "Node name '%s' not found", s->replaces); + return; + } + + /* TODO Translate this into child freeze system. */ + error_setg(&s->replace_blocker, + "block device is in use by block-job-complete"); + bdrv_op_block_all(s->to_replace, s->replace_blocker); + bdrv_ref(s->to_replace); } =20 - /* TODO Translate this into child freeze system. */ - error_setg(&s->replace_blocker, - "block device is in use by block-job-complete"); - bdrv_op_block_all(s->to_replace, s->replace_blocker); - bdrv_ref(s->to_replace); + s->should_complete =3D true; } =20 - s->should_complete =3D true; - /* If the job is paused, it will be re-entered when it is resumed */ WITH_JOB_LOCK_GUARD() { if (!job->paused) { --=20 2.47.3 From nobody Tue Apr 7 22:04:14 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 1773241112678809.410100925369; Wed, 11 Mar 2026 07:58:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0L0F-0001Pf-3r; Wed, 11 Mar 2026 10:57:39 -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 1w0L0D-0001NL-1A; Wed, 11 Mar 2026 10:57:37 -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 1w0L0A-0002oQ-Pz; Wed, 11 Mar 2026 10:57:36 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2837A874F9; Wed, 11 Mar 2026 15:57:26 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, jsnow@redhat.com, qemu-stable@nongnu.org Subject: [PATCH 2/3] iotests/041: add test for mirror with throttled NBD export as target Date: Wed, 11 Mar 2026 15:54:26 +0100 Message-ID: <20260311145717.668492-3-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260311145717.668492-1-f.ebner@proxmox.com> References: <20260311145717.668492-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: 1773241010367 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: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1773241116358154100 Content-Type: text/plain; charset="utf-8" Mostly in preparation for commit "iotests/041: add test for duplicate job-complete with throttled target". Signed-off-by: Fiona Ebner --- tests/qemu-iotests/041 | 112 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/041.out | 4 +- 2 files changed, 113 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 8452845f44..a7e1980f13 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -24,7 +24,7 @@ import os import re import json import iotests -from iotests import qemu_img, qemu_img_map, qemu_io +from iotests import qemu_img, qemu_img_map, qemu_io, QemuStorageDaemon =20 backing_img =3D os.path.join(iotests.test_dir, 'backing.img') target_backing_img =3D os.path.join(iotests.test_dir, 'target-backing.img') @@ -1373,6 +1373,116 @@ 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 3 * 1024 * 1024 + bps_total =3D 1 * 1024 * 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', 'write -P 23 0 3M', test_img) + + self.qsd =3D QemuStorageDaemon('--nbd-server', + f'addr.type=3Dunix,addr.path=3D{nbd_s= ock_path}', + qmp=3DTrue) + + self.qsd.cmd('object-add', { + 'qom-type': 'throttle-group', + 'id': 'thrgr-target', + 'limits': { + 'bps-total': self.bps_total, + } + }) + + self.qsd.cmd('blockdev-add', { + 'node-name': 'target', + 'driver': 'throttle', + 'throttle-group': 'thrgr-target', + 'file': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + } + } + }) + + self.qsd.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 + } + }) + + def tearDown(self): + 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') + + time.sleep(1) + result =3D self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/ready', False) + self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000}') + time.sleep(1) # in real time, the rest should now comlpete fast + result =3D self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/ready', True) + + self.complete_and_wait('mirror') + self.vm.shutdown() + self.qsd.stop() + 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 From nobody Tue Apr 7 22:04:14 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 1773241078698457.6586680130092; Wed, 11 Mar 2026 07:57:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0L0I-0001R2-4V; Wed, 11 Mar 2026 10:57:42 -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 1w0L0D-0001Nr-Vh; Wed, 11 Mar 2026 10:57:37 -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 1w0L0A-0002oP-UY; Wed, 11 Mar 2026 10:57:37 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0610C874F4; Wed, 11 Mar 2026 15:57:26 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, jsnow@redhat.com, qemu-stable@nongnu.org Subject: [PATCH 3/3] iotests/041: add test for duplicate job-complete with throttled target Date: Wed, 11 Mar 2026 15:54:27 +0100 Message-ID: <20260311145717.668492-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260311145717.668492-1-f.ebner@proxmox.com> References: <20260311145717.668492-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: 1773241010444 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: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1773241081160158500 Content-Type: text/plain; charset="utf-8" This would fail without commit "block/mirror: fix assertion failure upon duplicate complete for job using 'replaces'". Signed-off-by: Fiona Ebner --- tests/qemu-iotests/041 | 41 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index a7e1980f13..a09fdd4ad6 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1456,6 +1456,8 @@ class TestThrottledNBDTarget(iotests.QMPTestCase): } }) =20 + self.drive_qdev =3D '/machine/peripheral/virtio' + def tearDown(self): os.remove(test_img) os.remove(target_img) @@ -1483,6 +1485,45 @@ class TestThrottledNBDTarget(iotests.QMPTestCase): self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirrorin= g') =20 + def test_duplicate_complete_with_replaces(self): + self.qsd.cmd('qom-set', { + 'path': 'thrgr-target', + 'property': 'limits', + 'value' : {}, + }) + + self.vm.cmd('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + replaces=3D'source', + sync=3D'full') + self.wait_ready(drive=3D'mirror') + + self.qsd.cmd('qom-set', { + 'path': 'thrgr-target', + 'property': 'limits', + 'value' : { + 'bps-total': self.bps_total, + } + }) + + self.vm.hmp_qemu_io(self.drive_qdev, 'aio_write -P 7 0 1M', qdev= =3DTrue) + self.vm.hmp_qemu_io(self.drive_qdev, 'aio_write -P 7 1M 1M', qdev= =3DTrue) + self.vm.hmp_qemu_io(self.drive_qdev, 'aio_write -P 7 2M 1M', qdev= =3DTrue) + + self.vm.cmd('job-complete', id=3D'mirror') + # The fact that the target is externally throttled ensures that th= e job + # won't be finished yet when the second command is issued. + self.vm.cmd('job-complete', id=3D'mirror') + + self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000}') + self.wait_until_completed('mirror') + + self.vm.shutdown() + self.qsd.stop() + 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 5273ce86c3..96a0752f44 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= .................................. +..........................................................................= ................................... ---------------------------------------------------------------------- -Ran 108 tests +Ran 109 tests =20 OK --=20 2.47.3