Revert "mke2fs: prevent creation of unmountable ext4 with large flex_bg count"
PATCH 1/2 Revert "mke2fs: prevent creation of unmountable ext4 with large flex_bg count"
This reverts commit d988201ef9cb6f7b521e544061976ab4270a3f89.
The problem with this commit is that causes common small file system configurations to fail. For example:
mke2fs -O flex_bg -b 4096 -I 1024 -F /tmp/tt 79106
mke2fs 1.42.11 (09-Jul-2014)
/tmp/tt: Invalid argument passed to ext2 library while setting
up superblockThis check in ext2fs_initialize() was added to prevent the metadata from being allocated beyond the end of the filesystem, but it is also causing a wide range of failures for small filesystems.
We'll address this in a different way, by using a smarter algorithm for deciding the layout of metadata blocks for the last flex block group.
Reported: Andreas Dilger <[email protected]>
--- lib/ext2fs/initialize.c | 24 ------------------------ 1 file changed, 24 deletions(-)
lib/ext2fs/initialize.c +0 -22
@@ -91,10 +91,8 @@ errcode_t ext2fs_initialize(const char *name, int flags,unsigned int rem;unsigned int overhead =0 ;unsigned int ipg; -unsigned int flexbg_size;dgrp_t i;blk64_t free_blocks; -blk64_t flexbg_overhead;blk_t numblocks;int rsv_gdt;int csum_flag;
@@ -421,28 +419,6 @@ ipg_retry: }/* -* Calculate the flex_bg related metadata blocks count. -* It includes the boot block, the super block, -* the block group descriptors, the reserved gdt blocks, -* the block bitmaps, the inode bitmaps and the inode tables. -* This is a simple check, so that the backup superblock and -* other feature related blocks are not considered. -*/ - flexbg_size =1 << fs->super->s_log_groups_per_flex; - flexbg_overhead = super->s_first_data_block +1 + - fs->desc_blocks + super->s_reserved_gdt_blocks + - (__u64 )flexbg_size * (2 + fs->inode_blocks_per_group); - -/* -* Disallow creating ext4 which breaks flex_bg metadata layout -* obviously. -*/ -if (flexbg_overhead >ext2fs_blocks_count (fs->super)) { - retval =EXT2_ET_INVALID_ARGUMENT ; - goto cleanup; - }
PATCH 2/2 libext2fs: place metadata blocks in the last flex_bg so they are contiguous
Place the allocation bitmaps and inode table blocks so they are adjacent, even in the last flexbg.
Previously, after running "mke2fs -t ext4 DEV 286720", the layout of the last few block groups would look like this:
Group 32: (Blocks 262145-270336) [INODE_UNINIT, ITABLE_ZEROED]
Block bitmap at 262145 (+0), Inode bitmap at 262161 (+16) Inode table at 262177-262432 (+32)
Group 33: (Blocks 270337-278528) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Block bitmap at 262146 (bg #32 + 1), Inode bitmap at 262162 (bg #32 + 17) Inode table at 262433-262688 (bg #32 + 288)
Group 34: (Blocks 278529-286719) [INODE_UNINIT, ITABLE_ZEROED]
Block bitmap at 262147 (bg #32 + 2), Inode bitmap at 262163 (bg #32 + 18) Inode table at 262689-262944 (bg #32 + 544)
Now, they look like this:
Group 32: (Blocks 262145-270336) [INODE_UNINIT, ITABLE_ZEROED]
Block bitmap at 262145 (+0), Inode bitmap at 262148 (+3)
Inode table at 262151-262406 (+6)
Group 33: (Blocks 270337-278528) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Block bitmap at 262146 (bg #32 + 1), Inode bitmap at 262149 (bg #32 + 4) Inode table at 262407-262662 (bg #32 + 262)
Group 34: (Blocks 278529-286719) [INODE_UNINIT, ITABLE_ZEROED]
Block bitmap at 262147 (bg #32 + 2), Inode bitmap at 262150 (bg #32 + 5) Inode table at 262663-262918 (bg #32 + 518)
This reduces the free space fragmentation in a freshly created file system. It also allows the following mke2fs command to succeed:
mke2fs -t ext4 -b 4096 -O ^resize_inode -G $((2**20)) DEV 2130483
(Note that while this allows people to run mke2fs with insanely large flexbg sizes, this is not a recommended practice, as the kernel may refuse to resize such a file system while mounted, since it currently tries to allocate an in-memory data structure based on the size of the flexbg, and so a file system with a very large flexbg size will cause the memory allocation to fail. This will hopefully be fixed in a future kernel release, but if the goal is to force all of the metadata blocks to be at the beginning of the file system, it's better to use the packed_meta_blocks configuration parameter in mke2fs.conf.)
--- lib/ext2fs/alloc_tables.c | 18 ++- tests/m_bigjournal/expect.1 | 338 ++++++++++++++++++++++---------------------- 2 files changed, 184 insertions(+), 172 deletions(-)
lib/ext2fs/alloc_tables.c +15 -3
@@ -87,7 +87,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,errcode_t retval;blk64_t group_blk, start_blk, last_blk, new_blk;dgrp_t last_grp =0 ; -int rem_grps =0 , flexbg_size =0 ; +int rem_grps =0 , flexbg_size =0 , table_offset =0 ; group_blk =ext2fs_group_first_block2 (fs, group); last_blk =ext2fs_group_last_block2 (fs, group);
@@ -124,8 +124,20 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,if (flexbg_size) {blk64_t prev_block =0 ; + table_offset = flexbg_size;if (group % flexbg_size) prev_block =ext2fs_block_bitmap_loc (fs, group -1 ) +1 ; +else if (last_grp == fs->group_desc_count-1 ) { +/* +* If we are allocating for the last flex_bg +* keep the metadata tables contiguous +*/ + table_offset = last_grp & (flexbg_size -1 ); +if (table_offset ==0 ) + table_offset = flexbg_size; +else + table_offset++; + }/* FIXME: Take backup group descriptor blocks into account * if the flexbg allocations will grow to overlap them... */ start_blk = flexbg_offset(fs, group, prev_block, bmap,
@@ -158,7 +170,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, prev_block =ext2fs_inode_bitmap_loc (fs, group -1 ) +1 ; else prev_block =ext2fs_block_bitmap_loc (fs, group) + - flexbg_size; + table_offset;/* FIXME: Take backup group descriptor blocks into account * if the flexbg allocations will grow to overlap them... */ start_blk = flexbg_offset(fs, group, prev_block, bmap,
@@ -196,7 +208,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, fs->inode_blocks_per_group; else prev_block =ext2fs_inode_bitmap_loc (fs, group) + - flexbg_size; + table_offset;/* FIXME: Take backup group descriptor blocks into account * if the flexbg allocations will grow to overlap them... */
tests/m_bigjournal/expect.1 +169 -169
693 lines not on this page · raw message
Signature · 1 line
2.0.0