public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Tiezhu Yang" <kernelpatch@126.com>
To: "Chao Yu" <yuchao0@huawei.com>
Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v2] f2fs: introduce get_checkpoint_version for cleanup
Date: Tue, 27 Sep 2016 22:17:23 +0800 (CST)	[thread overview]
Message-ID: <64e4b270.d679.1576c01dbe0.Coremail.kernelpatch@126.com> (raw)
In-Reply-To: <352dc6bd-4335-1dff-c992-2966a244d536@huawei.com>

Hi Chao,

At 2016-09-27 17:46:30, "Chao Yu" <yuchao0@huawei.com> wrote:
>On 2016/9/27 10:05, Tiezhu Yang wrote:
>> 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: Tiezhu Yang <kernelpatch@126.com>
>> ---
>>  fs/f2fs/checkpoint.c | 63 ++++++++++++++++++++++++++++++----------------------
>>  1 file changed, 37 insertions(+), 26 deletions(-)
>> 
>> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
>> index de8693c..2dbc834 100644
>> --- a/fs/f2fs/checkpoint.c
>> +++ b/fs/f2fs/checkpoint.c
>> @@ -663,45 +663,56 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
>>  	}
>>  }
>>  
>> -static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
>> -				block_t cp_addr, unsigned long long *version)
>> +static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
>> +			struct f2fs_checkpoint *cp_block, struct page *cp_page,
>
>struct f2fs_checkpoint **cp_block, struct page **cp_page,

Thank you for pointing out my mistake, I will send a v3 patch.

Thanks,
>
>> +			unsigned long long *version)
>>  {
>> -	struct page *cp_page_1, *cp_page_2 = NULL;
>>  	unsigned long blk_size = sbi->blocksize;
>> -	struct f2fs_checkpoint *cp_block;
>> -	unsigned long long cur_version = 0, pre_version = 0;
>> -	size_t crc_offset;
>> +	size_t crc_offset = 0;
>>  	__u32 crc = 0;
>>  
>> -	/* Read the 1st cp block in this CP pack */
>> -	cp_page_1 = get_meta_page(sbi, cp_addr);
>> +	cp_page = get_meta_page(sbi, cp_addr);
>> +	cp_block = (struct f2fs_checkpoint *)page_address(cp_page);
>
>*cp_page = get_meta_page(sbi, cp_addr);
>*cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
>
>>  
>> -	/* get the version number */
>> -	cp_block = (struct f2fs_checkpoint *)page_address(cp_page_1);
>>  	crc_offset = le32_to_cpu(cp_block->checksum_offset);
>
>ditto
>
>> -	if (crc_offset >= blk_size)
>> -		goto invalid_cp1;
>> +	if (crc_offset >= blk_size) {
>> +		f2fs_msg(sbi->sb, KERN_WARNING,
>> +			"%s: crc_offset is greater than or equal to blk_size.",
>> +			__func__);
>> +		return -EINVAL;
>> +	}
>>  
>>  	crc = le32_to_cpu(*((__le32 *)((unsigned char *)cp_block + crc_offset)));
>> -	if (!f2fs_crc_valid(sbi, crc, cp_block, crc_offset))
>> -		goto invalid_cp1;
>> +	if (!f2fs_crc_valid(sbi, crc, cp_block, crc_offset)) {
>
>ditto
>
>> +		f2fs_msg(sbi->sb, KERN_WARNING,
>> +			"%s: f2fs_crc_valid returns false.", __func__);
>> +		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 */
>> -	cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1;
>> -	cp_page_2 = get_meta_page(sbi, cp_addr);
>> +static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
>> +				block_t cp_addr, unsigned long long *version)
>> +{
>> +	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);
>> -	crc_offset = le32_to_cpu(cp_block->checksum_offset);
>> -	if (crc_offset >= blk_size)
>> -		goto invalid_cp2;
>> +	err = get_checkpoint_version(sbi, cp_addr, cp_block,
>> +					cp_page_1, version);
>
>err = get_checkpoint_version(sbi, cp_addr, &cp_block, &cp_page_1, version);
>
>> +	if (err)
>> +		goto invalid_cp1;
>> +	pre_version = *version;
>>  
>> -	crc = le32_to_cpu(*((__le32 *)((unsigned char *)cp_block + crc_offset)));
>> -	if (!f2fs_crc_valid(sbi, crc, cp_block, crc_offset))
>> +	cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1;
>> +	err = get_checkpoint_version(sbi, cp_addr, cp_block,
>> +					cp_page_2, version);
>
>ditto
>
>Thanks,
>
>> +	if (err)
>>  		goto invalid_cp2;
>> -
>> -	cur_version = cur_cp_version(cp_block);
>> +	cur_version = *version;
>>  
>>  	if (cur_version == pre_version) {
>>  		*version = cur_version;
>> 
>

      reply	other threads:[~2016-09-27 14:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27  2:05 [PATCH v2] f2fs: introduce get_checkpoint_version for cleanup Tiezhu Yang
2016-09-27  9:46 ` [f2fs-dev] " Chao Yu
2016-09-27 14:17   ` Tiezhu Yang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64e4b270.d679.1576c01dbe0.Coremail.kernelpatch@126.com \
    --to=kernelpatch@126.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox