Skip to content

Commit 6a4d7b5

Browse files
tytsogregkh
authored andcommitted
ext4: fix online resize's handling of a too-small final block group
commit f0a459d upstream. Avoid growing the file system to an extent so that the last block group is too small to hold all of the metadata that must be stored in the block group. This problem can be triggered with the following reproducer: umount /mnt mke2fs -F -m0 -b 4096 -t ext4 -O resize_inode,^has_journal \ -E resize=1073741824 /tmp/foo.img 128M mount /tmp/foo.img /mnt truncate --size 1708M /tmp/foo.img resize2fs /dev/loop0 295400 umount /mnt e2fsck -fy /tmp/foo.img Reported-by: Torsten Hilbrich <torsten.hilbrich@secunet.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 22654a3 commit 6a4d7b5

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

fs/ext4/resize.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,26 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
19561956
}
19571957
}
19581958

1959+
/*
1960+
* Make sure the last group has enough space so that it's
1961+
* guaranteed to have enough space for all metadata blocks
1962+
* that it might need to hold. (We might not need to store
1963+
* the inode table blocks in the last block group, but there
1964+
* will be cases where this might be needed.)
1965+
*/
1966+
if ((ext4_group_first_block_no(sb, n_group) +
1967+
ext4_group_overhead_blocks(sb, n_group) + 2 +
1968+
sbi->s_itb_per_group + sbi->s_cluster_ratio) >= n_blocks_count) {
1969+
n_blocks_count = ext4_group_first_block_no(sb, n_group);
1970+
n_group--;
1971+
n_blocks_count_retry = 0;
1972+
if (resize_inode) {
1973+
iput(resize_inode);
1974+
resize_inode = NULL;
1975+
}
1976+
goto retry;
1977+
}
1978+
19591979
/* extend the last group */
19601980
if (n_group == o_group)
19611981
add = n_blocks_count - o_blocks_count;

0 commit comments

Comments
 (0)