aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2013-06-18 20:37:05 -0500
committerTheodore Ts'o <tytso@mit.edu>2013-06-20 22:47:16 -0400
commit80391dcd2ec853981a11e1178ff7a19598a4e81c (patch)
tree07625c26a53a9ecce0f5b89e3a9e12dd4ca2bd70
parentb49d67ddd8af9568bd5eee319af0479f042db4fd (diff)
downloade2fsprogs-80391dcd2ec853981a11e1178ff7a19598a4e81c.tar.gz
e2fsprogs-80391dcd2ec853981a11e1178ff7a19598a4e81c.tar.xz
e2fsprogs-80391dcd2ec853981a11e1178ff7a19598a4e81c.zip
resize2fs: move bitmaps if shrinking would orphan them
It is possible to have a flex_bg filesystem with block groups which have inode & block bitmaps at some point well past the start of the group. If an offline shrink puts the new size somewhere between the start of the block group and the (old) location of the bitmaps, they can be left beyond the end of the filesystem, i.e. result in fs corruption. Check each remaining block group for whether its bitmaps are beyond the end of the new filesystem, and reallocate them in a new location if needed. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--resize/resize2fs.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 7c4f86a3..204b10af 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -856,6 +856,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
dgrp_t i, max_groups, g;
blk64_t blk, group_blk;
blk64_t old_blocks, new_blocks;
+ blk64_t new_size;
unsigned int meta_bg, meta_bg_size;
errcode_t retval;
ext2_filsys fs, old_fs;
@@ -884,6 +885,32 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
fs = rfs->new_fs;
/*
+ * If we're shrinking the filesystem, we need to move any group's
+ * bitmaps which are beyond the end of the new filesystem.
+ */
+ new_size = ext2fs_blocks_count(fs->super);
+ if (new_size < ext2fs_blocks_count(old_fs->super)) {
+ for (g = 0; g < fs->group_desc_count; g++) {
+ /*
+ * ext2fs_allocate_group_table re-allocates bitmaps
+ * which are set to block 0.
+ */
+ if (ext2fs_block_bitmap_loc(fs, g) >= new_size) {
+ ext2fs_block_bitmap_loc_set(fs, g, 0);
+ retval = ext2fs_allocate_group_table(fs, g, 0);
+ if (retval)
+ return retval;
+ }
+ if (ext2fs_inode_bitmap_loc(fs, g) >= new_size) {
+ ext2fs_inode_bitmap_loc_set(fs, g, 0);
+ retval = ext2fs_allocate_group_table(fs, g, 0);
+ if (retval)
+ return retval;
+ }
+ }
+ }
+
+ /*
* If we're shrinking the filesystem, we need to move all of
* the blocks that don't fit any more
*/