add patch fix-bigalloc-cluster-free-when-hole-punching-under-load
[ext4-patch-queue.git] / fix-crash-during-online-resizing
blob7af17c8a6c0d2bbe4aa2c08c7b3bdbf93fb7c34e
1 ext4: fix crash during online resizing
3 From: Jan Kara <jack@suse.cz>
5 When computing maximum size of filesystem possible with given number of
6 group descriptor blocks, we forget to include s_first_data_block into
7 the number of blocks. Thus for filesystems with non-zero
8 s_first_data_block it can happen that computed maximum filesystem size
9 is actually lower than current filesystem size which confuses the code
10 and eventually leads to a BUG_ON in ext4_alloc_group_tables() hitting on
11 flex_gd->count == 0. The problem can be reproduced like:
13 truncate -s 100g /tmp/image
14 mkfs.ext4 -b 1024 -E resize=262144 /tmp/image 32768
15 mount -t ext4 -o loop /tmp/image /mnt
16 resize2fs /dev/loop0 262145
17 resize2fs /dev/loop0 300000
19 Fix the problem by properly including s_first_data_block into the
20 computed number of filesystem blocks.
22 Fixes: 1c6bd7173d66 "ext4: convert file system to meta_bg if needed..."
23 Signed-off-by: Jan Kara <jack@suse.cz>
24 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
25 Cc: stable@vger.kernel.org
26 ---
27  fs/ext4/resize.c | 3 ++-
28  1 file changed, 2 insertions(+), 1 deletion(-)
30 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
31 index 48421de803b7..3d9b18505c0c 100644
32 --- a/fs/ext4/resize.c
33 +++ b/fs/ext4/resize.c
34 @@ -1960,7 +1960,8 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
35                                 le16_to_cpu(es->s_reserved_gdt_blocks);
36                         n_group = n_desc_blocks * EXT4_DESC_PER_BLOCK(sb);
37                         n_blocks_count = (ext4_fsblk_t)n_group *
38 -                               EXT4_BLOCKS_PER_GROUP(sb);
39 +                               EXT4_BLOCKS_PER_GROUP(sb) +
40 +                               le32_to_cpu(es->s_first_data_block);
41                         n_group--; /* set to last group number */
42                 }
44 -- 
45 2.16.4