Blame SOURCES/e2fsprogs-1.42.9-resize2fs-clear-uninit-BG.patch

0c4d09
commit f3745728bc254892da4c569ba3fd8801895f3524
0c4d09
Author: Eric Sandeen <sandeen@redhat.com>
0c4d09
Date:   Sun Mar 6 21:51:23 2016 -0500
0c4d09
0c4d09
    resize2fs: clear uninit BG if allocating from new group
0c4d09
    
0c4d09
    If resize2fs_get_alloc_block() allocates from a BLOCK_UNINIT group, we
0c4d09
    need to make sure that the UNINIT flag is cleared on both file system
0c4d09
    structures which are maintained by resize2fs.  This causes the
0c4d09
    modified bitmaps to not get written out, which leads to post-resize2fs
0c4d09
    e2fsck errors; used blocks in UNINIT groups, not marked in the block
0c4d09
    bitmap.  This was seen on r_ext4_small_bg.
0c4d09
    
0c4d09
    This patch uses clear_block_uninit() to clear the flag,
0c4d09
    and my problem goes away.
0c4d09
    
0c4d09
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
0c4d09
    Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
0c4d09
    Reviewed-by: Andreas Dilger <adilger@dilger.ca>
0c4d09
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>
0c4d09
0c4d09
Index: e2fsprogs-1.42.9/lib/ext2fs/alloc.c
0c4d09
===================================================================
0c4d09
--- e2fsprogs-1.42.9.orig/lib/ext2fs/alloc.c
0c4d09
+++ e2fsprogs-1.42.9/lib/ext2fs/alloc.c
0c4d09
@@ -27,6 +27,22 @@
0c4d09
 #include "ext2fs.h"
0c4d09
 
0c4d09
 /*
0c4d09
+ * Clear the uninit block bitmap flag if necessary
0c4d09
+ */
0c4d09
+void ext2fs_clear_block_uninit(ext2_filsys fs, dgrp_t group)
0c4d09
+{
0c4d09
+	if (!(ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT)))
0c4d09
+		return;
0c4d09
+
0c4d09
+	/* uninit block bitmaps are now initialized in read_bitmaps() */
0c4d09
+
0c4d09
+	ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
0c4d09
+	ext2fs_group_desc_csum_set(fs, group);
0c4d09
+	ext2fs_mark_super_dirty(fs);
0c4d09
+	ext2fs_mark_bb_dirty(fs);
0c4d09
+}
0c4d09
+
0c4d09
+/*
0c4d09
  * Check for uninit block bitmaps and deal with them appropriately
0c4d09
  */
0c4d09
 static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map,
0c4d09
Index: e2fsprogs-1.42.9/lib/ext2fs/ext2fs.h
0c4d09
===================================================================
0c4d09
--- e2fsprogs-1.42.9.orig/lib/ext2fs/ext2fs.h
0c4d09
+++ e2fsprogs-1.42.9/lib/ext2fs/ext2fs.h
0c4d09
@@ -639,6 +639,7 @@ static inline int ext2fs_needs_large_fil
0c4d09
 }
0c4d09
 
0c4d09
 /* alloc.c */
0c4d09
+extern void ext2fs_clear_block_uninit(ext2_filsys fs, dgrp_t group);
0c4d09
 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
0c4d09
 				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
0c4d09
 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
0c4d09
Index: e2fsprogs-1.42.9/resize/resize2fs.c
0c4d09
===================================================================
0c4d09
--- e2fsprogs-1.42.9.orig/resize/resize2fs.c
0c4d09
+++ e2fsprogs-1.42.9/resize/resize2fs.c
0c4d09
@@ -1196,6 +1196,7 @@ static errcode_t resize2fs_get_alloc_blo
0c4d09
 {
0c4d09
 	ext2_resize_t rfs = (ext2_resize_t) fs->priv_data;
0c4d09
 	blk64_t blk;
0c4d09
+	int group;
0c4d09
 
0c4d09
 	blk = get_new_block(rfs);
0c4d09
 	if (!blk)
0c4d09
@@ -1208,6 +1209,12 @@ static errcode_t resize2fs_get_alloc_blo
0c4d09
 
0c4d09
 	ext2fs_mark_block_bitmap2(rfs->old_fs->block_map, blk);
0c4d09
 	ext2fs_mark_block_bitmap2(rfs->new_fs->block_map, blk);
0c4d09
+
0c4d09
+	group = ext2fs_group_of_blk2(rfs->old_fs, blk);
0c4d09
+	ext2fs_clear_block_uninit(rfs->old_fs, group);
0c4d09
+	group = ext2fs_group_of_blk2(rfs->new_fs, blk);
0c4d09
+	ext2fs_clear_block_uninit(rfs->new_fs, group);
0c4d09
+
0c4d09
 	*ret = (blk64_t) blk;
0c4d09
 	return 0;
0c4d09
 }