From nobody Sat Nov 15 22:26:57 2025 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=dupond.be ARC-Seal: i=1; a=rsa-sha256; t=1745922734; cv=none; d=zohomail.com; s=zohoarc; b=QkPRU1Q8he3WpqsT+a4TPV4iC6EIxcRMMmfiKjM9vjHEVn0MSfZBbsarISx4hF+AoKaJjsulcAqSCsI6aHuP28LCl2a4bDun2Z6TMBisbVwshsRV17A5nLD0DxHc0n4muToc6EqezCvedFwtwsbXehBVnzn7Bc3WP4Z4c8mC7wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745922734; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WYCS5iAb/Nn8x3gGPhGp/cJX9hFVTuhSLnP3r8HVESs=; b=DYa+XXEEQN3Db3AWsSVsOhteMb2yvpWWFKbVAtQplCKDt4Tn3r17lo3n1H+BIffVblXJJlL+ltET7yOllV28Xj9tQz22gIlbVeV6DvBNE4+QAGeabUkPv5Vj2pnyE1LTlBjtHXGKz0YWn69D559qBtOwIiYgDoZh5vMPiQwVkFU= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174592273432832.15501300715687; Tue, 29 Apr 2025 03:32:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u9iFr-0000Wo-2k; Tue, 29 Apr 2025 06:31:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u9iFk-0000Pl-8k; Tue, 29 Apr 2025 06:31:52 -0400 Received: from apollo.dupie.be ([51.159.20.238]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u9iFh-0007QB-82; Tue, 29 Apr 2025 06:31:51 -0400 Received: from localhost.localdomain (unknown [IPv6:2a00:1c98:fff1:1001:aee7:ee9c:3ae8:78e2]) by apollo.dupie.be (Postfix) with ESMTPSA id 70BE91520F34; Tue, 29 Apr 2025 12:31:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dupond.be; s=dkim; t=1745922699; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WYCS5iAb/Nn8x3gGPhGp/cJX9hFVTuhSLnP3r8HVESs=; b=P9QWHKX+5+MKLiQOa0jN+Bm5Sq/wbcI0pr5Ddg0AXCs4h5xcHmcJYBBvz2RhFTWxkVUTw4 wcY6mlPaHiU05+OBYhBFEhrWz3TJEAPSl6baguBKeZK+oAMCm/vwBolO7ke1hUUfwR+/g1 EIeJwJPLNR4FC//DXKxV5mng8d/SSFxCyMXGXzDA6PknsNVCoXoTYNLFXrIzzJ9IlWSSar Tia2nKCiMbRjSQkHaHAdxtXHB9zXsnT17V2LUU36xDUXlZDnGZe0RyaqUeYe0N0kkFyN0f S+K+gcnatrIOIurxTPjwpCnivW/gjcY/Kk/WFKOTpfifG+7sGSgJ3JX8WvwFbw== From: Jean-Louis Dupond To: qemu-devel@nongnu.org Cc: Alexander Ivanov , Kevin Wolf , Andrey Drobyshev , Hanna Reitz , qemu-block@nongnu.org, Jean-Louis Dupond Subject: [PATCH 1/2] qcow2: rename update_refcount_discard to queue_discard Date: Tue, 29 Apr 2025 12:31:09 +0200 Message-ID: <20250429103110.761910-2-jean-louis@dupond.be> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429103110.761910-1-jean-louis@dupond.be> References: <20250429103110.761910-1-jean-louis@dupond.be> 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=lists.gnu.org; Received-SPF: pass client-ip=51.159.20.238; envelope-from=jean-louis@dupond.be; helo=apollo.dupie.be 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @dupond.be) X-ZM-MESSAGEID: 1745922737375019000 Content-Type: text/plain; charset="utf-8" The function just queues discards, and doesn't do any refcount change. So let's change the function name to align with its function. Signed-off-by: Jean-Louis Dupond --- block/qcow2-refcount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 0266542cee..d796018970 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -754,8 +754,8 @@ void qcow2_process_discards(BlockDriverState *bs, int r= et) } } =20 -static void update_refcount_discard(BlockDriverState *bs, - uint64_t offset, uint64_t length) +static void queue_discard(BlockDriverState *bs, + uint64_t offset, uint64_t length) { BDRVQcow2State *s =3D bs->opaque; Qcow2DiscardRegion *d, *p, *next; @@ -902,7 +902,7 @@ update_refcount(BlockDriverState *bs, int64_t offset, i= nt64_t length, } =20 if (s->discard_passthrough[type]) { - update_refcount_discard(bs, cluster_offset, s->cluster_siz= e); + queue_discard(bs, cluster_offset, s->cluster_size); } } } --=20 2.49.0 From nobody Sat Nov 15 22:26:57 2025 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=dupond.be ARC-Seal: i=1; a=rsa-sha256; t=1745922739; cv=none; d=zohomail.com; s=zohoarc; b=cPOFuCH5NhbBqIG65+2EE5bNdwCyC8+MI149FEKQ7vUtdihs002gKUp5e/R1W7nJitPY2XafLnrfai0z80vElfDcBwxJMk7OtvPk2bDXATVcaqYQ1aIeHgoOsZUPjvxjrtsxkYNed3iFyF0iWhDOTar/0xIxBMNLsEE/ccy3GLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745922739; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jVp86qViDU7DDwyQQT2b4pbEQjMTBw9671dYZtNMZ+E=; b=lfsQlrsBhlePpnKnBCL0bxun4GN3lEaKdQM55Vcfoyl+D8kXlLkApCMHbdNpadNX0xQ8jDInWcW/4HP9qXngI8qP6SDWnKkNeVnqIKFOlI/8K/fgrLflqPRD4HUdsp6kVLwQAW4OcDxdOFryZSnVkjDRrBIJZNt3ua+O8I4zD7Q= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174592273944152.477444356305; Tue, 29 Apr 2025 03:32:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u9iFw-0000a4-N2; Tue, 29 Apr 2025 06:32:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u9iFk-0000Pp-BV; Tue, 29 Apr 2025 06:31:53 -0400 Received: from apollo.dupie.be ([51.159.20.238]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u9iFh-0007QD-8S; Tue, 29 Apr 2025 06:31:52 -0400 Received: from localhost.localdomain (unknown [IPv6:2a00:1c98:fff1:1001:aee7:ee9c:3ae8:78e2]) by apollo.dupie.be (Postfix) with ESMTPSA id D63B71520F5A; Tue, 29 Apr 2025 12:31:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dupond.be; s=dkim; t=1745922699; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jVp86qViDU7DDwyQQT2b4pbEQjMTBw9671dYZtNMZ+E=; b=c3knlpaqoyXpmOzLLWheMRQyB2m2yedq7VCrRlXmV9TzBotLh9834HhkcXHMMz7Qc0BrAp xYxVvwxBQGuwPKm+fvWs+2glT84iuCdvzSA7ocSRNB+jCd38xzu11S5IMDZiX5lv7uZ4m8 tpVKLU6GRA631BU7niXZMo+3ph1QG4MS+G8kDdkWU6bOn4xblMwMtDhwHecx2wL9cCDJYw H/ngIDWsv/ftYCWvwf0ZA3YAtKnped1H48RwxNqueehvoUBnLtt8gHmWl6ALDtSQy9Ezvp NdBceixHGS+r2Sah0YaaQBLYDKpm7BxQIaSmDKUXLwnsmFxabgu62mmw+vzcDg== From: Jean-Louis Dupond To: qemu-devel@nongnu.org Cc: Alexander Ivanov , Kevin Wolf , Andrey Drobyshev , Hanna Reitz , qemu-block@nongnu.org, Jean-Louis Dupond Subject: [PATCH 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled Date: Tue, 29 Apr 2025 12:31:10 +0200 Message-ID: <20250429103110.761910-3-jean-louis@dupond.be> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429103110.761910-1-jean-louis@dupond.be> References: <20250429103110.761910-1-jean-louis@dupond.be> 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=lists.gnu.org; Received-SPF: pass client-ip=51.159.20.238; envelope-from=jean-louis@dupond.be; helo=apollo.dupie.be 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @dupond.be) X-ZM-MESSAGEID: 1745922741713019000 Content-Type: text/plain; charset="utf-8" When discard-no-unref is enabled, discards are not queued like it should. This was broken since discard-no-unref was added. Add some helper function qcow2_discard_cluster which handles some common checks and calls the queue_discards function if needed to add the discard request to the queue. Signed-off-by: Jean-Louis Dupond Reviewed-by: Hanna Czenczek --- block/qcow2-cluster.c | 16 ++++++---------- block/qcow2-refcount.c | 19 ++++++++++++++++++- block/qcow2.h | 4 ++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ce8c0076b3..c655bf6df4 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1978,12 +1978,10 @@ discard_in_l2_slice(BlockDriverState *bs, uint64_t = offset, uint64_t nb_clusters, if (!keep_reference) { /* Then decrease the refcount */ qcow2_free_any_cluster(bs, old_l2_entry, type); - } else if (s->discard_passthrough[type] && - (cluster_type =3D=3D QCOW2_CLUSTER_NORMAL || - cluster_type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC)) { + } else { /* If we keep the reference, pass on the discard still */ - bdrv_pdiscard(s->data_file, old_l2_entry & L2E_OFFSET_MASK, - s->cluster_size); + qcow2_discard_cluster(bs, old_l2_entry & L2E_OFFSET_MASK, + s->cluster_size, cluster_type, type); } } =20 @@ -2092,12 +2090,10 @@ zero_in_l2_slice(BlockDriverState *bs, uint64_t off= set, if (!keep_reference) { /* Then decrease the refcount */ qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_REQ= UEST); - } else if (s->discard_passthrough[QCOW2_DISCARD_REQUEST] && - (type =3D=3D QCOW2_CLUSTER_NORMAL || - type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC)) { + } else { /* If we keep the reference, pass on the discard still */ - bdrv_pdiscard(s->data_file, old_l2_entry & L2E_OFFSET_MASK, - s->cluster_size); + qcow2_discard_cluster(bs, old_l2_entry & L2E_OFFSET_MASK, + s->cluster_size, type, QCOW2_DISCARD_REQUEST); } } } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index d796018970..e1f830504d 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1205,6 +1205,23 @@ void qcow2_free_any_cluster(BlockDriverState *bs, ui= nt64_t l2_entry, } } =20 +void qcow2_discard_cluster(BlockDriverState *bs, uint64_t offset, + uint64_t length, QCow2ClusterType ctype, + enum qcow2_discard_type dtype) { + + BDRVQcow2State *s =3D bs->opaque; + + if (s->discard_passthrough[dtype] && + (ctype =3D=3D QCOW2_CLUSTER_NORMAL || + ctype =3D=3D QCOW2_CLUSTER_ZERO_ALLOC)) { + if (has_data_file(bs)) { + bdrv_pdiscard(s->data_file, offset, length); + } else { + queue_discard(bs, offset, length); + } + } +} + int qcow2_write_caches(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; @@ -3619,7 +3636,7 @@ qcow2_discard_refcount_block(BlockDriverState *bs, ui= nt64_t discard_block_offs) /* discard refblock from the cache if refblock is cached */ qcow2_cache_discard(s->refcount_block_cache, refblock); } - update_refcount_discard(bs, discard_block_offs, s->cluster_size); + queue_discard(bs, discard_block_offs, s->cluster_size); =20 return 0; } diff --git a/block/qcow2.h b/block/qcow2.h index a9e3481c6e..547bb2b814 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -880,6 +880,10 @@ void GRAPH_RDLOCK qcow2_free_clusters(BlockDriverState= *bs, void GRAPH_RDLOCK qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry, enum qcow2_discard_type type); +void GRAPH_RDLOCK +qcow2_discard_cluster(BlockDriverState *bs, uint64_t offset, + uint64_t length, QCow2ClusterType ctype, + enum qcow2_discard_type dtype); =20 int GRAPH_RDLOCK qcow2_update_snapshot_refcount(BlockDriverState *bs, int64_t l1_table_offs= et, --=20 2.49.0