Skip to contentSkip to conversation

ext4: fix to report fstrim.minlen back to userspace

PATCH In review Chao Yu 2 participants 3 messages Apr 6, 2023 – Jun 5, 2023 ext4 file system

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v2 1/1 ext4: fix to report fstrim.minlen back to userspace

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.

---
v2:
- fix the wrong calculation of range->minlen.

 fs/ext4/mballoc.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ext4/mballoc.c +4 -0
index d8b9d6a83d1e..4af51a16fc64 100644
@@ -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;
Signature · 1 line
2.25.1
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Chao Yu

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.

Looks good to me. Feel free to add:

Honza

Quoted 24 lines

---
v2:
- fix the wrong calculation of range->minlen.

 fs/ext4/mballoc.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ext4/mballoc.c +4 -0
index d8b9d6a83d1e..4af51a16fc64 100644
@@ -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;
Signature · 1 line
2.25.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#2 lore raw

Ping,

Quoted 43 lines · Jan Kara
Quoted 11 lines · Chao Yu

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.

Looks good to me. Feel free to add:

Honza

Quoted 24 lines

---
v2:
- fix the wrong calculation of range->minlen.

  fs/ext4/mballoc.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/ext4/mballoc.c +4 -0
index d8b9d6a83d1e..4af51a16fc64 100644
@@ -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;
Signature · 1 line
2.25.1