Re: [PATCH 2/2] ext4: avoid resizing to a partial cluster size

Jan Kara
2022-07-14T13:56:25Z

On Thu 30-06-22 02:17:22, Kiselev, Oleg wrote:
> 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>
> ---
...

> @@ -1624,7 +1624,8 @@ static int ext4_setup_next_flex_gd(struct super_block *sb,
>
> o_blocks_count = ext4_blocks_count(es);
>
> - if (o_blocks_count == n_blocks_count)
> + if ((o_blocks_count == n_blocks_count) ||
> + ((n_blocks_count - o_blocks_count) < sbi->s_cluster_ratio))
> return 0;

So why do you silently do nothing with unaligned size? I'd expect we should
catch this condition already in ext4_resize_fs() and return EINVAL in that
case...

Also this code does something else than what the commit log says. You
actually check whether there are less than one cluster worth of blocks
instead of checking whether n_blocks_count is properly aligned. Why is that
enough?

Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR