Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3661293pxb; Mon, 24 Jan 2022 14:44:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAHsGbfCyxh323BE/jDyNjMp06ECG8cLOogmuCKJEUc1bXT1rmx50aoRki3h/PDdpGwGnt X-Received: by 2002:a63:9142:: with SMTP id l63mr13336009pge.476.1643064169747; Mon, 24 Jan 2022 14:42:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064169; cv=none; d=google.com; s=arc-20160816; b=UbmBFX82xHZYB4ApiMJlWofS7sJNnbsOXH0cK4kbuG6tM4VEtt9lxNSK/E81mqTt+y js/8oKCeutHZxXXVNkcSUxcDTS0Gpq3mXR8iUhLyowRrWnCg39xL2/49gwRJ1Hsu7bCA ivsEuTpgSxzS/I0Zrs4Zy9E/CLF2DWZtWXeLVD7pjyy/xgoYsbJAa9dPCoqAuk8/qQsg oJHidBfANrhRzm+uMqHfJir808IqKNPaZTMj/TRTde9fmpOI0zDtr6Czim+0FPBo7teN AVMF41RJERNph2xXQfabrRFV6C4lMFbhY8HsQm0HEA9uJ666KzZXX+tAfNpT/+hNoSYq f+WA== 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=Q6GstDUK3vQDxJrNA3pfPPbC1aM1QFUua1JTz2GXw4s=; b=BC5np6flNSnfxKz0b01ORz+5XSVBAtD9e/qBQzFXp9vQYHdcaVVTHc/SD/PO3jkiOT //oRu5r1YHZZUgz1ltHUaBnBB7nhebAgdwlMJFnXjjk0cQRW+7eXLIHYh/WBeHkazEiV 6z/PT8BAOH3SNkZYjoVonYRK3ZuiYh1nAEWL26Vam3lw9xYwMeX6p9VjzpWrKWJoN1Iq sfvdX5bt+bVFpwMxDuce1BCvNFAD4jysRA7i2yByq96bCB1CRAN8y3wrAumg//Fmdzz1 RHDiaFQIUB0J8eBEeEi3xVZXCeOJKzZARj74CpnjMtwNY+trcQlx0GSVhlULjT53U/Vj nASg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GxKWz9gl; 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 p23si15656034plr.190.2022.01.24.14.42.37; Mon, 24 Jan 2022 14:42:49 -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=GxKWz9gl; 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 S1836509AbiAXWjz (ORCPT + 99 others); Mon, 24 Jan 2022 17:39:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1457359AbiAXVlb (ORCPT ); Mon, 24 Jan 2022 16:41:31 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB227C07E321; Mon, 24 Jan 2022 12:28:23 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8FDFAB80FA1; Mon, 24 Jan 2022 20:28:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCAC3C340E5; Mon, 24 Jan 2022 20:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056102; bh=bxIi2xZ2w1xq56iz0Khve0LPSXIVSl9cFGc65n6xGTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GxKWz9glmVejHzoolEV3Ky69W9w1GlUyxNhF+xL7r7oNIU0TkLR0juFQ9LcTcakQz Gql7s135VWFf7KjFog07I8/NhqLwxxvqpZzz9r4cwOYQ4WyDpqQTIWk5EtOFMV21/U 6u41vSLzUjjRZcVWPHoj1PRWdvjRDJYh/SZAin+M= 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 5.15 372/846] ext4: avoid trim error on fs with small groups Date: Mon, 24 Jan 2022 19:38:09 +0100 Message-Id: <20220124184113.777312207@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 606dee9e08a32..220a4c8178b5e 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -1117,8 +1117,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 72bfac2d6dce9..7174add7b1539 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6405,6 +6405,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group, */ 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; @@ -6423,6 +6424,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