fsck.f2fs: introduce fsck_chk_curseg_info
authorSheng Yong <shengyong1@huawei.com>
Wed, 20 Jun 2018 11:12:13 +0000 (19:12 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 28 Aug 2018 06:49:26 +0000 (23:49 -0700)
If curseg is an empty segment, it will not be checked. This patch
introduces fsck_chk_curseg_info() to check SIT/SSA type of cursegs
to avoid curseg corruption.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c
fsck/fsck.h
fsck/main.c

index b1741d9..9a84024 100644 (file)
@@ -2422,6 +2422,45 @@ out:
        return cnt;
 }
 
+int fsck_chk_curseg_info(struct f2fs_sb_info *sbi)
+{
+       struct curseg_info *curseg;
+       struct seg_entry *se;
+       struct f2fs_summary_block *sum_blk;
+       int i, ret = 0;
+
+       for (i = 0; i < NO_CHECK_TYPE; i++) {
+               curseg = CURSEG_I(sbi, i);
+               se = get_seg_entry(sbi, curseg->segno);
+               sum_blk = curseg->sum_blk;
+
+               if (se->type != i) {
+                       ASSERT_MSG("Incorrect curseg [%d]: segno [0x%x] "
+                                  "type(SIT) [%d]", i, curseg->segno,
+                                  se->type);
+                       if (c.fix_on || c.preen_mode)
+                               se->type = i;
+                       ret = -1;
+               }
+               if (i <= CURSEG_COLD_DATA && IS_SUM_DATA_SEG(sum_blk->footer)) {
+                       continue;
+               } else if (i > CURSEG_COLD_DATA && IS_SUM_NODE_SEG(sum_blk->footer)) {
+                       continue;
+               } else {
+                       ASSERT_MSG("Incorrect curseg [%d]: segno [0x%x] "
+                                  "type(SSA) [%d]", i, curseg->segno,
+                                  sum_blk->footer.entry_type);
+                       if (c.fix_on || c.preen_mode)
+                               sum_blk->footer.entry_type =
+                                       i <= CURSEG_COLD_DATA ?
+                                       SUM_TYPE_DATA : SUM_TYPE_NODE;
+                       ret = -1;
+               }
+       }
+
+       return ret;
+}
+
 int fsck_verify(struct f2fs_sb_info *sbi)
 {
        unsigned int i = 0;
index 3e13fc6..0b98113 100644 (file)
@@ -144,6 +144,7 @@ extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, u32, struct child_info *,
 int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
                struct child_info *);
 int fsck_chk_meta(struct f2fs_sb_info *sbi);
+int fsck_chk_curseg_info(struct f2fs_sb_info *);
 int convert_encrypted_name(unsigned char *, int, unsigned char *, int);
 
 extern void update_free_segments(struct f2fs_sb_info *);
index c4dd8b1..240551d 100644 (file)
@@ -574,6 +574,8 @@ static void do_fsck(struct f2fs_sb_info *sbi)
 
        print_cp_state(flag);
 
+       fsck_chk_curseg_info(sbi);
+
        if (!c.fix_on && !c.bug_on) {
                switch (c.preen_mode) {
                case PREEN_MODE_1: