resize.f2fs: fix the number of moved ssa blocks in migrate_ssa

If the offset passed in migrate_ssa is not zero, it means that there're
offset segments of old main will disappear after migrating, then there're
offset blocks of old ssa should be invalidated and removed accordingly.
So, the number of moved ssa blocks should be: TOTAL_SEGS(sbi) - offset,
and the expanded summary, which is filled with zero_blocks, should start
from: new_sum_blkaddr + TOTAL_SEGS(sbi) - offset.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Junling Zheng 2016-11-30 11:23:42 +08:00 committed by Jaegeuk Kim
parent 361b0185ed
commit e8768a998d

View File

@ -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);
else
move_ssa(sbi, offset--, blkaddr);
blkaddr--;
if (blkaddr >= expand_sum_blkaddr) {
ret = dev_write_block(zero_block, blkaddr--);
ASSERT(ret >=0);
} else {
move_ssa(sbi, offset--, blkaddr--);
}
}
}