From nobody Fri Apr 19 05:35:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663927701012196.47875579019615; Fri, 23 Sep 2022 03:08:21 -0700 (PDT) Received: from localhost ([::1]:60694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obfbX-0004U6-EL for importer@patchew.org; Fri, 23 Sep 2022 06:08:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obfWY-0002zW-3e for qemu-devel@nongnu.org; Fri, 23 Sep 2022 06:03:10 -0400 Received: from [106.39.185.58] (port=50296 helo=smtp.cecloud.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obfWT-0001AH-Sg for qemu-devel@nongnu.org; Fri, 23 Sep 2022 06:03:09 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.cecloud.com (Postfix) with ESMTP id EE77117E021E; Fri, 23 Sep 2022 18:02:55 +0800 (CST) Received: from localhost.localdomain (unknown [111.48.58.10]) by smtp.cecloud.com (postfix) whith ESMTP id P2473742T281457593741680S1663927373869602_; Fri, 23 Sep 2022 18:02:55 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 X-IP-DOMAINF: 1 X-UNIQUE-TAG: <37c38f24dcf6df71435c7280cea64cd4> X-RL-SENDER: luzhipeng@cestc.cn X-SENDER: luzhipeng@cestc.cn X-LOGIN-NAME: luzhipeng@cestc.cn X-FST-TO: qemu-devel@nongnu.org X-RCPT-COUNT: 5 X-SENDER-IP: 111.48.58.10 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 From: luzhipeng To: qemu-devel Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , lu zhipeng Subject: [PATCH] block: unmap (discard) blocks only if discard_zeros flag is true Date: Fri, 23 Sep 2022 18:02:24 +0800 Message-Id: <20220923100224.537-1-luzhipeng@cestc.cn> X-Mailer: git-send-email 2.34.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 106.39.185.58 (failed) 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=106.39.185.58; envelope-from=luzhipeng@cestc.cn; helo=smtp.cecloud.com X-Spam_score_int: 22 X-Spam_score: 2.2 X-Spam_bar: ++ X-Spam_report: (2.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SBL_CSS=3.335, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1663927702773100001 Content-Type: text/plain; charset="utf-8" From: lu zhipeng we can unmap(discard) blocks for block devices of supporting discard zeros or regular file. Signed-off-by: lu zhipeng --- block/file-posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..c35dbc0d88 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -799,7 +799,8 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, #endif s->needs_alignment =3D raw_needs_alignment(bs); =20 - bs->supported_zero_flags =3D BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK; + bs->supported_zero_flags =3D s->discard_zeroes ? + BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK := 0; if (S_ISREG(st.st_mode)) { /* When extending regular files, we get zeros from the OS */ bs->supported_truncate_flags =3D BDRV_REQ_ZERO_WRITE; --=20 2.31.1