From ada50f11014f841b56d5691fa272570841d6eafc Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Fri, 11 Feb 2022 09:42:37 +0800 Subject: [PATCH] e2fsprogs: fix three issues to improve reliablity when exec fsck - e2fsck: exit journal recovery when find EIO, ENOMEM errors Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZUT?from=project-issue - e2fsck: exit journal recovery when jounral superblock fails to update Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4S0SD?from=project-issue - e2fsck: add env param E2FS_UNRELIABLE_IO to fix unreliable io case Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZVX?from=project-issue Signed-off-by: Zhiqiang Liu --- ...nal-recovery-when-find-EIO-ENOMEM-er.patch | 51 ++++++++++ ...nal-recovery-when-jounral-superblock.patch | 93 +++++++++++++++++++ ...aram-E2FS_UNRELIABLE_IO-to-fix-unrel.patch | 41 ++++++++ e2fsprogs.spec | 15 ++- 4 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 0005-e2fsck-exit-journal-recovery-when-find-EIO-ENOMEM-er.patch create mode 100644 0006-e2fsck-exit-journal-recovery-when-jounral-superblock.patch create mode 100644 0007-e2fsck-add-env-param-E2FS_UNRELIABLE_IO-to-fix-unrel.patch diff --git a/0005-e2fsck-exit-journal-recovery-when-find-EIO-ENOMEM-er.patch b/0005-e2fsck-exit-journal-recovery-when-find-EIO-ENOMEM-er.patch new file mode 100644 index 0000000..49374ee --- /dev/null +++ b/0005-e2fsck-exit-journal-recovery-when-find-EIO-ENOMEM-er.patch @@ -0,0 +1,51 @@ +From e10240ea69ac21a09687d4e571b1c96a44073753 Mon Sep 17 00:00:00 2001 +From: lihaotian +Date: Tue, 15 Dec 2020 11:46:07 +0000 +Subject: [PATCH 1/3] e2fsck: exit journal recovery when find EIO, ENOMEM + errors + +jbd2_journal_revocer() may fail when some error occers +such as ENOMEM. However, jsb->s_start is still cleared +by func e2fsck_journal_release(). This may break +consistency between metadata and data in disk. Sometimes, +failure in jbd2_journal_revocer() is temporary but retry +e2fsck will skip the journal recovery when the temporary +problem is fixed. + +To fix this case, we use "fatal_error" instead "goto errout" +when recover journal failed. If journal recovery fails, we +will send error message to user and reserve the recovery +flags to recover the journal when try e2fsck again. + +Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZUT?from=project-issue + +Conflict: fix context conflict due to func rename + +Reported-by: Liangyun +Signed-off-by: Haotian Li +Signed-off-by: Zhiqiang Liu +--- + e2fsck/journal.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/e2fsck/journal.c b/e2fsck/journal.c +index fe4e018..7081b6e 100644 +--- a/e2fsck/journal.c ++++ b/e2fsck/journal.c +@@ -1636,6 +1636,13 @@ static errcode_t recover_ext3_journal(e2fsck_t ctx) + goto errout; + + retval = -jbd2_journal_recover(journal); ++ if (retval == EIO || retval == ENOMEM || retval == EXT2_ET_NO_MEMORY) { ++ ctx->fs->flags &= ~EXT2_FLAG_VALID; ++ com_err(ctx->program_name, 0, ++ _("Journal recovery failed " ++ "on %s, retval=%d \n"), ctx->device_name, retval); ++ fatal_error(ctx, 0); ++ } + if (retval) + goto errout; + +-- +2.21.1 (Apple Git-122.3) + diff --git a/0006-e2fsck-exit-journal-recovery-when-jounral-superblock.patch b/0006-e2fsck-exit-journal-recovery-when-jounral-superblock.patch new file mode 100644 index 0000000..535edfc --- /dev/null +++ b/0006-e2fsck-exit-journal-recovery-when-jounral-superblock.patch @@ -0,0 +1,93 @@ +From 62c7993512f58e2c8a582938c518c0deeeae740c Mon Sep 17 00:00:00 2001 +From: liangyun2 +Date: Sat, 19 Dec 2020 12:05:37 +0800 +Subject: [PATCH 2/3] e2fsck: exit journal recovery when jounral superblock + fails to update + +Jounral superblock may be failed to update in e2fsck_journal_release. +But if needs_recovery flag is cleared, e2fsck_check_ext3_journal will be failed. + +To fix this case, we use "fatal_error" when recover journal failed. +So we can reserve the recovery flag to recover the journal when try e2fsck again. + +Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4S0SD?from=project-issue + +Conflict: fix context conflict in recover_ext3_journal() + +Reported-by: Liangyun +Signed-off-by: Haotian Li +Signed-off-by: Zhiqiang Liu +--- + e2fsck/journal.c | 25 ++++++++++++++++++++++++- + 1 file changed, 24 insertions(+), 1 deletion(-) + +diff --git a/e2fsck/journal.c b/e2fsck/journal.c +index 7081b6e..253fb49 100644 +--- a/e2fsck/journal.c ++++ b/e2fsck/journal.c +@@ -1444,10 +1444,12 @@ static errcode_t e2fsck_journal_fix_corrupt_super(e2fsck_t ctx, + return 0; + } + +-static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, ++static errcode_t e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, + int reset, int drop) + { + journal_superblock_t *jsb; ++ errcode_t err = 0; ++ errcode_t err2; + + if (drop) + mark_buffer_clean(journal->j_sb_buffer); +@@ -1461,6 +1463,16 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, + } + brelse(journal->j_sb_buffer); + ++ if(reset == 1 && drop == 0) { ++ err = sync_blockdev(journal->j_fs_dev); ++ /* Make sure all replayed data is on permanent storage */ ++ if (journal->j_flags & JFS_BARRIER) { ++ err2 = blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL); ++ if (!err) ++ err = err2; ++ } ++ } ++ + if (ctx->journal_io) { + if (ctx->fs && ctx->fs->io != ctx->journal_io) + io_channel_close(ctx->journal_io); +@@ -1474,6 +1486,8 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, + if (journal->j_fs_dev) + ext2fs_free_mem(&journal->j_fs_dev); + ext2fs_free_mem(&journal); ++ ++ return err; + } + + /* +@@ -1612,6 +1626,7 @@ static errcode_t recover_ext3_journal(e2fsck_t ctx) + struct problem_context pctx; + journal_t *journal; + errcode_t retval; ++ errcode_t recover_retval; + + clear_problem_context(&pctx); + +@@ -1660,6 +1675,14 @@ errout: + jbd2_journal_destroy_revoke_record_cache(); + jbd2_journal_destroy_revoke_table_cache(); + e2fsck_journal_release(ctx, journal, 1, 0); ++ recover_retval = e2fsck_journal_release(ctx, journal, 1, 0); ++ if(recover_retval == -EIO) { ++ ctx->fs->flags &= ~EXT2_FLAG_VALID; ++ com_err(ctx->program_name, 0, ++ _("e2fsck journal release failed " ++ "on %s, retval=%d \n"), ctx->device_name, recover_retval); ++ fatal_error(ctx, 0); ++ } + return retval; + } + +-- +2.21.1 (Apple Git-122.3) + diff --git a/0007-e2fsck-add-env-param-E2FS_UNRELIABLE_IO-to-fix-unrel.patch b/0007-e2fsck-add-env-param-E2FS_UNRELIABLE_IO-to-fix-unrel.patch new file mode 100644 index 0000000..76ecbae --- /dev/null +++ b/0007-e2fsck-add-env-param-E2FS_UNRELIABLE_IO-to-fix-unrel.patch @@ -0,0 +1,41 @@ +From f9531c00da6fe23c3d38d1ae29076606369a30cf Mon Sep 17 00:00:00 2001 +From: Haotian +Date: Wed, 17 Mar 2021 17:34:14 +0800 +Subject: [PATCH 3/3] e2fsck: add env param E2FS_UNRELIABLE_IO to fix + unreliable io case + +Func write_primary_superblock() has two way to wirte disk. One is 1k block, +the other is byte by byte as default. On unreliable IO case such as flaky +network, the byte-by-byte method may lost some data of ext4-superblock. +Then, the superblock may lose consistency and the sb checksum error will +occur. + +We provide the env param E2FS_UNRELIABLE_IO for users to choose if it's +necessary to take 1k block way on writing disk. + +Fix issue:https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZVX?from=project-issue + +Signed-off-by: Haotian Li +Signed-off-by: Zhiqiang Liu +--- + lib/ext2fs/closefs.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c +index 69cbdd8..95f1de3 100644 +--- a/lib/ext2fs/closefs.c ++++ b/lib/ext2fs/closefs.c +@@ -195,8 +195,9 @@ static errcode_t write_primary_superblock(ext2_filsys fs, + __u16 *old_super, *new_super; + int check_idx, write_idx, size; + errcode_t retval; ++ int is_unreliable_io = getenv("E2FS_UNRELIABLE_IO") ? 1 : 0; + +- if (!fs->io->manager->write_byte || !fs->orig_super) { ++ if (!fs->io->manager->write_byte || !fs->orig_super || is_unreliable_io) { + fallback: + io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET); + retval = io_channel_write_blk64(fs->io, 1, -SUPERBLOCK_SIZE, +-- +2.21.1 (Apple Git-122.3) + diff --git a/e2fsprogs.spec b/e2fsprogs.spec index bfac585..9cc40b6 100644 --- a/e2fsprogs.spec +++ b/e2fsprogs.spec @@ -1,6 +1,6 @@ Name: e2fsprogs Version: 1.46.4 -Release: 2 +Release: 3 Summary: Second extended file system management tools License: GPLv2+ and LGPLv2 and MIT URL: http://e2fsprogs.sourceforge.net/ @@ -10,6 +10,9 @@ Patch1: 0001-e2fsprogs-set-hugefile-from-4T-to-1T-in-hugefile-tes.patch Patch2: 0002-libss-add-newer-libreadline.so.8-to-dlopen-path.patch Patch3: 0003-tests-update-expect-files-for-f_mmp_garbage.patch Patch4: 0004-tests-update-expect-files-for-f_large_dir-and-f_larg.patch +Patch5: 0005-e2fsck-exit-journal-recovery-when-find-EIO-ENOMEM-er.patch +Patch6: 0006-e2fsck-exit-journal-recovery-when-jounral-superblock.patch +Patch7: 0007-e2fsck-add-env-param-E2FS_UNRELIABLE_IO-to-fix-unrel.patch BuildRequires: gcc pkgconfig texinfo BuildRequires: fuse-devel libblkid-devel libuuid-devel @@ -131,6 +134,16 @@ exit 0 %{_mandir}/man8/* %changelog +* Fri Feb 11 2022 Zhiqiang Liu - 1.46.4-3 +- fix three issues: + - e2fsck: exit journal recovery when find EIO, ENOMEM errors + Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZUT?from=project-issue + - e2fsck: exit journal recovery when jounral superblock fails to update + Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4S0SD?from=project-issue + - e2fsck: add env param E2FS_UNRELIABLE_IO to fix unreliable io case + Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZVX?from=project-issue + + * Thu Jan 27 2022 zhanchengbin - 1.46.4-2 - replace License in spec -- Gitee