]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.172/f2fs-introduce-get_checkpoint_version-for-cleanup.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.172 / f2fs-introduce-get_checkpoint_version-for-cleanup.patch
1 From foo@baz Fri Jan 18 09:16:11 CET 2019
2 From: Tiezhu Yang <kernelpatch@126.com>
3 Date: Fri, 30 Sep 2016 08:24:53 +0800
4 Subject: f2fs: introduce get_checkpoint_version for cleanup
5
6 From: Tiezhu Yang <kernelpatch@126.com>
7
8 commit fc0065adb202518e25fb929cda7d5887a456f774 upstream.
9
10 There exists almost same codes when get the value of pre_version
11 and cur_version in function validate_checkpoint, this patch adds
12 get_checkpoint_version to clean up redundant codes.
13
14 Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
15 Reviewed-by: Chao Yu <yuchao0@huawei.com>
16 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 [bwh: Backported to 4.4: f2fs_crc_valid() doesn't take an f2fs_sb_info pointer]
18 Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 fs/f2fs/checkpoint.c | 66 +++++++++++++++++++++++++++++----------------------
22 1 file changed, 38 insertions(+), 28 deletions(-)
23
24 --- a/fs/f2fs/checkpoint.c
25 +++ b/fs/f2fs/checkpoint.c
26 @@ -601,45 +601,55 @@ static void write_orphan_inodes(struct f
27 }
28 }
29
30 -static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
31 - block_t cp_addr, unsigned long long *version)
32 +static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
33 + struct f2fs_checkpoint **cp_block, struct page **cp_page,
34 + unsigned long long *version)
35 {
36 - struct page *cp_page_1, *cp_page_2 = NULL;
37 unsigned long blk_size = sbi->blocksize;
38 - struct f2fs_checkpoint *cp_block;
39 - unsigned long long cur_version = 0, pre_version = 0;
40 - size_t crc_offset;
41 + size_t crc_offset = 0;
42 __u32 crc = 0;
43
44 - /* Read the 1st cp block in this CP pack */
45 - cp_page_1 = get_meta_page(sbi, cp_addr);
46 + *cp_page = get_meta_page(sbi, cp_addr);
47 + *cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
48
49 - /* get the version number */
50 - cp_block = (struct f2fs_checkpoint *)page_address(cp_page_1);
51 - crc_offset = le32_to_cpu(cp_block->checksum_offset);
52 - if (crc_offset >= blk_size)
53 - goto invalid_cp1;
54 + crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
55 + if (crc_offset >= blk_size) {
56 + f2fs_msg(sbi->sb, KERN_WARNING,
57 + "invalid crc_offset: %zu", crc_offset);
58 + return -EINVAL;
59 + }
60
61 - crc = le32_to_cpu(*((__le32 *)((unsigned char *)cp_block + crc_offset)));
62 - if (!f2fs_crc_valid(crc, cp_block, crc_offset))
63 - goto invalid_cp1;
64 + crc = le32_to_cpu(*((__le32 *)((unsigned char *)*cp_block
65 + + crc_offset)));
66 + if (!f2fs_crc_valid(crc, *cp_block, crc_offset)) {
67 + f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
68 + return -EINVAL;
69 + }
70
71 - pre_version = cur_cp_version(cp_block);
72 + *version = cur_cp_version(*cp_block);
73 + return 0;
74 +}
75
76 - /* Read the 2nd cp block in this CP pack */
77 - cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1;
78 - cp_page_2 = get_meta_page(sbi, cp_addr);
79 +static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
80 + block_t cp_addr, unsigned long long *version)
81 +{
82 + struct page *cp_page_1 = NULL, *cp_page_2 = NULL;
83 + struct f2fs_checkpoint *cp_block = NULL;
84 + unsigned long long cur_version = 0, pre_version = 0;
85 + int err;
86
87 - cp_block = (struct f2fs_checkpoint *)page_address(cp_page_2);
88 - crc_offset = le32_to_cpu(cp_block->checksum_offset);
89 - if (crc_offset >= blk_size)
90 - goto invalid_cp2;
91 + err = get_checkpoint_version(sbi, cp_addr, &cp_block,
92 + &cp_page_1, version);
93 + if (err)
94 + goto invalid_cp1;
95 + pre_version = *version;
96
97 - crc = le32_to_cpu(*((__le32 *)((unsigned char *)cp_block + crc_offset)));
98 - if (!f2fs_crc_valid(crc, cp_block, crc_offset))
99 + cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1;
100 + err = get_checkpoint_version(sbi, cp_addr, &cp_block,
101 + &cp_page_2, version);
102 + if (err)
103 goto invalid_cp2;
104 -
105 - cur_version = cur_cp_version(cp_block);
106 + cur_version = *version;
107
108 if (cur_version == pre_version) {
109 *version = cur_version;