linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: zhanchengbin <zhanchengbin1@huawei.com>
Cc: tytso@mit.edu, linux-ext4@vger.kernel.org, linfeilong@huawei.com,
	louhongxiang@huawei.com
Subject: Re: [PATCH] e2fsck: restore sb->s_state before journal recover
Date: Fri, 2 Jun 2023 08:18:58 -0700	[thread overview]
Message-ID: <20230602151858.GA16844@frogsfrogsfrogs> (raw)
In-Reply-To: <20230602082759.4062633-1-zhanchengbin1@huawei.com>

On Fri, Jun 02, 2023 at 04:27:59PM +0800, zhanchengbin wrote:
> ext4_handle_error
>     EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
>     if remount-ro
>         ext4_commit_super(sb);
> As you can see, when the filesystem error in the kernel, the last sb commit
> not record the journal, So sb->s_state will be overwritten by journal recover.
> In some cases , modifying metadata and superblock data are placed in two
> transactions, if the previous transaction is already in the journal, and
> ext4_handle_error occurs when updating sb, the filesystem is still error even
> if the journal is recovered(I know that this situation should not occur in
> theory, but I encountered this error when testing quota. Therefore, I think
> we cannot fully rely on the kernel).
> So when the filesystem is error before the journal recover, keep the error
> state and perform deep check later.
> 
> Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
> ---
>  e2fsck/journal.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index c7868d89..6f49321d 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -1683,6 +1683,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
>  	errcode_t	retval, recover_retval;
>  	io_stats	stats = 0;
>  	unsigned long long kbytes_written = 0;
> +	__u16 state = ctx->fs->super->s_state;
>  
>  	printf(_("%s: recovering journal\n"), ctx->device_name);
>  	if (ctx->options & E2F_OPT_READONLY) {
> @@ -1722,6 +1723,9 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
>  	ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
>  	ctx->fs->super->s_kbytes_written += kbytes_written;
>  
> +	if (EXT2_ERROR_FS | state)

Isn't this  ^^^^^^^^^^^^^^^^^^^^^ expression always nonzero?

> +		ctx->fs->super->s_state = state | EXT2_ERROR_FS;

/me doesn't understand this bit logic at all.

--D

> +
>  	/* Set the superblock flags */
>  	e2fsck_clear_recover(ctx, recover_retval != 0);
>  
> -- 
> 2.31.1
> 

  reply	other threads:[~2023-06-02 15:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  8:27 [PATCH] e2fsck: restore sb->s_state before journal recover zhanchengbin
2023-06-02 15:18 ` Darrick J. Wong [this message]
2023-06-03  3:49   ` zhanchengbin
2023-06-06  9:09 ` zhanchengbin

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=20230602151858.GA16844@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=linfeilong@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=louhongxiang@huawei.com \
    --cc=tytso@mit.edu \
    --cc=zhanchengbin1@huawei.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).