fix error flag covered by journal recovery
v5 cover fix error flag covered by journal recovery
From: Ye Bin <[email protected]>
Diff v5 Vs v4:
Only commit error info to disk when bdev is not readonly.
Diff v4 Vs v3:
After journal replay recover 'es->s_state' error flag like recover error info.
Diff v3 Vs v2:
Only fix fs error flag lost when previous journal errno is not record in disk. As this may lead to drop orphan list, however fs not record error flag, then fsck will not repair deeply.
Diff v2 vs v1:
Move call 'j_replay_prepare_callback' and 'j_replay_end_callback' from ext4_load_journal() to jbd2_journal_recover().
When do fault injection test, got issue as follows:
EXT4-fs (dm-5): warning: mounting fs with errors, running e2fsck is recommended EXT4-fs (dm-5): Errors on filesystem, clearing orphan list.
EXT4-fs (dm-5): recovery complete
EXT4-fs (dm-5): mounted filesystem with ordered data mode. Opts: data_err=abort,errors=remount-ro
EXT4-fs (dm-5): recovery complete
EXT4-fs (dm-5): mounted filesystem with ordered data mode. Opts: data_err=abort,errors=remount-ro
Without do file system check, file system is clean when do second mount. Theoretically, the kernel will not clear fs error flag. In errors=remount-ro mode the last super block is commit directly. So super block in journal is not uptodate. When do jounral recovery, the uptodate super block will be covered by jounral data. If super block submit all failed after recover journal, then file system error flag is lost. When do "fsck -a" couldn't repair file system deeply.
To solve above issue we need to do extra handle when do super block journal recovery.
Ye Bin (2):
ext4: commit super block if fs record error when journal record
without error
ext4: make sure fs error flag setted before clear journal error
fs/ext4/super.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
PATCH v5 1/2 ext4: commit super block if fs record error when journal record without error
From: Ye Bin <[email protected]>
Now, 'es->s_state' maybe covered by recover journal. And journal errno maybe not recorded in journal sb as IO error. ext4_update_super() only update error information when 'sbi->s_add_error_count' large than zero. Then 'EXT4_ERROR_FS' flag maybe lost.
To solve above issue just recover 'es->s_state' error flag after journal replay like error info.
--- fs/ext4/super.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ext4/super.c +9 -0
@@ -5920,6 +5920,7 @@ static int ext4_load_journal(struct super_block *sb, err =jbd2_journal_wipe (journal, !really_read_only);if (!err) {char *save =kmalloc (EXT4_S_ERR_LEN ,GFP_KERNEL ); +if (save)memcpy (save, ((char *) es) +EXT4_S_ERR_START ,EXT4_S_ERR_LEN );
@@ -5928,6 +5929,14 @@ static int ext4_load_journal(struct super_block *sb,memcpy (((char *) es) +EXT4_S_ERR_START , save,EXT4_S_ERR_LEN );kfree (save); + es->s_state |=cpu_to_le16 (EXT4_SB (sb)->s_mount_state & +EXT4_ERROR_FS ); +/* Write out restored error information to the superblock */ +if (!bdev_read_only (sb->s_bdev)) { +int err2; + err2 =ext4_commit_super (sb); + err = err ? : err2; + } }if (err) {
Signature · 1 line
2.31.1
Re: [PATCH v5 1/2] ext4: commit super block if fs record error when journal record without error
Quoted 10 lines · Ye Bin
From: Ye Bin <[email protected]>
Now, '
es->s_state' maybe covered by recover journal. And journal errno maybe not recorded in journal sb as IO error.ext4_update_super()only update error information when 'sbi->s_add_error_count' large than zero. Then 'EXT4_ERROR_FS' flag maybe lost.
To solve above issue just recover 'es->s_state' error flag after journal replay like error info.Signed-off-by Ye Bin <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 34 lines
--- fs/ext4/super.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/ext4/super.c +9
-0@@ -5920,6 +5920,7 @@ static int ext4_load_journal(struct super_block *sb, err =jbd2_journal_wipe (journal, !really_read_only);if (!err) {char *save =kmalloc (EXT4_S_ERR_LEN ,GFP_KERNEL ); +if (save)memcpy (save, ((char *) es) +EXT4_S_ERR_START ,EXT4_S_ERR_LEN );@@ -5928,6 +5929,14 @@ static int ext4_load_journal(struct super_block *sb,memcpy (((char *) es) +EXT4_S_ERR_START , save,EXT4_S_ERR_LEN );kfree (save); + es->s_state |=cpu_to_le16 (EXT4_SB (sb)->s_mount_state & +EXT4_ERROR_FS ); +/* Write out restored error information to the superblock */ +if (!bdev_read_only (sb->s_bdev)) { +int err2; + err2 =ext4_commit_super (sb); + err = err ? : err2; + } }if (err) {Signature · 1 line
2.31.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v5 1/2] ext4: commit super block if fs record error when journal record without error
In reply to Ye BinQuoted 10 lines · Ye Bin
From: Ye Bin <[email protected]>
Now, '
es->s_state' maybe covered by recover journal. And journal errno maybe not recorded in journal sb as IO error.ext4_update_super()only update error information when 'sbi->s_add_error_count' large than zero. Then 'EXT4_ERROR_FS' flag maybe lost.
To solve above issue just recover 'es->s_state' error flag after journal replay like error info.Signed-off-by Ye Bin <[email protected]>
Looks good to me.
Quoted 31 lines
--- fs/ext4/super.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/ext4/super.c +9
-0@@ -5920,6 +5920,7 @@ static int ext4_load_journal(struct super_block *sb, err =jbd2_journal_wipe (journal, !really_read_only);if (!err) {char *save =kmalloc (EXT4_S_ERR_LEN ,GFP_KERNEL ); +if (save)memcpy (save, ((char *) es) +EXT4_S_ERR_START ,EXT4_S_ERR_LEN );@@ -5928,6 +5929,14 @@ static int ext4_load_journal(struct super_block *sb,memcpy (((char *) es) +EXT4_S_ERR_START , save,EXT4_S_ERR_LEN );kfree (save); + es->s_state |=cpu_to_le16 (EXT4_SB (sb)->s_mount_state & +EXT4_ERROR_FS ); +/* Write out restored error information to the superblock */ +if (!bdev_read_only (sb->s_bdev)) { +int err2; + err2 =ext4_commit_super (sb); + err = err ? : err2; + } }if (err) {
Signature · 3 lines
With Best Regards, Baokun Li .
PATCH v5 2/2 ext4: make sure fs error flag setted before clear journal error
In reply to Ye BinFrom: Ye Bin <[email protected]>
Now, jounral error number maybe cleared even though ext4_commit_super() failed. This may lead to error flag miss, then fsck will miss to check file system deeply.
--- fs/ext4/super.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ext4/super.c +4 -2
@@ -6166,11 +6166,13 @@ static int ext4_clear_journal_err(struct super_block *sb, errstr =ext4_decode_error (sb, j_errno, nbuf);ext4_warning (sb,"Filesystem error recorded " "from previous mount: %s" , errstr); -ext4_warning (sb,"Marking fs in need of filesystem check." );EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ; es->s_state |=cpu_to_le16 (EXT4_ERROR_FS ); -ext4_commit_super (sb); + j_errno =ext4_commit_super (sb); +if (j_errno) +return j_errno; +ext4_warning (sb,"Marked fs in need of filesystem check." );jbd2_journal_clear_err (journal);jbd2_journal_update_sb_errno (journal);
Signature · 1 line
2.31.1