From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322511; cv=none; d=zohomail.com; s=zohoarc; b=NQrLXSzJ6R7Z3H0uqdjzlpzzYu4FCwUPhOuQHDZMNAM4v9vCAvXd+YvnDKxgNDhpvhmjilg5cjBbmW7TWLRdZ/CfDwUrUKEvbqiskXDLbZBce0xrabxNtlZvkhFfwok5C7Qv07vPd5OiVYhzgYmU0wcFD6Zw5RizbBgz5e9/Df0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322511; h=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=71SB0FrjFwut8s/0OfdT1uGzvIsW+clScFF+JCSKOjE=; b=kVzls2hxHdBUQzU134BL2PKt4OS21ZpSg/BGZPw8y1+me3GLCjYyQ5r2IziBKqQx1C+92IkrTs7w6B3kz5XGw6BOhSXzZspwTib3koKvYj82vi1FuXCWLspYHB1MezI5WyMbLl5jKoNoarufpDba/o/23b/CrPSOQrAaC2mLrP4= 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 1793322511670711.8715464853502; Thu, 29 Oct 2026 18:08:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb4w-0002HL-AO; Thu, 29 Oct 2026 21:06:46 -0400 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 1xMb4e-0002CL-La for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:34 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4a-0006E2-5w for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:25 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a5036bbac7so602485e9.3 for ; Thu, 29 Oct 2026 18:06:23 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322382; x=1793927182; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=71SB0FrjFwut8s/0OfdT1uGzvIsW+clScFF+JCSKOjE=; b=GNphpGHl+pgVUE1oG1HATk9vhu1aOq6bQBC9jgpmKdkDwxK53a+S1lz7BwWfrxEbh/ FTpEgZ4qmTcmB7ODSTN+OPs6gG+DbWF5pnzyd79ncvH6M256Pe+WCSKPTWqAHPvf4n0Q zBmL/uj/H5r6s8TgRDiIhFFm4liKs0wf4S2Ajp+XLnHU59TsXHMzngl2PtLpu5ebjl8N VDCy9VdL8965I8YAMrGmMpNezbwDZyU0o6i0Q415ATU1iP0UhYAct9j+QC+Y5iASlN4d a/SUkZubVts8v3Df6hj33mVo6/XJnpaTKKK0/CF/kYS2P3YBbcvmx3yau70+0WRzK/+3 TuOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322382; x=1793927182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=71SB0FrjFwut8s/0OfdT1uGzvIsW+clScFF+JCSKOjE=; b=da1qtbgc0nZ1iMNM6JTwbU9Vi2nWtnwh+2pw17baG8Ko15LFTpTNYWTK1EpsJFJFGC MVPzwQr++I/n6FyM/PxvptrTMuZOnI0Gra3nDk6g8zO+amhOhSo6IjHo67WM0XCY3NQQ qJQQWEpF0MScBJjJq3M1OA4oHj5943sXklrrZRddXXRmHSbybeFdUdXDlLIQl8V4XlxO kcd9hebdaFmmFxC46SGm7GaLA/yLZezuhwPRn+RFgZcaiH15Gsw+yF+tTE+Zc5+nN4tA hbr3eqEqufL+kQBqqysoYHNSlwmbpCom4kI3ays/yVIghD0pJQ89aiW1nMFB9luOaxdf hN/A== X-Gm-Message-State: AFq9FYIKPP9YExhM80yQzihdcUYlnar0DYDcD2JhzVXXa0xaI8k7BqKO fk1cnGhduVPtHQHqUt02uFZsdqXKsTovtZ/vBfp6/ZE2ZQLBb95hz8M8q1tKuHgQoebRkATup81 ymVZm X-Gm-Gg: AYBFou3n325aReJ6ULbN/Ufoj4bY5mZrsT/H6/gqNMbBcKOgL44FIrF66ZabRiocQFc q73czCQBqDjtt7eoMLGfZmEjBp2/2kyUmVirEtJ9gnvXa0QZjitBteaT+IoKq3qglGHd4cVmk1o V2MV4eG49a72XjwdqYLZ1x3QqZs93CuFOggPOVLTnkv3dxAsQTR4ihgx5OfVRpOuoQ8EdjLuvSo knx/ox5H+8ur2MSFViboEICRHzDZ+oXsplgMI0+NM5GC5BTdxAVaqRUmYUiPlvRU7XiUZ8E4N8o MUQtzprb+dDCAssh/5Ve57swFgVUalnIhm2B2SIRAM+lKSyVLQNr7x08zNUh6Bej8HI91v+G1NR 9FOl7X1dS/+KAF6x+CSKrvNqCC3DlcZyLL0AXkQCdAIJN1fbokFW19h/0SeZ9RE6UchPBSsB/Ny 8wP0CC5eBk8dfapUPXp4GfWfHAq9j8xl/Sw8qnHpKC46B8it1UoOVLEhV03yGqYW2N3SOqDsBuz jIxFl0jXO8gzKzKDYE4YI9zJ0nHSvP9wACUYEwWUouq429MVZ7prqC9weeqLB614lIdGYOVZH7/ 8G3skPOTQJqe6FRDHSO5XCmRBy+DEl2EnA19Gk4= X-Received: by 2002:a5d:5d06:0:b0:48e:2a04:4ea3 with SMTP id ffacd0b85a97d-48e6e2c05e3mr2283359f8f.8.1793322382350; Thu, 29 Oct 2026 18:06:22 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 01/12] block/commit: pass BDRV_WANT_PRECISE to block-status Date: Fri, 30 Oct 2026 02:06:01 +0100 Message-ID: <20261030010613.1612771-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::32b; envelope-from=den@openvz.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322513840154100 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 --- block/commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/commit.c b/block/commit.c index 2d52c39594..4e0b0f9029 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); } =20 trace_commit_one_iteration(s, offset, bytes, ret); --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322425; cv=none; d=zohomail.com; s=zohoarc; b=XZ1pMnd8M6esyhtxs+Kbs4xb4/bi9JHfMJVnzoWCeYIwHeH3Bx7PX1cRY98GAly33jkL4VAlgqNAMU5PF2jTYMMykuGAP3wkk8USBusepXczFtVnHXwgfm36G1GE1MCpUrvmf9jMQNOMYu3fPFLV0vipdXxJWKxa00oJfSli/8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322425; h=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=Tzcnv4iV/M0//lehS771fIWvmHTFMU4220mA9TA0Wtk=; b=MOyU739qhugi/U4Us7tenA8rgIKWHnwPd4MZtP/yUpckMvNv6ONXoBE89MZwPkyY7dkHIEuMUJJVXHJQz0L5Mf5qbv6jxRO4bpNM97QRQcj+zeFv9BO8yfCxV8uoXg6H3TvIRG29gvZtZuP9jcuh57+ae8G0Z4ch9r7hP/KKBHA= 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 1793322425730609.6461183150391; Thu, 29 Oct 2026 18:07:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb4w-0002HI-36; Thu, 29 Oct 2026 21:06:46 -0400 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 1xMb4e-0002CN-Pv for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:35 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4b-0006EN-Mr for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:27 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-48c5358fc28so141248f8f.0 for ; Thu, 29 Oct 2026 18:06:25 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322384; x=1793927184; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Tzcnv4iV/M0//lehS771fIWvmHTFMU4220mA9TA0Wtk=; b=LTU+oGRr9C59gJfxsi3rZKYdXli1dZFjD8z/xZFlDcbcpkePJTYUpYghk6f9zQStNZ nSD45RAwrTexIPbILymka1JxHeBlcgnhtStUVjQwcpTSn1uk9WmmeeWeAD87Dmokslc9 mdMIS4Be9rsWMMjDL3RI0uZsa2OnihTm9TTdrdklbayF6vfldD/YUafOyrhdY9nb7FOa 8/lXU7yeXFU7ZMIw/VJWnPemLpZ4YLtp6BStqw/rzDqc5tGRPOmaOkFc9xF/ZGiIClkX HWpKC6esDbF/muv1c1uvmAme1EWnr0j5DO2zybUX5ddw+Zfz3R96yx0hLwhWYb7PZRuM Q1Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322384; x=1793927184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Tzcnv4iV/M0//lehS771fIWvmHTFMU4220mA9TA0Wtk=; b=biTO/YcJdMo/u+VscqZtQX67Yb/9nl1c9LHXNVmq4XSNlmRPwIcvWhyr4egbnNbYr2 EKV1qha4TrGg6fXj8NswrD+coSHWj+TN8jlEjPqe/sIbMLcLMQeJxnYfJRFPgip1ruaW Pqg1R5zKDj2EuvgPf4u1dRlh1K8LnHwzyhvoAWiuCrpncEGTZyfSRTsgLqxFzHfeQ7s5 IS8PTiBJz6kLaYVf3KDGEFT5jTBMHqT8CDPyw/NZ7iaNae6icosAAodeRaN7P4sladj1 Mn44vRYnhs2yK4COmejceFTNr9CIjYAN5epy6+uQctSsWSAhUYpIJ3Anbjbuq/mERUMb lllQ== X-Gm-Message-State: AFq9FYIcuzEflaw95mT3029wnXxpuU5JRxZtjklqC4Av2Z13+7dPv9bg r/J+Ov9KO5DMXhWlWEmn8qZr/OFHKLjYLrT8FZwYkr/5/cIu4lqQDFz39Cx1lSehi2BksD9qO/Y qL4Md X-Gm-Gg: AYBFou0TN4zTSq36vzVer724W+K4wn7heDqCiA9qQVI7YEMnt6PluMVAZVjLVeTDOL4 RmbQff2FbHW7vo/oWpyymWR3CoOd27t4SI3f1nIcJkJCA3iw/PTGCRPIIpb1QZxfH8gDFb1E3Vy fVvGjz/eB4+R7J/npiADQ3vrJea8c/Hgom1FEe80zy7lFscfDNtDPIb0OL2phAx+/7tdxmtWhEk WDSEauFTe3/CsCxYdaWhqqJq5NPKOxIEAacvCUEhrH4IegCjaRPqIVV8MCFdL9KT306cS0kyb61 6AY+5slwl6be+8+6/cSPZAnj7ilPZxqx4Bc2m760TixFUeyCTxLvU5Fk8UGyUKORK4G8tC5hzjO IqHcuFskYes4p0Ey73VG6j0Wj6bgyLKGUKmyIYCMgpJhZ9wxXwu2N99GuIfSsrmJ+Hos5EQL0Qc P3fKTPW7Kp0Sz8qWvBjr1JaNaRoCvA2koEG+s7IwBXKtp8A5BkLtsima+SQ3TWPlesm5Ug23e+q XTxpUpvWwfDpX9ljmK7wRxjDYK86axd3VDjoX1k9y2NkvpBxW8l5M4tXovfgoG8+kKMyBFQ5Mnr W/1tOu0LguZWyB1uFD3aGbslZS8mvtvJs+JngPE= X-Received: by 2002:a05:6000:4b02:b0:48d:f99d:a0d2 with SMTP id ffacd0b85a97d-48e6e2e76famr2147601f8f.15.1793322384063; Thu, 29 Oct 2026 18:06:24 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 02/12] iotests/040: cover large and fragmented commit runs Date: Fri, 30 Oct 2026 02:06:02 +0100 Message-ID: <20261030010613.1612771-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::430; envelope-from=den@openvz.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322429184154100 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 --- 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 5c18e413ec..e01c9385ba 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 =20 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') =20 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') =20 +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 1bb1dc5f0e..d2e2a2d98f 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -................................................................. +................................................................... ---------------------------------------------------------------------- -Ran 65 tests +Ran 67 tests =20 OK --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322531; cv=none; d=zohomail.com; s=zohoarc; b=LE5n9gkeE1gDTwe6jgRmJAui3Fact745C1qbFUDj5JLZc+GO8LAo57rvzD3i8kIFDbL4HuhBkHa2zWjXcsEMelqsJcFnG3D8Ud7oyXj6EZhwDp7mjWaXI66hlh6CllwBL1avOR4w4TffpylDfrhfZ6dOxohp7NkUxCJlC0biXik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322531; h=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=CoR8CLrpuVAT0u8yvV1K/ZhWofQiYj1zPlWlm27XYIA=; b=I5VLvKB8C73ryMLlo4iuavhh7wel6JSblHn9XG1JjDrV8nrBCjfw1eZNaHi4ZLgOUDZNz8qy52Ua9pAgnO8ZtTOavNSrfBKdvV+oDfTc2RfENugyqAlPJR/pI2YSP9NYiIykr3rBKyUP99LHFpyOwu9Kxf5SaYv7P3hW9VxmEZ4= 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 1793322531445766.3044986249114; Thu, 29 Oct 2026 18:08:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb52-0002MU-MK; Thu, 29 Oct 2026 21:06:52 -0400 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 1xMb4h-0002Cj-OE for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:35 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4e-0006Ee-Fz for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:30 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-48e00eee27dso79323f8f.0 for ; Thu, 29 Oct 2026 18:06:27 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322386; x=1793927186; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CoR8CLrpuVAT0u8yvV1K/ZhWofQiYj1zPlWlm27XYIA=; b=jWklFvcWXWxi3r3XNMIKWQrSHdR6jlW9gSRKpsUSoJoDsI04FgNeOM7ZY4IXGODf3l TRYQwLExqgYnVqvjVsh/3OIwVx89VDd0pyZIXu8gxt9odMqinMJT4BR6lK03CgopCfLN sdKBBUSn2z+9qMz2NCd/x8I2BEjG0cIE5xF/CmxsR53h9ox1aoJpXE38f4F81wi0w+3v h0m6iPCyRsvL2J421mbPrgcK6e2/Piv9Uokwr6Pu/ZZXcSxIgzxSaFD//ADT/1Z6OOsC tPfDRe6CHRXZK3QuaBhJTo9yvvoTAL1b6YoLrOs37U7cDKv30tfJSxNPgQvnDWNzJf39 IsfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322386; x=1793927186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=CoR8CLrpuVAT0u8yvV1K/ZhWofQiYj1zPlWlm27XYIA=; b=GmOQGD5LeauuCqDMY96+Png/eDqkGDZpDTwd6Q7/++YGeyRsHAXOEq/BnqIyJ0d3YU A5jnR/eGu15it+shpcDwILmZrgKiK6+CPY+qScCXgCSfmw3eA2MLH0QMVspOo7KqrVsk HYGwZvsVXQxK1YBSechNj5nB92hvNnhHlEVAA53uhwc6qXHW4SYlY1pTvtVVxH+/8I50 9ffGaXTXGKe4TEFd+sLHhs0fpUM+GLNtv+kqB4f4euGLzDgp4++YyiUcZ1zwJeXGvIAn GeovG25tYTY5YACUizgZuXFoskhY37+M5hqUMZtOZP6qy83aKQNNFfZC1/LPkhzU116U 0alA== X-Gm-Message-State: AFq9FYIh/r2iqledclkNJUaPHsY7YbhKZQ+tlinJDkl5ulOiDzxB62ua V2bd6ZK5nN5nXTqbpbENzao6xuKsdTxOxwRVJgsip2gjfFZYPL1NhM6pT/SiJ+FNnPIRUKjNA2w fK326 X-Gm-Gg: AYBFou3i91TGmOyHO17JkXWJDKr48rl71xZOrwr0iHMPKcZ1kNQyoiSKCSLgzyrJnku r3NOlk76GQY5mnSUesf6DUIjhl04Gai2KD7brpyztQl3iIin8NkOCGeEHsIsgOlt4jmHpWZo8UY t6dudWTcAMdon8miItQA2wF+SM4roqvGYiY6D77+v9Vr/hVP2qKTx6rUls8uXvW65ZVk4MDXll5 lB3Gvwo6Sc9+aphXWbnNS7yGAP8cVDfHl11FPgDQv9duWf/UnSwwB/YCdm887azH59Tc1pRAumY 2ciF79qPEm3/b/P0ADPpzL91KLCFxzwxtWEmPgWquRTQDfWLFvAdJA2FpnJFA/Sj3S+y6ETloc7 AxO4KDR65mw/HNuXxUwGrDRfRkx/WX5m2AMtXPg+ydbuxhOpLg0h3IECdonsy2I5E5GxY/vLNzO pcLuCbBLX9iUjS2p+2LlWiwl+E6Rrq8vWTL32zhRNKpm32BneE9TRX71nt7TtMxZzWZZ4H6gDQO 0yGRhyrZ114ZmD32L8O4CoKErUkdWoxAvu8Zhn9P5BJZ3uS04g9A8ZPwXeQO4a/OOUX+w1aqoUq d6eoiYsfMxMlYsTCvg== X-Received: by 2002:a5d:5d13:0:b0:48e:103e:846f with SMTP id ffacd0b85a97d-48e6e2f91b5mr2229959f8f.9.1793322386194; Thu, 29 Oct 2026 18:06:26 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 03/12] block/commit: batch block-status queries Date: Fri, 30 Oct 2026 02:06:03 +0100 Message-ID: <20261030010613.1612771-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::435; envelope-from=den@openvz.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322532389158500 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 --- block/commit.c | 58 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/block/commit.c b/block/commit.c index 4e0b0f9029..e8ddd46053 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 */ }; =20 +/* 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) =20 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; =20 - /* 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; } =20 - trace_commit_one_iteration(s, offset, bytes, ret); + ret =3D st->ret; + bytes =3D st->end - offset; =20 - if (ret < 0) { - goto fail; + /* 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); } =20 + trace_commit_one_iteration(s, offset, bytes, ret); + 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 }; =20 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) } =20 buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); + st.len =3D len; =20 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; } =20 - ret =3D commit_iteration(s, offset, &n, buf); + ret =3D commit_iteration(s, offset, &n, buf, &st); =20 if (ret < 0) { return ret; --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322464; cv=none; d=zohomail.com; s=zohoarc; b=im5zF4Pl8auts1y+dTR9GWF2/2cprfKo4aQpGIPTv69/Ui0SsSmZZJ5DZmEbJFG0wWV1ZbBv9F30ISs7VxCnL97g82dMSimMl+qzPUUmzGPdlb5K6d/t1ufXpC/ZIcCyqvih5geu3jtDIeL04AaS+xV/fcXOZ7KCMsaPXdTjFgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322464; h=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=+S1/3KCY/e5AtFCJmbOXsDaClNgRRxpruvo2J7fXjnM=; b=Lt0GdcUPUPgIzLJ/uQ3T57Vu3/xGLsCStOPphngLb1DE5kisVfWKI/5CfjHG1QBZgDiev/JRCV4dAxZcGD9RIiobegqQJWd8oBbp+5pAjRkmBHMjdkoWy3L5e5lIJWxAveKHim8PKyK+zlV2QoSwdt3vwBGiju+K9OQyswQoebo= 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 17933224645954.803750683003273; Thu, 29 Oct 2026 18:07:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb4w-0002HZ-LG; Thu, 29 Oct 2026 21:06:46 -0400 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 1xMb4l-0002DN-Iz for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:37 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4f-0006Eo-1s for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:33 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4a5036bbac7so602635e9.3 for ; Thu, 29 Oct 2026 18:06:28 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322387; x=1793927187; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+S1/3KCY/e5AtFCJmbOXsDaClNgRRxpruvo2J7fXjnM=; b=cV6HLhlj7XBjQWeD05U8J5XjPVrZ1or4vCqx9Y5zfE17uxScLFK5d0E7d50r/QP1fK ncSjRgIodk8lNLgFHPFHzs1HXhOdQBbmHSMqNsVdQcixl9cEJVVNL9DvASJXp18xoZO/ xToZLi7xEGVzpE+HY4u6ZaueePMCZekUyARc/t9ZboaZLupbjJvi8srTIVNukHP/G9Ct ilMOnh6gtgnuRMgCfLBomOfgV+d/LQCvCwBTrCQG8RKeZPf0t4egref2vFlb0vHxe+7q j6D8RPFhdGSPOqstk/W3e18S1ZSpgJQ198kYctiAQ8h/Vw5wxnlfKZ/J2qrrdO5vISzY gd6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322387; x=1793927187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+S1/3KCY/e5AtFCJmbOXsDaClNgRRxpruvo2J7fXjnM=; b=yila376gqxzH1e0PaybHp5ICtI/lIbs1F79GN9gyHLlBU9vL3fQym/AGOY068SJNyt yftndoxvLEZP+ArvPSKM0+EV/KnPiXjCCGICGMMvkNO6tlbVOerM+pWCxGsOH+yccFDl kDLxlXe2RRxHVqdX0kHU3UqEa5oNjrd/sm0D5uSrDK/pdhvyazDP+5JqxCvyj4MJ/FbJ eiXJ0ooT0NU0imIfFO3xq8y+2TUcpeMalErIguPTz/Jon/e1ZirzHZ7hJst2i+zvZw2j daHID8gf8J/bVPfmv5MUllbYokq4HwpM5QYHlv7zIU7AYh0U172u/2h8zuO0STo+rN/2 IwDw== X-Gm-Message-State: AFq9FYKcvCO/w0Dc2o0dnBcsqfRv3uMWVpGBDr8Qy52o/ZwVm0OOZm6X fjYJKMmwH9jWp5LDthSbKTMSSPOEAY9fdpF4UY574xgoY7QP3JUzXEznViJIjzGmBDCz8k4J+6s D4hFp X-Gm-Gg: AYBFou1LrPUehDNDy+ml6dlRE/UF5SnVbHW2y4/QMT8aOqrLRnJRb4f1OY4SzlNqF5g EIMVWkTRuCo9ggMrS0mxdc21OmMeQCJw2f8FmXX7DjFuNT5BefD0UYgjKgUsHiQGXkR+aQRdNqy 9ZSVmci9Ac5jgd3S2O7Lf+oX36Jh72cDnmc5xNI/1XrZps6nQLfj0oRtqoyasCX30WRH4LEqovv /zRFxFuhp6PuwA/jxRJMvpQw4uZXU8MyQC/NWDtakXgpFZWtnt+wyiqcp4a1CshvcS5mayTDfck Z9DZibXIMvYYCqQmv5QNQkNxh6lVZlRPACMa219fETC9Z1RZzD2PWq8stQcf6mND1vNYTQPAFcS 96MYrTLBRlMeog/TOIMc91ly0DWRS9ApUvn7Pf/KE9vqmUswyLqHRo9RtO45yGXYGUB+3+qFW// yMP6ZlmBLfBBslGqvs/iGh/KODIdsNcpn/G++SRAtyhEeEwj18QzhvBKemq5uWrudywgsxs5HNj 9n2U2DlEphm+HU27ea5oiNFsaCwPwrWGYGZkEOS6JQue8W5eb7FWhIYXdl5XJm8ncI4K1EaRTay cNKCcSDg7NKjlRryxg== X-Received: by 2002:a5d:4576:0:b0:48d:f58f:c98 with SMTP id ffacd0b85a97d-48e6e50abb7mr1582471f8f.40.1793322387524; Thu, 29 Oct 2026 18:06:27 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 04/12] iotests/124: cover backup of zero clusters and holes Date: Fri, 30 Oct 2026 02:06:04 +0100 Message-ID: <20261030010613.1612771-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::32f; envelope-from=den@openvz.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322467155158500 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 --- 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 ab9ea4d8b5..7afcf61324 100755 --- a/tests/qemu-iotests/124 +++ b/tests/qemu-iotests/124 @@ -22,8 +22,11 @@ # =20 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 =20 =20 @@ -748,6 +751,348 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBa= ckupBase): self.check_backups() =20 =20 +# 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 fa16b5ccef..5ce2f9a2ed 100644 --- a/tests/qemu-iotests/124.out +++ b/tests/qemu-iotests/124.out @@ -1,5 +1,5 @@ -............. +.............................. ---------------------------------------------------------------------- -Ran 13 tests +Ran 30 tests =20 OK --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322503; cv=none; d=zohomail.com; s=zohoarc; b=YTDnN9wYWdF8bveSb0PgutzvL9FRMXL4x8h6r7fD+W7hPXK32KxatM0zGIWf6VvNE1zerpc4lYI5N5Skw0+rDEH6VKB/Nw80irUcNIOX3Anin7DGl/RLp3bAGVY9NU/pHNc2Tk9zzT1emkJojbDoo950316Phcy40fCdcuy6ZsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322503; h=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=fJ9DARarrY1aTYCtlvGS85iKEp5hs4edfrbJfuPj5Sg=; b=lRSt7izw3eD18eO32kwueHKy0ULoctCqJZi8Tj7ITr4x2z2E2sjhxXGnzJe04a7tbQuwW16x14kvO/24dPS9uRaJFuoN6aY/DeAsv3EibFVf/DO7AiVJKVJXjoPq3HwC4bQknvW3kiSQUnMkmQ7wdNl9GQUAYXoDzBqLouYyf6U= 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 1793322503985594.9688569588766; Thu, 29 Oct 2026 18:08:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb4w-0002I2-Sf; Thu, 29 Oct 2026 21:06:46 -0400 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 1xMb4l-0002DK-HA for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:35 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4h-0006FC-BQ for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:32 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-48e20ed3b9dso160921f8f.2 for ; Thu, 29 Oct 2026 18:06:29 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322389; x=1793927189; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fJ9DARarrY1aTYCtlvGS85iKEp5hs4edfrbJfuPj5Sg=; b=k0XHg3cW6lOZbNOaWhrBkG7iMg6VddxC5sYdUfx8gdhZJ4XU8Oww7GP11YF0YojmxU uDIkchiJNcelIy6I5iTahltxrnjRnDuaIX/euXnOt/w1W/8dE7O36+GckEcNmfs6nVaJ jJWBmB1Bn1BfQMYMKx6cOOwIPXYdVr6tofLChpZChLhtooo1Lt7n+5gmA8mY4QBHpcMe 92vuan/TDCspG6XqlC/QH4zD9ZM+urcmXJAIx+a7M9wJUvCFihpxG7zR1jxQuDHdIMZs XgemZ4O1H/3yTUs04CvW9u/v9lgXNRrCdf0u1ZIKfIANPp+92i9oYKBSz/vwS66zUB++ lI+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322389; x=1793927189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fJ9DARarrY1aTYCtlvGS85iKEp5hs4edfrbJfuPj5Sg=; b=uglTXnoFryBOFMUAMi73PtcTFTX0Ks5sB8YM883e8FRr8f9YYKoZklyTahlxYjDG5y gGSVyihiNzfWOR/tpZU4MOnIBNnLS1PiVi7Yv5OvS5VNSK8uNokAC/1CyC9Saeh/690j peZIJ5Bqbv6qdu7LzwvcTDQO+pLrSCnzFpZPN9E+pNav7amKngjF/QxZDJ4H+MRnYfub aEIltQRbz6qPTv1TWo+hvIbDSn7bodOw04oTbGm6LOoM00M44Tht8mxiuVQ//Prst0Yo UCS0ai200FKw3NhPTWIsdU8vKA4Bke83YItE7amw+M3+B4qc0nODp6cxvk60XYYC059E sinA== X-Gm-Message-State: AFq9FYJrGs6PNqnIkdvwGBu41OHM1xJmDOG8zYzaZRU0rSoYL95+4yoh J/TjCwkqk7tSDs2pm57arkiCXqtKNrAsHojYEdil90B+918ix0pa5UL/WIQfI70VB/fRw5g2ceI /hPSZ X-Gm-Gg: AYBFou2nt+MrS/MNWf5ApGcPLuNBirr5Q+YsifTmvH47QeTE0axvdZI71et6Cond/CR lHx52yaq/w4Q6aK2/vAxBpE6v07cqhql6N13afpyT5JOWArNYOxJFbuPNePLqNUw0sqLEzTFMc7 mGZIDVgBb19Ve95BjydmDbORJRGgeCICBiJ/HIMtbKs5WcgDDEZsD1QyA03j03yYM59C/WjVW1x M15gSs/Qz4m3NK0K5vuT4RAEGV7toLh9RVyzcu8WBg0y26yCN9sas589gCQLON2NNOIWsFgfWx+ 98RXPyHNNKfd7Q34I2psFb4L+avFWQ0lLkpdsMVt5yMePawaDbGie1zZQbaAcP8B9PRF6+TTxid fPRYYs/8+E9iq1aQEQa7D2opVNm6jciobe4J8/seYYYn3hcIzf4eHm9yRWCQFreEfE/r/Eph1fU oPgvTJm95PfRIk+CeiW947KmozxqZfLwirVrIstcDSCU/JG4vxvhIkT/VnD9TSOo/0aDAj3S1e3 gH2u6MzMblDY25nHQBG0C8q79NZxk3Loi+4LpShqqX1Wk+BBBcqexTcv7IR3RgdzVqfydzfL1Ci r62ARL2cb/o9zW3KGFhwa7y05YmneaSi4mOwbGI= X-Received: by 2002:a5d:4391:0:b0:487:219e:5e20 with SMTP id ffacd0b85a97d-48e6e529631mr1474478f8f.51.1793322388584; Thu, 29 Oct 2026 18:06:28 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 05/12] block/block-copy: extract block_copy_set_task_method() Date: Fri, 30 Oct 2026 02:06:05 +0100 Message-ID: <20261030010613.1612771-6-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::430; envelope-from=den@openvz.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1793322505721154101 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 --- 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 1826c2e1c7..33c43cdf92 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; } =20 +/* + * 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; =20 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) =20 found_dirty =3D true; =20 - 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; - } =20 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.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322470; cv=none; d=zohomail.com; s=zohoarc; b=M0GmWVcW6gdU5/AxuAJglaQRfUmgm+8bcY6kuY7bOg8m21h7HQDwB1FNurzsRa65LThRhsvZhJyODlL8X9hhpKnIRAFc/sYFtPqLMRytIaN17VaPnB3kf/7nTS7ciCb+yIhj16Yo3fC6uR1Bs8J1hbEXDtVxKxXczz1BoQR9Crk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322470; h=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=p/zyvxZVY7PjKaEL8YryOuhSnkGifhnEQlKKyC9dRBA=; b=ipWzHF5rjer/NiPc0d0BdkiLXQImfGq2tBmOd6DWty64biqRLsMsdiUjdYVQz7sDHCzbuzVxKBhrwBUJZhW9muBYaOcKFyZEt9j3x2uxpttbzI+HDAo6CeRJwkdt4/LHb74cKTyHgotGrZr7QQ9VuUvN+P8YQuDmhHLlRZuzQCg= 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 1793322470564843.0622374347786; Thu, 29 Oct 2026 18:07:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb51-0002Lm-Az; Thu, 29 Oct 2026 21:06:51 -0400 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 1xMb4n-0002Dw-Dh for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:41 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4j-0006Fe-RJ for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:37 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4a20a37703bso846745e9.1 for ; Thu, 29 Oct 2026 18:06:32 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322391; x=1793927191; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=p/zyvxZVY7PjKaEL8YryOuhSnkGifhnEQlKKyC9dRBA=; b=MLk7wO3AG2CzAbFiDB/jBpfSz9OIUwehmw77vPVuM7XCoNXCUsAZfCO29JHy+2xZzZ 0LB62bJDNJF5JPVbziSI58exxZPAVVKBN0Bi7MOTlVtPveQBpbf20ZCR50mKv7lu+929 jpHvvSF6/79OGhotccdRceDYsvEpVZbp4vChl7Niio2n1dEvlcGwP5tFkkt77aViJGAe 4JM+bLO1gTeAwO0G5EQhQ4BYEwptxCo6m6qxZcDMf/X2ull3cSa33Q3tlC3Yz+/FtFdJ rq/6JZNAjK4csg7jXY/74v+PsZLXDn+NW+BQEgT4ML+TDyVwui0RSK+SEeIPzt8VToKQ VhNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322391; x=1793927191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=p/zyvxZVY7PjKaEL8YryOuhSnkGifhnEQlKKyC9dRBA=; b=lpT6xWaF9e7N0wglcfwEZ9ZvJADyGWrj5npORpfWvc+vHoo4PBVXlo058lncP3cII7 4CowACC2p04XLWApHsCaLrtq1w+2q6abR+lScsoWkBmhTrd4SyCOYVaVIw3uPPNl6jU4 MoN4k1qW13Ew65sswO4h+FfapVRlroyB4mB8rlOAyLQxsNnlSzyvjn6DIadf3uCEjd0q eKO+1fhlbSg4v91JiEQHvjojXunOO3Fl0Y5dhMwad3dXy03hSetefN0skPglAUi5yhQF LqJt/fM45SaYHe6abd3zooVtmVH/6IdHlPPKoarOJFkoAlBZoC0MQT9CtN2spBg1JNt9 fXiw== X-Gm-Message-State: AFq9FYKoLfGiaObe6OWaeyliozyRG4c5Hg4Mj8ZE6sSw8ODtJQ2Nx8Az qHQcS0gSI+UuJEpMo0qN4H3xMznNUT7l3G3a1lKnn70zuhPcA1yOq+jNobBfBCmV+clKgBbw6uH o3chq X-Gm-Gg: AYBFou0seeKYZcZmMNSQpEbftoKqR81zK8XVLfFf0T63UgYr26pQjxX20IGD9dqcbxR gf060BU1xph3+v3GjWx/cnqQHq6bAraNz+gW6qP8lP6wNxp1LvS7L9eIv/vVTc4HQttzIgUPgn2 Tpsri1Wo/5JBPEpojWFPILzDVjJdDgFEtjRI8SYvzoCCb8ngbvsg5CEb+v78hbqep2Slx8S4497 xRTUAlj3UzXR8DWi4pZ6ykrr8oEBoDgphg2In8R4iVV5ue9+AunsnFV8Jt62f3J9IPShKux04Q+ JEN9dHTyURsaApTXePEZ4/NIoTr5nJCxta47ZVPhNltKq60yZKkZZl0HBpXofngwEyOTdYWBbx+ YyDxMP3yxb4HSFUJtO+u8cZ3lLKpZ+VHkU1TYQc6qCHn4vUE7sJbii0T/1YPPHEuu7DYMs+rTL4 +ebPBLLh5mqt0kq1V8GHCWn6xDm2gNizwC47xhkPU0LeEjJsjhIJHDhFoyfhAF9Qb1PYBBn+pFU 7+ihKnDHyQshQzwOmUfSNO5ELAN4E4LXWUeceuf9Ya6vjtK0Uyq7a5/9BPuwYZ8RYmVPUuXCE+l hA4d9PI8FSt2IPUxqg== X-Received: by 2002:a05:600c:4e08:b0:4a1:ce33:1536 with SMTP id 5b1f17b1804b1-4ac1719112emr13886385e9.9.1793322391254; Thu, 29 Oct 2026 18:06:31 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 06/12] block/block-copy: track known-zero source clusters Date: Fri, 30 Oct 2026 02:06:06 +0100 Message-ID: <20261030010613.1612771-7-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::336; envelope-from=den@openvz.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322473386154100 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 --- block/backup.c | 1 + block/block-copy.c | 108 ++++++++++++++++++++++++++++++++----- include/block/block-copy.h | 1 + 3 files changed, 98 insertions(+), 12 deletions(-) diff --git a/block/backup.c b/block/backup.c index d4713fa1cd..11d70243e2 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); } =20 if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { diff --git a/block/block-copy.c b/block/block-copy.c index 33c43cdf92..507c4bab90 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; =20 QEMU_LOCK_GUARD(&s->lock); @@ -201,6 +208,27 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCal= lState *call_state, return NULL; } =20 + 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); =20 @@ -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); =20 @@ -271,6 +299,9 @@ void block_copy_state_free(BlockCopyState *s) =20 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; } =20 +/* 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; =20 - 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; } =20 +/* 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; =20 @@ -669,25 +729,37 @@ block_copy_is_cluster_allocated(BlockCopyState *s, in= t64_t offset, =20 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; } =20 + if (!zero_broken) { + if (ret & BDRV_BLOCK_ZERO) { + zero_count +=3D count; + } else { + zero_broken =3D true; + } + } + total_count +=3D count; =20 - 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); } =20 /* 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; } =20 @@ -747,6 +819,12 @@ block_copy_set_task_method(BlockCopyState *s, BlockCop= yTask *task) int ret; int64_t status_bytes; =20 + /* 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); } =20 +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); diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 0df2771181..e4e5b56753 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); =20 #endif /* BLOCK_COPY_H */ --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322485; cv=none; d=zohomail.com; s=zohoarc; b=n6po4Xw1jXcERXmHoIifylZfJIuYvd51mSrbEAk3/E+MWLvD0JNdO2b4le32It5kq8mM8Q4x4oMY/+pmSNEtQn2aALc70w2cM2ZdCTbMQsA5oma8hdmGQSy9eB3SmOfH8tsEEMOUqE9qd515Ev1EZ4W5rBZZitKYOkZGi7hHs2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322485; h=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=f20d2Ek+xNWNYFT8dEXpzY4CN9pgSsWok3ap5ujGf/Q=; b=NRNayfniy99E53/XsOVuv+oVVobCOKvYgcqQG6ZHgLEdgAinRAxcVeUNwXfBeL+BDkWMF8wbHy3M9z4DUDB1dChXRJ+1oKUMP86y2YM1ICswpSJgKDOfmCKjvvee/MlNMLK09oaQdF2rgli94AG1yNahahDUqkqJBcjAR6oxw4c= 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 179332248516223.324778438457315; Thu, 29 Oct 2026 18:08:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb54-0002NX-Jk; Thu, 29 Oct 2026 21:06:54 -0400 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 1xMb4t-0002Fl-6y for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:45 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4l-0006Fu-9A for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:38 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-48e0d1da913so124698f8f.1 for ; Thu, 29 Oct 2026 18:06:34 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322393; x=1793927193; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f20d2Ek+xNWNYFT8dEXpzY4CN9pgSsWok3ap5ujGf/Q=; b=rHQEe2yZo/nr5t6mPfgMa1ysuaXmR42K0g9Q0fKvkrm5l5fhlpyTB6SJxxra1JVtya j1T/dahWh55Ou3by563b2Kuf/dBjzQHTKi9M6gpB9mG7weQZxMEnwY3ns+UUyNPIOlcP /xIFldmLXIXw11V56And884AN3vqATkUH657+DNNzEqQOWrNP68EwZUh/+D5/1AWKf2p 42V69YrAqHMBmUsn5hXcT8E5bx6GmRNn0BQraUECOs0xMNo6v5dDU3OvtZva9bK+tZkk /XpRhr0Ts79nNzSlRAlxPmol3ch4xUQyyNAqXapljBwGcQXvIpCH2pz4iVz7+RMTcIdA 7n4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322393; x=1793927193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=f20d2Ek+xNWNYFT8dEXpzY4CN9pgSsWok3ap5ujGf/Q=; b=ROCjJPf4JfmCtoddtsPgi0gTet7ZeTeBxG6p7ZoxMC8btrQzIlrQ/l6hF3DuAi/Xb5 r3jvwtLb6rdAZUxy0K0NCVE3jh9mD5ynL2CkVUEPqtb0VJXola8UmLRiNOFCHfo6WcYw 5hn9VCPq27fwbd+hLK7bZYVS42u5BVhLSzZ9nsq30Xgi6zqaW9VBRdw2ijSUwJ1l6JQE khc6+O8WO5JomSVO0cKDcwYirsMQUHGIqOYwxpt8x2uGGFysJE/cNEjYaVfRcxXlkNIW PGNR9AwLEmKSBvgz4YGNQPA8JW77fYdMvbm99WYcO2fYeaewtWaSJZnrezcj3Izw3xKS E4rw== X-Gm-Message-State: AFq9FYJbkPxUuPD36o3JFGRzW5XqCx19X1yIcBCJC+EAnOIp70SXzM27 Z89CA8Zlb84m1MNUBu8WCx6+ps5Qa3vZijNpQUL/MDEZmSMsRhgKFnHRLZtRmSkPnzd0AY6MRSu C7YT3 X-Gm-Gg: AYBFou3w0NwRCuSFYnhBm4oYIC4EErevpMPmAy7b/pqU72O0Jud+uktqXQZfIi50d+1 EMnYY8OZ6yW7c3LfLUpkFIP5Dr2+o9RPapXdf6149GhXZJECiPFryTvIUWrjOuYukk/1r53bkks z7p3deGnZXz3rotKEuoebG/kZR7Xqs5kZhDGk1oApYTw3lUEBMllJEMQGQlKLwWwOL5lKYceqlX 4p1+gTC8U/iyFzw37vAJ44TSOGB0OgFGRstrsjpluT+VIJF6swhmTkg7BOkDBescmAUtolLwLrR Yk5w1hYcK24w1mZRgwjEc2wjK+lIMEDYj3XOI8crDh6ERVXOGjB5ENlh42aYJBwpsuzMlOIXE09 DM1Vs0dT8PaRLvIkq4mzFF+V8deTBkkoAOx1zvoB7yg0uzDp+IPTc5wUH+N8moGcY1GfZjWL/Zm NqwsFgZdy+z2qc/KQpduRcRzhueUSvKPW7M4CkfN+0xVGkDSrxd0QCJiXlBVvZgOyiCmr+xag28 eCBXWtXPGVpQQHVYH793DRhNtWvQtYXMnTr3dksdIbYGVEPvJV6dcS/EKVJP4cRcyHXOjXCgcZJ hqOWnhrG/RoqWljjiw== X-Received: by 2002:a05:6000:2c0d:b0:48e:661e:8766 with SMTP id ffacd0b85a97d-48e661e88c5mr9849074f8f.17.1793322392992; Thu, 29 Oct 2026 18:06:32 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v4 07/12] block/backup: pre-fill zero_bitmap for full/bitmap Date: Fri, 30 Oct 2026 02:06:07 +0100 Message-ID: <20261030010613.1612771-8-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::42f; envelope-from=den@openvz.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322487503154100 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 --- block/backup.c | 94 ++++++++++++++++++++++++-------------- block/block-copy.c | 42 +++++++++++++++++ include/block/block-copy.h | 4 ++ 3 files changed, 106 insertions(+), 34 deletions(-) diff --git a/block/backup.c b/block/backup.c index 11d70243e2..38b0838d69 100644 --- a/block/backup.c +++ b/block/backup.c @@ -247,59 +247,85 @@ static void backup_init_bcs_bitmap(BackupBlockJob *jo= b) job_progress_set_remaining(&job->common.job, estimate); } =20 -static int coroutine_fn backup_run(Job *job, Error **errp) +/* + * 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) { - BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); - int ret; - - backup_init_bcs_bitmap(s); - - if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP) { - int64_t offset =3D 0; - int64_t count; + 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; =20 - for (offset =3D 0; offset < s->len; ) { - if (job_is_cancelled(job)) { - return -ECANCELED; - } + for (offset =3D 0; offset < s->len; offset +=3D count) { + if (job_is_cancelled(job)) { + return -ECANCELED; + } =20 - job_pause_point(job); + job_pause_point(job); =20 - if (job_is_cancelled(job)) { - return -ECANCELED; - } + if (job_is_cancelled(job)) { + return -ECANCELED; + } =20 - /* rdlock protects the subsequent call to bdrv_is_allocated() = */ - bdrv_graph_co_rdlock(); + /* rdlock protects the block-status queries below */ + bdrv_graph_co_rdlock(); + if (top) { ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); - bdrv_graph_co_rdunlock(); - if (ret < 0) { - return ret; - } + } else { + block_copy_calculate_zero_bitmap(s->bcs, offset, &cached_end, + &count); + } + bdrv_graph_co_rdunlock(); =20 - offset +=3D count; + if (ret < 0) { + return ret; } + } + + if (top) { block_copy_set_skip_unallocated(s->bcs, false); - block_copy_set_zero_bitmap_valid(s->bcs); } + block_copy_set_zero_bitmap_valid(s->bcs); =20 - if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { + return 0; +} + +static int coroutine_fn backup_run(Job *job, Error **errp) +{ + BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); + int ret; + + backup_init_bcs_bitmap(s); + + 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; + } + break; + + 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(); } =20 - return 0; + return backup_loop(s); } =20 static void coroutine_fn backup_pause(Job *job) diff --git a/block/block-copy.c b/block/block-copy.c index 507c4bab90..4f128a0ebd 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; } =20 +/* + * 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, diff --git a/include/block/block-copy.h b/include/block/block-copy.h index e4e5b56753..3a61066b55 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); =20 +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, --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322480; cv=none; d=zohomail.com; s=zohoarc; b=MH3N8QSvxuiD4TzEZacTnIkm+eQ35kdUqeHhvDi8U3zxTpTikV7zOF0Ohu+/suGrxNA10YfiPXACONKTrNpj/7aC4WxdiJd/fQx7t+eqzZaUHP3aX1/oXDmh+2CId7fc7124+WS5WrnTDmCcVasr8hBAou2YehqIfG3IVCxEcEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322480; h=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=QkHRhSns5Bho057K1prrFbTgtQFEeAH3lNc5pa8hbfg=; b=GAv+/pqIhIF7SnQpRjoYuMmftDxoyw47XSE2M75c+YY5cXpMNh94gflvZXcFmHxernB30fG3RbuiGYW5fHdYG7yBdJNAw98t6tIHkQ3eGw5MzYzlw+Uj06GFUNQzQTYRT6F9p8vgNJZJGxxwktrQjuiJcxTNcJQXuiAXZBEOmtU= 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 179332248006619.361037344246483; Thu, 29 Oct 2026 18:08:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb53-0002Mo-6A; Thu, 29 Oct 2026 21:06:53 -0400 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 1xMb4x-0002It-JS for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:47 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4n-0006G3-6X for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:43 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4a35ac4475dso724265e9.2 for ; Thu, 29 Oct 2026 18:06:34 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322394; x=1793927194; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QkHRhSns5Bho057K1prrFbTgtQFEeAH3lNc5pa8hbfg=; b=fV2nIHl5q/eVU/cRlNwow8cLepUdsGPBiaRKQmF2U5m2o600LxnsuZxc+wx75GTFYW 7ti/q9WSmbsUj6iGJW/xTYIJfZ9PQQP18k8+D8IHZM7/ZdXPr8oRzG7274ZuNFgzm9Tg pTUv/5iidwDaw5+W29yo3+NfyXHlyOqc6Mdfpyammz481uclW7JVZf5RnTFf2FnEin5B XWvDSWKd0Ps0Skehisni8u1PTXFq0poQ1HmKDpUYA5buCNOP4KoIj4gVIeuX9WbhWM2a cqHRAAvR5jNgBG6D6jU/hQmJeBg91LekzUXoh21JrrG3DD0gn0IIIIAp4b+qy5pIHbYL 6Oqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322394; x=1793927194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QkHRhSns5Bho057K1prrFbTgtQFEeAH3lNc5pa8hbfg=; b=gAgmH2N467sludJA4xVfhXkHrpjONvtPGTH4SqJ7MAKgP/6ZO2xI1YH5xnJAso19Td j/BNdyhUt0l1X+qhW5Q7pyC7D2ur2aimPP98xaeFgMxs624uG+h4yNVv5ojjBSCfNCfw J8wd3wooO1kfONqrRDIJigPhopLj1RXecfjkjm9SIhkkP1gqYDlI2vA3nQwn5YV19TgZ fitWOxQgEA0u9Foh3D2nGRlNedul9kvxMgVI9TVjvbRVcMcAc1YCPbAs6qKvzUlOurnL dfmIbzsyUsGT5SsqUg52M+uRNQw4TFk8LGMvmKjKosxpulhXAozMISXSEr5DtRsmIWqd YbGw== X-Gm-Message-State: AFq9FYJIR9zAP4ECueDzBeg1xzY/J9Rl+QXZTflNRAZukMfvRQ+cBmB/ T1OVOLKNon+nbDAsfSR11ztIi8xU9O6ECq45tm4uQ9Y/GJEglZXEaaYeM2uXPHCs5hk+qq/7UeH 56V+Y X-Gm-Gg: AYBFou09Ohh6LIqk6vyB3yuJ6t/hkpzbgPRCnhPs55Fh0eVDGaFcWNq9R+NLiqXyiJx HwLwHuSfD097nR/x3yV+sLNvx97ooKuHXj0yiUV/PJawTs8UzP5/pMLlhiIEHGaOVY0NsDw8ncB ps++flkM7Xf4g+WIF+AM8efPVaC7niBXQTH2vkq9po/HHMWQQ6LAMMYkXAxzFlnRu+imY3QCABf XvUPUvbhrSb6AKKe9R6iSEbiNbgngbi6vGGQxAuQagWOIcD2Gja8n2tX/91c7BNcG/I2iXkR0yq i9a26KIHyrDNQofdZ7/GkJ9E7+nm0VGVhzK0PIWLYCxIndq6JP/gM3hhNJekDc4vvW7r6GcOux4 QQsY1R/GLhBhtdAWe3jsbENHHigJcLwnkqiFYZYZVZ6wumJWQxGdldNo12KAh3v8F3G07AE92Ux Mr+NDDwFn/Pw47aUVyMeXbvMNCEkRNaA6Nd6JJM7VkPdovK1fUfuYPT69T6Gn5ihz5dQS1+Wkzb 8eajEtsCRYYjcGt4R36/eaWMFMqSgjGg56RldEGAYvoWr4FII0H/aUhQvSL29OKDTmTD+pQkzmq VB6GAzcpYx5285MemA== X-Received: by 2002:a05:600c:3554:b0:4a1:f7f4:7cf2 with SMTP id 5b1f17b1804b1-4ac1737c474mr13341435e9.17.1793322393914; Thu, 29 Oct 2026 18:06:33 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev Subject: [PATCH v4 08/12] block/block-copy: rename block_copy_is_cluster_allocated() Date: Fri, 30 Oct 2026 02:06:08 +0100 Message-ID: <20261030010613.1612771-9-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::32e; envelope-from=den@openvz.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322481366154100 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 --- 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 4f128a0ebd..ad358f4d2f 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, } =20 /* - * 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; =20 - 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); =20 if (ret >=3D 0) { *cached_end =3D query_offset + clusters * s->cluster_size; --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322519; cv=none; d=zohomail.com; s=zohoarc; b=NSdXwcKTiOlIrT+fSc+xMXH4ZoiZCsWuk2JXsDu46oeN63B6QslQK7HAeohDIiiV+1n/r4MR2ggFyOjDpRl3QW6b5JuF7HPo0Bk9ih8PeuXZhO43XSGiXlc6W/SnORJegMzP0qyfWchAIAsMm/F5pzS/essalcYshJcHXYNJkIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322519; 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=FOP9eWIZEsEM0uhGEfT1U3RerCwOgmk215ry3JCIszA=; b=c8HCc6AYRs8IC9MLOF/c0i89PhuJh++/NdDrtkUrYIvBurGCzNDTf6qt8wKygWkGBv7bOVH0I9T48mC0GnjGsbfoA73mdkxe/oZ/9cNleLVTOd6trOCaIs1PNIFsRHUzWaUapj3ktJVGo/nnbREahJcTrZ3BMjT1AHBvQqi66HA= 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 1793322519451736.1026793460326; Thu, 29 Oct 2026 18:08:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb51-0002MN-Qo; Thu, 29 Oct 2026 21:06:52 -0400 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 1xMb4x-0002Is-JZ for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:47 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4n-0006GN-6L for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:43 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-48e0d885929so133857f8f.3 for ; Thu, 29 Oct 2026 18:06:36 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322395; x=1793927195; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=FOP9eWIZEsEM0uhGEfT1U3RerCwOgmk215ry3JCIszA=; b=iox2hQmDy0mMeo3i2hg01bBUGP1FXQdIhx+H5BrHxTe+bCnOWJvFQizK8S/UWmuiQ+ Xw3RLKv8XomDHlby53NtZ6v09Z7KmATNT/4kNquD37q058k+ldXN7BvSAbKgJ9RVMxi9 Bnt4SmzP5JuwhxhOLpYjc+y8MK6krCuWO2afJ3htuMK6fVwvvZWzCXdGElYXsOe3iw8X 2jwTk9HSQqBWYg7pkuB0bRXl3AxMTluVG5NH8yUu5ChI7odg5fpELoAdjbNSUO9dUOXp RXWnxDQiVYgOLaA7uz/dpzDjL2bwAUjNE+IUr90F9jSutTfaB//piiyivr5+m/S2NM61 2VRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322395; x=1793927195; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FOP9eWIZEsEM0uhGEfT1U3RerCwOgmk215ry3JCIszA=; b=Twu5muP5EInhyeTbD6+nGPt6kzAk+8HotQnVl9UWeEJ8pGkb8CM6s0p0QtOhE49Psl TLfiKKtz2SFSijexdZWp4LHA6ejAjbNyeeJmk4BcUuU/u4POn+55spiVOrS2bbLio8t4 GQmdLjzTIKEciElurTzlfYLB0EYOUhh6usFIYrb/qrp0edgt5jlZaYqn7Q8JZvlz9oMP JjJ3qQBOUkCHpK830C+Ssb0fcHv456a4B3L9Mswy0iQ1MY3ocdJyqSvyGVExcjht+zWl xHk4c7N4ZooxAV8Cth3bo5JLPdKzfG0NnuDzT3ZVOOdnPvfgcEaNgPoFskymdgIpRdHv myXw== X-Gm-Message-State: AFq9FYJ70GerjYtZLn10rZ5cYwjEpuY9P3gAGub3T4AUKQYADIfbNNYf OU+c4yNz9Yw33UPSZm3YXi/khSI12gTlb3jJTH/yEDkIoGjQBO1R1tvNKUO5v6U7zp+6b49J33r HX/UK X-Gm-Gg: AYBFou2JH3TZLqsCreEIlKVhq1T7yZOMreXAqEH9prk2Mp9hc1yjQ1u9xFhdMIuZW39 4mbDkykPcYyhA93mgI3tH0MEuvzu5tsq6/n66ySXmGr6H3sCuvLMSI7S/X16XkNljgKx0L2fTaO ch7h1B9Sv3OsqCg9UCxgfx1GS7epHAsqFeFqM1KoE7dndnR581+O5tRnv5bYM1+SuHIE9HjCnTF c4+xdR0fQQNVjat94BsJbAGFc4hoo1o0p63nShzFBv0J/O7tc1UsUlp/8+rEinD9QcZvQ/1l1BG h/P6Tl4JM2wEcSmVtqrrol8KHZZ8klKmcVVyWCqDNlwxce76zAGGcpiaBAOeYHzJzRIK38kN40m feE9CBaH8iqm1UfhbLxyimyZxYDpRnv1oBPy888K8WIGN/rQe350pahh1hVhAe46YlHMXSxHRQA 6BWZZR6F795pnwRxkHK9On0p/JKX0RyXRBrZ/vm5UO2JFPQvyyk1PKP80kmzbt/AQBHqlguNVN5 dBGS9JtdkX5IOYwV/YLdlAGap+1Zl6rRqPBSQDlAkL2Lu9znRj7VVkarwRjI3sE/0+GpLpEIIsL Mqn/kjcglKPwyTEyYvvFtXtkUo9JOzJhx/f0tu1u X-Received: by 2002:a05:6000:4007:b0:48e:6812:5ef1 with SMTP id ffacd0b85a97d-48e6e4f55f9mr2391871f8f.25.1793322394903; Thu, 29 Oct 2026 18:06:34 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev Subject: [PATCH v4 09/12] block/block-copy: merge the two backup scan steps into block_copy_prescan() Date: Fri, 30 Oct 2026 02:06:09 +0100 Message-ID: <20261030010613.1612771-10-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::436; envelope-from=den@openvz.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @openvz.org) X-ZM-MESSAGEID: 1793322522147154100 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 --- block/backup.c | 7 +---- block/block-copy.c | 63 ++++++++++++++------------------------ include/block/block-copy.h | 9 ++---- 3 files changed, 27 insertions(+), 52 deletions(-) diff --git a/block/backup.c b/block/backup.c index 38b0838d69..60c00fca67 100644 --- a/block/backup.c +++ b/block/backup.c @@ -271,12 +271,7 @@ static int coroutine_fn backup_scan_source(BackupBlock= Job *s) =20 /* 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(); =20 if (ret < 0) { diff --git a/block/block-copy.c b/block/block-copy.c index ad358f4d2f..78cc855b5b 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=E2=80=99s allocati= on 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) } =20 /* - * 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. - */ -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. + * 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. */ -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, =20 if (!found) { *count =3D s->len - offset; - return; + return 0; } dirty_end =3D dirty_offset + dirty_bytes; =20 @@ -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); =20 - 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); + } } } =20 *count =3D MIN(*cached_end, dirty_end) - offset; + return 0; } =20 /* diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 3a61066b55..dc51316fcf 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -41,12 +41,9 @@ void block_copy_state_free(BlockCopyState *s); =20 void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes); =20 -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); =20 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322427; cv=none; d=zohomail.com; s=zohoarc; b=AbhqjkE7QT1EHJIf3gfV9GftxIAR/VjdEo3ICWyJl25QS7vu3cvFpErT3FXyLXcwylpaECje5Zdi6pL2wh/EMyLr2fH77X7mxUcpDYVeccBy0UczSfd5uB7Omz2RVGt5sWWl5iSBeQOdezZq31a8h0ODrPy4wLj6aA+cZCp4ztU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322427; h=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=Oz8qaSH8q7QLfFH7Onpz/KPGPQOPaL0tV0IWAOGIqq0=; b=ETFu8Ut7ukpGeBGfdtSWuzqytt+n2kZgFoBB7NLuGC0OVgKkY3kx1zkf5FydRq4QuJVPVhrzHCyzgrPFvlHrVqrHu85GaLyOES99U340qh6XgwcQ47PEwxGiBR59lsGn8eiU1LXGV6lZMl1bcop40VPL6/0YjAbZu+g75NXxAYE= 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 1793322427820193.5501983204034; Thu, 29 Oct 2026 18:07:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb55-0002Nt-3l; Thu, 29 Oct 2026 21:06:55 -0400 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 1xMb4x-0002Ir-JQ for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:47 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4q-0006Gf-Jp for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:45 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-48df54150dfso74976f8f.0 for ; Thu, 29 Oct 2026 18:06:37 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322396; x=1793927196; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Oz8qaSH8q7QLfFH7Onpz/KPGPQOPaL0tV0IWAOGIqq0=; b=qV8eyf6Tl27P6BJmMS7XelrlKTpzj7A3AsbSjevtXXUXh26e2VpEMH7xrhY/ipGn1k MYH4D2t13wZPYiqjvFYqNBvfWmJoGqIu7KCFjJVmIkDwoOMD6h754sXt5vM27/WIYsBH OI3SOnBLb/5rHX9lFWlYNfHSU9klfRKeTNNpKGEc507GjNnqsPG36gMzZ58PPbi80yf+ IlOYodsGRJD6mMm0yupG+Hbshu095PpcKEf9Ob4GYcLdIJQxUJ6eYrLEEptbDXucleS2 0GNRyzJ3qd8Ae+rVMmFgdQZ/yaK8v+XWAVf98JANGyueJsFgHjmjsFBcZLd4lEnzW9kI BC5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322396; x=1793927196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Oz8qaSH8q7QLfFH7Onpz/KPGPQOPaL0tV0IWAOGIqq0=; b=o2QyhRUf8AC3PO3ZvQIFiNwS98r86Cy30jROac1tTcd5Hf7NZ3/vRwen6VBhK6AC0L rAg3LOY1xnoUrkxj9lGMxyh02CemjbRqNSB6NBX+czVZgf3ZxJ4bEW4oWk+anJoXc/9W eRplDiGBANFvO5+VaU+VT9KHBieOyIjsbW2P6r70fqn04lafTJsQlW5TLEA2pROixlF/ fMaOdsJeEDIwuZ6rQJT8dJ2eLhpb1SXwaN8Sol/N/qbeErKfhIkQxmDzV8Q/Z/ISYa0/ pQ8gUImlbCWByISXNN/RNXC7WE6lbis7hMp3lB85okXI7a7xR5XCD2lmuNehGjOmMdx8 AitA== X-Gm-Message-State: AFq9FYJB9VfFG22yDcZkcJEr1f+jMHY6dX7Z2XcgIcfy+ffnCL9o5GIr vwBjygy71sZnKOsYtOfyqqaeO6KC+wEC9XUi2N+EayeUipFbolh5udOcGiiVib+grtsKHfiPohn Ydbxb X-Gm-Gg: AYBFou2u3UDO9HW+F747bJbY44fy3FhbBsNblJJEaCHlBYOAmtkiUKbQM3L6Zv/RC0A cSBM/MCBoxK1/ribFTzv29KXc0RoyLGrf17X51jNC4YwSoZCrKPfEuwEozsQnDp2IunAusKtMO7 6bJqcHtgTuynDbJF8bGCU0oyOr/nFXt9GCbjzg+Mu3/3RvVfnhvuM8ltJGDU2asRUEs+pd4LR+F w0dbf3TUYcwfTlXaFfgzf2Z20ULSA6rHlvwkj3o5KJukDEkwDMR5ow5elZj62kjCmjvmPTBC0nF HESdcorSf1lQa19G9LuLYSy9Zcfkz5RTB9L7m6zlamjtkv/lPiSAFBAkixGtdx1uL/z08cQfg8V DjIMRQQ3v1GvW2ENQNFVk04mF+SzHMbYBlzN3LtIoRWOR65dSqF8gOZWVDtKRKdldrvIi8Sfmuh 47WiMYTQ9TEVJWZ1ho/66FeGORScbiugfkzNppwXhcnYV2GAOv0cC/SYrlLbvsfKPgrMXxB7WUy 8WvFbH7et/xCtLKTpCRsTzeeiL/RUkAnU6cmQNoNj8+stP1hqBEwK5nbw3uEGskEZbi9oblh7up as9g+5dSX41gMTcEaQ== X-Received: by 2002:a05:6000:cb:b0:486:f42f:6860 with SMTP id ffacd0b85a97d-48e6e50361dmr1612813f8f.56.1793322396583; Thu, 29 Oct 2026 18:06:36 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev Subject: [PATCH v4 10/12] block/block-copy: replace zero_bitmap_valid with scan_done Date: Fri, 30 Oct 2026 02:06:10 +0100 Message-ID: <20261030010613.1612771-11-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::42f; envelope-from=den@openvz.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1793322430727154100 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 --- block/backup.c | 6 +----- block/block-copy.c | 19 ++++++++++++------- include/block/block-copy.h | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/block/backup.c b/block/backup.c index 60c00fca67..1bf6cbedac 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; =20 @@ -279,10 +278,7 @@ static int coroutine_fn backup_scan_source(BackupBlock= Job *s) } } =20 - 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); =20 return 0; } diff --git a/block/block-copy.c b/block/block-copy.c index 78cc855b5b..3b7e282e5b 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; =20 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; } =20 -/* 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; =20 /* 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; } =20 @@ -1179,10 +1183,11 @@ void block_copy_set_skip_unallocated(BlockCopyState= *s, bool skip) qatomic_set(&s->skip_unallocated, skip); } =20 -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); } =20 void block_copy_set_speed(BlockCopyState *s, uint64_t speed) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index dc51316fcf..e82c96586e 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); =20 #endif /* BLOCK_COPY_H */ --=20 2.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322521; cv=none; d=zohomail.com; s=zohoarc; b=VZ3BUAXJGd75Qq+AecaZsf9nCidUUUl2miyAa0L6e0acea/BD9Hp88HRnEVH8iNUbutURqr8ynHILRPSpmM7oyWS3SSH+Ew7bhihy3pyw0TWPSzwibgEtqX6Q9ZTDYtueomck3C7DyhXzzc/MftB56P6kx3k2eA41ad3qXlB8yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322521; h=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=yzK/GS6n415GXdjNQIzyla58d/FKSuepRUvbDI0J/bs=; b=LOyPnflgLFHNlTNqYMnmPL7KSstAAKNqWCaXJDKhsDAD9kQzcPitHHMlTSeR3BnlJwK9oCnQW3cywBpOWuH5TPUWc+5NKXb9nssfrCm56UbZGDNjOAzvPqESLyhn72H4wzRA0K1DGhhL6qBln+HTx5uP6l6zL44Q7jhjWX9TUFQ= 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 1793322521247728.2772231991274; Thu, 29 Oct 2026 18:08:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb55-0002Ot-Qo; Thu, 29 Oct 2026 21:06:55 -0400 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 1xMb4z-0002Jx-36 for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:49 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4s-0006H0-Vk for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:48 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-48df0fa43c5so89455f8f.0 for ; Thu, 29 Oct 2026 18:06:39 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322399; x=1793927199; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yzK/GS6n415GXdjNQIzyla58d/FKSuepRUvbDI0J/bs=; b=kV79nYd4s8i9FcN/Aa/ndgYVW7fmkR5jI8R6MVKRlbGNGXIxEoIUbhlQpZnULXZGG3 KJv0Czw8TZOHjPtQTVfpKjULGhM9ndqKFhqLQIvO37durZoCuUfRq0fsxClbcwF+3pv3 JSLRhnFQHkuOBHYZW2exnhROOnL96jwq2lTeiv7wRPhcgYJnKanGt1C/9zmtx+O9QYGt T971jw6f9MRqDXQIVHhkJizYy0hApxzB111FG+CEsAW0BPQ8OZnSc0Vi0c3P82m/4x3t 4ZcGV4Q9GCCsw/dEKWGu0ZsxVZ/99AcC6qf/apLePDp8W+pMQB5J8A13ORH9mI1XoZ4v gWWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322399; x=1793927199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=yzK/GS6n415GXdjNQIzyla58d/FKSuepRUvbDI0J/bs=; b=h0Yi7toFYiPXDGaK6G2SyJwhHeA5sMt8nudjyKctzkgfu0UGpNhR17TpHgzKzreRYv ygElfU8aBuHZLMkpf76LUhY3ZbVGi+zBAvpTvNo7AkkwUFFNcNm4dk0SgLjNaKKHdrSm fteWiY8UJ8JZTln5v5vgbq3frIRdHWY1SIWsQDyv7euobtAwbq1VC54izK8+Jh82HePf 4iovE+Qd+aNqLNElV08JsKeuixMZsSILvOiylOhCfAGJ2wNC4C6J6+ZjKhNazTuthLda z06mRdCLhQpHrNyfUpTDCvQZJGlkRKX1KYkFLJKIjG3bLO+RKpq6EIs4aySIoAYbLKMm RXkA== X-Gm-Message-State: AFq9FYJLtpjhupjv+02WLHqcYjS+wb04gIQnvmJp467IozI020gDqxy4 zaCzcPT0OusZ3FXbfwZZbCUSiwrST6LLzrul+FUAL+pEJQKWH3aUVuXxtDgudLcUS71925fckoE gAZ87 X-Gm-Gg: AYBFou1Aa2pDIeh0DE9FNRdZYJ/1vC6ISsKJz91K9rS0gpkVRNIOIJ07O4/9995AZAJ z9ceHVPFB1TElEUgPykr9ysr1IHpLkRiCGSbV24u0vLh+/Z/74eRNGd8rZw0rnv0kSmKFGO8aXC noaEgcmPaaWmNTf6rUatifX5wIYNiwJKv97jjV37JldaVJn3Usj+3h7NFid5WYlDYaYJzrZtAzH aRrK/6EfFGEGzAz5QMflESLDQ7iKcea5nj2/AoW8vJUtBYM3S+shSkHPj9td5uZGyngifmZZ9oB RWPJp6GJ/JoX1KUE65DHRNjHGha1+jCVltv3pI1naDb81znypTyCvZHYiHxMJOzXGXfbS6AHT2e xhKqYVSRb2VWdNUIHaZkc8sLV52D54t7qPXpVQNtRSjXe+0jycMzvvWN0VbO6lsumzXNR17bVvN cE4qAP+MGk4YXlaTSDFSETF9RJLz7Ojdbvly04n/kdogVhEl1kwfPNCZt+vThCEA9jzfKspI55H puxHDzEI5wN6fviTRhQoK6XjkeKbfGpJ7uOQ+wa/wdsqvxs8hSkkePBvhdw6gNHvf8rTvpSn1/X dqDaaUz/Dfw5W7MTGlL3b819Tu+NnIS8T/omdBk= X-Received: by 2002:a5d:5e8c:0:b0:48e:5c9b:f12c with SMTP id ffacd0b85a97d-48e6e2d4c32mr2533928f8f.16.1793322398780; Thu, 29 Oct 2026 18:06:38 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev Subject: [PATCH v4 11/12] util/co-shared-resource: skip the mutex for an empty request Date: Fri, 30 Oct 2026 02:06:11 +0100 Message-ID: <20261030010613.1612771-12-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::429; envelope-from=den@openvz.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1793322529723154100 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 --- 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 752eb5a1c5..f9b6af0072 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) =20 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.53.0 From nobody Mon Nov 23 04:28:00 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1793322528; cv=none; d=zohomail.com; s=zohoarc; b=fOxifWkydwemEH+lcBYWW8nh3cs6uVxqXlLiUficdKupsTH5AEVnRua/o34/Hg5FWx9UOnm7FB8xnYZCms5odl5B213lHdTUhRtsoVN4tvXHCMaoaY3cjUQzdPXR6rYKF+cDcDr7qZKia127KJCw8AJQViECx5DcP4/GhuMVB/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793322528; h=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=EQqkfnTRKNDcpWPgKSjM/iwuCtOPgHBiaJ7/UMTgM+M=; b=nZn3DgjJh7cRfju5Ft0wwjDB34/a6W9sIahVbseMzNd1PZKo1O9SFtoqNs2jm3lnLlFYDOB3Igy7Is9QuJn2980syQMkzEzHia6J13A2jz+i4yQt0hX7e3Q3PWHG3mhTlKdodFhw2LWyOB4I0RQa/u7PaPe42ulSE6jDbSNIFbw= 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 1793322528005186.80915030341612; Thu, 29 Oct 2026 18:08:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMb58-0002QE-TY; Thu, 29 Oct 2026 21:06:58 -0400 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 1xMb50-0002Kn-98 for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:50 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMb4t-0006H7-0H for qemu-devel@nongnu.org; Thu, 29 Oct 2026 21:06:49 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-48df4e9d2d4so78807f8f.3 for ; Thu, 29 Oct 2026 18:06:41 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b80333sm210023f8f.32.2026.10.29.18.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 18:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793322400; x=1793927200; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EQqkfnTRKNDcpWPgKSjM/iwuCtOPgHBiaJ7/UMTgM+M=; b=RdxfCWuDdRm2cOEcotWNpAZw1ZmHoSG1j36BHTqAFHEZQWYvCJu/UQQ+8QdKL++69i uZZ9Ms2HcckwnhjRteBiGkOx055D903n9tNAqAHIaml/HBw9gmraSRbmo6JNejYPX0+i YkL2QkXLKOInPnM3RVNngVy8/2gFVpFhD0ACQTGbsz+vGdcRpowdlnNKDEtk6rYZujqp QQRZO9p1aLwlK7H5KWlb9AadCQzOacLQy0/nykeBaiNzUjI8w2/MIzIO4ievL1xpJYeJ mPKhMfPw0yp+8aJph/f8Xbs4GVx9GrMjqFvobDZIuhr3jolJJpJnJ8FkLvrqUgz4BOn0 mmgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793322400; x=1793927200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=EQqkfnTRKNDcpWPgKSjM/iwuCtOPgHBiaJ7/UMTgM+M=; b=NNZ8eqPYKIdjx8i1YIvJrkLZXio4pPQAdo8pjP7rL5b7gdpJ/TY2VmAMBRdaVzsQmI neOmjFq51wGmIYvusbXG380/h98eD+Wvix/TARhFA3I7eoSp6FAqM64xAOS44KPdWeEE FbysvKzWjMbYHM+5hQyeAJ01MW5+pIXxv1gZk1//gRIbyu/wa9OmJQ1Y9J+8W1RQN2eh Us8/aucnpx9EnUZ0wxXlaqRFgdadVVZyfEwfo0dIOgfYeKgYtcYBnp3RfUG5SBl6Stn7 eX+m9nNGkdcBY2mkCbDm+Hi7wYmRgbDqU1UL5dxaAWMg/Fl6VOqD4Q2CzLlCWQMKkX5W R+qw== X-Gm-Message-State: AFq9FYLUEDsnm1J5zyVnuvMj+Z+1WdF2bHSnKDH/YV6tEIoFOgEpEtb3 1pB7cHFu/13jtUhF5wrvbz5adiIPTlzBjpWSh/A4Bw8MS/kmFWy8WcfxULJ5qGM47rsMwuaLSrV 0P0oH X-Gm-Gg: AYBFou3Kav1bVi1+7d1+RALcQFCxuDPSxTj5GWEmGY4maDs7v1K/FfArZs4gaH09+dL ZjbD9Y2Tj9VVRxp7cVJQpMrkzIYZIuXJ6T6H7l8xflfrClrf6cA473MjXs0t6O+eSK/Bzl1xD3c 7iE5x21pAdryeCsJxXrR5NqkoAKSCLkFCraT3jDzH2WkGQ0SrUEH4PXc6ov36cE0U3cBOb9vIoO 4lZYt52aNc6f3IpUWNbyPMyUfP4Wff2M3eVTZuZWtpwGpWlmY8sw9NVAZvd13yuxHU+/vX6cHaS HLKhQMM1dYq5tVbPHodp7gsj9ugDTZSn0ivM42nFC7yC6HZSyvEGpjY0QEFE44jeHC3TjaMAvta H/JszjBzMlHsy8yVaWL7KUJ7S01Tyc33A6HjqNAiROhtUuXxB5gTaaKboaUfHNKMd7CGTie2mqm 0qSoT2zeXf1NN2AH+fO9WaZ/W3LYhHbM8jX2Wm2xudZOlmDTrByMzby/Pi2LN2RvWA1q5KQGAnb MQDwPMTwaUsGuBw3ppBtAp4xWFSJ1rRDEy6LBK6AFUWTkLx3iRCHWvTQax6brlNEIJQJR8hny7j qHBx+ZFE6B9od83n1Q== X-Received: by 2002:a05:6000:2f84:b0:48e:e98:8b64 with SMTP id ffacd0b85a97d-48e6e2eb232mr2034244f8f.19.1793322399823; Thu, 29 Oct 2026 18:06:39 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev Subject: [PATCH v4 12/12] block/block-copy: coalesce write-zeroes tasks Date: Fri, 30 Oct 2026 02:06:12 +0100 Message-ID: <20261030010613.1612771-13-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030010613.1612771-1-den@openvz.org> References: <20261030010613.1612771-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::432; envelope-from=den@openvz.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1793322530134154100 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 --- block/block-copy.c | 96 +++++++++++++++++++++++++++++++++++++++----- qapi/block-core.json | 4 +- 2 files changed, 88 insertions(+), 12 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 3b7e282e5b..c96b9ce4f1 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; =20 /* * 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) } } =20 +/* + * 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; =20 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, =20 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); =20 @@ -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, }; =20 s->discard_source =3D discard_source; @@ -488,6 +518,15 @@ void block_copy_set_progress_meter(BlockCopyState *s, = ProgressMeter *pm) s->progress =3D pm; } =20 +/* + * 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, =20 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; } =20 +/* + * 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; =20 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); + } } =20 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); =20 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); } =20 return true; @@ -935,11 +1008,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_s= tate) } } =20 - ratelimit_calculate_delay(&s->rate_limit, task->req.bytes); + ratelimit_calculate_delay(&s->rate_limit, + block_copy_task_data_bytes(task)); =20 trace_block_copy_process(s, task->req.offset); =20 - co_get_from_shres(s->mem, task->req.bytes); + co_get_from_shres(s->mem, block_copy_task_data_bytes(task)); =20 offset =3D task_end(task); bytes =3D end - offset; diff --git a/qapi/block-core.json b/qapi/block-core.json index 741c8165c0..2edd3bccaa 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 --=20 2.53.0