Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3580236pxb; Mon, 24 Jan 2022 12:43:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxercffYeVZF36sotvObuLBSNU+HUkPIxg3A1BwXlpZwjOgFhi0lVVu5rGHHEkh7EYItMb0 X-Received: by 2002:a17:90b:3144:: with SMTP id ip4mr52196pjb.23.1643056993620; Mon, 24 Jan 2022 12:43:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056993; cv=none; d=google.com; s=arc-20160816; b=qOwsAyUPNz/wdvllktsejTaDctl+fBt7UeagH98shAX0f8GIdXq+8wJ1PmsWrMzjlU WFkLF3wRf0Czt2QokDKjENIclLVy6Za1bif8RwXlhJD4p7Yf5wGzjLRCqBEDRL0kD7/6 QfR6LQJcZRVkaeYIIN/w5H0JyGbiqQ3M2LUeGBVuSavSRBV91wE290APJ0EwYKNXO7ht jk6NCdnRlG5Wxd7gbYoljBLF4DeCwLgdBY7Y6DfzjTbmLVBSNSI0/UAWJY3yDMamx3/T DOcR+w7lGQMhpcxEiDeD07F9Vt4Izqs60AtIqQargrI/3VMG0NIdsEAOSBOpI3BBehgI Xb6g== 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=9e/WD2trBW73yAC6QmlAN5c0aNxOt59u0zxaxpfQdrQ=; b=V05vJsMEO9Wt4/e4vHTeo0SyUtBbozN81mwfaPfPGRSzbbVKWoZFTftJLmuxCZFyoF VS4gmDkVIm1EmAPRCvGfi7f76YxB5+9bxDXRR0ljRxkJne0MlAFKQcqFSGPBYh5HUZfO jpDLqlXaQtxBgvbgOnZ1EOISuhn9GKO0vdniEeXNbMQ4nyG+aXg8c8Q+lg7CkIy3lpl7 IYKCzBKLztv0J8//O7ePZcSngAxhVjO6NO7jBS6Fu2SyaYs+DSzB6M5loOYL1j05VfHb tEf6Q5bDWzIl4+XacoFkDEsJMtJZohRNwOpUuW0FjfG/sooW1faZpS/cAMKiOb6oUGFk cVmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ucL6Fnu2; 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 l6si15467606pgk.191.2022.01.24.12.42.54; Mon, 24 Jan 2022 12:43:13 -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=ucL6Fnu2; 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 S1344288AbiAXT4l (ORCPT + 99 others); Mon, 24 Jan 2022 14:56:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354667AbiAXTg7 (ORCPT ); Mon, 24 Jan 2022 14:36:59 -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 DD11AC0612F8; Mon, 24 Jan 2022 11:17:05 -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 9AE56B81236; Mon, 24 Jan 2022 19:17:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2E49C36AE9; Mon, 24 Jan 2022 19:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051823; bh=M2+xpmoMG2NGJVhNb6RBrBI9zSJc9RCc0W1WeKz/v80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ucL6Fnu2dcFxzz5Oz4SHNvrjL8pybacqBj8WblczGozRsJp+m0SrZeAkoB8Uk0SCg ByLea2dXXIJkLaPMqimPhM42xVomdLI0UsN05S74Vxoxe5ah7gZD3+WD7r1HFiGA0q 0HeXf3orYJNeGwsk/Qx5yazEId1nkIdi/HtoA3B4= 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.19 098/239] ext4: avoid trim error on fs with small groups Date: Mon, 24 Jan 2022 19:42:16 +0100 Message-Id: <20220124183946.222952786@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@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 21c9ebfe83478..484cb68c34d92 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -1052,8 +1052,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 447aa17c804e2..db8243627b085 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5260,6 +5260,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; @@ -5278,6 +5279,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