diff options
author | Kinglong Mee <kinglongmee@gmail.com> | 2017-02-25 06:53:39 -0500 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2017-02-27 13:07:47 -0500 |
commit | ced2c7ea8e99b46755a270872cd5ba61c27cffad (patch) | |
tree | 35fb8c20a172d24422d53738c878f16721b059dd | |
parent | 727ebb091e1778cc3a4842ae04f8f54da111eee0 (diff) |
f2fs: new helper cur_cp_crc() getting crc in f2fs_checkpoint
There are four places that getting the crc value in f2fs_checkpoint,
just add a new helper cur_cp_crc for them.
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | fs/f2fs/checkpoint.c | 3 | ||||
-rw-r--r-- | fs/f2fs/f2fs.h | 6 | ||||
-rw-r--r-- | fs/f2fs/node.c | 5 | ||||
-rw-r--r-- | fs/f2fs/node.h | 20 |
4 files changed, 15 insertions, 19 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 04d7c244c0f0..0339daf4ca02 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c | |||
@@ -683,8 +683,7 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr, | |||
683 | return -EINVAL; | 683 | return -EINVAL; |
684 | } | 684 | } |
685 | 685 | ||
686 | crc = le32_to_cpu(*((__le32 *)((unsigned char *)*cp_block | 686 | crc = cur_cp_crc(*cp_block); |
687 | + crc_offset))); | ||
688 | if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) { | 687 | if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) { |
689 | f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value"); | 688 | f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value"); |
690 | return -EINVAL; | 689 | return -EINVAL; |
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 633f2efc8c17..4d332b396384 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -1126,6 +1126,12 @@ static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) | |||
1126 | return le64_to_cpu(cp->checkpoint_ver); | 1126 | return le64_to_cpu(cp->checkpoint_ver); |
1127 | } | 1127 | } |
1128 | 1128 | ||
1129 | static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) | ||
1130 | { | ||
1131 | size_t crc_offset = le32_to_cpu(cp->checksum_offset); | ||
1132 | return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); | ||
1133 | } | ||
1134 | |||
1129 | static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) | 1135 | static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) |
1130 | { | 1136 | { |
1131 | unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); | 1137 | unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 24ea49f98891..8e53181d5db1 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -2462,9 +2462,6 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) | |||
2462 | unsigned int nat_bits_bytes = nm_i->nat_blocks / BITS_PER_BYTE; | 2462 | unsigned int nat_bits_bytes = nm_i->nat_blocks / BITS_PER_BYTE; |
2463 | unsigned int i; | 2463 | unsigned int i; |
2464 | __u64 cp_ver = cur_cp_version(ckpt); | 2464 | __u64 cp_ver = cur_cp_version(ckpt); |
2465 | size_t crc_offset = le32_to_cpu(ckpt->checksum_offset); | ||
2466 | __u64 crc = le32_to_cpu(*((__le32 *) | ||
2467 | ((unsigned char *)ckpt + crc_offset))); | ||
2468 | block_t nat_bits_addr; | 2465 | block_t nat_bits_addr; |
2469 | 2466 | ||
2470 | if (!enabled_nat_bits(sbi, NULL)) | 2467 | if (!enabled_nat_bits(sbi, NULL)) |
@@ -2487,7 +2484,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) | |||
2487 | f2fs_put_page(page, 1); | 2484 | f2fs_put_page(page, 1); |
2488 | } | 2485 | } |
2489 | 2486 | ||
2490 | cp_ver |= (crc << 32); | 2487 | cp_ver |= (cur_cp_crc(ckpt) << 32); |
2491 | if (cpu_to_le64(cp_ver) != *(__le64 *)nm_i->nat_bits) { | 2488 | if (cpu_to_le64(cp_ver) != *(__le64 *)nm_i->nat_bits) { |
2492 | disable_nat_bits(sbi, true); | 2489 | disable_nat_bits(sbi, true); |
2493 | return 0; | 2490 | return 0; |
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 3fc9c4b1dce9..2f9603fa85a5 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h | |||
@@ -300,14 +300,11 @@ static inline void fill_node_footer_blkaddr(struct page *page, block_t blkaddr) | |||
300 | { | 300 | { |
301 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); | 301 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); |
302 | struct f2fs_node *rn = F2FS_NODE(page); | 302 | struct f2fs_node *rn = F2FS_NODE(page); |
303 | size_t crc_offset = le32_to_cpu(ckpt->checksum_offset); | 303 | __u64 cp_ver = cur_cp_version(ckpt); |
304 | __u64 cp_ver = le64_to_cpu(ckpt->checkpoint_ver); | 304 | |
305 | if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) | ||
306 | cp_ver |= (cur_cp_crc(ckpt) << 32); | ||
305 | 307 | ||
306 | if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) { | ||
307 | __u64 crc = le32_to_cpu(*((__le32 *) | ||
308 | ((unsigned char *)ckpt + crc_offset))); | ||
309 | cp_ver |= (crc << 32); | ||
310 | } | ||
311 | rn->footer.cp_ver = cpu_to_le64(cp_ver); | 308 | rn->footer.cp_ver = cpu_to_le64(cp_ver); |
312 | rn->footer.next_blkaddr = cpu_to_le32(blkaddr); | 309 | rn->footer.next_blkaddr = cpu_to_le32(blkaddr); |
313 | } | 310 | } |
@@ -315,14 +312,11 @@ static inline void fill_node_footer_blkaddr(struct page *page, block_t blkaddr) | |||
315 | static inline bool is_recoverable_dnode(struct page *page) | 312 | static inline bool is_recoverable_dnode(struct page *page) |
316 | { | 313 | { |
317 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); | 314 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); |
318 | size_t crc_offset = le32_to_cpu(ckpt->checksum_offset); | ||
319 | __u64 cp_ver = cur_cp_version(ckpt); | 315 | __u64 cp_ver = cur_cp_version(ckpt); |
320 | 316 | ||
321 | if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) { | 317 | if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) |
322 | __u64 crc = le32_to_cpu(*((__le32 *) | 318 | cp_ver |= (cur_cp_crc(ckpt) << 32); |
323 | ((unsigned char *)ckpt + crc_offset))); | 319 | |
324 | cp_ver |= (crc << 32); | ||
325 | } | ||
326 | return cp_ver == cpver_of_node(page); | 320 | return cp_ver == cpver_of_node(page); |
327 | } | 321 | } |
328 | 322 | ||