fsck.f2fs: Fix up nat journal corruption with -a (auto-fix) option
authorSahitya Tummala <stummala@codeaurora.org>
Fri, 24 May 2019 06:09:47 +0000 (11:39 +0530)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 20 Aug 2019 18:23:51 +0000 (11:23 -0700)
Build segment manager and node manager always to catch and auto-fix
invalid NAT entries found in the NAT journal.

Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/mount.c

index aecd0cd..73ad04d 100644 (file)
@@ -1069,6 +1069,7 @@ static int f2fs_init_nid_bitmap(struct f2fs_sb_info *sbi)
                        "NAT_JOURNAL_ENTRIES(%lu)\n",
                        nats_in_cursum(journal), NAT_JOURNAL_ENTRIES);
                journal->n_nats = cpu_to_le16(NAT_JOURNAL_ENTRIES);
+               c.fix_on = 1;
        }
 
        for (i = 0; i < nats_in_cursum(journal); i++) {
@@ -1078,6 +1079,7 @@ static int f2fs_init_nid_bitmap(struct f2fs_sb_info *sbi)
                if (!IS_VALID_BLK_ADDR(sbi, addr)) {
                        MSG(0, "\tError: f2fs_init_nid_bitmap: addr(%u) is invalid!!!\n", addr);
                        journal->n_nats = cpu_to_le16(i);
+                       c.fix_on = 1;
                        continue;
                }
 
@@ -1085,6 +1087,7 @@ static int f2fs_init_nid_bitmap(struct f2fs_sb_info *sbi)
                if (!IS_VALID_NID(sbi, nid)) {
                        MSG(0, "\tError: f2fs_init_nid_bitmap: nid(%u) is invalid!!!\n", nid);
                        journal->n_nats = cpu_to_le16(i);
+                       c.fix_on = 1;
                        continue;
                }
                if (addr != NULL_ADDR)
@@ -2668,19 +2671,6 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
                        c.fix_on = 1;
        }
 
-       if (c.auto_fix || c.preen_mode) {
-               u32 flag = get_cp(ckpt_flags);
-
-               if (flag & CP_FSCK_FLAG ||
-                       flag & CP_QUOTA_NEED_FSCK_FLAG ||
-                       (exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
-                       c.fix_on = 1;
-               } else if (!c.preen_mode) {
-                       print_cp_state(flag);
-                       return 1;
-               }
-       }
-
        c.bug_on = 0;
 
        tune_sb_features(sbi);
@@ -2706,6 +2696,19 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
                return -1;
        }
 
+       if (!c.fix_on && (c.auto_fix || c.preen_mode)) {
+               u32 flag = get_cp(ckpt_flags);
+
+               if (flag & CP_FSCK_FLAG ||
+                       flag & CP_QUOTA_NEED_FSCK_FLAG ||
+                       (exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
+                       c.fix_on = 1;
+               } else if (!c.preen_mode) {
+                       print_cp_state(flag);
+                       return 1;
+               }
+       }
+
        /* Check nat_bits */
        if (c.func == FSCK && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
                if (check_nat_bits(sbi, sb, cp) && c.fix_on)