Commit fd2f997a authored by Tiezhu Yang's avatar Tiezhu Yang Committed by Stefan Bader

f2fs: introduce get_checkpoint_version for cleanup

BugLink: https://bugs.launchpad.net/bugs/1818797

commit fc0065ad upstream.

There exists almost same codes when get the value of pre_version
and cur_version in function validate_checkpoint, this patch adds
get_checkpoint_version to clean up redundant codes.
Signed-off-by: default avatarTiezhu Yang <kernelpatch@126.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
[bwh: Backported to 4.4: f2fs_crc_valid() doesn't take an f2fs_sb_info pointer]
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent a044bac9
...@@ -601,45 +601,55 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) ...@@ -601,45 +601,55 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
} }
} }
static struct page *validate_checkpoint(struct f2fs_sb_info *sbi, static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
block_t cp_addr, unsigned long long *version) struct f2fs_checkpoint **cp_block, struct page **cp_page,
unsigned long long *version)
{ {
struct page *cp_page_1, *cp_page_2 = NULL;
unsigned long blk_size = sbi->blocksize; unsigned long blk_size = sbi->blocksize;
struct f2fs_checkpoint *cp_block; size_t crc_offset = 0;
unsigned long long cur_version = 0, pre_version = 0;
size_t crc_offset;
__u32 crc = 0; __u32 crc = 0;
/* Read the 1st cp block in this CP pack */ *cp_page = get_meta_page(sbi, cp_addr);
cp_page_1 = get_meta_page(sbi, cp_addr); *cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
/* get the version number */ crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
cp_block = (struct f2fs_checkpoint *)page_address(cp_page_1); if (crc_offset >= blk_size) {
crc_offset = le32_to_cpu(cp_block->checksum_offset); f2fs_msg(sbi->sb, KERN_WARNING,
if (crc_offset >= blk_size) "invalid crc_offset: %zu", crc_offset);
goto invalid_cp1; return -EINVAL;
}
crc = le32_to_cpu(*((__le32 *)((unsigned char *)cp_block + crc_offset))); crc = le32_to_cpu(*((__le32 *)((unsigned char *)*cp_block
if (!f2fs_crc_valid(crc, cp_block, crc_offset)) + crc_offset)));
goto invalid_cp1; if (!f2fs_crc_valid(crc, *cp_block, crc_offset)) {
f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
return -EINVAL;
}
pre_version = cur_cp_version(cp_block); *version = cur_cp_version(*cp_block);
return 0;
}
/* Read the 2nd cp block in this CP pack */ static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1; block_t cp_addr, unsigned long long *version)
cp_page_2 = get_meta_page(sbi, cp_addr); {
struct page *cp_page_1 = NULL, *cp_page_2 = NULL;
struct f2fs_checkpoint *cp_block = NULL;
unsigned long long cur_version = 0, pre_version = 0;
int err;
cp_block = (struct f2fs_checkpoint *)page_address(cp_page_2); err = get_checkpoint_version(sbi, cp_addr, &cp_block,
crc_offset = le32_to_cpu(cp_block->checksum_offset); &cp_page_1, version);
if (crc_offset >= blk_size) if (err)
goto invalid_cp2; goto invalid_cp1;
pre_version = *version;
crc = le32_to_cpu(*((__le32 *)((unsigned char *)cp_block + crc_offset))); cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1;
if (!f2fs_crc_valid(crc, cp_block, crc_offset)) err = get_checkpoint_version(sbi, cp_addr, &cp_block,
&cp_page_2, version);
if (err)
goto invalid_cp2; goto invalid_cp2;
cur_version = *version;
cur_version = cur_cp_version(cp_block);
if (cur_version == pre_version) { if (cur_version == pre_version) {
*version = cur_version; *version = cur_version;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment