Blame SOURCES/e2fsprogs-1.45.6-resize2fs-disable-the-meta_bg-feature-if-necessary.patch

3b974a
From 92bd5b69d7e7096fffc8cab08cc6886fe22df77d Mon Sep 17 00:00:00 2001
3b974a
From: Theodore Ts'o <tytso@mit.edu>
3b974a
Date: Sat, 9 Aug 2014 12:33:11 -0400
3b974a
Subject: [PATCH 2/5] resize2fs: disable the meta_bg feature if necessary
3b974a
3b974a
When shrinking a file system, if the number block groups drops below
3b974a
the point where we started using the meta_bg layout, disable the
3b974a
meta_bg feature and set s_first_meta_bg to zero.  This is necessary to
3b974a
avoid creating an invalid/corrupted file system after the shrink.
3b974a
3b974a
Addresses-Debian-Bug: #756922
3b974a
3b974a
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3b974a
Reported-by: Marcin Wolcendorf <antymat+debian@chelmska.waw.pl>
3b974a
Tested-by: Marcin Wolcendorf <antymat+debian@chelmska.waw.pl>
3b974a
---
3b974a
 resize/resize2fs.c | 17 +++++++++++++----
3b974a
 1 file changed, 13 insertions(+), 4 deletions(-)
3b974a
3b974a
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
3b974a
index a73390de..a2ff29ad 100644
3b974a
--- a/resize/resize2fs.c
3b974a
+++ b/resize/resize2fs.c
3b974a
@@ -461,6 +461,13 @@ retry:
3b974a
 		fs->super->s_reserved_gdt_blocks = new;
3b974a
 	}
3b974a
 
3b974a
+	if ((fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
3b974a
+	    (fs->super->s_first_meta_bg > fs->desc_blocks)) {
3b974a
+		fs->super->s_feature_incompat &=
3b974a
+			~EXT2_FEATURE_INCOMPAT_META_BG;
3b974a
+		fs->super->s_first_meta_bg = 0;
3b974a
+	}
3b974a
+
3b974a
 	/*
3b974a
 	 * If we are shrinking the number of block groups, we're done
3b974a
 	 * and can exit now.
3b974a
@@ -946,13 +953,15 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
3b974a
 		ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk);
3b974a
 	}
3b974a
 
3b974a
-	if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) {
3b974a
+	if (old_fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
3b974a
 		old_blocks = old_fs->super->s_first_meta_bg;
3b974a
+	else
3b974a
+		old_blocks = old_fs->desc_blocks +
3b974a
+			old_fs->super->s_reserved_gdt_blocks;
3b974a
+	if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
3b974a
 		new_blocks = fs->super->s_first_meta_bg;
3b974a
-	} else {
3b974a
-		old_blocks = old_fs->desc_blocks + old_fs->super->s_reserved_gdt_blocks;
3b974a
+	else
3b974a
 		new_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks;
3b974a
-	}
3b974a
 
3b974a
 	if (old_blocks == new_blocks) {
3b974a
 		retval = 0;
3b974a
-- 
3b974a
2.21.3
3b974a