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: Fri, 25 Nov 2016 11:32:29 +0800 [thread overview]
Message-ID: <5837B0CD.4020206@huawei.com> (raw)
In-Reply-To: <20161124073315.26936-1-heyunlei@huawei.com>
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);
+ }
}
} 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--;
> }
> }
>
------------------------------------------------------------------------------
next prev parent reply other threads:[~2016-11-25 3:32 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 [this message]
2016-11-25 3:53 ` Junling Zheng
2016-11-29 8:43 ` Junling Zheng
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=5837B0CD.4020206@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).