Skip to contentSkip to conversation

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

PATCH New Junling Zheng 1 participant 1 message Nov 30, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
 fsck/resize.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
fsck/resize.c +14 -11
index ba7bb88..3e8fdd8 100644
@@ -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--);
 		}
 	}
 
Signature · 4 lines
2.7.4


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