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 <[email protected]>
---
 fs/f2fs/checkpoint.c |  3 +--
 fs/f2fs/f2fs.h       |  6 ++++++
 fs/f2fs/node.c       |  5 +----
 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 cd71321..37a216b 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -682,8 +682,7 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, 
block_t cp_addr,
                return -EINVAL;
        }
 
-       crc = le32_to_cpu(*((__le32 *)((unsigned char *)*cp_block
-                                                       + crc_offset)));
+       crc = cur_cp_crc(*cp_block);
        if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) {
                f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
                return -EINVAL;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 8b6d496..79da17e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1135,6 +1135,12 @@ static inline unsigned long long cur_cp_version(struct 
f2fs_checkpoint *cp)
        return le64_to_cpu(cp->checkpoint_ver);
 }
 
+static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
+{
+       size_t crc_offset = le32_to_cpu(cp->checksum_offset);
+       return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
+}
+
 static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned 
int f)
 {
        unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 8190329..1876288 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2540,9 +2540,6 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
        unsigned int nat_bits_bytes = nm_i->nat_blocks / BITS_PER_BYTE;
        unsigned int i;
        __u64 cp_ver = cur_cp_version(ckpt);
-       size_t crc_offset = le32_to_cpu(ckpt->checksum_offset);
-       __u64 crc = le32_to_cpu(*((__le32 *)
-                               ((unsigned char *)ckpt + crc_offset)));
        block_t nat_bits_addr;
 
        if (!enabled_nat_bits(sbi, NULL))
@@ -2565,7 +2562,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
                f2fs_put_page(page, 1);
        }
 
-       cp_ver |= (crc << 32);
+       cp_ver |= (cur_cp_crc(ckpt) << 32);
        if (cpu_to_le64(cp_ver) != *(__le64 *)nm_i->nat_bits) {
                disable_nat_bits(sbi, true);
                return 0;
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index 3fc9c4b..2f9603f 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)
 {
        struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page));
        struct f2fs_node *rn = F2FS_NODE(page);
-       size_t crc_offset = le32_to_cpu(ckpt->checksum_offset);
-       __u64 cp_ver = le64_to_cpu(ckpt->checkpoint_ver);
+       __u64 cp_ver = cur_cp_version(ckpt);
+
+       if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG))
+               cp_ver |= (cur_cp_crc(ckpt) << 32);
 
-       if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) {
-               __u64 crc = le32_to_cpu(*((__le32 *)
-                               ((unsigned char *)ckpt + crc_offset)));
-               cp_ver |= (crc << 32);
-       }
        rn->footer.cp_ver = cpu_to_le64(cp_ver);
        rn->footer.next_blkaddr = cpu_to_le32(blkaddr);
 }
@@ -315,14 +312,11 @@ static inline void fill_node_footer_blkaddr(struct page 
*page, block_t blkaddr)
 static inline bool is_recoverable_dnode(struct page *page)
 {
        struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page));
-       size_t crc_offset = le32_to_cpu(ckpt->checksum_offset);
        __u64 cp_ver = cur_cp_version(ckpt);
 
-       if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) {
-               __u64 crc = le32_to_cpu(*((__le32 *)
-                               ((unsigned char *)ckpt + crc_offset)));
-               cp_ver |= (crc << 32);
-       }
+       if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG))
+               cp_ver |= (cur_cp_crc(ckpt) << 32);
+
        return cp_ver == cpver_of_node(page);
 }
 
-- 
2.9.3


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to