fsck.f2fs: fix SIT entry types
authorJaegeuk Kim <jaegeuk@kernel.org>
Thu, 6 Nov 2014 04:25:49 +0000 (20:25 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 7 Nov 2014 02:27:11 +0000 (18:27 -0800)
Sometimes, SIT entry type is broken, so we need to rebuild it.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c
fsck/mount.c

index f6039b8..90ea441 100644 (file)
 char *tree_mark;
 uint32_t tree_mark_size = 256;
 
-static inline int f2fs_set_main_bitmap(struct f2fs_sb_info *sbi, u32 blk)
+static inline int f2fs_set_main_bitmap(struct f2fs_sb_info *sbi, u32 blk,
+                                                               int type)
 {
        struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
-
+       struct seg_entry *se;
+
+       se = get_seg_entry(sbi, GET_SEGNO(sbi, blk));
+       if (se->type != type) {
+               if (type == CURSEG_WARM_DATA) {
+                       if (se->type != CURSEG_COLD_DATA) {
+                               FIX_MSG("Wrong segment type [0x%x] %x -> %x\n",
+                                               GET_SEGNO(sbi, blk), se->type,
+                                               CURSEG_WARM_DATA);
+                               se->type = CURSEG_WARM_DATA;
+                               config.bug_on = 1;
+                       }
+               } else {
+                       FIX_MSG("Wrong segment type [0x%x] %x -> %x\n",
+                               GET_SEGNO(sbi, blk), se->type, type);
+                       se->type = type;
+                       config.bug_on = 1;
+               }
+       }
        return f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, blk), fsck->main_area_bitmap);
 }
 
@@ -286,7 +305,7 @@ static int fsck_chk_xattr_blk(struct f2fs_sb_info *sbi, u32 ino,
        }
 
        *blk_cnt = *blk_cnt + 1;
-       f2fs_set_main_bitmap(sbi, ni.blk_addr);
+       f2fs_set_main_bitmap(sbi, ni.blk_addr, CURSEG_COLD_NODE);
        DBG(2, "ino[0x%x] x_nid[0x%x]\n", ino, x_nid);
 out:
        free(node_blk);
@@ -309,18 +328,22 @@ int fsck_chk_node_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
        if (ntype == TYPE_INODE) {
                fsck_chk_inode_blk(sbi, nid, ftype, node_blk, blk_cnt, &ni);
        } else {
-               f2fs_set_main_bitmap(sbi, ni.blk_addr);
-
                switch (ntype) {
                case TYPE_DIRECT_NODE:
+                       f2fs_set_main_bitmap(sbi, ni.blk_addr,
+                                                       CURSEG_WARM_NODE);
                        fsck_chk_dnode_blk(sbi, inode, nid, ftype, node_blk,
                                        blk_cnt, &ni);
                        break;
                case TYPE_INDIRECT_NODE:
+                       f2fs_set_main_bitmap(sbi, ni.blk_addr,
+                                                       CURSEG_COLD_NODE);
                        fsck_chk_idnode_blk(sbi, inode, ftype, node_blk,
                                        blk_cnt);
                        break;
                case TYPE_DOUBLE_INDIRECT_NODE:
+                       f2fs_set_main_bitmap(sbi, ni.blk_addr,
+                                                       CURSEG_COLD_NODE);
                        fsck_chk_didnode_blk(sbi, inode, ftype, node_blk,
                                        blk_cnt);
                        break;
@@ -353,10 +376,11 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
                fsck->chk.valid_inode_cnt++;
 
        if (ftype == F2FS_FT_DIR) {
-               f2fs_set_main_bitmap(sbi, ni->blk_addr);
+               f2fs_set_main_bitmap(sbi, ni->blk_addr, CURSEG_HOT_NODE);
        } else {
                if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0) {
-                       f2fs_set_main_bitmap(sbi, ni->blk_addr);
+                       f2fs_set_main_bitmap(sbi, ni->blk_addr,
+                                                       CURSEG_WARM_NODE);
                        if (i_links > 1) {
                                /* First time. Create new hard link node */
                                add_into_hard_link_list(sbi, nid, i_links);
@@ -820,13 +844,16 @@ int fsck_chk_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
                ASSERT_MSG("Duplicated data [0x%x]. pnid[0x%x] idx[0x%x]",
                                blk_addr, parent_nid, idx_in_node);
 
-       f2fs_set_main_bitmap(sbi, blk_addr);
 
        fsck->chk.valid_blk_cnt++;
 
-       if (ftype == F2FS_FT_DIR)
+       if (ftype == F2FS_FT_DIR) {
+               f2fs_set_main_bitmap(sbi, blk_addr, CURSEG_HOT_DATA);
                return fsck_chk_dentry_blk(sbi, blk_addr, child_cnt,
                                child_files, last_blk);
+       } else {
+               f2fs_set_main_bitmap(sbi, blk_addr, CURSEG_WARM_DATA);
+       }
        return 0;
 }
 
index 9ec6004..9a9c842 100644 (file)
@@ -1021,7 +1021,8 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
                se = get_seg_entry(sbi, segno);
                type = se->type;
                if (type >= NO_CHECK_TYPE) {
-                       ASSERT(valid_blocks);
+                       ASSERT_MSG("Invalide type and valid blocks=%x,%x",
+                                       segno, valid_blocks);
                        type = 0;
                }
                sit->vblocks = cpu_to_le16((type << SIT_VBLOCKS_SHIFT) |