linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH] resize2fs: update sb journal backup if journal was moved
Date: Wed, 17 Jun 2009 20:55:39 -0500	[thread overview]
Message-ID: <4A399E9B.4080207@redhat.com> (raw)
In-Reply-To: <4A3946A3.2040401@redhat.com>

This was reported in Fedora, since the livecd creator does
a lot of resizing.

If we've moved the journal blocks during resize (more likely now,
due to the journal being in the middle) the backup blocks in the
superblock don't get updated, and a subsequent e2fsck will find 
issues:

e2fsck 1.41.6 (30-May-2009)
Backing up journal inode block information.

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/mnt/test/img: ***** FILE SYSTEM WAS MODIFIED *****
/mnt/test/img: 11/16000 files (0.0% non-contiguous), 17789/38400 blocks

This can be shown in a simple test:

# dd if=/dev/zero of=img bs=1 count=0 seek=3000M
# mke2fs -t ext4 -F img
# resize2fs img 150M
# e2fsck -f img

(thanks to the Fedora reporter Mads Kiilerich for the testcase!
https://bugzilla.redhat.com/show_bug.cgi?id=506105#c2)

So, update the backup journal in the superblock before resize2fs exits.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Resolves-RH-Bugzilla: 505339
---

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 0d5dc81..63c469f 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -49,6 +49,7 @@ static errcode_t inode_ref_fix(ext2_resize_t rfs);
 static errcode_t move_itables(ext2_resize_t rfs);
 static errcode_t fix_resize_inode(ext2_filsys fs);
 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs);
+static errcode_t fix_sb_journal_backup(ext2_filsys fs);
 
 /*
  * Some helper CPP macros
@@ -148,6 +149,10 @@ errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
 	if (retval)
 		goto errout;
 
+	retval = fix_sb_journal_backup(rfs->new_fs);
+	if (retval)
+		goto errout;
+
 	rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
 	retval = ext2fs_close(rfs->new_fs);
 	if (retval)
@@ -1857,6 +1862,28 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
 }
 
 /*
+ *  Journal may have been relocated; update the backup journal blocks
+ *  in the superblock.
+ */
+static errcode_t fix_sb_journal_backup(ext2_filsys fs)
+{
+	errcode_t	  retval;
+	struct ext2_inode inode;
+
+	if (!(fs->super->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL))
+		return 0;
+
+	retval = ext2fs_read_inode(fs, fs->super->s_journal_inum, &inode);
+	if (retval)
+		return retval;
+	memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4);
+	fs->super->s_jnl_blocks[16] = inode.i_size;
+	fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS;
+	ext2fs_mark_super_dirty(fs);
+	return 0;
+}
+
+/*
  * calcluate the minimum number of blocks the given fs can be resized to
  */
 blk_t calculate_minimum_resize_size(ext2_filsys fs)


  reply	other threads:[~2009-06-18  1:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 19:40 [PATCH, RFC] resize2fs: update sb backup journal if journal was moved Eric Sandeen
2009-06-18  1:55 ` Eric Sandeen [this message]
2009-06-18 11:48   ` [PATCH] resize2fs: update sb journal backup " Theodore Tso

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=4A399E9B.4080207@redhat.com \
    --to=sandeen@redhat.com \
    --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).