1From f923f6ddbd555801f1d6495904de4fefb363fa57 Mon Sep 17 00:00:00 2001 2From: liangyun2 <liangyun2@huawei.com> 3Date: Sat, 19 Dec 2020 12:05:37 +0800 4Subject: [PATCH] e2fsck: exit journal recovery when jounral superblock fails 5 to update 6 7Jounral superblock may be failed to update in e2fsck_journal_release. 8But if needs_recovery flag is cleared, e2fsck_check_ext3_journal will be failed. 9 10To fix this case, we use "fatal_error" when recover journal failed. 11So we can reserve the recovery flag to recover the journal when try e2fsck again. 12 13Fix issue: https://gitee.com/src-openeuler/e2fsprogs/issues/I4S0SD?from=project-issue 14 15conflict: journal_destroy_revoke -> jbd2_journal_destroy_revoke 16 journal_destroy_revoke_caches -> jbd2_journal_destroy_revoke_record_cache 17 jbd2_journal_destroy_revoke_table_cache 18 JFS_BARRIER -> JBD2_BARRIER 19 blkdev_issue_flush(kdev, a, b) -> blkdev_issue_flush(kdev) 20 21Reported-by: Liangyun <liangyun2@huawei.com> 22Signed-off-by: Haotian Li <lihaotian9@huawei.com> 23Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> 24--- 25 e2fsck/journal.c | 26 ++++++++++++++++++++++++-- 26 1 file changed, 24 insertions(+), 2 deletions(-) 27 28diff --git a/e2fsck/journal.c b/e2fsck/journal.c 29index 7081b6e..f4253c0 100644 30--- a/e2fsck/journal.c 31+++ b/e2fsck/journal.c 32@@ -1444,10 +1444,12 @@ static errcode_t e2fsck_journal_fix_corrupt_super(e2fsck_t ctx, 33 return 0; 34 } 35 36-static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, 37+static errcode_t e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, 38 int reset, int drop) 39 { 40 journal_superblock_t *jsb; 41+ errcode_t err = 0; 42+ errcode_t err2; 43 44 if (drop) 45 mark_buffer_clean(journal->j_sb_buffer); 46@@ -1461,6 +1463,16 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, 47 } 48 brelse(journal->j_sb_buffer); 49 50+ if(reset == 1 && drop == 0) { 51+ err = sync_blockdev(journal->j_fs_dev); 52+ /* Make sure all replayed data is on permanent storage */ 53+ if (journal->j_flags & JBD2_BARRIER) { 54+ err2 = blkdev_issue_flush(journal->j_fs_dev); 55+ if (!err) 56+ err = err2; 57+ } 58+ } 59+ 60 if (ctx->journal_io) { 61 if (ctx->fs && ctx->fs->io != ctx->journal_io) 62 io_channel_close(ctx->journal_io); 63@@ -1474,6 +1486,8 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, 64 if (journal->j_fs_dev) 65 ext2fs_free_mem(&journal->j_fs_dev); 66 ext2fs_free_mem(&journal); 67+ 68+ return err; 69 } 70 71 /* 72@@ -1612,6 +1626,7 @@ static errcode_t recover_ext3_journal(e2fsck_t ctx) 73 struct problem_context pctx; 74 journal_t *journal; 75 errcode_t retval; 76+ errcode_t recover_retval; 77 78 clear_problem_context(&pctx); 79 80@@ -1659,7 +1674,14 @@ errout: 81 jbd2_journal_destroy_revoke(journal); 82 jbd2_journal_destroy_revoke_record_cache(); 83 jbd2_journal_destroy_revoke_table_cache(); 84- e2fsck_journal_release(ctx, journal, 1, 0); 85+ recover_retval = e2fsck_journal_release(ctx, journal, 1, 0); 86+ if(recover_retval == -EIO) { 87+ ctx->fs->flags &= ~EXT2_FLAG_VALID; 88+ com_err(ctx->program_name, 0, 89+ _("e2fsck journal release failed " 90+ "on %s, retval=%d \n"), ctx->device_name, recover_retval); 91+ fatal_error(ctx, 0); 92+ } 93 return retval; 94 } 95 96-- 971.8.3.1 98 99