Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2277752rwl; Thu, 6 Apr 2023 08:07:09 -0700 (PDT) X-Google-Smtp-Source: AKy350Y9/+bgx2hKooJpFJIqudR2EnBeAxCEXEdNWmRjpvXuJyiTlbhC41s5WvCAvoCWtHaCoHyP X-Received: by 2002:a17:906:f8c9:b0:947:eaed:1f87 with SMTP id lh9-20020a170906f8c900b00947eaed1f87mr5779507ejb.19.1680793629209; Thu, 06 Apr 2023 08:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680793629; cv=none; d=google.com; s=arc-20160816; b=HhDqULR7bl7oufRStmvVys5Rlyqk9k28DcyKrqWj3Y4GZITRH0zl6uQUBNJNYfL2qB omScAldLQ6SP7FT0EkkftYyZYVoOR92QdF798ZhlFGUl03HwatP/WrSEHs1fT3c3EWSl 349YbzTXOpZovyJq99zjvKBAy4KZFJDiwHq67Fhd/2sxnj1EkFxAc+Af9ZQnVTWfTR6Z 1JHIWYYmBT0l6Zv6c5rUSNl/RlRSnftg8F9crA4MUPkEKXYJS5W76F1AFqcvjD5aJhhH GzGdndNiRKoO2weLqbYsHBbSoR+xelUYoW19EpD71VlIaZlONscWUI48ozSdiIlkIaeY C0fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=jtU8EoT7EpJB9XU8bp7gjC2nFnxrET/WIeW+7XkaIGc=; b=GXs1yMxG6sLSk3Uc6YYAzcJ56MhA5EMQBh/oiE3vfl71HFxDD+9xDaKxS1ZKdE4VdC vN72BAPvTIUd+/tgUTt9d7SazGmyFcEaV0/ncXAiBNoYExMNGVyQRq3J8AHIIdC4TE6f Y7jJJ1ekuQwsey4bmLwPBjqPTFSAMaKN9IIOmNT7ifdZvHKG/dX3P3lhkfy2bGOR9dGo UzJ8DrNuo20NuYz8Js4hBT/tKIRCOJF2p7G/Yi2gD8uwxdY7k/NIbDpGi+++VhFVMNwA 2McunHKRHhoORwa/ItayPANo18OX32zRZ6oolbqgQpx4JPsjfGgCEi/qsKQnvfBH5hB5 MEpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oCiIggbX; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 12-20020a170906018c00b009311151f1c3si1183639ejb.426.2023.04.06.08.06.35; Thu, 06 Apr 2023 08:07:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oCiIggbX; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239501AbjDFPFf (ORCPT + 99 others); Thu, 6 Apr 2023 11:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239429AbjDFPF0 (ORCPT ); Thu, 6 Apr 2023 11:05:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51919619F; Thu, 6 Apr 2023 08:05:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E004960EAE; Thu, 6 Apr 2023 15:05:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F340EC433D2; Thu, 6 Apr 2023 15:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680793517; bh=4XTqoOIzV1pxO6uiQBLvYXY23I2rTr+JdRE8YKQSOtw=; h=From:To:Cc:Subject:Date:From; b=oCiIggbXe3BgCKtrTHBwVF+8Hja3/ccC2vEhQsEal9BJRvZhGbwurz76UG6+dU+4/ YHVTSseZitltDrfhBrE1vCsH+wrlB/GCrtOzz1NH7zd7VoTYmPC9F5xzc4VscpeDBc ncvRPXWn31GnWvyZo/TXSSRjYHxLV3BALR0LR3kX4Haz9MAsoF8KniOn2SAQI2w1QS 2ZwvDNAqDE5gnEAamGuA6v9ebBMcQ4ZfzubKNAVXYLGYPaHbJNIqdmJJmE6HOojhZh MEQTDVMF2eRt713mKxqok4l/eIJHSVGenCoZg79J0fF6rDiREFKQVVhVHebPxSUUa7 hrwZ1fHaV4p7g== From: Chao Yu To: Theodore Ts'o , Andreas Dilger Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v2] ext4: fix to report fstrim.minlen back to userspace Date: Thu, 6 Apr 2023 23:04:10 +0800 Message-Id: <20230406150410.3853001-1-chao@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Quoted from manual of fstrim(8): "-m, --minimum minimum-size ..., if it's smaller than the device's minimum, and report that (fstrim_range.minlen) back to userspace." So this patch tries to report adjusted fstrim_range.minlen back to userspace via FITRIM interface, if the value is smaller than device's minimum discard granularity. Signed-off-by: Chao Yu --- v2: - fix the wrong calculation of range->minlen. fs/ext4/mballoc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index d8b9d6a83d1e..4af51a16fc64 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6491,6 +6491,10 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) discard_granularity >> sb->s_blocksize_bits); if (minlen > EXT4_CLUSTERS_PER_GROUP(sb)) goto out; + + /* Report adjusted minlen back to userspace */ + range->minlen = EXT4_C2B(EXT4_SB(sb), minlen) << + sb->s_blocksize_bits; } if (end >= max_blks - 1) { end = max_blks - 1; -- 2.25.1