From nobody Sat Nov 15 22:26:55 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=1747142853; cv=none; d=zohomail.com; s=zohoarc; b=KE9qMEcFpKGZ128jNvgqH+2h1OHr6930htBuApc72/jvsX2ZVhIPK51WBx4clJJDllDnk7CA7vK7JuhGp0t6OMepryb1TwTFdSuIWMzT3zsGRqwRclh0GRpt9T7h6mE84HHeuslIpfaIKNVSTKukd51BAuknCvuY6nCjlXRlcqI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747142853; 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=VKUlPURd0yKtXisyN/ucg5vGc32HVkh3h91cluIAy5U=; b=ewHJ4gn+B5/023re3aFugvE9C5PQEUQrUpCoeCUqcg0TJ14Ko0q+h+K/f4LlwUlPI9Jphif58VDh3dsfmjpDLx2/4Xe4jBpIaZDgf8/SQHa9NgQYJTrIB1ZexqW7xln8bL6hIMPKNwH7afgWPq/xWQ2Hn2U+8o1GPcCu23yKAkc= 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 1747142853553810.535460805986; Tue, 13 May 2025 06:27:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uEpf1-0006Vw-NW; Tue, 13 May 2025 09:27:07 -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 1uEpey-0006Uq-3p; Tue, 13 May 2025 09:27:04 -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 1uEpej-00073u-NK; Tue, 13 May 2025 09:27:02 -0400 Received: from localhost.localdomain (unknown [IPv6:2a00:1c98:fff1:1001:aee7:ee9c:3ae8:78e2]) by apollo.dupie.be (Postfix) with ESMTPSA id 9894A1520F81; Tue, 13 May 2025 15:26:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dupond.be; s=dkim; t=1747142803; 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=VKUlPURd0yKtXisyN/ucg5vGc32HVkh3h91cluIAy5U=; b=dpwdjC1kmqqOEJ4auM76kbG08lC57vGaECIpKV2vGfRLgCfPNxejito+DGmHsrlvqCesTe p2frapvner7tOTxnrpgP+GNf5bFngV27cpzaUY6QBV9H0JLx9XZlNNm4JYWKs+MXGH0R8x BX8Z2kSyiDhyShFsKl99+LXrfs3NVqE72gEWjXodTybMK7FWFS6QtFg9fjfXAXbddmLGtD rCAni9ZVctXtYkup3NLWqijFIUfzPljmV/9yRc/Lj0PXp2ZKhzcw/lcmjpYs4Hjyn2WEAD 4Qt0Mb7XgBv3r94RbS+OKL/2QWFlD7WIG4QAj2EZ8Wef/qgKGl1nBlFeYjWKFg== From: Jean-Louis Dupond To: qemu-devel@nongnu.org Cc: Hanna Reitz , Kevin Wolf , Alexander Ivanov , Andrey Drobyshev , qemu-block@nongnu.org, Jean-Louis Dupond Subject: [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled Date: Tue, 13 May 2025 15:26:28 +0200 Message-ID: <20250513132628.1055549-3-jean-louis@dupond.be> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250513132628.1055549-1-jean-louis@dupond.be> References: <20250513132628.1055549-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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: 1747142857684019000 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: Eric Blake --- block/qcow2-cluster.c | 16 ++++++---------- block/qcow2-refcount.c | 17 +++++++++++++++++ block/qcow2.h | 4 ++++ 3 files changed, 27 insertions(+), 10 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 8fb210501c..6512cda407 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; 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