linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] resize.f2fs: fix an error in migrate_ssa
@ 2016-11-24  7:33 Yunlei He
  2016-11-25  3:32 ` Junling Zheng
  0 siblings, 1 reply; 5+ messages in thread
From: Yunlei He @ 2016-11-24  7:33 UTC (permalink / raw)
  To: linux-f2fs-devel, jaegeuk, yuchao0

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--;
 		}
 	}
-- 
2.10.1


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-11-29 20:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).