public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: cgxu519 <cgxu519@gmx.com>
Cc: Amir Goldstein <amir73il@gmail.com>,
	Chengguang Xu <cgxu519@icloud.com>, Eryu Guan <eguan@redhat.com>,
	fstests <fstests@vger.kernel.org>,
	Ext4 <linux-ext4@vger.kernel.org>
Subject: Re: problem with tune2fs after ext4 godown
Date: Sat, 1 Sep 2018 14:42:45 -0400	[thread overview]
Message-ID: <20180901184245.GB25570@thunk.org> (raw)
In-Reply-To: <92bd7ae7-3601-9682-d131-258500393e9b@gmx.com>

On Fri, Aug 31, 2018 at 10:53:54PM +0800, cgxu519 wrote:
> steps to reproduce:
> 
> 1) mount an ext4 fs
> 2) write a file in the fs
> 3) sync / or do nothing
> 4) running godown tool in xfstest to the fs
> 5) umount the fs
> 6) mount the fs
> 7) tune2fs -l <dev>
> 
> tune2fs -l will fail with below error.
> 
> [root@x201 xfstests-dev]# tune2fs -l /dev/mapper/test-test1
> tune2fs 1.44.2 (14-May-2018)
> tune2fs: Superblock checksum does not match superblock while trying to
> open /dev/mapper/test-test1
> Couldn't find valid filesystem superblock.
> 
> NOTE, I don't know this is a real issue or just by design.

It's a real issue, thanks.  The fix is below:

					- Ted

>From 4274f516d4bc50648a4d97e4f67ecbd7b65cde4a Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <tytso@mit.edu>
Date: Sat, 1 Sep 2018 14:42:14 -0400
Subject: [PATCH] ext4: recalucate superblock checksum after updating free
 blocks/inodes

When mounting the superblock, ext4_fill_super() calculates the free
blocks and free inodes and stores them in the superblock.  It's not
strictly necessary, since we don't use them any more, but it's nice to
keep them roughly aligned to reality.

Since it's not critical for file system correctness, the code doesn't
call ext4_commit_super().  The problem is that it's in
ext4_commit_super() that we recalculate the superblock checksum.  So
if we're not going to call ext4_commit_super(), we need to call
ext4_superblock_csum_set() to make sure the superblock checksum is
consistent.

Most of the time, this doesn't matter, since we end up calling
ext4_commit_super() very soon thereafter, and definitely by the time
the file system is unmounted.  However, it doesn't work in this
sequence:

mke2fs -Fq -t ext4 /dev/vdc 128M
mount /dev/vdc /vdc
cp xfstests/git-versions /vdc
godown /vdc
umount /vdc
mount /dev/vdc
tune2fs -l /dev/vdc

With this commit, the "tune2fs -l" no longer fails.

Reported-by: Chengguang Xu <cgxu519@gmx.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
---
 fs/ext4/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f7750bc5b85a..e41da553b430 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4378,11 +4378,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	block = ext4_count_free_clusters(sb);
 	ext4_free_blocks_count_set(sbi->s_es, 
 				   EXT4_C2B(sbi, block));
+	ext4_superblock_csum_set(sb);
 	err = percpu_counter_init(&sbi->s_freeclusters_counter, block,
 				  GFP_KERNEL);
 	if (!err) {
 		unsigned long freei = ext4_count_free_inodes(sb);
 		sbi->s_es->s_free_inodes_count = cpu_to_le32(freei);
+		ext4_superblock_csum_set(sb);
 		err = percpu_counter_init(&sbi->s_freeinodes_counter, freei,
 					  GFP_KERNEL);
 	}
-- 
2.18.0.rc0

      reply	other threads:[~2018-09-01 22:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-15  7:47 [PATCH v5 1/3] common/rc: add scratch shutdown support for overlayfs Chengguang Xu
2017-12-15  7:47 ` [PATCH v5 2/3] common/rc: check syncfs support Chengguang Xu
2017-12-15  7:47 ` [PATCH v5 3/3] generic/471: add syncfs test Chengguang Xu
2018-08-26 14:53   ` Amir Goldstein
2018-08-30  3:12     ` cgxu519
2018-08-31 14:19       ` cgxu519
2018-08-31 14:28         ` problem with tune2fs after ext4 godown Amir Goldstein
2018-08-31 14:53           ` cgxu519
2018-09-01 18:42             ` Theodore Y. Ts'o [this message]

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=20180901184245.GB25570@thunk.org \
    --to=tytso@mit.edu \
    --cc=amir73il@gmail.com \
    --cc=cgxu519@gmx.com \
    --cc=cgxu519@icloud.com \
    --cc=eguan@redhat.com \
    --cc=fstests@vger.kernel.org \
    --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