fsck.f2fs: try to recover cp_payload from valid cp pack
authorChao Yu <yuchao0@huawei.com>
Fri, 28 Sep 2018 12:26:00 +0000 (20:26 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 21 Nov 2018 19:38:23 +0000 (11:38 -0800)
If sb checksum is not enabled, and cp pack is valid due to no
crc inconsistence, let's try to recover cp_payload based on
cp_pack_start_sum in cp pack.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/f2fs.h
fsck/mount.c

index d216444..0d0d5e2 100644 (file)
@@ -259,6 +259,11 @@ static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
        return 0;
 }
 
+static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
+{
+       return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
+}
+
 static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
 {
        struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
index 7c39ac4..b6cd5c8 100644 (file)
@@ -977,12 +977,16 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
        }
 
        cp_pack_start_sum = __start_sum_addr(sbi);
-       cp_payload = get_sb(cp_payload);
+       cp_payload = __cp_payload(sbi);
        if (cp_pack_start_sum < cp_payload + 1 ||
                cp_pack_start_sum > blocks_per_seg - 1 -
                        NR_CURSEG_TYPE) {
-               MSG(0, "\tWrong cp_pack_start_sum(%u)\n", cp_pack_start_sum);
-               return 1;
+               MSG(0, "\tWrong cp_pack_start_sum(%u) or cp_payload(%u)\n",
+                       cp_pack_start_sum, cp_payload);
+               if ((get_sb(feature) & F2FS_FEATURE_SB_CHKSUM))
+                       return 1;
+               set_sb(cp_payload, cp_pack_start_sum - 1);
+               update_superblock(sb, SB_MASK_ALL);
        }
 
        return 0;