linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: George Spelvin <linux@horizon.com>, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 3/6] resize2fs: reserve all metadata blocks for flex_bg file systems
Date: Sat, 29 Dec 2012 03:55:25 -0500	[thread overview]
Message-ID: <1356771328-18196-4-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1356771328-18196-1-git-send-email-tytso@mit.edu>

For flex_bg file systems, if we need to relocate an allocation bitmap
or inode table, we need to make sure that all metadata blocks have
been reserved, lest we end up overwriting a metadata block belonging
to a different block group.

This change fixes the following test case:

rm -f foo.img; touch foo.img
truncate -s 32G foo.img
mke2fs -F -t ext4 -E resize=12582912 foo.img
e2fsck -f foo.img
truncate -s 64G foo.img
./resize2fs foo.img
e2fsck -fy foo.img

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 resize/resize2fs.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index c5d8a23..9702645 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -783,6 +783,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
 	ext2_filsys 	fs, old_fs;
 	ext2fs_block_bitmap	meta_bmap;
 	__u32		save_incompat_flag;
+	int		flex_bg;
 
 	fs = rfs->new_fs;
 	old_fs = rfs->old_fs;
@@ -874,6 +875,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
 	 * gets interesting....
 	 */
 	meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
+	flex_bg = fs->super->s_feature_incompat &
+		EXT4_FEATURE_INCOMPAT_FLEX_BG;
 	/* first reserve all of the existing fs meta blocks */
 	for (i = 0; i < max_groups; i++) {
 		has_super = ext2fs_bg_has_super(fs, i);
@@ -903,18 +906,37 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
 		/*
 		 * Reserve the existing meta blocks that we know
 		 * aren't to be moved.
+		 *
+		 * For flex_bg file systems, in order to avoid
+		 * overwriting fs metadata (especially inode table
+		 * blocks) belonging to a different block group when
+		 * we are relocating the inode tables, we need to
+		 * reserve all existing fs metadata blocks.
 		 */
 		if (ext2fs_block_bitmap_loc(fs, i))
 			ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
 				 ext2fs_block_bitmap_loc(fs, i));
+		else if (flex_bg && i < old_fs->group_desc_count)
+			ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
+				 ext2fs_block_bitmap_loc(old_fs, i));
+
 		if (ext2fs_inode_bitmap_loc(fs, i))
 			ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
 				 ext2fs_inode_bitmap_loc(fs, i));
+		else if (flex_bg && i < old_fs->group_desc_count)
+			ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
+				 ext2fs_inode_bitmap_loc(old_fs, i));
+
 		if (ext2fs_inode_table_loc(fs, i))
 			for (blk = ext2fs_inode_table_loc(fs, i), j=0;
 			     j < fs->inode_blocks_per_group ; j++, blk++)
 				ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
 							 blk);
+		else if (flex_bg && i < old_fs->group_desc_count)
+			for (blk = ext2fs_inode_table_loc(old_fs, i), j=0;
+			     j < old_fs->inode_blocks_per_group ; j++, blk++)
+				ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
+							  blk);
 
 		group_blk += rfs->new_fs->super->s_blocks_per_group;
 	}
-- 
1.7.12.rc0.22.gcdd159b


  parent reply	other threads:[~2012-12-29  8:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-29  8:55 [PATCH RFC 0/6] add full off-line resize2fs support for flex_bg file systems Theodore Ts'o
2012-12-29  8:55 ` [PATCH 1/6] mke2fs: fix crash when parsing "-E resize=NNN" with "-O 64bit" Theodore Ts'o
2012-12-29  8:55 ` [PATCH 2/6] resize2fs: reserve fs metadata blocks first in blocks_to_move() Theodore Ts'o
2012-12-29  8:55 ` Theodore Ts'o [this message]
2012-12-29  8:55 ` [PATCH 4/6] resize2fs: handle bg descriptors which overlap with other bg's metadata Theodore Ts'o
2012-12-29  8:55 ` [PATCH 5/6] resize2fs: allow resizing flex_bg && !resize_inode file systems Theodore Ts'o
2012-12-29  8:55 ` [PATCH 6/6] resize2fs: create optimized flex_bg block groups Theodore Ts'o
2012-12-29  9:32 ` [PATCH RFC 0/6] add full off-line resize2fs support for flex_bg file systems Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1356771328-18196-4-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux@horizon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).