Linux-f2fs-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Junling Zheng <zhengjunling@huawei.com>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH] resize.f2fs: fix an error in migrate_ssa
Date: Tue, 29 Nov 2016 12:01:00 -0800	[thread overview]
Message-ID: <20161129200100.GA30493@jaegeuk> (raw)
In-Reply-To: <583D3F9E.2090107@huawei.com>

Could you please resubmit a complete patch?

On Tue, Nov 29, 2016 at 04:43:10PM +0800, Junling Zheng wrote:
> 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 20:01 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
2016-11-29 20:01       ` Jaegeuk Kim [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=20161129200100.GA30493@jaegeuk \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=zhengjunling@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