Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564730pxb; Mon, 24 Jan 2022 12:19:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJybWHoShK45DDCBFPeVQU1amSw3ig2hrIFpGvb1r/yCceBCwgRnUY3yd5YB8ms2+pYXsMQ0 X-Received: by 2002:a63:3704:: with SMTP id e4mr12986965pga.551.1643055476909; Mon, 24 Jan 2022 12:17:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055476; cv=none; d=google.com; s=arc-20160816; b=BWrt5IiojNxMyea2H5AlpiNpH0ZvR7PVS2a6e+2mRW+ukr4hehHKdrkkg7fnmevCse RmSoLzIeDIbrK748dNtwLSoTXpzaN4sKW/6Ojy8fYj+JKgo1sojFhncL00AS7oDWBz2I LsGWGrc3xbup8vcbgCjYHhjSVwIBElQAxYXWQl6shAKc69JRT74kARqFwpl92zAugwwW TZ6LQhFhJev/g+dbW5sBfrphqXjOCyax8VHAgP+G2ecRBlw5AIe36phMH173f4/rdl71 TUQE1tNxMO8EN7gLJw2r4UtMMSgynczsgOCHyFg0Z5PfFC/BlwtCd6aCgQG2MTOnq/X5 1YfA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3nXFzH731Xy1Z+YPTAoj79fA4IG37X6Fwm+u6vZIlpM=; b=xHev9IH3in53zaSB+Q4pKB3Z0uQc106nCgPMGqodSVy13NRIpd17C+KuAu53wFAb2o vpoqnSZA5qNBaGtOI37bK/+ENMp35yoCqjvNCmgQ1QLFVn0UT2OFlyCFL8BzFi41mD+N ng1e5xk+lc0e3SU6P4Gi+RE9A0Tmme/LFvq+c/aTfFR78EDFRfPJl5/uxKvMLE3gomuW s3fxmxppKs3atZdkw+BFtOadYNbvUbbfJn3+7O0EIDd46JmIvEEl2bAUIYWMGAkSj+OE 8gkU8jmyP/Hq3LfZ5ItoeP5Zhdaut0lalWjB9+GoaMdrSNT26oPI8ldJFPxxJwSd/C+g sQnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EkNGlDXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p13si14713646plo.272.2022.01.24.12.17.42; Mon, 24 Jan 2022 12:17:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EkNGlDXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345276AbiAXTVg (ORCPT + 99 others); Mon, 24 Jan 2022 14:21:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346121AbiAXTNX (ORCPT ); Mon, 24 Jan 2022 14:13:23 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C10F8C061759; Mon, 24 Jan 2022 11:05:47 -0800 (PST) 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 60C08609EE; Mon, 24 Jan 2022 19:05:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23D61C340E8; Mon, 24 Jan 2022 19:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051146; bh=neIPTLVyB5ZDKcVbq97LECf0V9QFMR4MwIP1lmK80SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EkNGlDXcVuKfxqhZ9FKpf5ZYrkdlGqQ2hGmPB7/R9Txwfhx52WAH1WeUIAROGOGlh Y9RIHhs37hzcVQUpGMvGiTo8rCKCp9OSsRNC7eCidrBWBJylHYLvd5RQu/hFGfk5WL jMWvUaV16BceXNNFmNlxiZGCdhN/B4CtOKbH1pDs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Czerner , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 4.14 068/186] ext4: avoid trim error on fs with small groups Date: Mon, 24 Jan 2022 19:42:23 +0100 Message-Id: <20220124183939.315222726@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara [ Upstream commit 173b6e383d2a204c9921ffc1eca3b87aa2106c33 ] A user reported FITRIM ioctl failing for him on ext4 on some devices without apparent reason. After some debugging we've found out that these devices (being LVM volumes) report rather large discard granularity of 42MB and the filesystem had 1k blocksize and thus group size of 8MB. Because ext4 FITRIM implementation puts discard granularity into minlen, ext4_trim_fs() declared the trim request as invalid. However just silently doing nothing seems to be a more appropriate reaction to such combination of parameters since user did not specify anything wrong. CC: Lukas Czerner Fixes: 5c2ed62fd447 ("ext4: Adjust minlen with discard_granularity in the FITRIM ioctl") Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20211112152202.26614-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ioctl.c | 2 -- fs/ext4/mballoc.c | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 6718c7ccd6314..3bd79fc4e9487 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -992,8 +992,6 @@ resizefs_out: sizeof(range))) return -EFAULT; - range.minlen = max((unsigned int)range.minlen, - q->limits.discard_granularity); ret = ext4_trim_fs(sb, &range); if (ret < 0) return ret; diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index c40d3c44a1d69..28bee66c5fbf0 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5284,6 +5284,7 @@ out: */ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) { + struct request_queue *q = bdev_get_queue(sb->s_bdev); struct ext4_group_info *grp; ext4_group_t group, first_group, last_group; ext4_grpblk_t cnt = 0, first_cluster, last_cluster; @@ -5302,6 +5303,13 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) start >= max_blks || range->len < sb->s_blocksize) return -EINVAL; + /* No point to try to trim less than discard granularity */ + if (range->minlen < q->limits.discard_granularity) { + minlen = EXT4_NUM_B2C(EXT4_SB(sb), + q->limits.discard_granularity >> sb->s_blocksize_bits); + if (minlen > EXT4_CLUSTERS_PER_GROUP(sb)) + goto out; + } if (end >= max_blks) end = max_blks - 1; if (end <= first_data_blk) -- 2.34.1