Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jan Kara <jack@suse.cz>
Subject: Re: [PATCH] ext4: fix wrong calculation of minlen in ext4_trim_fs()
Date: Mon, 5 Jun 2023 12:15:32 +0800	[thread overview]
Message-ID: <b83ddb0e-0411-1ca8-dd76-238db056b710@kernel.org> (raw)
In-Reply-To: <20230421093502.n4x3c773udaapksl@quack3>

Ping,

On 2023/4/21 17:35, Jan Kara wrote:
> On Thu 06-04-23 23:06:21, Chao Yu wrote:
>> As Ted pointed out as below:
>>
>> "
>> However the minlen variable in ext4_trim_fs is in units of *clusters*.
>> And so it gets rounded up two places.  The first time is when it is
>> converted into units of a cluster:
>>
>> 	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
>> 			      range->minlen >> sb->s_blocksize_bits);
>>
>> Oh, and by the way, that first conversion is not correct as currently
>> written in ext4_fs_trim().   It should be
>>
>> 	minlen = (range->minlen + EXT4_CLUSTER_SIZE(sb) - 1) >>
>> 		(sb->s_blocksize_bits + EXT4_CLUSTER_BITS(sb));
>> "
>>
>> The reason is if range->minlen is smaller than block size of ext4,
>> original calculation "range->minlen >> sb->s_blocksize_bits" may
>> return zero, but since EXT4_NUM_B2C() expects a non-zero in-parameter,
>> so it needs to round up range->minlen to cluster size directly as above.
>>
>> Link: https://lore.kernel.org/lkml/20230311031843.GF860405@mit.edu/
>> Suggested-by: Theodore Ts'o <tytso@mit.edu>
>> Signed-off-by: Chao Yu <chao@kernel.org>
> 
> Looks good to me. Feel free to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 
> 								Honza
> 
>> ---
>>   fs/ext4/mballoc.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index 5b2ae37a8b80..d8b9d6a83d1e 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -6478,8 +6478,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
>>   
>>   	start = range->start >> sb->s_blocksize_bits;
>>   	end = start + (range->len >> sb->s_blocksize_bits) - 1;
>> -	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
>> -			      range->minlen >> sb->s_blocksize_bits);
>> +	minlen = (range->minlen + EXT4_CLUSTER_SIZE(sb) - 1) >>
>> +			(sb->s_blocksize_bits + EXT4_CLUSTER_BITS(sb));
>>   
>>   	if (minlen > EXT4_CLUSTERS_PER_GROUP(sb) ||
>>   	    start >= max_blks ||
>> -- 
>> 2.25.1
>>

      reply	other threads:[~2023-06-05  4:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06 15:06 [PATCH] ext4: fix wrong calculation of minlen in ext4_trim_fs() Chao Yu
2023-04-21  9:35 ` Jan Kara
2023-06-05  4:15   ` Chao Yu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b83ddb0e-0411-1ca8-dd76-238db056b710@kernel.org \
    --to=chao@kernel.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox