From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678168; cv=none; d=zohomail.com; s=zohoarc; b=NguZkKSdw6qxvrj4JFwuaZXdpP1Biuks6cQmlCIRvaSaXj0ioMtc9qWWL6nZfgS/ZC1Pp+SckfoG8yhxzigPrwpO0GV9MXFcyMCxlCGrxFvzLzJaKQT27Min/Q5P2i0jXDx2lWG9NNKrlZp2Twaa709wyqlRA4RXX0zb6rkTmwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678168; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IdGlJ5aAnq5HiG34FmseUzWZxekA1HiqPUXkJgfeAmo=; b=GSP3GSGTxUYIbE/W8+rm5+Si+WsIoM734Q7H+AwuwQ5Xdo7YMttgZVDvximqOGJ1PxsTB29rjmqeOr3Np+Hd/KsGcq/ylGIE462Hag5KljJrz0AaF5dLIvlF1l6Qm/3iUsA37e6xt8N2eFPvOjV/HcbtjPw7qXv/6TMN47jN3gs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678168760947.5851404172486; Mon, 2 Nov 2026 19:56:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cH-0006Lz-4X; Mon, 02 Nov 2026 22:55:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cF-0006LA-So for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cE-0000ZW-7G for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:19 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-262-v82xfX6fOBeP2WVQpDyZNA-1; Mon, 02 Nov 2026 22:55:14 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 48ABF1955F27; Tue, 3 Nov 2026 03:55:13 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0AE127E5; Tue, 3 Nov 2026 03:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IdGlJ5aAnq5HiG34FmseUzWZxekA1HiqPUXkJgfeAmo=; b=SRlVCF6so3bUvTWF+8BW2SFb3F332TDWZQ6s2q3tw9ldHs8B86Pg9PtnmuQCHeobwc+tkv u9+qxV1ujmSBoUBO589DcNHExnymmqNtK7OdZoFMhr2d9Zuo9GfCnobFjjvqMYzEiID1ta uww2YY7SUSnpFtzeZEXhkJaNnYh6bHM= X-MC-Unique: v82xfX6fOBeP2WVQpDyZNA-1 X-Mimecast-MFC-AGG-ID: v82xfX6fOBeP2WVQpDyZNA_1793678113 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 01/16] block: notify the parent when a replaced child has a different size Date: Mon, 2 Nov 2026 21:54:12 -0600 Message-ID: <20261103035506.2688772-19-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678170764158500 From: "Denis V. Lunev" bdrv_replace_child_bs() swaps the node a BdrvChild points to without telling the parent anything about it, so a parent which tracks the size of its child never learns that it changed. Every other way the size of a node changes goes through bdrv_co_truncate(), which does notify. The device models which care all register the same BlockDevOps hook: virtio-blk resize_cb =3D virtio_blk_resize(), ending up in virtio_notify_config() ide/ahci resize_cb =3D ide_resize_cb(), refreshing the cached size and the IDENTIFY data scsi-disk resize_cb =3D scsi_disk_resize_cb(), reporting CAPACITY DATA HAS CHANGED xen-block resize_cb =3D xen_block_resize_cb() Only scsi-disk is really hurt by the missing notification, because it is the one which validates guest requests against a cached size. virtio_blk_sect_range_ok() and ide_sect_range_ok() both call blk_get_geometry() for every request, so a missing notification leaves those guests with a stale idea of the size but never refuses I/O which the node underneath can serve. check_lba_range() compares against SCSIDevice.max_lba, filled in by scsi_disk_reset() and updated only by the READ CAPACITY(10) and (16) handlers, so with nothing to make the guest re-read the capacity every request past the end of the old node is refused for the whole life of the device. This is reachable with qom-set of the 'drive' property, which is allowed on a realized device, and it is silent on the host: out-of-range requests are answered by scsi_check_condition() and never reach scsi_handle_rw_error(), so there is no BLOCK_IO_ERROR event and io-status stays 'ok'. The guest sees ILLEGAL REQUEST / LOGICAL BLOCK ADDRESS OUT OF RANGE, which Linux turns into EREMOTEIO for reads as well as writes. Emit the notification from bdrv_replace_child_bs(), so that every device model gets it through the path it already implements rather than any of them being special cased. Send it only when the size really changed, which keeps the callback out of the common case of a replacement by an equally sized node. Signed-off-by: Denis V. Lunev Message-ID: <20260812121500.1034178-2-den@openvz.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Eric Blake --- include/block/block_int-io.h | 3 +++ block.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index ed8b5657d6a..95d0dd7a05f 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -197,4 +197,7 @@ void bdrv_bsc_fill(BlockDriverState *bs, int64_t offset= , int64_t bytes); void coroutine_fn GRAPH_RDLOCK bdrv_co_parent_cb_resize(BlockDriverState *bs); +void co_wrapper_bdrv_rdlock +bdrv_parent_cb_resize(BlockDriverState *bs); + #endif /* BLOCK_INT_IO_H */ diff --git a/block.c b/block.c index e72268db8d9..9b60831137b 100644 --- a/block.c +++ b/block.c @@ -5547,9 +5547,12 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDri= verState *new_bs, Transaction *tran =3D tran_new(); g_autoptr(GSList) refresh_list =3D NULL; BlockDriverState *old_bs =3D child->bs; + int64_t old_len; GLOBAL_STATE_CODE(); + old_len =3D bdrv_getlength(old_bs); + bdrv_ref(old_bs); bdrv_drained_begin(old_bs); bdrv_drained_begin(new_bs); @@ -5565,6 +5568,16 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDri= verState *new_bs, tran_finalize(tran, ret); bdrv_graph_wrunlock(); + + /* A parent caching the child size has to learn that it changed */ + if (ret =3D=3D 0) { + int64_t new_len =3D bdrv_getlength(new_bs); + + if (new_len >=3D 0 && new_len !=3D old_len) { + bdrv_parent_cb_resize(new_bs); + } + } + bdrv_drained_end(old_bs); bdrv_drained_end(new_bs); bdrv_unref(old_bs); --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678192; cv=none; d=zohomail.com; s=zohoarc; b=nl8BNXp6QSFBfmcMVnQL4vr8WRSEnrxbDp4OaliNwt6ChAegRQluThfw0KJ1ir+bI/pth9UX9NtQC9IcIfS4TFFp1D88Li60No1IGCNzcbunPn4az8yIrffeFEs2j60HIvpwk42PnnCdJMNC30iAs10q2mTLZKL0JEU1xyglE70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678192; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ws45s9ALQiZnFe7ikPfCPiZoWwRG0FJMRtCKQwmrToQ=; b=Ak8dj1QR6BlNmtwk3+d1HqBFXS8VWLosaZDBbo7P4QA9/8roBq2wFewTiMYMSsIKKxTckjH3qyyhGzeIPiwY/Lg4VzbDNCarQPIjsGtJyiLlYUi43NokGSJSzn0KknEiL3754Skx4ZZ1gXMfP9ciRScMufYkuLX0wXXjFyciVes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678192273604.9658933094844; Mon, 2 Nov 2026 19:56:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cK-0006N8-Nw; Mon, 02 Nov 2026 22:55:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cI-0006M8-7Z for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cG-0000Zt-LD for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:21 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-5---gLq6IcMG-ZKHvs4z9I_w-1; Mon, 02 Nov 2026 22:55:16 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0C4571800471; Tue, 3 Nov 2026 03:55:15 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9A5157E8; Tue, 3 Nov 2026 03:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678119; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ws45s9ALQiZnFe7ikPfCPiZoWwRG0FJMRtCKQwmrToQ=; b=Kd2oqvgU5jIKue/shy/yRMzf856wqmK4vLKTLKyYEs1S2ICWLItmSH3mKfbCAyX2nx5fLQ 3rjjvwVyDO2ZOfYGNC09U1Uasjczam2dDv6GRLN98pRnxHPSTula/FqORsfb2QLtwt7qqR sGWM/a3Chm9vX0rkvfcVu9Z2IqNG3jQ= X-MC-Unique: --gLq6IcMG-ZKHvs4z9I_w-1 X-Mimecast-MFC-AGG-ID: --gLq6IcMG-ZKHvs4z9I_w_1793678115 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Fam Zheng Subject: [PULL 02/16] scsi-disk: refresh the cached capacity from the resize callback Date: Mon, 2 Nov 2026 21:54:13 -0600 Message-ID: <20261103035506.2688772-20-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678193218158500 From: "Denis V. Lunev" scsi_disk_resize_cb() reports CAPACITY DATA HAS CHANGED but leaves SCSIDevice.max_lba alone, and max_lba is what check_lba_range() compares every request against. Until the guest reacts to the unit attention and issues READ CAPACITY, requests beyond the old size keep being refused with LOGICAL BLOCK ADDRESS OUT OF RANGE, and a guest which never re-reads the capacity never recovers at all. A guest migrated onto a device whose size changed underneath it is exactly such a guest. ide_resize_cb() refreshes its cached size along with the IDENTIFY data it reports to the guest. Do the same here, so that the notification is what tells the guest about the new capacity rather than what unblocks the device. Factor the computation out of scsi_disk_reset(), which already had it. Signed-off-by: Denis V. Lunev Message-ID: <20260812121500.1034178-3-den@openvz.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Eric Blake --- hw/scsi/scsi-disk.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 6341089ddf2..de2b6d85da8 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2398,13 +2398,10 @@ static int32_t scsi_disk_dma_command(SCSIRequest *r= eq, uint8_t *buf) } } -static void scsi_disk_reset(DeviceState *dev) +static void scsi_disk_refresh_max_lba(SCSIDiskState *s) { - SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev.qdev, dev); uint64_t nb_sectors; - scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET)); - blk_get_geometry(s->qdev.conf.blk, &nb_sectors); nb_sectors /=3D s->qdev.blocksize / BDRV_SECTOR_SIZE; @@ -2412,6 +2409,15 @@ static void scsi_disk_reset(DeviceState *dev) nb_sectors--; } s->qdev.max_lba =3D nb_sectors; +} + +static void scsi_disk_reset(DeviceState *dev) +{ + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev.qdev, dev); + + scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET)); + + scsi_disk_refresh_max_lba(s); /* reset tray statuses */ s->tray_locked =3D 0; s->tray_open =3D 0; @@ -2437,6 +2443,8 @@ static void scsi_disk_resize_cb(void *opaque) { SCSIDiskState *s =3D opaque; + scsi_disk_refresh_max_lba(s); + /* SPC lists this sense code as available only for * direct-access devices. */ --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678143; cv=none; d=zohomail.com; s=zohoarc; b=oFvUxadE9BfFNwxbIJBB5R63lTDpsnS2xWNqBGLc7Y+NENrE4Lqjg5AexywuNs2udMY7k+GhTYPye5GVZZyzstwrp1OisKEFxK/pd5pMY+NqBNViRo76RoX0ly5zV+lYGdPSTXLx50zej1OjJbqtIE4aZyoBi6JesB86Y4IVAhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678143; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UW3eAHIVbNg3x5s+iHlq9p1VjyqRHEnAy06IQicSRoE=; b=mMBRuDItvvuwgZO8cUgy8cpOLy65QjYBVygePmvspjwZ2QKeUPxIJiMPgQDpNRPNlN8F9b9WbMXhK6kLfSQ8X/dKt7mS3sQQjJyRHA5mJg0IGWKno8byIcdEgUCJr2Us6cq47cmLSFCy47HAorSt5MpsS9qR7LlFtaj53mam1XU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678143173197.64822667033695; Mon, 2 Nov 2026 19:55:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cM-0006OF-RZ; Mon, 02 Nov 2026 22:55:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cK-0006N6-Fd for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cI-0000a8-Sg for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:24 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-RtR-wQCNO6Ozn9skfB5QEA-1; Mon, 02 Nov 2026 22:55:18 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 443661800760; Tue, 3 Nov 2026 03:55:17 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8D9067E2; Tue, 3 Nov 2026 03:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UW3eAHIVbNg3x5s+iHlq9p1VjyqRHEnAy06IQicSRoE=; b=L5jzKzwdKW200CruoHrvVoRFYRJhumB/mO5oeij7UjUSJtQYvA4nAnYbbl4zD23pWAH2B/ VPqx8W+Z14GwSSOEhoco5bhc1DYgOsXGMKs6F4tVXWuodsB1l98DVjiMEZKGWlzjT+mfW9 An9p+36x5YdsUhBo134Zee536P6wYs4= X-MC-Unique: RtR-wQCNO6Ozn9skfB5QEA-1 X-Mimecast-MFC-AGG-ID: RtR-wQCNO6Ozn9skfB5QEA_1793678117 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Fam Zheng , Fabiano Rosas , Laurent Vivier Subject: [PULL 03/16] tests/qtest/virtio-scsi: cover a replacement that changes the size Date: Mon, 2 Nov 2026 21:54:14 -0600 Message-ID: <20261103035506.2688772-21-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678146615158500 From: "Denis V. Lunev" Realize a scsi-hd on a 1 MiB node, replace it with a 128 MiB one using qom-set, and check that the device reports CAPACITY DATA HAS CHANGED and then serves a read which only fits in the new node. Both halves regress on their own. Without the notification from bdrv_replace_child_bs() the first command after the replacement fails with ILLEGAL REQUEST / LOGICAL BLOCK ADDRESS OUT OF RANGE instead of the unit attention. Without the refresh in scsi_disk_resize_cb() the read after it is refused the same way, since nothing here issues READ CAPACITY. Signed-off-by: Denis V. Lunev Message-ID: <20260812121500.1034178-4-den@openvz.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Eric Blake --- tests/qtest/virtio-scsi-test.c | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c index e2350c52f6f..f82b7e5de9c 100644 --- a/tests/qtest/virtio-scsi-test.c +++ b/tests/qtest/virtio-scsi-test.c @@ -236,6 +236,53 @@ static void test_unmap_large_lba(void *obj, void *data, qvirtio_scsi_pci_free(vs); } +/* Test replacing the backing node with one of a different size */ +static void test_replaced_node_size(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QVirtioSCSI *scsi =3D obj; + QVirtioSCSIQueues *vs; + uint8_t buf[512] =3D { 0 }; + /* READ(10), LBA 0, transfer length 1 */ + const uint8_t read_low_cdb[VIRTIO_SCSI_CDB_SIZE] =3D { + 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 + }; + /* READ(10), LBA 0x1000 (2 MiB), transfer length 1 */ + const uint8_t read_high_cdb[VIRTIO_SCSI_CDB_SIZE] =3D { + 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00 + }; + struct virtio_scsi_cmd_resp resp; + + alloc =3D t_alloc; + vs =3D qvirtio_scsi_init(scsi->vdev); + + /* LBA 0 is inside the 1 MiB node the device was realized with */ + virtio_scsi_do_command(vs, read_low_cdb, buf, sizeof(buf), NULL, 0, &r= esp); + g_assert_cmphex(resp.response, =3D=3D, 0); + g_assert_cmphex(resp.status, =3D=3D, GOOD); + + /* Swap in a 128 MiB node; the device is not reset by this */ + qtest_qmp_assert_success(global_qtest, + "{'execute': 'qom-set', 'arguments': {" + " 'path': '/machine/peripheral/scsi-hd0'," + " 'property': 'drive', 'value': 'big'}}"); + + /* The guest has to be told that the capacity it knows is stale */ + virtio_scsi_do_command(vs, read_high_cdb, buf, sizeof(buf), NULL, 0, &= resp); + g_assert_cmphex(resp.response, =3D=3D, 0); + g_assert_cmphex(resp.status, =3D=3D, CHECK_CONDITION); + g_assert_cmphex(resp.sense[2], =3D=3D, UNIT_ATTENTION); + g_assert_cmphex(resp.sense[12], =3D=3D, 0x2a); + g_assert_cmphex(resp.sense[13], =3D=3D, 0x09); /* CAPACITY DATA HAS CH= ANGED */ + + /* LBA 0x1000 is past the old node but well inside the new one */ + virtio_scsi_do_command(vs, read_high_cdb, buf, sizeof(buf), NULL, 0, &= resp); + g_assert_cmphex(resp.response, =3D=3D, 0); + g_assert_cmphex(resp.status, =3D=3D, GOOD); + + qvirtio_scsi_pci_free(vs); +} + static void test_write_to_cdrom(void *obj, void *data, QGuestAllocator *t_alloc) { @@ -365,6 +412,18 @@ static void *virtio_scsi_setup_4k(GString *cmd_line, v= oid *arg) return arg; } +static void *virtio_scsi_setup_replace(GString *cmd_line, void *arg) +{ + g_string_append(cmd_line, + " -blockdev driver=3Dnull-co,read-zeroes=3Don," + "size=3D1048576,node-name=3Dsmall" + " -blockdev driver=3Dnull-co,read-zeroes=3Don," + "size=3D134217728,node-name=3Dbig" + " -device scsi-hd,id=3Dscsi-hd0,drive=3Dsmall," + "lun=3D0,scsi-id=3D1"); + return arg; +} + static void *virtio_scsi_setup_cd(GString *cmd_line, void *arg) { g_string_append(cmd_line, @@ -399,6 +458,10 @@ static void register_virtio_scsi_test(void) qos_add_test("large-lba-unmap", "virtio-scsi", test_unmap_large_lba, &opts); + opts.before =3D virtio_scsi_setup_replace; + qos_add_test("replaced-node-size", "virtio-scsi", + test_replaced_node_size, &opts); + opts.before =3D virtio_scsi_setup_cd; qos_add_test("write-to-cdrom", "virtio-scsi", test_write_to_cdrom, &op= ts); --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678243; cv=none; d=zohomail.com; s=zohoarc; b=Po1hRH0ujvi8jT38ziW9WTIRDy9fBgD26SA1yaqP0D+eXWfY+rAEiHBW8ad6hDgXN/xOFAnxAXJe24YrYUgmMKnz28NfWk4zWUVjjd2bZ9/EGvP0lLuMbOn+DM4yWy2WEjlBzS4lZK7CzdrB/EfFYS0aJNGhPd/TL2UyNAZGZPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678243; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kBSdWXyr2z5Qa5bk8zHw/mmsn+OzV2/YeeQlS+BdwYU=; b=nZ7khSz4HjLwMFuT2ysORd3VyfJTdz7osI4iYO1tR7amT9osu42zF0ixCeMi7mqlCHK9fZHdXGo2NtpAlssqIQ9J01nySjFy3h2RYi5nVwZkWk/ouMa9t0nGYwqBFrGePfpKHSVDojKK3OjVp/A+5/lqIocudKpAuR8RVihuwBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678243905609.0611313755791; Mon, 2 Nov 2026 19:57:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cN-0006OI-GK; Mon, 02 Nov 2026 22:55:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cM-0006Nk-0t for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cK-0000aO-96 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:25 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-cNg6cYD-PmyaQhZuxSADcQ-1; Mon, 02 Nov 2026 22:55:20 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C9D7E1800758; Tue, 3 Nov 2026 03:55:18 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 96A287E2; Tue, 3 Nov 2026 03:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kBSdWXyr2z5Qa5bk8zHw/mmsn+OzV2/YeeQlS+BdwYU=; b=VbcGNzuZz3v/w/kQ9wIzlFAy1Soo+8Wxds4tiyNI48DLo1pwPMiD8gEo0tM27KVKaEbsyz A8MACrh49U6BrYNpid9UaRKj4UGwwSPJQfCzsO2Y24TDbHOA0PZpCmky4xkOt5Lz6IYEXO T9isybzqA2FnsK5g137rvuKEVP+kBJQ= X-MC-Unique: cNg6cYD-PmyaQhZuxSADcQ-1 X-Mimecast-MFC-AGG-ID: cNg6cYD-PmyaQhZuxSADcQ_1793678119 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 04/16] tests/qemu-iotests/qom-set-drive: replace with a differently sized node Date: Mon, 2 Nov 2026 21:54:15 -0600 Message-ID: <20261103035506.2688772-22-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678244252158500 From: "Denis V. Lunev" All images in this test have the same size, so the test never reaches the size change path of bdrv_replace_child_bs(). Add a node of a different size and point a device at it. The notification itself is not visible over QMP, so this only covers the block layer side. What the device does with it is checked by tests/qtest/virtio-scsi-test.c. Signed-off-by: Denis V. Lunev Message-ID: <20260812121500.1034178-5-den@openvz.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Eric Blake --- tests/qemu-iotests/tests/qom-set-drive | 14 +++++++++++--- tests/qemu-iotests/tests/qom-set-drive.out | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/tests/qom-set-drive b/tests/qemu-iotests/te= sts/qom-set-drive index ec8ddac4fdd..52d7eb96da8 100755 --- a/tests/qemu-iotests/tests/qom-set-drive +++ b/tests/qemu-iotests/tests/qom-set-drive @@ -24,12 +24,15 @@ import iotests from iotests import imgfmt, log, qemu_img_create, QMPTestCase image_size =3D 1 * 1024 * 1024 -images =3D [os.path.join(iotests.test_dir, f'{i}.img') for i in range(0, 4= )] +images =3D [os.path.join(iotests.test_dir, f'{i}.img') for i in range(0, 5= )] + +# node4 is deliberately larger, to cover a replacement which changes the s= ize +image_sizes =3D [image_size] * 4 + [2 * image_size] class TestQOMSetDrive(QMPTestCase): def setUp(self) -> None: - for image in images: - qemu_img_create('-f', imgfmt, image, str(image_size)) + for image, size in zip(images, image_sizes): + qemu_img_create('-f', imgfmt, image, str(size)) self.vm =3D iotests.VM() for i, image in enumerate(images): @@ -68,6 +71,11 @@ class TestQOMSetDrive(QMPTestCase): log(self.vm.qmp('qom-get', path=3D'/machine/peripheral/no-iot', property=3D'drive')) + log(self.vm.qmp('qom-set', path=3D'/machine/peripheral/no-iot', + property=3D'drive', value=3D'node4')) + log(self.vm.qmp('qom-get', path=3D'/machine/peripheral/no-iot', + property=3D'drive')) + if __name__ =3D=3D '__main__': iotests.activate_logging() # LUKS would require special key-secret handling in add_blockdevs() diff --git a/tests/qemu-iotests/tests/qom-set-drive.out b/tests/qemu-iotest= s/tests/qom-set-drive.out index 7fc243dca6c..6f6e5e2b31c 100644 --- a/tests/qemu-iotests/tests/qom-set-drive.out +++ b/tests/qemu-iotests/tests/qom-set-drive.out @@ -4,6 +4,8 @@ {"return": "node1"} {"return": {}} {"return": "node3"} +{"return": {}} +{"return": "node4"} . ---------------------------------------------------------------------- Ran 1 tests --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678173; cv=none; d=zohomail.com; s=zohoarc; b=fUOdoeG4ZIjz1G/TMzsxQ3Oe9D/4/Jz8MyxfhfAqu2rNvOgHROOaeeXPZxTTRrVUWHuA+2bx06PXq3x3t+y91S7LZXveLqVwUJAAVjqMbGEkyEiYF9TXE9ailFv3T8s8LM42llFbqmrvQvL+Kmm42oHmggFUoiDnMkAvD/bgD0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678173; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w78tCYP68rMTuwxkj9MuJeTlekv5AnqHLoZ8SbWDuvQ=; b=KB300yfqmIkda9SYxAkTF52XLdx2cXW7RBY4iCri6e9ecoMakQl3R87sC+Q936RHCwEZGUlcKB97ePwYe9EUAzSYSD/80kdcuJCTg1rhH8L7sy045ghiFukhb00N3leYREkXlG88WwZftKbRMzLAxYH79CfCaOlRLR66NGIAioA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678173957421.09496408665575; Mon, 2 Nov 2026 19:56:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cS-0006QO-F7; Mon, 02 Nov 2026 22:55:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cQ-0006PB-3Y for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cN-0000az-LU for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:29 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-9HIMX7NlMzSc-TCeBxS-zg-1; Mon, 02 Nov 2026 22:55:22 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4D9531800758; Tue, 3 Nov 2026 03:55:21 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6F57D7E2; Tue, 3 Nov 2026 03:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w78tCYP68rMTuwxkj9MuJeTlekv5AnqHLoZ8SbWDuvQ=; b=GRwXDJsFv2qNe0VxDeUGZwO30sIPqCQ6/7a6bTIMTPtNy2XExVLrDlbVv8UVDoQmAbRUNJ C7gJmZvUKN67I/EbM0lPml536/vOgO/wu2Mz81/QSRuG3zfBatlvUeU51gm9XTRt8z3z2C VMjNojeUFXvkDAu+AAS7A2FMtlnrisA= X-MC-Unique: 9HIMX7NlMzSc-TCeBxS-zg-1 X-Mimecast-MFC-AGG-ID: 9HIMX7NlMzSc-TCeBxS-zg_1793678121 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 05/16] block/commit: pass BDRV_WANT_PRECISE to block-status Date: Mon, 2 Nov 2026 21:54:16 -0600 Message-ID: <20261103035506.2688772-23-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678174903158501 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" c33159dec790 replaced the want_zero bool with a bitmask of BDRV_WANT_* flags. block/commit.c was missed and still passes "true", which is BDRV_BLOCK_DATA, not BDRV_WANT_PRECISE. Convert it like the other callers. Fixes: c33159dec790 ("block: Expand block status mode from bool to flags") Reviewed-by: Andrey Drobyshev Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev CC: Eric Blake Message-ID: <20261030010613.1612771-2-den@openvz.org> Signed-off-by: Eric Blake --- block/commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/commit.c b/block/commit.c index 2d52c39594c..4e0b0f9029b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -140,8 +140,8 @@ commit_iteration(CommitBlockJob *s, int64_t offset, /* Copy if allocated above the base */ WITH_GRAPH_RDLOCK_GUARD() { ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), - s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE, - &bytes, NULL, NULL, NULL); + s->base_overlay, true, BDRV_WANT_PRECISE, offset, + COMMIT_BUFFER_SIZE, &bytes, NULL, NULL, NULL); } trace_commit_one_iteration(s, offset, bytes, ret); --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678234; cv=none; d=zohomail.com; s=zohoarc; b=h/+LkBiGmecYc3+1wTZOaMnKGud3LYm97mhAejQMOqVULzNF/DrjeEqMTEnN6+F0zwQjUAKghYybT0WVnzWW7bjgQuFdCyb/GQgAuG2K7Lgj6mJTQOi4QwHpEFJmbOcceWk3DCvtRSiDhhVZOqhs8q3TPXkBdDKT++uo3rwijJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678234; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w46zRlPYmZtu6PckmhIkKlhVU77eOMnlyzNZpnwauWk=; b=Wz71GG7TPCxt4AY/NEmO0M0nn8GXhnJUIfnyBaWUfs3Wtvhms03mqLkBssjNuL0MSbvxhUdJikrYLmwzoSOirbY2cdLyowQW169LqsM27GplzLvdQ4XIfmWmhv+eZ51j3Avi/R4fH4Lp3IYAc7VpEasaK99Sa5JW+Oj7aC4GyCc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678234171780.3702694939949; Mon, 2 Nov 2026 19:57:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cQ-0006PK-N8; Mon, 02 Nov 2026 22:55:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cO-0006Om-Sw for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cN-0000at-3D for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:28 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-4jZqCJITNF6b6cjosy7hbg-1; Mon, 02 Nov 2026 22:55:24 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 55BAE1956049; Tue, 3 Nov 2026 03:55:23 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A49037E5; Tue, 3 Nov 2026 03:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w46zRlPYmZtu6PckmhIkKlhVU77eOMnlyzNZpnwauWk=; b=imchHksj1WvkveyFeJkHtLAox/sH1j/MvGt8tqgSiepszGlGcG4VUl8ab7GI52m9xpZpFC 0Fn1SokYf1VzXBuJGt6ss1FQp8l000SThA/2+gbaEVrKQZqIjxwykebkn1W8Jmn1ZJaB9n WoDa1a977R3uPHWOm7XsEP4lem3+okE= X-MC-Unique: 4jZqCJITNF6b6cjosy7hbg-1 X-Mimecast-MFC-AGG-ID: 4jZqCJITNF6b6cjosy7hbg_1793678123 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 06/16] iotests/040: cover large and fragmented commit runs Date: Mon, 2 Nov 2026 21:54:17 -0600 Message-ID: <20261103035506.2688772-24-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678236163158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" 040 never commits runs long enough to span more than one block-status query, so the answer that commit_iteration() is about to start caching goes untested. Add two cases on a base <- mid <- active chain, committing mid so the job takes the regular commit path rather than active commit, and compare base against a snapshot of mid taken before the commit. One case mixes multi-megabyte data, zero and hole runs, the other fragments them down to single clusters with every transition off the 512K boundary. Reviewed-by: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-3-den@openvz.org> Signed-off-by: Eric Blake --- tests/qemu-iotests/040 | 102 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/040.out | 4 +- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index 5c18e413ec9..e01c9385bae 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -25,13 +25,14 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_create, qemu_io, compare_images import struct import errno backing_img =3D os.path.join(iotests.test_dir, 'backing.img') mid_img =3D os.path.join(iotests.test_dir, 'mid.img') test_img =3D os.path.join(iotests.test_dir, 'test.img') +reference_img =3D os.path.join(iotests.test_dir, 'reference.img') class ImageCommitTestCase(iotests.QMPTestCase): '''Abstract base class for image commit test cases''' @@ -951,6 +952,105 @@ class TestCommitWithOverriddenBacking(iotests.QMPTest= Case): self.vm.qmp('block-job-complete', device=3D'commit') self.vm.event_wait('BLOCK_JOB_COMPLETED') +class TestCommitLargeRuns(iotests.QMPTestCase): + """Commit runs long enough to cross commit_iteration()'s cached span."= "" + + MB =3D 1024 * 1024 + CLUSTER =3D 64 * 1024 + + # Runs several COMMIT_BUFFER_SIZE (512K) chunks long, of every kind. + SIZE =3D 32 * MB + LAYOUT =3D [ + (0, 4 * MB, 'data'), + (4 * MB, 6 * MB, 'hole'), + (10 * MB, 4 * MB, 'data'), + (14 * MB, 6 * MB, 'zero'), + (20 * MB, 4 * MB, 'data'), + (24 * MB, 8 * MB, 'hole'), + ] + + # The same, with every transition off the 512K boundary. + SIZE_FRAGMENTED =3D 384 * CLUSTER # 24M + LAYOUT_FRAGMENTED =3D [ + (0, 45 * CLUSTER, 'data'), + (45 * CLUSTER, 55 * CLUSTER, 'hole'), + (100 * CLUSTER, CLUSTER, 'data'), + (101 * CLUSTER, 49 * CLUSTER, 'zero'), + (150 * CLUSTER, 80 * CLUSTER, 'data'), + (230 * CLUSTER, CLUSTER, 'hole'), + (231 * CLUSTER, 69 * CLUSTER, 'data'), + (300 * CLUSTER, 83 * CLUSTER, 'zero'), + (383 * CLUSTER, CLUSTER, 'hole'), + ] + + def setUp(self): + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + for img in (backing_img, mid_img, test_img, reference_img): + if os.path.exists(img): + os.remove(img) + + def build_images(self, layout, size): + # A pattern of its own in base, so a misplaced cluster shows up. + qemu_img_create('-f', iotests.imgfmt, backing_img, str(size)) + qemu_io('-c', f'write -P 0x11 0 {size}', backing_img) + + qemu_img_create('-f', iotests.imgfmt, '-b', backing_img, '-F', + iotests.imgfmt, mid_img, str(size)) + for offset, length, kind in layout: + if kind =3D=3D 'data': + qemu_io('-c', f'write -P 0x22 {offset} {length}', mid_img) + elif kind =3D=3D 'zero': + qemu_io('-c', f'write -z {offset} {length}', mid_img) + + # What base must equal once mid is committed into it. + qemu_img('convert', '-f', iotests.imgfmt, '-O', iotests.imgfmt, + mid_img, reference_img) + + # An empty layer above mid, so top_node=3Dmid is not the active on= e. + qemu_img_create('-f', iotests.imgfmt, '-b', mid_img, '-F', + iotests.imgfmt, test_img, str(size)) + + self.vm.cmd('blockdev-add', { + 'node-name': 'base', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': backing_img}, + }) + self.vm.cmd('blockdev-add', { + 'node-name': 'mid', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': mid_img}, + 'backing': 'base', + }) + self.vm.cmd('blockdev-add', { + 'node-name': 'active', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': test_img}, + 'backing': 'mid', + }) + + def commit_and_verify(self): + self.vm.cmd('block-commit', job_id=3D'commit0', device=3D'active', + top_node=3D'mid', base_node=3D'base') + self.wait_until_completed(drive=3D'commit0') + + self.vm.cmd('blockdev-del', node_name=3D'active') + self.vm.cmd('blockdev-del', node_name=3D'mid') + self.vm.cmd('blockdev-del', node_name=3D'base') + self.assertTrue(compare_images(reference_img, backing_img)) + + def test_commit_large_runs(self): + self.build_images(self.LAYOUT, self.SIZE) + self.commit_and_verify() + + def test_commit_fragmented_runs(self): + self.build_images(self.LAYOUT_FRAGMENTED, self.SIZE_FRAGMENTED) + self.commit_and_verify() + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 1bb1dc5f0ea..d2e2a2d98f6 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -................................................................. +................................................................... ---------------------------------------------------------------------- -Ran 65 tests +Ran 67 tests OK --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678159; cv=none; d=zohomail.com; s=zohoarc; b=K6LP9QDcTJAvvKytf71pVWdTWmlVT6HDZSvW2Vkh937BocTVTUGUO9s1zfGchNu2r4YQJZeLqBb+9ywNFFM3tvMnP1Tuwuv/iLnuRQcrjGe/oV306Rdod0Gd4sEVxckroFErWj4k5kPrn9yPvgNp9pnX/nxfm/pTZYTtRdEqdno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678159; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lbDOZMrnoovdgvZbU+ME7GmL1tQpLGQ3Ex+2H8vLRJ4=; b=l6qj9V5tdiHJv1ESr5Fk5pff4xLSgVc4kM9LPGZ+DlgoUwpfwcNQzLHK5jQz88fQKPW3GSg3DJgmFf1JWxhxed8BOrbSTmHT7KVOjv2i+vjCMB2qFKcoIPSw7wOsXyyg7kM0avd4HRlqmfLbgcDuMoDNNNXKtIPd3kp2nNi6AI0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678159587499.3886445832004; Mon, 2 Nov 2026 19:55:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cV-0006Ri-38; Mon, 02 Nov 2026 22:55:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cS-0006Q8-5B for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cQ-0000bd-FS for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:31 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-6uKHZtofMLCWNr2ZV2eC3g-1; Mon, 02 Nov 2026 22:55:26 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 45E9A195605A; Tue, 3 Nov 2026 03:55:25 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A7B3F7E2; Tue, 3 Nov 2026 03:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lbDOZMrnoovdgvZbU+ME7GmL1tQpLGQ3Ex+2H8vLRJ4=; b=R/LDRDbJuGGXTwksgYuoQhFP3BsEGBIwpegCW3kUM0hE8wfBnbTJTbzIcm3cFiP1IiIl87 IFe0HX+7eSJhXFkLmZyggzK2bJ61l98fiG477u6O1AxqJFRmQoog2c4asXkwvecPRSaiIT nDWn8JqI+JMl8EjMBCzuF/K7FScALmo= X-MC-Unique: 6uKHZtofMLCWNr2ZV2eC3g-1 X-Mimecast-MFC-AGG-ID: 6uKHZtofMLCWNr2ZV2eC3g_1793678125 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 07/16] block/commit: batch block-status queries Date: Mon, 2 Nov 2026 21:54:18 -0600 Message-ID: <20261103035506.2688772-25-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678160843158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" commit_iteration() asks for block status COMMIT_BUFFER_SIZE (512K) at a time, so a long run above base pays one query per 512K for an answer the whole run shares. Query the remainder of the image instead and keep the answer in a CommitStatus owned by commit_run(). No device or export writes top above base_overlay while the job runs: they ask for BLK_PERM_CONSISTENT_READ along with BLK_PERM_WRITE, and the job withholds CONSISTENT_READ there, having to share WRITE or it would block its own writes to base through the backing chain. A job target asks for WRITE alone and is refused by the op blocker instead. From filtered_base downwards CONSISTENT_READ is shared again, and there only the job writes. Copying is still bounded by the read buffer. Zeroes need no buffer, so COMMIT_ZERO_CHUNK bounds them, keeping a cancel from waiting on a huge write-zeroes, and an unallocated span is crossed in one step. Reviewed-by: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-4-den@openvz.org> Signed-off-by: Eric Blake --- block/commit.c | 60 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/block/commit.c b/block/commit.c index 4e0b0f9029b..e8ddd460534 100644 --- a/block/commit.c +++ b/block/commit.c @@ -31,8 +31,23 @@ enum { * contiguous regions of the image is efficient. */ COMMIT_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ + + /* + * Zeroes need no buffer, so they are bounded by this instead. It stays + * well under BDRV_REQUEST_MAX_BYTES and keeps a cancel from waiting on + * a multi-gigabyte write. + */ + COMMIT_ZERO_CHUNK =3D 256 * 1024 * 1024, /* in bytes */ }; +/* Last block-status answer, covering [offset, end). Empty when equal. */ +typedef struct CommitStatus { + int64_t len; + int64_t offset; + int64_t end; + int ret; +} CommitStatus; + typedef struct CommitBlockJob { BlockJob common; BlockDriverState *commit_top_bs; @@ -130,26 +145,45 @@ static void commit_clean(Job *job) static int coroutine_fn commit_iteration(CommitBlockJob *s, int64_t offset, - int64_t *requested_bytes, void *buf) + int64_t *requested_bytes, void *buf, CommitStatus *st) { BlockErrorAction action; - int64_t bytes =3D *requested_bytes; + int64_t bytes; int ret =3D 0; bool error_in_source =3D true; - /* Copy if allocated above the base */ - WITH_GRAPH_RDLOCK_GUARD() { - ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), - s->base_overlay, true, BDRV_WANT_PRECISE, offset, - COMMIT_BUFFER_SIZE, &bytes, NULL, NULL, NULL); + assert(offset >=3D st->offset); + + if (offset >=3D st->end) { + /* Copy if allocated above the base */ + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), + s->base_overlay, true, BDRV_WANT_PRECISE, offset, + st->len - offset, &bytes, NULL, NULL, NULL); + } + + if (ret < 0) { + trace_commit_one_iteration(s, offset, 0, ret); + goto fail; + } + + st->offset =3D offset; + st->end =3D offset + bytes; + st->ret =3D ret; + } + + ret =3D st->ret; + bytes =3D st->end - offset; + + /* An unallocated span costs no I/O, so it is crossed in one step. */ + if (ret & BDRV_BLOCK_ZERO) { + bytes =3D MIN(bytes, COMMIT_ZERO_CHUNK); + } else if (ret & BDRV_BLOCK_ALLOCATED) { + bytes =3D MIN(bytes, COMMIT_BUFFER_SIZE); } trace_commit_one_iteration(s, offset, bytes, ret); - if (ret < 0) { - goto fail; - } - if (ret & BDRV_BLOCK_ALLOCATED) { if (ret & BDRV_BLOCK_ZERO) { /* @@ -215,6 +249,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) int64_t n =3D 0; /* bytes */ QEMU_AUTO_VFREE void *buf =3D NULL; int64_t len, base_len; + CommitStatus st =3D { 0 }; len =3D blk_co_getlength(s->top); if (len < 0) { @@ -235,6 +270,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) } buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); + st.len =3D len; for (offset =3D 0; offset < len; offset +=3D n) { /* Note that even when no rate limit is applied we need to yield @@ -245,7 +281,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) break; } - ret =3D commit_iteration(s, offset, &n, buf); + ret =3D commit_iteration(s, offset, &n, buf, &st); if (ret < 0) { return ret; --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678239; cv=none; d=zohomail.com; s=zohoarc; b=jw52YRj7ElHI16xtNe1Nr2skFCwM8zWDj4wl47eHJ88pWBMoWXaEGytCMZ+9vu3LvO+UBA2jojjY/rlEsvSrbRUdZ1k0qzxhzV7902kXqJL8C5HqAKaGpE1U8SgtX1Z46R1rD1kC8eXu8pKtaQqLztRubysqVh1z/N29W7J1ahU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678239; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2d2M2em0NBvHvpwykvSpbjKbZkMyzBnODVtR+5DKOcA=; b=nviLb4k/pXRdChRU+McJV1CnTpZnFwgoIXOvgLp3YHiA2XG3TKBd/I9ICFCefIpKRTmVz0TezzZ4xxpRMaW8yr0mNiDTTFRzuv5REzbvTFHs+RfFn/HYnRJUIfDsrJbot58bmZ3TgvZipK8IYSLWoFl/gudVPQkJ6kEUX3qVQE8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678239753360.43477744834786; Mon, 2 Nov 2026 19:57:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cW-0006SY-K5; Mon, 02 Nov 2026 22:55:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cT-0006R9-MK for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cQ-0000bc-TW for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:33 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-il635yhoPCuXPhwa4pX4wQ-1; Mon, 02 Nov 2026 22:55:28 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 373B51955F73; Tue, 3 Nov 2026 03:55:27 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A49237E7; Tue, 3 Nov 2026 03:55:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2d2M2em0NBvHvpwykvSpbjKbZkMyzBnODVtR+5DKOcA=; b=IxlcmB8zQphJzhfhIULRI1cehj/LOJUREYoHOUWR63ECqVOvCUAi+58HICcu+dUgb4QJCd hED9rV8i9wULMGDXAKivot5vH/7LcHiJUFAXCE91i2kzZMTp9KMx1E6PICazM2grkeBapQ WrhPXzKlMjpjvKxNd6EOsvD+E1xtqrQ= X-MC-Unique: il635yhoPCuXPhwa4pX4wQ-1 X-Mimecast-MFC-AGG-ID: il635yhoPCuXPhwa4pX4wQ_1793678127 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 08/16] iotests/124: cover backup of zero clusters and holes Date: Mon, 2 Nov 2026 21:54:19 -0600 Message-ID: <20261103035506.2688772-26-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678240235158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" The backup tests compare content only, and their sources hold data alone, so nothing pins how backup treats zero clusters and holes. Back up a source mixing data, write-zero and holes with sync=3Dfull, sync=3Dtop and sync=3Dbitmap, and check the target with qemu-img map, which tells a copied cluster apart from a write-zero and from an untouched one. Reviewed-by: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-5-den@openvz.org> Signed-off-by: Eric Blake --- tests/qemu-iotests/124 | 347 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/124.out | 4 +- 2 files changed, 348 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/124 b/tests/qemu-iotests/124 index ab9ea4d8b59..7afcf61324d 100755 --- a/tests/qemu-iotests/124 +++ b/tests/qemu-iotests/124 @@ -22,8 +22,11 @@ # import os +from collections import namedtuple + import iotests -from iotests import try_remove +from iotests import (compare_images, qemu_img_create, qemu_img_map, qemu_i= o, + try_remove) from qemu.qmp.qmp_client import ExecuteError @@ -748,6 +751,348 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBa= ckupBase): self.check_backups() +# Backup of sources mixing data, zero clusters and holes. + +Extent =3D namedtuple('Extent', ['start', 'length', 'kind']) +Case =3D namedtuple('Case', ['size', 'layout', 'expected'], defaults=3D[No= ne]) + +source_img =3D os.path.join(iotests.test_dir, 'source') +base_img =3D os.path.join(iotests.test_dir, 'base') +target_img =3D os.path.join(iotests.test_dir, 'target') + +SIZE =3D 64 * 1024 * 1024 +MB =3D 1024 * 1024 +CLUSTER =3D 64 * 1024 + +# Data, write-zero and holes, every combination at a cluster boundary. +MIXED =3D Case(SIZE, [ + (0, MB, 'data'), + (2 * MB, MB, 'zero'), + (5 * MB, 2 * MB, 'data'), + (8 * MB, MB, 'zero'), + (10 * MB, MB // 2, 'data'), + (20 * MB, 4 * MB, 'zero'), + (30 * MB, MB, 'data'), +]) + +# Single-cluster runs, and a zero run ending exactly at EOF. +BOUNDARY_SIZE =3D 16 * MB +BOUNDARY =3D Case(BOUNDARY_SIZE, [ + (0, CLUSTER, 'zero'), + (CLUSTER, CLUSTER, 'data'), + (2 * CLUSTER, CLUSTER, 'zero'), + (3 * CLUSTER, CLUSTER, 'data'), + (4 * CLUSTER, 8 * MB, 'zero'), + (4 * CLUSTER + 8 * MB, CLUSTER, 'data'), + (BOUNDARY_SIZE - CLUSTER, CLUSTER, 'zero'), +]) + +# A zero run past the old block_copy_chunk_size() 16M cap. +LARGE_ZERO =3D Case(48 * MB, [ + (0, MB, 'data'), + (4 * MB, 32 * MB, 'zero'), + (40 * MB, MB, 'data'), +]) + +# Image size not a multiple of the cluster size: a partial tail cluster. +TAIL_SIZE =3D 4 * MB + 4096 +TAIL_CLUSTER =3D (TAIL_SIZE // CLUSTER) * CLUSTER +TAIL_DATA =3D Case(TAIL_SIZE, [ + (0, MB, 'data'), + (2 * MB, MB, 'zero'), + (4 * MB, TAIL_SIZE - 4 * MB, 'data'), +]) +# The partial tail cluster falls out of zero_bitmap, so it copies as data. +TAIL_ZERO =3D Case(TAIL_SIZE, [ + (0, MB, 'data'), + (2 * MB, TAIL_SIZE - 2 * MB, 'zero'), +], [ + (0, MB, 'data'), + (2 * MB, TAIL_CLUSTER - 2 * MB, 'zero'), + (TAIL_CLUSTER, TAIL_SIZE - TAIL_CLUSTER, 'data'), +]) + + +def coalesce(extents): + out =3D [] + for e in extents: + prev =3D out[-1] if out else None + adjacent =3D prev is not None and prev.start + prev.length =3D=3D = e.start + if adjacent and prev.kind =3D=3D e.kind: + out[-1] =3D prev._replace(length=3Dprev.length + e.length) + else: + out.append(e) + return out + + +def layout_to_extents(layout, size, gap=3D'hole'): + extents =3D [] + pos =3D 0 + for offset, length, kind in layout: + if offset > pos: + extents.append(Extent(pos, offset - pos, gap)) + extents.append(Extent(offset, length, kind)) + pos =3D offset + length + if pos < size: + extents.append(Extent(pos, size - pos, gap)) + return coalesce(extents) + + +def create_image(path, size, backing=3DNone, opts=3DNone): + args =3D ['-f', iotests.imgfmt] + if opts: + args +=3D ['-o', opts] + if backing: + args +=3D ['-b', backing, '-F', iotests.imgfmt] + qemu_img_create(*args, path, str(size)) + + +class TestBackupZeroClusters(iotests.QMPTestCase): + def setUp(self): + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + for img in (source_img, base_img, target_img): + if os.path.exists(img): + os.remove(img) + + def hmp_write(self, drive, cmd): + res =3D self.vm.hmp_qemu_io(drive, cmd) + self.assertNotIn('error', res['return'].lower()) + + def write_layout(self, layout): + for offset, length, kind in layout: + opt =3D '-z' if kind =3D=3D 'zero' else '-P 0x5a' + self.hmp_write('src', f'write {opt} {offset} {length}') + + def assert_map(self, case, backing=3DFalse, gap=3D'hole'): + # Content is not enough, pin the data/zero/hole split as well. + def classify(e): + is_hole =3D e['depth'] > 0 if backing else not e['present'] + return 'hole' if is_hole else ('zero' if e['zero'] else 'data') + + actual =3D coalesce([Extent(e['start'], e['length'], classify(e)) + for e in qemu_img_map(target_img)]) + layout =3D case.expected if case.expected else case.layout + + self.assertEqual(actual, layout_to_extents(layout, case.size, gap)) + + def add_source(self, case=3DMIXED, backing=3DNone, opts=3DNone): + create_image(source_img, case.size, backing, opts) + + self.vm.cmd('blockdev-add', { + 'node-name': 'src', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': source_img}, + }) + + # Write through the node, so an attached bitmap sees it. + self.write_layout(case.layout) + + def dirty_layout(self, case): + # A new bitmap tracks nothing yet: dirty all, then re-apply. + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + self.hmp_write('src', f'write -z 0 {case.size}') + self.write_layout(case.layout) + + def do_backup(self, sync, case, target_backing=3DNone, prefill=3DNone, + **kwargs): + create_image(target_img, case.size, target_backing) + + if prefill is not None: + # Not zero, so a skipped cluster is provably untouched. + qemu_io('-c', f'write -P {prefill} 0 {case.size}', target_img) + + self.vm.cmd('blockdev-add', { + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': target_img}, + }) + + self.vm.cmd('blockdev-backup', device=3D'src', target=3D'target', + job_id=3D'bk0', sync=3Dsync, **kwargs) + self.wait_until_completed(drive=3D'bk0') + + self.vm.cmd('blockdev-del', node_name=3D'target') + self.vm.cmd('blockdev-del', node_name=3D'src') + + def backup_and_check(self, sync, case, gap=3D'zero', backing=3DFalse, + **kwargs): + self.do_backup(sync, case, **kwargs) + self.assertTrue(compare_images(source_img, target_img)) + self.assert_map(case, backing=3Dbacking, gap=3Dgap) + + def test_full(self): + self.add_source() + self.backup_and_check('full', MIXED) + + def test_full_zero_overwrite(self): + # full skips holes, so only check that zero overwrites prefill. + case =3D Case(SIZE, [(2 * MB, MB, 'zero')]) + self.add_source(case) + self.do_backup('full', case, prefill=3D0xcc) + qemu_io('-c', f'read -P 0 {2 * MB} {MB}', target_img) + + def test_bitmap(self): + self.add_source() + self.dirty_layout(MIXED) + self.backup_and_check('bitmap', MIXED, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_top(self): + # Non-zero backing data, so a hole and an explicit zero differ. + create_image(base_img, SIZE) + qemu_io('-c', f'write -P 0x33 0 {SIZE}', base_img) + + self.add_source(backing=3Dbase_img) + self.backup_and_check('top', MIXED, gap=3D'hole', backing=3DTrue, + target_backing=3Dbase_img) + + def test_boundary_full(self): + self.add_source(BOUNDARY) + self.backup_and_check('full', BOUNDARY) + + def test_boundary_bitmap(self): + self.add_source(BOUNDARY) + self.dirty_layout(BOUNDARY) + self.backup_and_check('bitmap', BOUNDARY, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_large_zero_full(self): + self.add_source(LARGE_ZERO) + self.backup_and_check('full', LARGE_ZERO) + + def test_large_zero_bitmap(self): + self.add_source(LARGE_ZERO) + self.dirty_layout(LARGE_ZERO) + self.backup_and_check('bitmap', LARGE_ZERO, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_huge_zero(self): + # A zero run past the cap on a single write-zeroes request, so it + # has to be split. qemu-io caps one write at 2G, hence three. + case =3D Case(2560 * MB, [(0, 1024 * MB, 'zero'), + (1024 * MB, 1024 * MB, 'zero'), + (2048 * MB, 512 * MB, 'zero')]) + self.add_source(case) + self.backup_and_check('full', case) + + def test_tail_data(self): + self.add_source(TAIL_DATA) + self.backup_and_check('full', TAIL_DATA) + + def test_tail_zero(self): + self.add_source(TAIL_ZERO) + self.backup_and_check('full', TAIL_ZERO) + + def test_tail_zero_bitmap(self): + # Same tail rounding as test_tail_zero, via the bitmap scan. + self.add_source(TAIL_ZERO) + self.dirty_layout(TAIL_ZERO) + self.backup_and_check('bitmap', TAIL_ZERO, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_mixed_cluster(self): + # 4K source clusters, so content varies inside one 64K cluster. + case =3D Case(2 * CLUSTER, [ + (0, 8 * 1024, 'zero'), + (8 * 1024, 8 * 1024, 'data'), + (CLUSTER, CLUSTER, 'zero'), + ], [ + # A mixed cluster must be data, or the data at [8k, 16k) is lo= st. + (0, CLUSTER, 'data'), + (CLUSTER, CLUSTER, 'zero'), + ]) + self.add_source(case, opts=3D'cluster_size=3D4k') + self.backup_and_check('full', case) + + def test_top_zero_broken(self): + # An overlay hole before an explicit-zero run: the zero prefix + # must stop at the hole, or the backing data under it is lost. + size =3D 2 * CLUSTER + create_image(base_img, size, opts=3D'cluster_size=3D4k') + qemu_io('-c', f'write -P 0x33 0 {size}', base_img) + + # [0, 4k) stays a hole, the zero run spills into cluster 1. + case =3D Case(size, [(4096, CLUSTER, 'zero')]) + self.add_source(case, backing=3Dbase_img, opts=3D'cluster_size=3D4= k') + + self.do_backup('top', case, target_backing=3Dbase_img) + self.assertTrue(compare_images(source_img, target_img)) + + def test_bitmap_straddle(self): + # One dirty run straddling a zero/data transition, both ways. + case =3D Case(SIZE, []) + self.add_source(case) + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + + # One contiguous dirty run each: [7M, 9M) zero to data, and + # [15M, 17M) data to zero. + layout =3D [ + (7 * MB, MB, 'zero'), + (8 * MB, MB, 'data'), + (15 * MB, MB, 'data'), + (16 * MB, MB, 'zero'), + ] + self.write_layout(layout) + + self.do_backup('bitmap', case, bitmap=3D'bm0', bitmap_mode=3D'neve= r') + self.assertTrue(compare_images(source_img, target_img)) + # Nothing outside the two dirty runs may reach the target. + self.assert_map(case._replace(layout=3Dlayout)) + + def test_bitmap_fragmented(self): + # Isolated single-cluster dirty spots: nothing outside them + # may reach the target. + case =3D Case(SIZE, []) + self.add_source(case) + + # Written before the bitmap exists, so untracked. + self.hmp_write('src', f'write -P 0x5a 0 {16 * MB}') + + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + + # The only dirty bit in the data region, with a pattern of its own. + data_island =3D 4 * MB + self.hmp_write('src', f'write -P 0x7b {data_island} {CLUSTER}') + + # The only dirty bit in the hole region. + zero_island =3D 24 * MB + self.hmp_write('src', f'write -z {zero_island} {CLUSTER}') + + self.do_backup('bitmap', case, bitmap=3D'bm0', bitmap_mode=3D'neve= r', + prefill=3D0xcc) + + # Only the two isolated spots should have reached target ... + qemu_io('-c', f'read -P 0x7b {data_island} {CLUSTER}', target_img) + qemu_io('-c', f'read -P 0 {zero_island} {CLUSTER}', target_img) + + # ... everything else must still hold the prefill pattern. + qemu_io('-c', f'read -P 0xcc 0 {CLUSTER}', target_img) + qemu_io('-c', f'read -P 0xcc {8 * MB} {CLUSTER}', target_img) + + def test_bitmap_clean_zero_gap(self): + # A clean zero run between two dirty ones must stay prefilled. + case =3D Case(16 * MB, []) + self.add_source(case) + self.hmp_write('src', f'write -z 0 {16 * MB}') + + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + self.write_layout([(2 * MB, MB, 'zero'), (6 * MB, MB, 'zero')]) + + self.do_backup('bitmap', case, bitmap=3D'bm0', bitmap_mode=3D'neve= r', + prefill=3D0xcc) + + qemu_io('-c', f'read -P 0 {2 * MB} {MB}', target_img) + qemu_io('-c', f'read -P 0 {6 * MB} {MB}', target_img) + + qemu_io('-c', f'read -P 0xcc 0 {2 * MB}', target_img) + qemu_io('-c', f'read -P 0xcc {3 * MB} {3 * MB}', target_img) + qemu_io('-c', f'read -P 0xcc {7 * MB} {9 * MB}', target_img) + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], supported_protocols=3D['file'], diff --git a/tests/qemu-iotests/124.out b/tests/qemu-iotests/124.out index fa16b5cceff..5ce2f9a2ed9 100644 --- a/tests/qemu-iotests/124.out +++ b/tests/qemu-iotests/124.out @@ -1,5 +1,5 @@ -............. +.............................. ---------------------------------------------------------------------- -Ran 13 tests +Ran 30 tests OK --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678207; cv=none; d=zohomail.com; s=zohoarc; b=f4mPpEJZsSAsJI5jIOcRmMySylV/oRrVFG9LB4JTS3m3TYPU/iCcnmNHJS2yqPLcx5VsDKxytO6pK/zbGyV3qzGXIR4P9XYe0z+yw5xqrTDGW/Q+J2lCVqCRguuSkM4ultKfd1hnTtyoZWWhaUsEZVRUJr6ikEoTi1UNMeJ9xGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678207; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ncwx/OzxZmxb0/5gzr8OFxCr+ZcPkRp5UOQTMmNAzHw=; b=Y9xxT4tY0G+BWlsQTtY427CQkNye2fRDhumN0VPT/TvgSNfxxFsnAP+Mo1Y49Zsb8f6q6g0JfL9sezWVdwxSAoEnq0kmFyyhOZYzplcsvUGbuCTzXNmPgL7fNDEWt3iDa1q6CYb0x9+2W3iYXsIryAgqEtuQhmCH5w0iddETXfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678207462222.56157189146734; Mon, 2 Nov 2026 19:56:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cW-0006SK-2s; Mon, 02 Nov 2026 22:55:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cT-0006RC-QU for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cS-0000c3-15 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:33 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-Lm9XEGnyN6CCEnO87SrT8w-1; Mon, 02 Nov 2026 22:55:30 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 110C718007EB; Tue, 3 Nov 2026 03:55:29 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 89F6E7E2; Tue, 3 Nov 2026 03:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ncwx/OzxZmxb0/5gzr8OFxCr+ZcPkRp5UOQTMmNAzHw=; b=OW+xuziicYYXee+du4yMTs1NO+Gbc68TSSdJCvGcLc2TpZahn29ROqx719xHqAUN0x5mTX V97bkNYfJ3FGdvOEJkd38EwTsS3eG9f0qprhjzisie1CjvMz1pSTKkMEKGmNn9RhQAmNVt j5vZzjAGeUa6oZzRZiZanTXipXlHTd4= X-MC-Unique: Lm9XEGnyN6CCEnO87SrT8w-1 X-Mimecast-MFC-AGG-ID: Lm9XEGnyN6CCEnO87SrT8w_1793678129 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 09/16] block/block-copy: extract block_copy_set_task_method() Date: Mon, 2 Nov 2026 21:54:20 -0600 Message-ID: <20261103035506.2688772-27-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678209553158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Move the per-task block-status query and its skip_unallocated and BDRV_BLOCK_ZERO handling out of block_copy_dirty_clusters() into block_copy_set_task_method(). No behavior change. The next patch changes that decision, and having it in one place keeps that change to just the new logic. The block-status result no longer lands in the caller's @ret, so drop the note saying @ret may be positive at the out: label. Reviewed-by: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-6-den@openvz.org> Signed-off-by: Eric Blake --- block/block-copy.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 1826c2e1c7b..33c43cdf929 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -736,6 +736,35 @@ int64_t coroutine_fn block_copy_reset_unallocated(Bloc= kCopyState *s, return ret; } +/* + * Decide how @task is copied: COPY_WRITE_ZEROES if it reads as zero. May + * shrink @task. Returns false if @task is to be skipped (already ended, + * not freed). + */ +static bool coroutine_fn GRAPH_RDLOCK +block_copy_set_task_method(BlockCopyState *s, BlockCopyTask *task) +{ + int ret; + int64_t status_bytes; + + ret =3D block_copy_block_status(s, task->req.offset, task->req.bytes, + &status_bytes); + assert(ret >=3D 0); /* never fail */ + if (status_bytes < task->req.bytes) { + block_copy_task_shrink(task, status_bytes); + } + if (qatomic_read(&s->skip_unallocated) && !(ret & BDRV_BLOCK_ALLOCATED= )) { + block_copy_task_end(task, 0); + trace_block_copy_skip_range(s, task->req.offset, task->req.bytes); + return false; + } + if (ret & BDRV_BLOCK_ZERO) { + task->method =3D COPY_WRITE_ZEROES; + } + + return true; +} + /* * block_copy_dirty_clusters * @@ -768,7 +797,6 @@ block_copy_dirty_clusters(BlockCopyCallState *call_stat= e) while (bytes && aio_task_pool_status(aio) =3D=3D 0 && !qatomic_read(&call_state->cancelled)) { BlockCopyTask *task; - int64_t status_bytes; task =3D block_copy_task_create(s, call_state, offset, bytes); if (!task) { @@ -782,24 +810,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_st= ate) found_dirty =3D true; - ret =3D block_copy_block_status(s, task->req.offset, task->req.byt= es, - &status_bytes); - assert(ret >=3D 0); /* never fail */ - if (status_bytes < task->req.bytes) { - block_copy_task_shrink(task, status_bytes); - } - if (qatomic_read(&s->skip_unallocated) && - !(ret & BDRV_BLOCK_ALLOCATED)) { - block_copy_task_end(task, 0); - trace_block_copy_skip_range(s, task->req.offset, task->req.byt= es); + if (!block_copy_set_task_method(s, task)) { offset =3D task_end(task); bytes =3D end - offset; g_free(task); continue; } - if (ret & BDRV_BLOCK_ZERO) { - task->method =3D COPY_WRITE_ZEROES; - } if (!call_state->ignore_ratelimit) { uint64_t ns =3D ratelimit_calculate_delay(&s->rate_limit, 0); @@ -840,8 +856,6 @@ out: * block_copy_task_run. If it fails, it means some task already fa= iled * for real reason, let's return first failure. * Still, assert that we don't rewrite failure by success. - * - * Note: ret may be positive here because of block-status result. */ assert(ret >=3D 0 || aio_task_pool_status(aio) < 0); ret =3D aio_task_pool_status(aio); --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678234; cv=none; d=zohomail.com; s=zohoarc; b=gnNggdmXwoDO7xJ2tcTSoY0g5/5REM0WhAG0p/qJgQzpcDB70BB2MUzhKxaYfx1rO3yIsB/Tof2Txvo/8YWTWzU52W0BuVvs1SVCIR87c/MfQ0TABefzBIXjIqOoBWoBoRXmxE9AOOQwgnX8w72G88uee7ysu0V3o76KUWYZrjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678234; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uL+eo+J+d2iX5Q7E1v+V3vfgg/dyC6Zx3h7wLpXdPE8=; b=iPHSYRc2n6JXKMbe13LO7WYtI0XlhDalNybbjlk1p6qvZy+Zh+doJm32rrh0gpdn+FQiceTekXDPHEPYffKIFFFLDw7pnKXUzdRIqGPv4fcxyfr58khz3Di7X8PWIX9arxZ8g7SmZ5I4idrE8RXMRJ8jDmvgr21AD/Eq7jJZaxo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678234170308.9878279271319; Mon, 2 Nov 2026 19:57:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5ca-0006Uk-D7; Mon, 02 Nov 2026 22:55:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cY-0006Ts-NS for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cW-0000co-Cb for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:38 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-yDGNbosfMCidG2MvdVRzJQ-1; Mon, 02 Nov 2026 22:55:32 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED1741800EF4; Tue, 3 Nov 2026 03:55:30 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6AC437E7; Tue, 3 Nov 2026 03:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uL+eo+J+d2iX5Q7E1v+V3vfgg/dyC6Zx3h7wLpXdPE8=; b=Gq6a2NfCWRYbLPSVzpt0/iMZn2TKBxCef3Nd08yfP3AenGxlJggYOQv1/WOKD/lKvqAp6s UP215/SFiFa7s4YqemR8v+ZplEHUhvsiFMDwVbzPEnsLEOMUvksblUT2siL3vNG4rUewHZ npGONBKK1lfTMr4JB1OLHlkmSOr8Oww= X-MC-Unique: yDGNbosfMCidG2MvdVRzJQ-1 X-Mimecast-MFC-AGG-ID: yDGNbosfMCidG2MvdVRzJQ_1793678131 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 10/16] block/block-copy: track known-zero source clusters Date: Mon, 2 Nov 2026 21:54:21 -0600 Message-ID: <20261103035506.2688772-28-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678236188158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" block_copy_reset_unallocated()'s up-front scan already queries the source, and the same query reports zero-ness. The copy loop re-queries per task and, having no answer up front, can only size a task by the copy buffer, so a mostly-zero image is cut into thousands of pieces that each turn out to read as zero. Cache the answer in zero_bitmap, published by zero_bitmap_valid once the scan is done. block_copy_task_create() then picks the method from the bitmap and ends the task where the answer changes, so a zero task never reaches into data and a copy task never swallows a zero run. The per-task query stays as the fallback until the flag is set, since CBW intercepts guest writes while the scan is still running. The scan and the query it replaces must resolve BDRV_BLOCK_ZERO against the same part of the chain, so the scan moves from bdrv_co_is_allocated() to bdrv_co_block_status_above() and the base selection is factored out into block_copy_status_base(). zero_bitmap is a plain HBitmap, not a BdrvDirtyBitmap: an internal cache has no business in query-named-block-nodes. One writer and readers gated by the flag need no mutex, but the publish needs ordering, hence store-release and load-acquire. It is allocated on demand, so sync=3Dnone and a standalone copy-before-write filter do not pay for it. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-7-den@openvz.org> Signed-off-by: Eric Blake --- include/block/block-copy.h | 1 + block/backup.c | 1 + block/block-copy.c | 108 ++++++++++++++++++++++++++++++++----- 3 files changed, 98 insertions(+), 12 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 0df2771181b..e4e5b567538 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -101,5 +101,6 @@ void block_copy_call_cancel(BlockCopyCallState *call_st= ate); BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s); int64_t block_copy_cluster_size(BlockCopyState *s); void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip); +void block_copy_set_zero_bitmap_valid(BlockCopyState *s); #endif /* BLOCK_COPY_H */ diff --git a/block/backup.c b/block/backup.c index d4713fa1cd4..11d70243e24 100644 --- a/block/backup.c +++ b/block/backup.c @@ -280,6 +280,7 @@ static int coroutine_fn backup_run(Job *job, Error **er= rp) offset +=3D count; } block_copy_set_skip_unallocated(s->bcs, false); + block_copy_set_zero_bitmap_valid(s->bcs); } if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { diff --git a/block/block-copy.c b/block/block-copy.c index 33c43cdf929..507c4bab909 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -20,6 +20,8 @@ #include "block/block_int-io.h" #include "block/dirty-bitmap.h" #include "block/reqlist.h" +#include "qemu/hbitmap.h" +#include "qemu/host-utils.h" #include "system/block-backend.h" #include "qemu/units.h" #include "qemu/co-shared-resource.h" @@ -157,6 +159,10 @@ typedef struct BlockCopyState { bool skip_unallocated; /* atomic */ /* State fields that use a thread-safe API */ BdrvDirtyBitmap *copy_bitmap; + /* Clusters reading as zero; allocated on demand, frozen once valid. */ + HBitmap *zero_bitmap; + /* Published only after the scan, with skip_unallocated already false.= */ + bool zero_bitmap_valid; /* atomic, store-release/load-acquire */ ProgressMeter *progress; SharedResource *mem; RateLimit rate_limit; @@ -190,6 +196,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, int64_t offset, int64_t bytes) { BlockCopyTask *task; + BlockCopyMethod method; int64_t max_chunk; QEMU_LOCK_GUARD(&s->lock); @@ -201,6 +208,27 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCal= lState *call_state, return NULL; } + method =3D s->method; + + /* + * The scan already knows how this range reads: pick the method here a= nd + * stop the task where the answer changes. + */ + if (qatomic_load_acquire(&s->zero_bitmap_valid)) { + int64_t boundary; + + if (hbitmap_get(s->zero_bitmap, offset)) { + method =3D COPY_WRITE_ZEROES; + boundary =3D hbitmap_next_zero(s->zero_bitmap, offset, bytes); + } else { + boundary =3D hbitmap_next_dirty(s->zero_bitmap, offset, bytes); + } + + if (boundary >=3D 0) { + bytes =3D boundary - offset; + } + } + assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); bytes =3D QEMU_ALIGN_UP(bytes, s->cluster_size); @@ -215,7 +243,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, .task.func =3D block_copy_task_entry, .s =3D s, .call_state =3D call_state, - .method =3D s->method, + .method =3D method, }; reqlist_init_req(&s->reqs, &task->req, offset, bytes); @@ -271,6 +299,9 @@ void block_copy_state_free(BlockCopyState *s) ratelimit_destroy(&s->rate_limit); bdrv_release_dirty_bitmap(s->copy_bitmap); + if (s->zero_bitmap) { + hbitmap_free(s->zero_bitmap); + } shres_destroy(s->mem); g_free(s); } @@ -619,20 +650,24 @@ static coroutine_fn int block_copy_task_entry(AioTask= *task) return ret; } +/* The scan and the per-task query must resolve BDRV_BLOCK_ZERO alike. */ +static GRAPH_RDLOCK BlockDriverState *block_copy_status_base(BlockCopyStat= e *s) +{ + if (qatomic_read(&s->skip_unallocated)) { + return bdrv_backing_chain_next(s->source->bs); + } + + return NULL; +} + static coroutine_fn GRAPH_RDLOCK int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t byt= es, int64_t *pnum) { int64_t num; - BlockDriverState *base; + BlockDriverState *base =3D block_copy_status_base(s); int ret; - if (qatomic_read(&s->skip_unallocated)) { - base =3D bdrv_backing_chain_next(s->source->bs); - } else { - base =3D NULL; - } - ret =3D bdrv_co_block_status_above(s->source->bs, base, offset, bytes,= &num, NULL, NULL); if (ret < 0 || num < s->cluster_size) { @@ -652,16 +687,41 @@ int block_copy_block_status(BlockCopyState *s, int64_= t offset, int64_t bytes, return ret; } +/* Only the scan allocates, and it runs before zero_bitmap_valid. */ +static HBitmap *block_copy_zero_bitmap(BlockCopyState *s) +{ + if (!s->zero_bitmap) { + s->zero_bitmap =3D hbitmap_alloc(s->len, ctz32(s->cluster_size)); + } + + return s->zero_bitmap; +} + +static void block_copy_mark_zero_prefix(BlockCopyState *s, int64_t offset, + int64_t zero_count) +{ + int64_t zero_bytes =3D QEMU_ALIGN_DOWN(zero_count, s->cluster_size); + + if (zero_bytes > 0) { + hbitmap_set(block_copy_zero_bitmap(s), offset, zero_bytes); + } +} + /* * Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocati= on. + * Also marks the zero prefix of the range in zero_bitmap. */ static int coroutine_fn GRAPH_RDLOCK block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, int64_t *pnum) { BlockDriverState *bs =3D s->source->bs; + BlockDriverState *base =3D block_copy_status_base(s); + int64_t orig_offset =3D offset; int64_t count, total_count =3D 0; + int64_t zero_count =3D 0; + bool zero_broken =3D false; int64_t bytes =3D s->len - offset; int ret; @@ -669,25 +729,37 @@ block_copy_is_cluster_allocated(BlockCopyState *s, in= t64_t offset, while (true) { /* protected in backup_run() */ - ret =3D bdrv_co_is_allocated(bs, offset, bytes, &count); + ret =3D bdrv_co_block_status_above(bs, base, offset, bytes, &count, + NULL, NULL); if (ret < 0) { return ret; } + if (!zero_broken) { + if (ret & BDRV_BLOCK_ZERO) { + zero_count +=3D count; + } else { + zero_broken =3D true; + } + } + total_count +=3D count; - if (ret || count =3D=3D 0) { + if ((ret & BDRV_BLOCK_ALLOCATED) || count =3D=3D 0) { /* - * ret: partial segment(s) are considered allocated. + * BDRV_BLOCK_ALLOCATED: partial segment(s) are considered + * allocated. * otherwise: unallocated tail is treated as an entire segment. */ *pnum =3D DIV_ROUND_UP(total_count, s->cluster_size); - return ret; + block_copy_mark_zero_prefix(s, orig_offset, zero_count); + return !!(ret & BDRV_BLOCK_ALLOCATED); } /* Unallocated segment(s) with uncertain following segment(s) */ if (total_count >=3D s->cluster_size) { *pnum =3D total_count / s->cluster_size; + block_copy_mark_zero_prefix(s, orig_offset, zero_count); return 0; } @@ -747,6 +819,12 @@ block_copy_set_task_method(BlockCopyState *s, BlockCop= yTask *task) int ret; int64_t status_bytes; + /* block_copy_task_create() already decided, from zero_bitmap. */ + if (qatomic_load_acquire(&s->zero_bitmap_valid)) { + return true; + } + + /* CBW filter could call this early. */ ret =3D block_copy_block_status(s, task->req.offset, task->req.bytes, &status_bytes); assert(ret >=3D 0); /* never fail */ @@ -1076,6 +1154,12 @@ void block_copy_set_skip_unallocated(BlockCopyState = *s, bool skip) qatomic_set(&s->skip_unallocated, skip); } +void block_copy_set_zero_bitmap_valid(BlockCopyState *s) +{ + block_copy_zero_bitmap(s); + qatomic_store_release(&s->zero_bitmap_valid, true); +} + void block_copy_set_speed(BlockCopyState *s, uint64_t speed) { ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME); --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678209; cv=none; d=zohomail.com; s=zohoarc; b=AI9zVNwYE2/MpmrdzUSe7+QHZP5m10nJ3LfSaNtS+lVCWb8TQuKxTCr8DfCicz7tSeDRIvZ8EZVzG3jEKwOtTbzomJBD0WJmZ5X7slcBi1SAO/WQutYLYiojoH6Lun+Bi5RgQNxzpNsYxQ62eaDvnQhNzYCeFiv+HS9hgZqU2s0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678209; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=b0fqfWx9gV3NJq86T/JzOQT8U48EXMHicFem5q0R9Qk=; b=Q6iozQNXYrPMOnqq34z14thaoLKUvo+1F1qqwj/omzRQ5b3gIifCZwJm9K3jtEo1D0e4b2B40zdcWl8l9QsXBn0UsH7estv0prBBX7IaI1YZzqFrhVVmCaOhEJ+QHd/RSAKHzOC2WvcVL0LclAOdmJSdPLULKORcG3igpsOrJ6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678209186961.5203729301921; Mon, 2 Nov 2026 19:56:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5ce-0006Zx-RX; Mon, 02 Nov 2026 22:55:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cd-0006Yn-76 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5ca-0000do-W6 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:42 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-xl6O2bZ6Pb6NTythXl8nag-1; Mon, 02 Nov 2026 22:55:34 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB5D51956073; Tue, 3 Nov 2026 03:55:32 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 529077E2; Tue, 3 Nov 2026 03:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b0fqfWx9gV3NJq86T/JzOQT8U48EXMHicFem5q0R9Qk=; b=h+wvIiixwEkxjdW0Tmqr2JTwJAaEQvRm5bHZyZFA6YYzR8Z64t4UjIN6yFTqyoWMh7bcWo bqAa1TfLTMfq8/VtwrZ3kMRta6wu0nakBskYg7pqiCoDsEzfqUEM1brz+lwO9e5OD3bhAI W3N0TQLJIDiX1nPwvKz5l+p75z69CsE= X-MC-Unique: xl6O2bZ6Pb6NTythXl8nag-1 X-Mimecast-MFC-AGG-ID: xl6O2bZ6Pb6NTythXl8nag_1793678133 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 11/16] block/backup: pre-fill zero_bitmap for full/bitmap Date: Mon, 2 Nov 2026 21:54:22 -0600 Message-ID: <20261103035506.2688772-29-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678211633158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Only sync=3Dtop runs an up-front scan, so the previous patch did nothing for the other modes. FULL and BITMAP know their complete copy_bitmap before copying starts, and the same copy-before-write guarantee holds: a cluster still dirty when the copy loop reaches it has not been written since the scan. Add block_copy_calculate_zero_bitmap(), driven one query at a time from backup_scan_source() so the graph rdlock and the pause point are taken per query, and query each confirmed span once however many dirty areas it covers. Each step searches copy_bitmap only a bounded window ahead, since for sync=3Dfull the rest of the image is one dirty area. The scan only fills zero_bitmap and never clears copy_bitmap, so sync=3Dfull still writes zeroes for clusters the source never allocated; it just stops re-querying to find that out. Unlike the per-task queries it replaces the scan is serial, so a sparsely dirtied job against a slow source may spend more time here than it saves. The sync=3Dtop loop had the same shape, so both fold into backup_scan_source(). sync=3Dnone keeps the per-task query. Its bitmap says "anything may be copied", not "this will be copied", and it only ever copies what the guest writes during the fleecing window, so scanning the whole image at attach is the wrong trade. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-8-den@openvz.org> Signed-off-by: Eric Blake --- include/block/block-copy.h | 4 ++ block/backup.c | 98 ++++++++++++++++++++++++-------------- block/block-copy.c | 42 ++++++++++++++++ 3 files changed, 108 insertions(+), 36 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index e4e5b567538..3a61066b55f 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -44,6 +44,10 @@ void block_copy_reset(BlockCopyState *s, int64_t offset,= int64_t bytes); int64_t coroutine_fn GRAPH_RDLOCK block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *c= ount); +void coroutine_fn GRAPH_RDLOCK +block_copy_calculate_zero_bitmap(BlockCopyState *s, int64_t offset, + int64_t *cached_end, int64_t *count); + int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, BlockCopyAsyncCallbackFunc cb, diff --git a/block/backup.c b/block/backup.c index 11d70243e24..38b0838d694 100644 --- a/block/backup.c +++ b/block/backup.c @@ -247,6 +247,51 @@ static void backup_init_bcs_bitmap(BackupBlockJob *job) job_progress_set_remaining(&job->common.job, estimate); } +/* + * Walk the source before copying starts: fill zero_bitmap and, for sync= =3Dtop, + * drop the clusters that are not allocated above the backing. + */ +static int coroutine_fn backup_scan_source(BackupBlockJob *s) +{ + Job *job =3D &s->common.job; + bool top =3D s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP; + int64_t offset, cached_end =3D 0, count; + int ret =3D 0; + + for (offset =3D 0; offset < s->len; offset +=3D count) { + if (job_is_cancelled(job)) { + return -ECANCELED; + } + + job_pause_point(job); + + if (job_is_cancelled(job)) { + return -ECANCELED; + } + + /* rdlock protects the block-status queries below */ + bdrv_graph_co_rdlock(); + if (top) { + ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); + } else { + block_copy_calculate_zero_bitmap(s->bcs, offset, &cached_end, + &count); + } + bdrv_graph_co_rdunlock(); + + if (ret < 0) { + return ret; + } + } + + if (top) { + block_copy_set_skip_unallocated(s->bcs, false); + } + block_copy_set_zero_bitmap_valid(s->bcs); + + return 0; +} + static int coroutine_fn backup_run(Job *job, Error **errp) { BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); @@ -254,52 +299,33 @@ static int coroutine_fn backup_run(Job *job, Error **= errp) backup_init_bcs_bitmap(s); - if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP) { - int64_t offset =3D 0; - int64_t count; - - for (offset =3D 0; offset < s->len; ) { - if (job_is_cancelled(job)) { - return -ECANCELED; - } - - job_pause_point(job); - - if (job_is_cancelled(job)) { - return -ECANCELED; - } - - /* rdlock protects the subsequent call to bdrv_is_allocated() = */ - bdrv_graph_co_rdlock(); - ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); - bdrv_graph_co_rdunlock(); - if (ret < 0) { - return ret; - } - - offset +=3D count; + switch (s->sync_mode) { + case MIRROR_SYNC_MODE_TOP: + case MIRROR_SYNC_MODE_FULL: + case MIRROR_SYNC_MODE_BITMAP: + ret =3D backup_scan_source(s); + if (ret < 0) { + return ret; } - block_copy_set_skip_unallocated(s->bcs, false); - block_copy_set_zero_bitmap_valid(s->bcs); - } + break; - if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { + case MIRROR_SYNC_MODE_NONE: /* * All bits are set in bcs bitmap to allow any cluster to be copie= d. - * This does not actually require them to be copied. + * This does not actually require them to be copied. Yield until t= he + * job is cancelled and let the before_write notify callback servi= ce + * CoW requests. */ while (!job_is_cancelled(job)) { - /* - * Yield until the job is cancelled. We just let our before_w= rite - * notify callback service CoW requests. - */ job_yield(job); } - } else { - return backup_loop(s); + return 0; + + default: + g_assert_not_reached(); } - return 0; + return backup_loop(s); } static void coroutine_fn backup_pause(Job *job) diff --git a/block/block-copy.c b/block/block-copy.c index 507c4bab909..4f128a0ebdc 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -808,6 +808,48 @@ int64_t coroutine_fn block_copy_reset_unallocated(Bloc= kCopyState *s, return ret; } +/* + * One scan step, like block_copy_reset_unallocated(); @cached_end + * tracks progress across calls, @count how far @offset should move. + */ +void coroutine_fn GRAPH_RDLOCK +block_copy_calculate_zero_bitmap(BlockCopyState *s, int64_t offset, + int64_t *cached_end, int64_t *count) +{ + int64_t max_bytes =3D QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, + s->cluster_size); + int64_t dirty_offset, dirty_bytes, dirty_end; + bool found; + + /* CBW mutates copy_bitmap from its own AioContext meanwhile. */ + WITH_QEMU_LOCK_GUARD(&s->lock) { + found =3D bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap, offset, + s->len, max_bytes, + &dirty_offset, &dirty_by= tes); + } + + if (!found) { + *count =3D s->len - offset; + return; + } + dirty_end =3D dirty_offset + dirty_bytes; + + if (*cached_end < dirty_end) { + int64_t clusters; + int64_t query_offset =3D MAX(dirty_offset, *cached_end); + int ret =3D block_copy_is_cluster_allocated(s, query_offset, &clus= ters); + + if (ret >=3D 0) { + *cached_end =3D query_offset + clusters * s->cluster_size; + } else { + /* Best-effort: leave this area unmarked; it copies as data. */ + *cached_end =3D dirty_end; + } + } + + *count =3D MIN(*cached_end, dirty_end) - offset; +} + /* * Decide how @task is copied: COPY_WRITE_ZEROES if it reads as zero. May * shrink @task. Returns false if @task is to be skipped (already ended, --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678193; cv=none; d=zohomail.com; s=zohoarc; b=HaAAWR1SIApzbXEHSTAGiDibsVfMP1vu31ExoBasTOs2XvhcU1moZ6m9yk51WNAUz/vuj0+VKKLDUPtnEc3gO0fVUsggmb+xF0YdwYLYIzxITII6aoep1itxKOEusCuurDVpJ9WdNDFD10DDQTS9qNzleoefJIWrMolqVc6x3VA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678193; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0sjqfj2wzoXejfi4liZUWjd6OlZpf96usT4utaYmK6A=; b=NDdavdCAS+nhIxsr0B7ZmIv94DoHGuii3CgHsjv/LPY0FekszzYC9F2PkvGlBLOaid4XHFZSIkBKiCbe4IlmzXddwZtemcuSwc5CisfN0yf2UvCaxIMeR6qoplE1XJEJD31w9SjCLlFjQM853qdVDRS8N9FgJSy9kCIR0bmwXfs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678193145153.06584242946224; Mon, 2 Nov 2026 19:56:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cb-0006VO-EL; Mon, 02 Nov 2026 22:55:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5ca-0006Ug-65 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cY-0000d6-0K for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:39 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-IAaa0IZ2M96gWXTgzuV9gw-1; Mon, 02 Nov 2026 22:55:36 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B69AC1955E92; Tue, 3 Nov 2026 03:55:34 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3A0FF7E5; Tue, 3 Nov 2026 03:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0sjqfj2wzoXejfi4liZUWjd6OlZpf96usT4utaYmK6A=; b=Mr+mhBhQH4O2b9NJ6ji/bcDDMa7MIliIpYZ1WyKt/HPjAT7rjDeJLfIkCS5LyRPzu3JFfR twMfiJE3ujmtJGJavxyhWP29wpcMv+H/Am1FGPxFcGCUhSWuWa64cHcMV0gpammWauWYzD X+GDNtX8nDMESCl61aU/QErLJfJUVS0= X-MC-Unique: IAaa0IZ2M96gWXTgzuV9gw-1 X-Mimecast-MFC-AGG-ID: IAaa0IZ2M96gWXTgzuV9gw_1793678135 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 12/16] block/block-copy: rename block_copy_is_cluster_allocated() Date: Mon, 2 Nov 2026 21:54:23 -0600 Message-ID: <20261103035506.2688772-30-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678195209158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Since it started filling zero_bitmap, the function does more than its name says: it is the scan's block-status query, reporting allocation and recording zeroes. Rename it to block_copy_scan_status() and say so in its comment. No behavior change. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-9-den@openvz.org> Signed-off-by: Eric Blake --- block/block-copy.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 4f128a0ebdc..ad358f4d2f1 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -708,13 +708,13 @@ static void block_copy_mark_zero_prefix(BlockCopyStat= e *s, int64_t offset, } /* - * Check if the cluster starting at offset is allocated or not. - * return via pnum the number of contiguous clusters sharing this allocati= on. - * Also marks the zero prefix of the range in zero_bitmap. + * One block-status query of the scan at @offset: return 1 if the cluster + * there is allocated, 0 if not, -errno on failure, and via @pnum the numb= er + * of contiguous clusters sharing that allocation. Their zero prefix goes + * into zero_bitmap. */ static int coroutine_fn GRAPH_RDLOCK -block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, - int64_t *pnum) +block_copy_scan_status(BlockCopyState *s, int64_t offset, int64_t *pnum) { BlockDriverState *bs =3D s->source->bs; BlockDriverState *base =3D block_copy_status_base(s); @@ -793,7 +793,7 @@ int64_t coroutine_fn block_copy_reset_unallocated(Block= CopyState *s, int ret; int64_t clusters, bytes; - ret =3D block_copy_is_cluster_allocated(s, offset, &clusters); + ret =3D block_copy_scan_status(s, offset, &clusters); if (ret < 0) { return ret; } @@ -837,7 +837,7 @@ block_copy_calculate_zero_bitmap(BlockCopyState *s, int= 64_t offset, if (*cached_end < dirty_end) { int64_t clusters; int64_t query_offset =3D MAX(dirty_offset, *cached_end); - int ret =3D block_copy_is_cluster_allocated(s, query_offset, &clus= ters); + int ret =3D block_copy_scan_status(s, query_offset, &clusters); if (ret >=3D 0) { *cached_end =3D query_offset + clusters * s->cluster_size; --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678197; cv=none; d=zohomail.com; s=zohoarc; b=TVOxMiXlLAFcrqQfnIvsd2yE5xWdmkcRPHLNJp6vIP2vxJrEuYSzM6NVhLLje8a5Ke3ApeTNPQRTfOtHbTDqsFb9V59J8rnR+flSAFrKonflxz3Sen1BlsvEGS6WEQUyDnyGVHUie33Y/R9GjZdqByfTh+Qe8W1MXMKwA6FCJuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678197; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=55V3OL4QOhL126zAS/6Em8pgp/CM9gX2lo3RNeHL3HA=; b=TafPgFp7wDpnoCWB2Bu5rB9KK1IUbO453qdfs+n3MnoGFH9NcjexFnvQujqViuxAH9Aa0faHYTE7GxnIYTxdtmJH6wVehWDM4R5o0Vu0oCCV68OB7cTfhj8mYTpgl7N4HOhJNUc3PiVYwwky/5F/Q83bKONrPCwcxAAhRS1Zl1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678197655594.1786799024586; Mon, 2 Nov 2026 19:56:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5ce-0006Zh-Bh; Mon, 02 Nov 2026 22:55:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cc-0006XJ-H2 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5ca-0000de-Il for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:42 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-U8yVPZEqMdGFECdLiA9DHw-1; Mon, 02 Nov 2026 22:55:38 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 67FEA1955BCF; Tue, 3 Nov 2026 03:55:37 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1ABDD7E5; Tue, 3 Nov 2026 03:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=55V3OL4QOhL126zAS/6Em8pgp/CM9gX2lo3RNeHL3HA=; b=VeciIhJk2DH29PbIeb/IbokUmSnxSFGhO2j+XMOXVldR8MR3VXZn5smolQ0HGrx1VbrFYj gwngjBEcqlA18ZYWZLS3LQtdxlC5me7tfLn/ne7qk5IiYP9Q5tZdUM7OX0C1kj+YhtFLD0 CzONeCYPb5Unu6RhiIa/yghBWxQUa7I= X-MC-Unique: U8yVPZEqMdGFECdLiA9DHw-1 X-Mimecast-MFC-AGG-ID: U8yVPZEqMdGFECdLiA9DHw_1793678137 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 13/16] block/block-copy: merge the two backup scan steps into block_copy_prescan() Date: Mon, 2 Nov 2026 21:54:24 -0600 Message-ID: <20261103035506.2688772-31-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.238, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678199364158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" block_copy_reset_unallocated() and block_copy_calculate_zero_bitmap() are both one step of the same scan and differ only in what they do with the answer. Fold them into block_copy_prescan(), which drops unallocated clusters from copy_bitmap while skip_unallocated is set, so backup_scan_source() loses its per-mode branch. sync=3Dtop now walks the dirty areas the way full and bitmap do, so it no longer queries what copy-before-write has already copied during the scan. A failed query still fails sync=3Dtop, as nothing else can tell which clusters to skip, and still leaves the area to be copied as data otherwise. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-10-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- include/block/block-copy.h | 9 ++---- block/backup.c | 7 +---- block/block-copy.c | 63 ++++++++++++++------------------------ 3 files changed, 27 insertions(+), 52 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 3a61066b55f..dc51316fcff 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -41,12 +41,9 @@ void block_copy_state_free(BlockCopyState *s); void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes); -int64_t coroutine_fn GRAPH_RDLOCK -block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *c= ount); - -void coroutine_fn GRAPH_RDLOCK -block_copy_calculate_zero_bitmap(BlockCopyState *s, int64_t offset, - int64_t *cached_end, int64_t *count); +int coroutine_fn GRAPH_RDLOCK +block_copy_prescan(BlockCopyState *s, int64_t offset, int64_t *cached_end, + int64_t *count); int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, diff --git a/block/backup.c b/block/backup.c index 38b0838d694..60c00fca67d 100644 --- a/block/backup.c +++ b/block/backup.c @@ -271,12 +271,7 @@ static int coroutine_fn backup_scan_source(BackupBlock= Job *s) /* rdlock protects the block-status queries below */ bdrv_graph_co_rdlock(); - if (top) { - ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); - } else { - block_copy_calculate_zero_bitmap(s->bcs, offset, &cached_end, - &count); - } + ret =3D block_copy_prescan(s->bcs, offset, &cached_end, &count); bdrv_graph_co_rdunlock(); if (ret < 0) { diff --git a/block/block-copy.c b/block/block-copy.c index ad358f4d2f1..78cc855b5b1 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -153,8 +153,8 @@ typedef struct BlockCopyState { * This is indicated by skip_unallocated. * * In this case, block_copy() will query the source\ufffd\ufffd\ufffds= allocation status, - * skip unallocated regions, clear them in the copy_bitmap, and invoke - * block_copy_reset_unallocated() every time it does. + * skip unallocated regions and clear them in the copy_bitmap, as + * block_copy_prescan() does. */ bool skip_unallocated; /* atomic */ /* State fields that use a thread-safe API */ @@ -781,40 +781,17 @@ void block_copy_reset(BlockCopyState *s, int64_t offs= et, int64_t bytes) } /* - * Reset bits in copy_bitmap starting at offset if they represent unalloca= ted - * data in the image. May reset subsequent contiguous bits. - * @return 0 when the cluster at @offset was unallocated, - * 1 otherwise, and -ret on error. + * One step of the scan run before copying: query the next dirty area, fill + * zero_bitmap and, while skip_unallocated is set, drop the clusters which + * are not allocated above the backing from copy_bitmap. @cached_end tracks + * progress across calls, @count how far @offset should move. + * + * A failed query only leaves the area unmarked, so it copies as data, but + * sync=3Dtop cannot tell what to skip and fails instead. */ -int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, - int64_t offset, - int64_t *count) -{ - int ret; - int64_t clusters, bytes; - - ret =3D block_copy_scan_status(s, offset, &clusters); - if (ret < 0) { - return ret; - } - - bytes =3D clusters * s->cluster_size; - - if (!ret) { - block_copy_reset(s, offset, bytes); - } - - *count =3D bytes; - return ret; -} - -/* - * One scan step, like block_copy_reset_unallocated(); @cached_end - * tracks progress across calls, @count how far @offset should move. - */ -void coroutine_fn GRAPH_RDLOCK -block_copy_calculate_zero_bitmap(BlockCopyState *s, int64_t offset, - int64_t *cached_end, int64_t *count) +int coroutine_fn GRAPH_RDLOCK +block_copy_prescan(BlockCopyState *s, int64_t offset, int64_t *cached_end, + int64_t *count) { int64_t max_bytes =3D QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, s->cluster_size); @@ -830,7 +807,7 @@ block_copy_calculate_zero_bitmap(BlockCopyState *s, int= 64_t offset, if (!found) { *count =3D s->len - offset; - return; + return 0; } dirty_end =3D dirty_offset + dirty_bytes; @@ -839,15 +816,21 @@ block_copy_calculate_zero_bitmap(BlockCopyState *s, i= nt64_t offset, int64_t query_offset =3D MAX(dirty_offset, *cached_end); int ret =3D block_copy_scan_status(s, query_offset, &clusters); - if (ret >=3D 0) { - *cached_end =3D query_offset + clusters * s->cluster_size; - } else { - /* Best-effort: leave this area unmarked; it copies as data. */ + if (ret < 0) { + if (qatomic_read(&s->skip_unallocated)) { + return ret; + } *cached_end =3D dirty_end; + } else { + *cached_end =3D query_offset + clusters * s->cluster_size; + if (!ret && qatomic_read(&s->skip_unallocated)) { + block_copy_reset(s, query_offset, clusters * s->cluster_si= ze); + } } } *count =3D MIN(*cached_end, dirty_end) - offset; + return 0; } /* --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678172; cv=none; d=zohomail.com; s=zohoarc; b=mhrjKxCofc9fPiyq37mBml5iayagIfaVy1GsblDxR4SQlrfj+pFfZtYOmusIHX1d9NI5lRP1z68SoiVPUBLdmd2154g5MlhMShRic3PLkhOn5UthrQPZb37JoVovWVPPE8q6yTh9/o4YTg+m5wN0+WsD1DqbQPC/rPaWZP1/ZTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678172; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oe0DBpqOPzENdPHfYYs0jIPUlyTxk+RA3n49myVoAos=; b=bzi1e1WE3DIq3r5todWKwHEI+0tCL+ObFj3+y7VBWj212lvZHU8b74Ux3b1GhMSvMOzPy+5ZrBc1iXeRyoanxkzWulIT4XQh1ENEmC362YEBZ7qNyRFkYHbMYczSEUM5IHwlkA4BthQhW/Hpr5YLg/q+6VVjKLgCgWLhfrWWj1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678172987160.25677188701627; Mon, 2 Nov 2026 19:56:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cl-0006gM-Sg; Mon, 02 Nov 2026 22:55:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5ch-0006dP-JN for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cf-0000eY-BX for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:47 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220--iytbglPP3Ka7GQmvD502A-1; Mon, 02 Nov 2026 22:55:41 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1B0F1954B2E; Tue, 3 Nov 2026 03:55:39 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BBB617E8; Tue, 3 Nov 2026 03:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oe0DBpqOPzENdPHfYYs0jIPUlyTxk+RA3n49myVoAos=; b=DaXNXrBa5kLGwZQUBHfnoFEyOSSU1rat0HiwvTbpRbE+grdGlr+o0woLf3EpSW9YnXXetm tIsNjfhRXYxmhY3LSxnLSARLqgh6RNLug1ptMBHN6srK0X9wFbL+iuG4oK10Sg+xaIUmcA G3SrSR25l/rM57Q/vuDjZa2NnjsoEaw= X-MC-Unique: -iytbglPP3Ka7GQmvD502A-1 X-Mimecast-MFC-AGG-ID: -iytbglPP3Ka7GQmvD502A_1793678140 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 14/16] block/block-copy: replace zero_bitmap_valid with scan_done Date: Mon, 2 Nov 2026 21:54:25 -0600 Message-ID: <20261103035506.2688772-32-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678174918158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" zero_bitmap_valid says more than its name: a task created once it is set skips its own block-status query, the sync=3Dtop skipping included, because the scan has already settled what to copy. And the end of the scan was announced twice, clearing skip_unallocated and then publishing zero_bitmap_valid, with an ordering rule in a comment tying the two. Rename the flag to scan_done, and let block_copy_set_scan_done() clear skip_unallocated before publishing it, so backup_scan_source() makes one call and the order is kept in one place. skip_unallocated is left to mean that a sync=3Dtop scan is in progress. No behavior change. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-11-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- include/block/block-copy.h | 2 +- block/backup.c | 6 +----- block/block-copy.c | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index dc51316fcff..e82c96586e6 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -102,6 +102,6 @@ void block_copy_call_cancel(BlockCopyCallState *call_st= ate); BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s); int64_t block_copy_cluster_size(BlockCopyState *s); void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip); -void block_copy_set_zero_bitmap_valid(BlockCopyState *s); +void block_copy_set_scan_done(BlockCopyState *s); #endif /* BLOCK_COPY_H */ diff --git a/block/backup.c b/block/backup.c index 60c00fca67d..1bf6cbedaca 100644 --- a/block/backup.c +++ b/block/backup.c @@ -254,7 +254,6 @@ static void backup_init_bcs_bitmap(BackupBlockJob *job) static int coroutine_fn backup_scan_source(BackupBlockJob *s) { Job *job =3D &s->common.job; - bool top =3D s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP; int64_t offset, cached_end =3D 0, count; int ret =3D 0; @@ -279,10 +278,7 @@ static int coroutine_fn backup_scan_source(BackupBlock= Job *s) } } - if (top) { - block_copy_set_skip_unallocated(s->bcs, false); - } - block_copy_set_zero_bitmap_valid(s->bcs); + block_copy_set_scan_done(s->bcs); return 0; } diff --git a/block/block-copy.c b/block/block-copy.c index 78cc855b5b1..3b7e282e5b9 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -161,8 +161,12 @@ typedef struct BlockCopyState { BdrvDirtyBitmap *copy_bitmap; /* Clusters reading as zero; allocated on demand, frozen once valid. */ HBitmap *zero_bitmap; - /* Published only after the scan, with skip_unallocated already false.= */ - bool zero_bitmap_valid; /* atomic, store-release/load-acquire */ + /* + * Set when the scan is over: zero_bitmap is complete, and for sync=3D= top + * copy_bitmap holds no unallocated clusters, so a task needs no + * block-status query of its own. + */ + bool scan_done; /* atomic, store-release/load-acquire */ ProgressMeter *progress; SharedResource *mem; RateLimit rate_limit; @@ -214,7 +218,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, * The scan already knows how this range reads: pick the method here a= nd * stop the task where the answer changes. */ - if (qatomic_load_acquire(&s->zero_bitmap_valid)) { + if (qatomic_load_acquire(&s->scan_done)) { int64_t boundary; if (hbitmap_get(s->zero_bitmap, offset)) { @@ -687,7 +691,7 @@ int block_copy_block_status(BlockCopyState *s, int64_t = offset, int64_t bytes, return ret; } -/* Only the scan allocates, and it runs before zero_bitmap_valid. */ +/* Only the scan allocates, and it runs before scan_done. */ static HBitmap *block_copy_zero_bitmap(BlockCopyState *s) { if (!s->zero_bitmap) { @@ -845,7 +849,7 @@ block_copy_set_task_method(BlockCopyState *s, BlockCopy= Task *task) int64_t status_bytes; /* block_copy_task_create() already decided, from zero_bitmap. */ - if (qatomic_load_acquire(&s->zero_bitmap_valid)) { + if (qatomic_load_acquire(&s->scan_done)) { return true; } @@ -1179,10 +1183,11 @@ void block_copy_set_skip_unallocated(BlockCopyState= *s, bool skip) qatomic_set(&s->skip_unallocated, skip); } -void block_copy_set_zero_bitmap_valid(BlockCopyState *s) +void block_copy_set_scan_done(BlockCopyState *s) { block_copy_zero_bitmap(s); - qatomic_store_release(&s->zero_bitmap_valid, true); + qatomic_set(&s->skip_unallocated, false); + qatomic_store_release(&s->scan_done, true); } void block_copy_set_speed(BlockCopyState *s, uint64_t speed) --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678204; cv=none; d=zohomail.com; s=zohoarc; b=HnKnqVg7dB6cJKzqiWUW47GGtEkNTdhGh2QMJbc+jZFkewGxYRme+w2nwsjF+W3exzMLaffvSYwuBe+f4OyRuAYSejCizq3WlyqsCZ/ZwF/RMZg/EnINWjcj7+OllpuRHthdIMFxyVrndlZ0hFyYliJ7ZLJyOq7VJuTWC5smfC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678204; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+GqS6KYkrZQyo+6BwaP1LWErwgmIen4jwjJsOzZ/lDQ=; b=Bj9mx9njkKsY4g8Y6ZqY80jL36cPHMRff5QGMj0uUC8TDxzbz3uR/Xt25ovUCUDoMc25nB3aG33mEYAkE1bNxhWaADn6x76ED8q/plaeALemUY9E8LZavc+g5HDM+r7XnylhC5XoKaHq3x70ZqyCElnB5eEFRIxabUNbfNaOt6g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678204030632.6860169721276; Mon, 2 Nov 2026 19:56:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5cr-0006lS-Ko; Mon, 02 Nov 2026 22:55:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cj-0006fW-Ep for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5ch-0000ev-Ld for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:49 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-jj5UGQQAOWyw7vNeEy3Skw-1; Mon, 02 Nov 2026 22:55:42 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9BB7C1802147; Tue, 3 Nov 2026 03:55:41 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 116577EA; Tue, 3 Nov 2026 03:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+GqS6KYkrZQyo+6BwaP1LWErwgmIen4jwjJsOzZ/lDQ=; b=TmGMEHlWb38lpjB6sAbz5bfp8XRHnn15ajMACnYQjbJSRo2U4X5Jp1sj2CxhiJHmQVov5U mDM2rFqE6ouf1IP8YNA6cGDeIVsqDbdNpPVbUN/0Tl8Bjh+CJIwJTr2JBmlOVxP7iogiSI NoyF8NVkrDZTxE5bv4u4M9rMg7f9hXc= X-MC-Unique: jj5UGQQAOWyw7vNeEy3Skw-1 X-Mimecast-MFC-AGG-ID: jj5UGQQAOWyw7vNeEy3Skw_1793678141 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 15/16] util/co-shared-resource: skip the mutex for an empty request Date: Mon, 2 Nov 2026 21:54:26 -0600 Message-ID: <20261103035506.2688772-33-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678205427158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Getting or putting nothing cannot change the pool, yet both calls take the mutex, and co_put_to_shres() also wakes every waiter to find the pool unchanged. Return early when n is zero. block-copy is about to reserve nothing for write-zeroes tasks the target serves without a buffer, which makes such calls the common case for a mostly-zero image. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-12-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- util/qemu-co-shared-resource.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/util/qemu-co-shared-resource.c b/util/qemu-co-shared-resource.c index 752eb5a1c5f..f9b6af00729 100644 --- a/util/qemu-co-shared-resource.c +++ b/util/qemu-co-shared-resource.c @@ -69,6 +69,10 @@ static bool co_try_get_from_shres_locked(SharedResource = *s, uint64_t n) void coroutine_fn co_get_from_shres(SharedResource *s, uint64_t n) { assert(n <=3D s->total); + if (!n) { + return; + } + QEMU_LOCK_GUARD(&s->lock); while (!co_try_get_from_shres_locked(s, n)) { qemu_co_queue_wait(&s->queue, &s->lock); @@ -77,6 +81,10 @@ void coroutine_fn co_get_from_shres(SharedResource *s, u= int64_t n) void coroutine_fn co_put_to_shres(SharedResource *s, uint64_t n) { + if (!n) { + return; + } + QEMU_LOCK_GUARD(&s->lock); assert(s->total - s->available >=3D n); s->available +=3D n; --=20 2.56.0 From nobody Mon Nov 23 04:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793678191; cv=none; d=zohomail.com; s=zohoarc; b=bQYwjEeTH4V51KtqiYC3D34GRJIFQK8tHZHA/Q1/pnPH+Xw9HKurD9zo9MHwjgDNQQdrzbuQf8hgPRym4b9pFWrgLlcoI6hczBK8LhrtBhQwybLugPt/HMmKzZNxXz2pygcRZUB2AxBzyKA6bbmjHzID48lqyMqTJCkyqqVOua4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793678191; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4EDlI5F/X3ILuOnAB03eaLBMrQiOy1QudnmyKXfPybU=; b=Mrl43cwMKN8P0ae0tCDRYr91xvAagcaLoICtkRSYNXRTRNaD8mkTe5nJV5Jz4IFx0L9Ku/XYQMEFXEj8xc1kg5zOo72P9HykwtrhimCc09p99RxTwc4QqFPFaKHPsokwJ81gkXb2G96dTDlNz8xGYwG4iCEBiyOyllU8NN9aI9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793678191612909.6408647698709; Mon, 2 Nov 2026 19:56:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xO5d4-0006vK-Ic; Mon, 02 Nov 2026 22:56:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5cl-0006gi-GJ for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xO5ci-0000f9-Sh for qemu-devel@nongnu.org; Mon, 02 Nov 2026 22:55:50 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-MAjsRfycOk6ULYWSkirhyA-1; Mon, 02 Nov 2026 22:55:44 -0500 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B360318011C5; Tue, 3 Nov 2026 03:55:43 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F215D7E7; Tue, 3 Nov 2026 03:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793678148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4EDlI5F/X3ILuOnAB03eaLBMrQiOy1QudnmyKXfPybU=; b=eJnZY4ZFTa2k/xxsTWytTda/AMW3rQ2byrDKs+oOte2lTC80aLfBeN97VkOQ9iu/xWhpe7 rdRqj3IT+jaQ0zwt7WV884HJ6tlWAm4seOuVG6Onl3Vffy/lJmSh+D8GRgc5Pm1j0k6A6L kSibwBn9CotdE743iC79SR2pbTjqe+Y= X-MC-Unique: MAjsRfycOk6ULYWSkirhyA-1 X-Mimecast-MFC-AGG-ID: MAjsRfycOk6ULYWSkirhyA_1793678143 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev , Kevin Wolf , Hanna Reitz , Markus Armbruster , qemu-block@nongnu.org (open list:Block Jobs) Subject: [PULL 16/16] block/block-copy: coalesce write-zeroes tasks Date: Mon, 2 Nov 2026 21:54:27 -0600 Message-ID: <20261103035506.2688772-34-eblake@redhat.com> In-Reply-To: <20261103035506.2688772-18-eblake@redhat.com> References: <20261103035506.2688772-18-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793678193398158500 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Task size was capped to block_copy_chunk_size() regardless of method, which sizes a task by the copy buffer. A write-zeroes task carries no buffer, so that cap only splits one long known-zero run into a crowd of small COPY_WRITE_ZEROES tasks, each with its own request against the target. block_copy_task_create() already decides from zero_bitmap how far a task may run, so add block_copy_widen_zero_area() to that decision: a write-zeroes task runs to the next clean cluster of copy_bitmap, at most BDRV_REQUEST_MAX_BYTES aligned down to cluster_size, and the existing clamp cuts it back to where the zero run ends. The experimental x-perf max-chunk does not bound it, and its documentation now says so. Widening is safe: an overlapping caller waits on the task's BlockReq via reqlist_wait_one() rather than observing it mid-flight. A request that large is only cheap where the target zeroes by metadata. BDRV_REQ_NO_FALLBACK in supported_zero_flags rules out the targets which cannot, qcow2 v2 and iscsi among them, but it is optimistic for the rest: file-posix advertises it at open and only learns from a failing fallocate. So a write-zeroes task asks for it while the target is believed to oblige, which costs nothing when it does. A refusal ends the widening and shrinks the task to one cluster, written with fallback allowed. The rest of the range is dirty again, and the next pass of block_copy_common() picks it up as buffer-sized tasks running in parallel. Part of the refused range may already be zeroed, since -ENOTSUP only says the fast path is unavailable, and writing zeroes over it again changes nothing. Such a task is also the only one sure to need no buffer: without NO_FALLBACK, bdrv_co_do_pwrite_zeroes() writes the zeroes out through a bounce buffer. So it alone is left out of the memory pool and of the rate limit, where one widened request would otherwise hold the job back for as long as speed=3D takes to pass its whole length. The one-cluster write left after a refusal is not charged either, though it may bounce: that is at most one cluster per worker, once, as tasks created after the refusal are charged in full. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Message-ID: <20261030010613.1612771-13-den@openvz.org> Signed-off-by: Eric Blake --- qapi/block-core.json | 4 +- block/block-copy.c | 96 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 12 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 741c8165c06..2edd3bccaa2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1656,7 +1656,9 @@ # copying process. Doesn't influence copy-before-write # operations. 0 means unlimited. If max-chunk is non-zero then # it should not be less than job cluster size which is calculated -# as maximum of target image cluster size and 64k. Default 0. +# as maximum of target image cluster size and 64k. Write-zeroes +# requests to a target which zeroes efficiently are not bounded by +# it. Default 0. # # @min-cluster-size: Minimum size of blocks used by copy-before-write # and background copy operations. Has to be a power of 2. No diff --git a/block/block-copy.c b/block/block-copy.c index 3b7e282e5b9..c96b9ce4f13 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -92,19 +92,21 @@ typedef struct BlockCopyTask { BlockCopyState *s; BlockCopyCallState *call_state; /* - * @method can also be set again in the while loop of - * block_copy_dirty_clusters(), but it is never accessed concurrently - * because the only other function that reads it is + * @method and @zero_fast can also be set again in the while loop of + * block_copy_dirty_clusters(), but they are never accessed concurrent= ly + * because the only other function that reads them is * block_copy_task_entry() and it is invoked afterwards in the same * iteration. */ BlockCopyMethod method; + /* A write-zeroes task asking for BDRV_REQ_NO_FALLBACK. */ + bool zero_fast; /* * Generally, req is protected by lock in BlockCopyState, Still req.of= fset * is only set on task creation, so may be read concurrently after cre= ation. - * req.bytes is changed at most once, and need only protecting the cas= e of - * parallel read while updating @bytes value in block_copy_task_shrink= (). + * req.bytes only shrinks, and need only protecting the case of parall= el + * read while updating @bytes value in block_copy_task_shrink(). */ BlockReq req; } BlockCopyTask; @@ -159,6 +161,8 @@ typedef struct BlockCopyState { bool skip_unallocated; /* atomic */ /* State fields that use a thread-safe API */ BdrvDirtyBitmap *copy_bitmap; + /* Cleared once the target refuses BDRV_REQ_NO_FALLBACK. */ + bool zero_widen; /* atomic */ /* Clusters reading as zero; allocated on demand, frozen once valid. */ HBitmap *zero_bitmap; /* @@ -191,6 +195,23 @@ static int64_t block_copy_chunk_size(BlockCopyState *s) } } +/* + * A write-zeroes task carries no buffer, so it may cover far more than + * block_copy_chunk_size(). Return how far it may run; the caller clamps it + * to where the zero run ends. + */ +static int64_t block_copy_widen_zero_area(BlockCopyState *s, int64_t offse= t, + int64_t bytes) +{ + int64_t clean; + + bytes =3D MIN(bytes, QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, + s->cluster_size)); + clean =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset, bytes); + + return clean < 0 ? bytes : clean - offset; +} + /* * Search for the first dirty area in offset/bytes range and create task at * the beginning of it. @@ -201,7 +222,9 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, { BlockCopyTask *task; BlockCopyMethod method; + bool zero_fast =3D false; int64_t max_chunk; + int64_t search_end =3D offset + bytes; QEMU_LOCK_GUARD(&s->lock); max_chunk =3D MIN_NON_ZERO(block_copy_chunk_size(s), call_state->max_c= hunk); @@ -223,6 +246,11 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCal= lState *call_state, if (hbitmap_get(s->zero_bitmap, offset)) { method =3D COPY_WRITE_ZEROES; + zero_fast =3D qatomic_read(&s->zero_widen); + if (zero_fast) { + bytes =3D block_copy_widen_zero_area(s, offset, + search_end - offset); + } boundary =3D hbitmap_next_zero(s->zero_bitmap, offset, bytes); } else { boundary =3D hbitmap_next_dirty(s->zero_bitmap, offset, bytes); @@ -248,6 +276,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, .s =3D s, .call_state =3D call_state, .method =3D method, + .zero_fast =3D zero_fast, }; reqlist_init_req(&s->reqs, &task->req, offset, bytes); @@ -469,6 +498,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,= BdrvChild *target, .max_transfer =3D QEMU_ALIGN_DOWN( block_copy_max_transfer(source, target= ), cluster_size), + .zero_widen =3D target->bs->supported_zero_flags & BDRV_REQ_NO_FAL= LBACK, }; s->discard_source =3D discard_source; @@ -488,6 +518,15 @@ void block_copy_set_progress_meter(BlockCopyState *s, = ProgressMeter *pm) s->progress =3D pm; } +/* + * Bytes @task moves as data, for the memory pool and the rate limit. Only= a + * write-zeroes request that may not fall back is sure to need no buffer. + */ +static uint64_t block_copy_task_data_bytes(BlockCopyTask *task) +{ + return task->zero_fast ? 0 : task->req.bytes; +} + /* * Takes ownership of @task * @@ -509,7 +548,7 @@ static coroutine_fn int block_copy_task_run(AioTaskPool= *pool, aio_task_pool_wait_slot(pool); if (aio_task_pool_status(pool) < 0) { - co_put_to_shres(task->s->mem, task->req.bytes); + co_put_to_shres(task->s->mem, block_copy_task_data_bytes(task)); block_copy_task_end(task, -ECANCELED); g_free(task); return -ECANCELED; @@ -520,6 +559,34 @@ static coroutine_fn int block_copy_task_run(AioTaskPoo= l *pool, return 0; } +/* + * Widening a write-zeroes request only pays off where the target zeroes by + * metadata, so while the target is believed to oblige, a request asks to = fail + * instead of falling back to writing the zeroes out. A refusal ends the + * widening and shrinks @t to one cluster for the caller to write the usual + * way; the rest is dirty again and is picked up at the buffer chunk size. + */ +static int coroutine_fn GRAPH_RDLOCK +block_copy_write_zeroes_fast(BlockCopyTask *t, bool *error_is_read) +{ + BlockCopyState *s =3D t->s; + int64_t nbytes =3D MIN(t->req.offset + t->req.bytes, s->len) - t->req.= offset; + int ret; + + ret =3D bdrv_co_pwrite_zeroes(s->target, t->req.offset, nbytes, + (s->write_flags & ~BDRV_REQ_WRITE_COMPRESS= ED) | + BDRV_REQ_NO_FALLBACK); + if (ret =3D=3D -ENOTSUP) { + qatomic_set(&s->zero_widen, false); + block_copy_task_shrink(t, s->cluster_size); + } else if (ret < 0) { + trace_block_copy_write_zeroes_fail(s, t->req.offset, ret); + *error_is_read =3D false; + } + + return ret; +} + /* * block_copy_do_copy * @@ -622,8 +689,13 @@ static coroutine_fn int block_copy_task_entry(AioTask = *task) int ret =3D -1; WITH_GRAPH_RDLOCK_GUARD() { - ret =3D block_copy_do_copy(s, t->req.offset, t->req.bytes, &method, - &error_is_read); + if (t->zero_fast) { + ret =3D block_copy_write_zeroes_fast(t, &error_is_read); + } + if (!t->zero_fast || ret =3D=3D -ENOTSUP) { + ret =3D block_copy_do_copy(s, t->req.offset, t->req.bytes, &me= thod, + &error_is_read); + } } WITH_QEMU_LOCK_GUARD(&s->lock) { @@ -640,7 +712,7 @@ static coroutine_fn int block_copy_task_entry(AioTask *= task) progress_work_done(s->progress, t->req.bytes); } } - co_put_to_shres(s->mem, t->req.bytes); + co_put_to_shres(s->mem, block_copy_task_data_bytes(t)); block_copy_task_end(t, ret); if (s->discard_source && ret =3D=3D 0) { @@ -867,6 +939,7 @@ block_copy_set_task_method(BlockCopyState *s, BlockCopy= Task *task) } if (ret & BDRV_BLOCK_ZERO) { task->method =3D COPY_WRITE_ZEROES; + task->zero_fast =3D qatomic_read(&s->zero_widen); } return true; @@ -935,11 +1008,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_s= tate) } } - ratelimit_calculate_delay(&s->rate_limit, task->req.bytes); + ratelimit_calculate_delay(&s->rate_limit, + block_copy_task_data_bytes(task)); trace_block_copy_process(s, task->req.offset); - co_get_from_shres(s->mem, task->req.bytes); + co_get_from_shres(s->mem, block_copy_task_data_bytes(task)); offset =3D task_end(task); bytes =3D end - offset; --=20 2.56.0