Skip to content

Commit

Permalink
ext4: avoid resizing to a partial cluster size
Browse files Browse the repository at this point in the history
[ Upstream commit 69cb8e9 ]

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 <okiselev@amazon.com>
Link: https://lore.kernel.org/r/0E92A0AB-4F16-4F1A-94B7-702CC6504FDE@amazon.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Kiselev, Oleg authored and Greg Kroah-Hartman committed Aug 25, 2022
1 parent 835f95d commit 53f62a4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fs/ext4/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
}
brelse(bh);

/*
* For bigalloc, trim the requested size to the nearest cluster
* boundary to avoid creating an unusable filesystem. We do this
* silently, instead of returning an error, to avoid breaking
* callers that blindly resize the filesystem to the full size of
* the underlying block device.
*/
if (ext4_has_feature_bigalloc(sb))
n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1);

retry:
o_blocks_count = ext4_blocks_count(es);

Expand Down

0 comments on commit 53f62a4

Please sign in to comment.