Resize2fs corrupts ext4 fs with bigalloc [Was: Re: Release candidate for e2fsprogs 1.42.7]
Quoted 4 lines · Theodore Ts'o
I've just pushed an update to the e2fsprogs maint repository, and commit
8359f626a4e9(the tip of the maint branch) is a release candidate for 1.42.7. Please give it a test! If I don't get any show-stopping bug reports, I plan to release it as 1.42.7 in the day or two.
I'm affraid I have one for you :-(
I've just tested both the debian experimental e2fsprogs package, as well as manually built package from git 8359f626a4e9, both running on a debian testing system with a 3.7.3 kernel from experimental.
In both versions resize2fs corrupts a clean ext4 fs if bigalloc is enabled.
Attaching console output of example run.
Best regards
Jon Severinsson
jon@desora-core /tmp $ rm fs
jon@desora-core /tmp $ truncate -s 256G fs
jon@desora-core /tmp $ /sbin/mkfs.ext4 -T largefile4 -C 262144 -O bigalloc fs 128G mke2fs 1.42.7 (15-Jan-2013)
fs is not a block special device.
Proceed anyway? (y,n) y
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Cluster size=262144 (log=8)
Stride=0 blocks, Stripe width=0 blocks
32768 inodes, 33554432 blocks
1677721 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
16 block groups
2097152 blocks per group, 32768 clusters per group
2048 inodes per group
Superblock backups stored on blocks:
2097152, 6291456, 10485760, 14680064, 18874368
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
jon@desora-core /tmp $ /sbin/e2fsck -f fs
e2fsck 1.42.7 (15-Jan-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
fs: 11/32768 files (0.0% non-contiguous), 35392/33554432 blocks jon@desora-core /tmp $ /sbin/resize2fs -f fs
resize2fs 1.42.7 (15-Jan-2013)
Resizing the filesystem on fs to 67108864 (4k) blocks.
Illegal block number passed to ext2fs_unmark_block_bitmap #4194304 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #8388608 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #12582912 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #16777216 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #20971520 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #23068672 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #25165824 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #27262976 for block bitmap for fs Illegal block number passed to ext2fs_unmark_block_bitmap #29360128 for block bitmap for fs Illegal block number passed to ext2fs_mark_block_bitmap #2097153 for meta-data blocks Illegal block number passed to ext2fs_mark_block_bitmap #6291457 for meta-data blocks Illegal block number passed to ext2fs_mark_block_bitmap #10485761 for meta-data blocks Illegal block number passed to ext2fs_mark_block_bitmap #14680065 for meta-data blocks Illegal block number passed to ext2fs_mark_block_bitmap #18874369 for meta-data blocks The filesystem on fs is now 67108864 blocks long.
jon@desora-core /tmp $ /sbin/e2fsck -n -f fs
e2fsck 1.42.7 (15-Jan-2013)ext2fs_check_desc: Corrupt group descriptor: bad block for inode table /sbin/e2fsck: Group descriptors look bad... trying backup blocks... Pass 1: Checking inodes, blocks, and sizes
Group 16's inode bitmap at 33554496 conflicts with some other fs block. Relocate? no
Group 17's block bitmap at 33554624 conflicts with some other fs block. Relocate? no
Group 17's inode bitmap at 33554688 conflicts with some other fs block. Relocate? no
Group 18's block bitmap at 33554752 conflicts with some other fs block. Relocate? no
Group 18's inode bitmap at 33554816 conflicts with some other fs block. Relocate? no
Group 19's block bitmap at 33554880 conflicts with some other fs block. Relocate? no
Group 19's inode bitmap at 33554944 conflicts with some other fs block. Relocate? no
Group 20's block bitmap at 33555008 conflicts with some other fs block. Relocate? no
Group 20's inode bitmap at 33555072 conflicts with some other fs block. Relocate? no
Group 21's block bitmap at 33555136 conflicts with some other fs block. Relocate? no
Group 21's inode bitmap at 33555200 conflicts with some other fs block. Relocate? no
Group 22's block bitmap at 33555264 conflicts with some other fs block. Relocate? no
Group 22's inode bitmap at 33555328 conflicts with some other fs block. Relocate? no
Group 23's block bitmap at 33555392 conflicts with some other fs block. Relocate? no
Group 23's inode bitmap at 33555456 conflicts with some other fs block. Relocate? no
Group 24's block bitmap at 33555520 conflicts with some other fs block. Relocate? no
Group 24's inode bitmap at 33555584 conflicts with some other fs block. Relocate? no
Group 25's block bitmap at 33555648 conflicts with some other fs block. Relocate? no
Group 25's inode bitmap at 33555712 conflicts with some other fs block. Relocate? no
Group 26's block bitmap at 33555776 conflicts with some other fs block. Relocate? no
Group 26's inode bitmap at 33555840 conflicts with some other fs block. Relocate? no
Group 27's block bitmap at 33555904 conflicts with some other fs block. Relocate? no
Group 27's inode bitmap at 33555968 conflicts with some other fs block. Relocate? no
Group 28's block bitmap at 33556032 conflicts with some other fs block. Relocate? no
Group 28's inode bitmap at 33556096 conflicts with some other fs block. Relocate? no
Group 29's block bitmap at 33556160 conflicts with some other fs block. Relocate? no
Group 29's inode bitmap at 33556224 conflicts with some other fs block. Relocate? no
Group 30's block bitmap at 33556288 conflicts with some other fs block. Relocate? no
Group 30's inode bitmap at 33556352 conflicts with some other fs block. Relocate? no
Group 31's block bitmap at 33556416 conflicts with some other fs block. Relocate? no
Group 31's inode bitmap at 33556480 conflicts with some other fs block. Relocate? no
Deleted inode 51201 has zero dtime. Fix? no
Deleted inode 55297 has zero dtime. Fix? no
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #0 (63232, counted=32732). Fix? no
Free blocks count wrong for group #1 (65472, counted=32767). Fix? no
Free blocks count wrong for group #2 (0, counted=32768). Fix? no
Free blocks count wrong for group #3 (65472, counted=32767). Fix? no
Free blocks count wrong for group #4 (0, counted=32768). Fix? no
Free blocks count wrong for group #5 (65472, counted=32767). Fix? no
Free blocks count wrong for group #6 (0, counted=32768). Fix? no
Free blocks count wrong for group #7 (32704, counted=32255). Fix? no
Free blocks count wrong for group #8 (0, counted=32768). Fix? no
Free blocks count wrong for group #9 (65472, counted=32767). Fix? no
Free blocks count wrong for group #10 (0, counted=32768). Fix? no
Free blocks count wrong for group #11 (0, counted=32768). Fix? no
Free blocks count wrong for group #12 (0, counted=32768). Fix? no
Free blocks count wrong for group #13 (0, counted=32768). Fix? no
Free blocks count wrong for group #14 (0, counted=32768). Fix? no
Free blocks count wrong for group #15 (0, counted=32768). Fix? no
Free blocks count wrong for group #16 (63424, counted=32735). Fix? no
Free blocks count wrong for group #17 (0, counted=32768). Fix? no
Free blocks count wrong for group #18 (0, counted=32768). Fix? no
Free blocks count wrong for group #19 (0, counted=32768). Fix? no
Free blocks count wrong for group #20 (0, counted=32768). Fix? no
Free blocks count wrong for group #21 (0, counted=32768). Fix? no
Free blocks count wrong for group #22 (0, counted=32768). Fix? no
Free blocks count wrong for group #23 (0, counted=32768). Fix? no
Free blocks count wrong for group #24 (0, counted=32768). Fix? no
Free blocks count wrong for group #25 (65472, counted=32767). Fix? no
Free blocks count wrong for group #26 (0, counted=32768). Fix? no
Free blocks count wrong for group #27 (65472, counted=32767). Fix? no
Free blocks count wrong for group #28 (0, counted=32768). Fix? no
Free blocks count wrong for group #29 (0, counted=32768). Fix? no
Free blocks count wrong for group #30 (0, counted=32768). Fix? no
Free blocks count wrong for group #31 (0, counted=32768). Fix? no
fs: ********** WARNING: Filesystem still has errors **********
fs: 11/65536 files (0.0% non-contiguous), 37632/67108864 blocks jon@desora-core /tmp $
Quoted 4 lines · Jon Severinsson
In both versions resize2fs corrupts a clean ext4 fs if bigalloc is enabled.
Thanks for the bug report. From what I can tell, resize2fs never worked correctly on bigalloc file systems. The following patches seem to fix it, but we need to do more careful testing before I'd trust resize2fs to resize bigalloc file systems containing production data.
- Ted
PATCH 1/3 libext2fs: teach the ext2fs_*_block_bitmap_range2() about clusters
The ext2fs_{mark,unmark,test}_block_bitmap2() functions understand about clusters, and will take block numbers and convert them to clusters before checking the bitmap. The ext2fs_*_block_bitmap_range2() functions did not do this, which made them inconsistent. Fortunately, nothing has depended on this incorrect behavior, and in fact most of the usage of these functions have only recently been added, and only for optimizations that were only enabled for non-bigalloc file systems.
So this is a change in previously exported functions, but (a) it doesn't change the behavior at all for non-bigalloc file systems, and
(b) the change is more likely to fix bugs for bigalloc file systems. For example, this change fixes a problem with resize2fs and bigalloc file systems.
--- lib/ext2fs/gen_bitmap64.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
lib/ext2fs/gen_bitmap64.c +30 -0
@@ -624,6 +624,8 @@ void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap)int ext2fs_test_block_bitmap_range2 (ext2fs_block_bitmap bmap,blk64_t block,unsigned int num) { +__u64 end = block + num; +if (!bmap)return EINVAL ;
@@ -646,12 +648,26 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap,INC_STAT (bmap, test_ext_count); +/* convert to clusters if necessary */ + block >>= bmap->cluster_bits; + end += (1 << bmap->cluster_bits) -1 ; + end >>= bmap->cluster_bits; + num = end - block; + +if ((block < bmap->start) || (block+num-1 > bmap->end)) { +ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_TEST , block, + bmap->description); +return ; + } +return bmap->bitmap_ops->test_clear_bmap_extent (bmap, block, num); }void ext2fs_mark_block_bitmap_range2 (ext2fs_block_bitmap bmap,blk64_t block,unsigned int num) { +__u64 end = block + num; +if (!bmap)return ;
@@ -670,6 +686,12 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,INC_STAT (bmap, mark_ext_count); +/* convert to clusters if necessary */ + block >>= bmap->cluster_bits; + end += (1 << bmap->cluster_bits) -1 ; + end >>= bmap->cluster_bits; + num = end - block; +if ((block < bmap->start) || (block+num-1 > bmap->end)) {ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_MARK , block, bmap->description);
@@ -682,6 +704,8 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,void ext2fs_unmark_block_bitmap_range2 (ext2fs_block_bitmap bmap,blk64_t block,unsigned int num) { +__u64 end = block + num; +if (!bmap)return ;
@@ -700,6 +724,12 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap,INC_STAT (bmap, unmark_ext_count); +/* convert to clusters if necessary */ + block >>= bmap->cluster_bits; + end += (1 << bmap->cluster_bits) -1 ; + end >>= bmap->cluster_bits; + num = end - block; +if ((block < bmap->start) || (block+num-1 > bmap->end)) {ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_UNMARK , block, bmap->description);
Signature · 1 line
1.7.12.rc0.22.gcdd159b
PATCH 2/3 resize2fs: correctly account for clusters when calculating summary stats
Fixes resize2fs so it correctly calculates the number of free clusters in each block group for file systems with the bigalloc feature enabled.
--- resize/resize2fs.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)
resize/resize2fs.c +24 -13
@@ -62,6 +62,15 @@ static errcode_t fix_sb_journal_backup(ext2_filsys fs); ((blk) < (ext2fs_inode_table_loc((fs), (i)) + \ (fs)->inode_blocks_per_group))) +/* Some bigalloc helper macros which are more succint... */ +#define B2C (x) EXT2FS_B2C(fs, (x)) +#define C2B (x) EXT2FS_C2B(fs, (x)) +#define EQ_CLSTR (x, y) (B2C(x) == B2C(y)) +#define LE_CLSTR (x, y) (B2C(x) <= B2C(y)) +#define LT_CLSTR (x, y) (B2C(x) < B2C(y)) +#define GE_CLSTR (x, y) (B2C(x) >= B2C(y)) +#define GT_CLSTR (x, y) (B2C(x) > B2C(y)) +int lazy_itable_init;/*
@@ -1822,26 +1831,27 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)else old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; -for (blk = fs->super->s_first_data_block; - blk <ext2fs_blocks_count (fs->super); blk++) { +for (blk =B2C (fs->super->s_first_data_block); + blk <ext2fs_blocks_count (fs->super); + blk +=EXT2FS_CLUSTER_RATIO (fs)) {if ((uninit && - !((blk == super_blk) || + !(EQ_CLSTR (blk, super_blk) || ((old_desc_blk && old_desc_blocks && - (blk >= old_desc_blk) && - (blk < old_desc_blk + old_desc_blocks))) || - ((new_desc_blk && (blk == new_desc_blk))) || - (blk ==ext2fs_block_bitmap_loc (fs, group)) || - (blk ==ext2fs_inode_bitmap_loc (fs, group)) || - ((blk >=ext2fs_inode_table_loc (fs, group) && - (blk <ext2fs_inode_table_loc (fs, group) - + fs->inode_blocks_per_group))))) || +GE_CLSTR (blk, old_desc_blk) && +LT_CLSTR (blk, old_desc_blk + old_desc_blocks))) || + ((new_desc_blk &&EQ_CLSTR (blk, new_desc_blk))) || +EQ_CLSTR (blk,ext2fs_block_bitmap_loc (fs, group)) || +EQ_CLSTR (blk,ext2fs_inode_bitmap_loc (fs, group)) || + ((GE_CLSTR (blk,ext2fs_inode_table_loc (fs, group)) && +LT_CLSTR (blk,ext2fs_inode_table_loc (fs, group) + + fs->inode_blocks_per_group))))) || (!ext2fs_fast_test_block_bitmap2 (fs->block_map, blk))) { group_free++; total_blocks_free++; } count++; -if ((count == fs->super->s_blocks_per_group) || - (blk ==ext2fs_blocks_count (fs->super)-1 )) { +if ((count == fs->super->s_clusters_per_group) || +EQ_CLSTR (blk,ext2fs_blocks_count (fs->super)-1 )) {ext2fs_bg_free_blocks_count_set (fs, group, group_free);ext2fs_group_desc_csum_set (fs, group); group++;
@@ -1861,6 +1871,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs) fs->super->s_reserved_gdt_blocks; } } + total_blocks_free =C2B (total_blocks_free);ext2fs_free_blocks_count_set (fs->super, total_blocks_free);/*
Signature · 1 line
1.7.12.rc0.22.gcdd159b
PATCH 3/3 resize2fs: move a cluster at a time with bigalloc file systems
In reply to Theodore Ts'o--- resize/resize2fs.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
resize/resize2fs.c +23 -5
@@ -1178,8 +1178,9 @@ static errcode_t block_mover(ext2_resize_t rfs)*/ to_move = moved =0 ;init_block_alloc (rfs); -for (blk = old_fs->super->s_first_data_block; - blk <ext2fs_blocks_count (old_fs->super); blk++) { +for (blk =B2C (old_fs->super->s_first_data_block); + blk <ext2fs_blocks_count (old_fs->super); + blk +=EXT2FS_CLUSTER_RATIO (fs)) {if (!ext2fs_test_block_bitmap2 (old_fs->block_map, blk))continue ;if (!ext2fs_test_block_bitmap2 (rfs->move_blocks, blk))
@@ -1196,7 +1197,7 @@ static errcode_t block_mover(ext2_resize_t rfs) goto errout; }ext2fs_block_alloc_stats2 (fs, new_blk,+1 ); -ext2fs_add_extent_entry (rfs->bmap, blk, new_blk); +ext2fs_add_extent_entry (rfs->bmap,B2C (blk),B2C (new_blk)); to_move++; }
@@ -1226,6 +1227,9 @@ static errcode_t block_mover(ext2_resize_t rfs)if (retval) goto errout;if (!size)break ; + old_blk =C2B (old_blk); + new_blk =C2B (new_blk); + size =C2B (size);#ifdef RESIZE2FS_DEBUG if (rfs->flags &RESIZE_DEBUG_BMOVE ) printf("Moving %llu blocks %llu->%llu\n",
@@ -1276,6 +1280,20 @@ errout:*/ +/* +* The extent translation table is stored in clusters so we need to +* take special care when mapping a source block number to its +* destination block number. +*/ +__u64 extent_translate (ext2_filsys fs,ext2_extent extent,__u64 old_loc) +{ +__u64 new_block =C2B (ext2fs_extent_translate (extent,B2C (old_loc))); + +if (new_block !=0 ) + new_block += old_loc & (EXT2FS_CLUSTER_RATIO (fs) -1 ); +return new_block; +} +struct process_block_struct {ext2_resize_t rfs;ext2_ino_t ino;
@@ -1298,7 +1316,7 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr, pb = (struct process_block_struct *) priv_data; block = *block_nr;if (pb->rfs->bmap) { - new_block =ext2fs_extent_translate (pb->rfs->bmap, block); + new_block =extent_translate (fs, pb->rfs->bmap, block);if (new_block) { *block_nr = new_block; ret |=BLOCK_CHANGED ;
@@ -1424,7 +1442,7 @@ static errcode_t inode_scan_and_fix(ext2_resize_t rfs) pb.changed =0 ;if (ext2fs_file_acl_block (rfs->old_fs, inode) && rfs->bmap) { - new_block =ext2fs_extent_translate (rfs->bmap, + new_block =extent_translate (rfs->old_fs, rfs->bmap,ext2fs_file_acl_block (rfs->old_fs, inode));if (new_block) { ext2fs_file_acl_block_set(rfs->old_fs, inode,
Signature · 1 line
1.7.12.rc0.22.gcdd159b