Skip to contentSkip to conversation

ext4: Fix trimming of a single group

PATCH In review Jan Kara 2 participants 2 messages Jan 6, 2011 – Jan 7, 2011 ext4 file system

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Fix trimming of a single group

When ext4_trim_fs() is called to trim a part of a single group, the logic will wrongly set last block of the interval to 'len' instead of 'first_block + len'. Thus a shorter interval is possibly trimmed. Fix it.

CC Lukas Czerner <[email protected]>
---
 fs/ext4/mballoc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

I've already implemented this fix for ext3.

fs/ext4/mballoc.c +1 -1
index 5b4d4e3..4c4766c 100644
@@ -4851,7 +4851,7 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		if (len >= EXT4_BLOCKS_PER_GROUP(sb))
 			len -= (EXT4_BLOCKS_PER_GROUP(sb) - first_block);
 		else
-			last_block = len;
+			last_block = first_block + len;
 
 		if (e4b.bd_info->bb_free >= minlen) {
 			cnt = ext4_trim_all_free(sb, &e4b, first_block,
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 7 lines · Jan Kara

When ext4_trim_fs() is called to trim a part of a single group, the logic will wrongly set last block of the interval to 'len' instead of 'first_block + len'. Thus a shorter interval is possibly trimmed. Fix it.

CC Lukas Czerner <[email protected]>

Thanks, added to the ext4 tree.

- Ted