All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junling Zheng <zhengjunling@huawei.com>
To: Yunlei He <heyunlei@huawei.com>,
	linux-f2fs-devel@lists.sourceforge.net, jaegeuk@kernel.org,
	yuchao0@huawei.com
Subject: Re: [PATCH] resize.f2fs: fix an error in migrate_ssa
Date: Tue, 29 Nov 2016 16:43:10 +0800	[thread overview]
Message-ID: <583D3F9E.2090107@huawei.com> (raw)
In-Reply-To: <5837B5B8.2070605@huawei.com>

Ping ...

On 2016/11/25 11:53, Junling Zheng wrote:
> Sorry, I forget to get the return value of dev_write_block :(
> Please review the following patch :)
> 
> ---
>  fsck/resize.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index 46aa30e..9f9c7a6 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -207,30 +207,33 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
>  	block_t old_sum_blkaddr = get_sb(ssa_blkaddr);
>  	block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
>  	block_t end_sum_blkaddr = get_newsb(main_blkaddr);
> +	block_t expand_sum_blkaddr = new_sum_blkaddr +
> +					TOTAL_SEGS(sbi) - offset;
>  	block_t blkaddr;
> +	int ret;
>  	void *zero_block = calloc(BLOCK_SZ, 1);
> -
>  	ASSERT(zero_block);
> 
>  	if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
>  		blkaddr = new_sum_blkaddr;
>  		while (blkaddr < end_sum_blkaddr) {
> -			if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
> -				move_ssa(sbi, offset, blkaddr);
> -			else
> -				dev_write_block(zero_block, blkaddr);
> -			offset++;
> -			blkaddr++;
> +			if (blkaddr < expand_sum_blkaddr)
> +				move_ssa(sbi, offset++, blkaddr++);
> +			else {
> +				ret = dev_write_block(zero_block, blkaddr++);
> +				ASSERT(ret >=0);
> +			}
>  		}
>  	} else {
>  		blkaddr = end_sum_blkaddr - 1;
>  		offset = TOTAL_SEGS(sbi) - 1;
>  		while (blkaddr >= new_sum_blkaddr) {
> -			if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
> -				dev_write_block(zero_block, blkaddr);
> +			if (blkaddr >= expand_sum_blkaddr) {
> +				ret = dev_write_block(zero_block, blkaddr--);
> +				ASSERT(ret >=0);
> +			}
>  			else
> -				move_ssa(sbi, offset--, blkaddr);
> -			blkaddr--;
> +				move_ssa(sbi, offset--, blkaddr--);
>  		}
>  	}
> 
> 
> On 2016/11/25 11:32, Junling Zheng wrote:
>> How about the following patch, which I think would be a little better :)
>>
>> diff --git a/fsck/resize.c b/fsck/resize.c
>> index 46aa30e..c295a06 100644
>> --- a/fsck/resize.c
>> +++ b/fsck/resize.c
>> @@ -207,30 +207,33 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
>>  	block_t old_sum_blkaddr = get_sb(ssa_blkaddr);
>>  	block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
>>  	block_t end_sum_blkaddr = get_newsb(main_blkaddr);
>> +	block_t expand_sum_blkaddr = new_sum_blkaddr +
>> +					TOTAL_SEGS(sbi) - offset;
>>  	block_t blkaddr;
>> +	int ret;
>>  	void *zero_block = calloc(BLOCK_SZ, 1);
>> -
>>  	ASSERT(zero_block);
>>
>>  	if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
>>  		blkaddr = new_sum_blkaddr;
>>  		while (blkaddr < end_sum_blkaddr) {
>> -			if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
>> -				move_ssa(sbi, offset, blkaddr);
>> -			else
>> -				dev_write_block(zero_block, blkaddr);
>> -			offset++;
>> -			blkaddr++;
>> +			if (blkaddr < expand_sum_blkaddr)
>> +				move_ssa(sbi, offset++, blkaddr++);
>> +			else {
>> +				dev_write_block(zero_block, blkaddr++);
>> +				ASSERT(ret >=0);
> 
> forget to get the return value of dev_write_block :(
> 
>> +			}
>>  		}
>>  	} else {
>>  		blkaddr = end_sum_blkaddr - 1;
>>  		offset = TOTAL_SEGS(sbi) - 1;
>>  		while (blkaddr >= new_sum_blkaddr) {
>> -			if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
>> -				dev_write_block(zero_block, blkaddr);
>> +			if (blkaddr >= expand_sum_blkaddr) {
>> +				dev_write_block(zero_block, blkaddr--);
>> +				ASSERT(ret >=0);
>> +			}
>>  			else
>> -				move_ssa(sbi, offset--, blkaddr);
>> -			blkaddr--;
>> +				move_ssa(sbi, offset--, blkaddr--);
>>  		}
>>  	}
>>
>>
>> On 2016/11/24 15:33, Yunlei He wrote:
>>> This patch fix an error in migrate_ssa when resize with condition
>>> that offset is not zero && new_sum_blkaddr > old_sum_blkaddr + offset
>>>
>>> Signed-off-by: Yunlei He <heyunlei@huawei.com>
>>> ---
>>>  fsck/resize.c | 37 +++++++++++++++++++++++++++----------
>>>  1 file changed, 27 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/fsck/resize.c b/fsck/resize.c
>>> index 46aa30e..70dbef5 100644
>>> --- a/fsck/resize.c
>>> +++ b/fsck/resize.c
>>> @@ -208,28 +208,45 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
>>>  	block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
>>>  	block_t end_sum_blkaddr = get_newsb(main_blkaddr);
>>>  	block_t blkaddr;
>>> +	unsigned int offset1 = offset;
>>> +	int ret = 1;
>>>  	void *zero_block = calloc(BLOCK_SZ, 1);
>>>  
>>>  	ASSERT(zero_block);
>>>  
>>> -	if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
>>> -		blkaddr = new_sum_blkaddr;
>>> -		while (blkaddr < end_sum_blkaddr) {
>>> -			if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
>>> -				move_ssa(sbi, offset, blkaddr);
>>> -			else
>>> -				dev_write_block(zero_block, blkaddr);
>>> -			offset++;
>>> -			blkaddr++;
>>> +	if (offset) {
>>> +		if (new_sum_blkaddr < old_sum_blkaddr + offset) {
>>> +			blkaddr = new_sum_blkaddr;
>>> +			while (blkaddr < end_sum_blkaddr) {
>>> +				if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi) - offset1)
>>> +					move_ssa(sbi, offset, blkaddr);
>>> +				else
>>> +					ret = dev_write_block(zero_block, blkaddr);
>>> +				ASSERT(ret >= 0);
>>> +				offset++;
>>> +				blkaddr++;
>>> +			}
>>> +		} else {
>>> +			blkaddr = end_sum_blkaddr - 1;
>>> +			offset = TOTAL_SEGS(sbi)-1;
>>> +			while (blkaddr >= new_sum_blkaddr) {
>>> +				if (blkaddr >= TOTAL_SEGS(sbi) - offset1 + new_sum_blkaddr)
>>> +					ret = dev_write_block(zero_block, blkaddr);
>>> +				else
>>> +					move_ssa(sbi, offset--, blkaddr);
>>> +				ASSERT(ret >= 0);
>>> +				blkaddr--;
>>> +			}
>>>  		}
>>>  	} else {
>>>  		blkaddr = end_sum_blkaddr - 1;
>>>  		offset = TOTAL_SEGS(sbi) - 1;
>>>  		while (blkaddr >= new_sum_blkaddr) {
>>>  			if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
>>> -				dev_write_block(zero_block, blkaddr);
>>> +				ret = dev_write_block(zero_block, blkaddr);
>>>  			else
>>>  				move_ssa(sbi, offset--, blkaddr);
>>> +			ASSERT(ret >= 0);
>>>  			blkaddr--;
>>>  		}
>>>  	}
>>>
>>
>>
>>
>> .
>>
> 



------------------------------------------------------------------------------

  reply	other threads:[~2016-11-29  8:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24  7:33 [PATCH] resize.f2fs: fix an error in migrate_ssa Yunlei He
2016-11-25  3:32 ` Junling Zheng
2016-11-25  3:53   ` Junling Zheng
2016-11-29  8:43     ` Junling Zheng [this message]
2016-11-29 20:01       ` Jaegeuk Kim

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=583D3F9E.2090107@huawei.com \
    --to=zhengjunling@huawei.com \
    --cc=heyunlei@huawei.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.