f2fs: move sanity checking of cp into get_valid_checkpoint
authorShawn Lin <shawn.lin@rock-chips.com>
Wed, 17 Feb 2016 03:26:32 +0000 (11:26 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 23 Feb 2016 05:39:56 +0000 (21:39 -0800)
>From the function name of get_valid_checkpoint, it seems to return
the valid cp or NULL for caller to check. If no valid one is found,
f2fs_fill_super will print the err log. But if get_valid_checkpoint
get one valid(the return value indicate that it's valid, however actually
it is invalid after sanity checking), then print another similar err
log. That seems strange. Let's keep sanity checking inside the procedure
of geting valid cp. Another improvement we gained from this move is
that even the large volume is supported, we check the cp in advanced
to skip the following procedure if failing the sanity checking.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/super.c

index 359a805397e3411dc59c7abc7b1cfad77cdfa2f2..8d88a964dd040475331c5374bcf95936a17d7895 100644 (file)
@@ -708,6 +708,10 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
        cp_block = (struct f2fs_checkpoint *)page_address(cur_page);
        memcpy(sbi->ckpt, cp_block, blk_size);
 
+       /* Sanity checking of checkpoint */
+       if (sanity_check_ckpt(sbi))
+               goto fail_no_cp;
+
        if (cp_blks <= 1)
                goto done;
 
index fc302ea9b1fb8f0648fd2a54e270289083f31cdd..d24ae3b58e3d6d9c3cd8dff8eaac0c3dd1d2b7ee 100644 (file)
@@ -1783,6 +1783,7 @@ int f2fs_commit_super(struct f2fs_sb_info *, bool);
 int f2fs_sync_fs(struct super_block *, int);
 extern __printf(3, 4)
 void f2fs_msg(struct super_block *, const char *, const char *, ...);
+int sanity_check_ckpt(struct f2fs_sb_info *sbi);
 
 /*
  * hash.c
index 9e9493999bf33b219b0381a4f276c33a7bfb77a6..ebe5970315e91ddc004b7abfe9137f4f459d7271 100644 (file)
@@ -1106,7 +1106,7 @@ static int sanity_check_raw_super(struct super_block *sb,
        return 0;
 }
 
-static int sanity_check_ckpt(struct f2fs_sb_info *sbi)
+int sanity_check_ckpt(struct f2fs_sb_info *sbi)
 {
        unsigned int total, fsmeta;
        struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
@@ -1365,13 +1365,6 @@ try_onemore:
                goto free_meta_inode;
        }
 
-       /* sanity checking of checkpoint */
-       err = -EINVAL;
-       if (sanity_check_ckpt(sbi)) {
-               f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint");
-               goto free_cp;
-       }
-
        sbi->total_valid_node_count =
                                le32_to_cpu(sbi->ckpt->valid_node_count);
        sbi->total_valid_inode_count =
@@ -1539,7 +1532,6 @@ free_nm:
        destroy_node_manager(sbi);
 free_sm:
        destroy_segment_manager(sbi);
-free_cp:
        kfree(sbi->ckpt);
 free_meta_inode:
        make_bad_inode(sbi->meta_inode);
This page took 0.027335 seconds and 5 git commands to generate.