fsck.f2fs: rewrite entries info in segment manager
authorLiu Xue <liuxueliu.liu@huawei.com>
Wed, 2 Nov 2016 10:17:18 +0000 (18:17 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 2 Nov 2016 17:58:53 +0000 (10:58 -0700)
The entries info in segment manager may be not correct, since
corrupted blocks may already cleaned. So rewrite se info with
main area bitmap.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
[Jaegeuk Kim: remove obsolte variable in f2fs_fsck]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c
fsck/fsck.h
fsck/mount.c

index d0392c3..0009ea4 100644 (file)
@@ -1749,7 +1749,7 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
        set_cp(ckpt_flags, flags);
        set_cp(cp_pack_total_block_count, 8 + orphan_blks + get_sb(cp_payload));
 
-       set_cp(free_segment_count, fsck->chk.free_segs);
+       set_cp(free_segment_count, get_free_segments(sbi));
        set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
        set_cp(valid_node_count, fsck->chk.valid_node_cnt);
        set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
@@ -1979,9 +1979,9 @@ int fsck_verify(struct f2fs_sb_info *sbi)
                if (force || c.bug_on) {
                        fix_hard_links(sbi);
                        fix_nat_entries(sbi);
+                       rewrite_sit_area_bitmap(sbi);
                        move_curseg_info(sbi, SM_I(sbi)->main_blkaddr);
                        write_curseg_info(sbi);
-                       rewrite_sit_area_bitmap(sbi);
                        fix_checkpoint(sbi);
                } else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG)) {
                        write_checkpoint(sbi);
index 0aab55e..412e7b7 100644 (file)
@@ -58,7 +58,6 @@ struct f2fs_fsck {
                u32 multi_hard_link_files;
                u64 sit_valid_blocks;
                u32 sit_free_segs;
-               u32 free_segs;
        } chk;
 
        struct hard_link_node *hard_link_list_head;
@@ -165,6 +164,8 @@ extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
 
 extern void print_raw_sb_info(struct f2fs_super_block *);
 
+extern u32 get_free_segments(struct f2fs_sb_info *);
+
 /* dump.c */
 struct dump_option {
        nid_t nid;
index dd7a081..a3ab1ab 100644 (file)
@@ -11,7 +11,7 @@
 #include "fsck.h"
 #include <locale.h>
 
-static u32 get_free_segments(struct f2fs_sb_info *sbi)
+u32 get_free_segments(struct f2fs_sb_info *sbi)
 {
        u32 i, free_segs = 0;
 
@@ -1402,8 +1402,6 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
        /* remove sit journal */
        sum->journal.n_sits = 0;
 
-       fsck->chk.free_segs = 0;
-
        ptr = fsck->main_area_bitmap;
 
        for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
@@ -1423,6 +1421,8 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
                        valid_blocks += get_bits_in_byte(sit->valid_map[i]);
 
                se = get_seg_entry(sbi, segno);
+               memcpy(se->cur_valid_map, ptr, SIT_VBLOCK_MAP_SIZE);
+               se->valid_blocks = valid_blocks;
                type = se->type;
                if (type >= NO_CHECK_TYPE) {
                        ASSERT_MSG("Invalide type and valid blocks=%x,%x",
@@ -1434,15 +1434,6 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
                rewrite_current_sit_page(sbi, segno, sit_blk);
                free(sit_blk);
 
-               if (valid_blocks == 0 &&
-                               sbi->ckpt->cur_node_segno[0] != segno &&
-                               sbi->ckpt->cur_data_segno[0] != segno &&
-                               sbi->ckpt->cur_node_segno[1] != segno &&
-                               sbi->ckpt->cur_data_segno[1] != segno &&
-                               sbi->ckpt->cur_node_segno[2] != segno &&
-                               sbi->ckpt->cur_data_segno[2] != segno)
-                       fsck->chk.free_segs++;
-
                ptr += SIT_VBLOCK_MAP_SIZE;
        }
 }