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: Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 2/2] resize2fs: fix overhead calculation for meta_bg file systems
Date: Mon,  3 Sep 2012 12:45:58 -0400	[thread overview]
Message-ID: <1346690758-21072-2-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1346690758-21072-1-git-send-email-tytso@mit.edu>

The file system overhead calculation in calculate_minimum_resize_size
was incorrect meta_bg file systems.  This caused the minimum size to
underflow for very large file systems, which threw resize2fs into a
loop generally lasted longer than the user's patience.

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

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index dc2805d..1dce498 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -1890,6 +1890,8 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs)
 	blk64_t grp, data_needed, last_start;
 	blk64_t overhead = 0;
 	int num_of_superblocks = 0;
+	blk64_t super_overhead = 0;
+	int old_desc_blocks;
 	int extra_groups = 0;
 	int flexbg_size = 1 << fs->super->s_log_groups_per_flex;
 
@@ -1909,15 +1911,36 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs)
 	 * we need to figure out how many backup superblocks we have so we can
 	 * account for that in the metadata
 	 */
+	if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
+		old_desc_blocks = fs->super->s_first_meta_bg;
+	else
+		old_desc_blocks = fs->desc_blocks +
+			fs->super->s_reserved_gdt_blocks;
+
 	for (grp = 0; grp < fs->group_desc_count; grp++) {
+		blk64_t	super_blk, old_desc_blk, new_desc_blk;
+		int has_super;
+
+		ext2fs_super_and_bgd_loc2(fs, grp, &super_blk,
+					  &old_desc_blk, &new_desc_blk, 0);
+		has_super = ((grp == 0) || super_blk);
+		if (has_super)
+			super_overhead++;
+		if (old_desc_blk)
+			super_overhead += old_desc_blocks;
+		else if (new_desc_blk)
+			super_overhead++;
 		if (ext2fs_bg_has_super(fs, grp))
 			num_of_superblocks++;
+
 	}
+	printf("super overhead is %llu, old algorithm was %llu\n",
+	       super_overhead, SUPER_OVERHEAD(fs) * num_of_superblocks);
 
 	/* calculate how many blocks are needed for data */
 	data_needed = ext2fs_blocks_count(fs->super) -
 		ext2fs_free_blocks_count(fs->super);
-	data_needed -= SUPER_OVERHEAD(fs) * num_of_superblocks;
+	data_needed -= super_overhead;
 	data_needed -= META_OVERHEAD(fs) * fs->group_desc_count;
 
 	if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_FLEX_BG) {
-- 
1.7.12.rc0.22.gcdd159b


  reply	other threads:[~2012-09-03 16:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-02  9:52 [PATCH] resize2fs: support online-resizing for meta_bg and 64bits features Yongqiang Yang
2012-09-02 10:31 ` Yongqiang Yang
2012-09-03  0:50   ` Theodore Ts'o
2012-09-03 16:45   ` Theodore Ts'o
2012-09-03 16:45     ` [PATCH 1/2] resize2fs: allow meta_bg/64-bit file systems to be online resized Theodore Ts'o
2012-09-03 16:45       ` Theodore Ts'o [this message]
2012-09-04  1:59         ` [PATCH 2/2] resize2fs: fix overhead calculation for meta_bg file systems Yongqiang Yang
2012-09-04  2:14           ` Kevin Liao
2012-09-04  2:14           ` Theodore Ts'o
2012-09-04 17:05             ` Anssi Hannula
2012-09-05  2:10               ` Yongqiang Yang
2012-09-05  4:55                 ` Theodore Ts'o
2012-09-05  5:16                   ` Yongqiang Yang
2012-09-05  5:38                     ` Theodore Ts'o
2012-09-06 14:22                 ` Anssi Hannula
2012-09-06 16:19                   ` Yongqiang Yang
2012-09-05  6:32             ` Kevin Liao
2012-09-05  6:44               ` Yongqiang Yang
2012-09-05  6:50                 ` Kevin Liao
2012-09-13 23:21               ` Theodore Ts'o
2012-09-14  3:24                 ` Kevin Liao
2012-09-04  2:02         ` Yongqiang Yang
2012-09-03 21:02     ` [PATCH] resize2fs: support online-resizing for meta_bg and 64bits features Kai Grosshaus
2012-09-03 23:00       ` Theodore Ts'o
2012-09-03 23:33         ` Kai Großhaus
2012-09-04  2:01     ` Yongqiang Yang

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=1346690758-21072-2-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    /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).