Skip to content

Commit 69cb8e9

Browse files
Kiselev, Olegtytso
authored andcommitted
ext4: avoid resizing to a partial cluster size
This patch avoids an attempt to resize the filesystem to an unaligned cluster boundary. An online resize to a size that is not integral to cluster size results in the last iteration attempting to grow the fs by a negative amount, which trips a BUG_ON and leaves the fs with a corrupted in-memory superblock. Signed-off-by: Oleg Kiselev <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 026d0d2 commit 69cb8e9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/ext4/resize.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
20112011
}
20122012
brelse(bh);
20132013

2014+
/*
2015+
* For bigalloc, trim the requested size to the nearest cluster
2016+
* boundary to avoid creating an unusable filesystem. We do this
2017+
* silently, instead of returning an error, to avoid breaking
2018+
* callers that blindly resize the filesystem to the full size of
2019+
* the underlying block device.
2020+
*/
2021+
if (ext4_has_feature_bigalloc(sb))
2022+
n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1);
2023+
20142024
retry:
20152025
o_blocks_count = ext4_blocks_count(es);
20162026

0 commit comments

Comments
 (0)