Skip to contentSkip to conversation

fsck.f2fs: fix to maintain ckpt_valid_blocks correctly

PATCH New Chao Yu via Linux-f2fs-devel 1 participant 1 message Sep 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsck.f2fs: fix to maintain ckpt_valid_blocks correctly

From: Chao Yu <[email protected]>

When need_fsync_data_record() is true (e.g. after sudden power-off or shutdown), get_seg_vblocks() returns se->ckpt_valid_blocks.

In reserve_new_block(), se->ckpt_valid_blocks is correctly incremented along with setting the bit in se->ckpt_valid_map. However, in update_block() and release_block(), while se->ckpt_valid_map is updated, se->ckpt_valid_blocks is never incremented or decremented.

As a result, if blocks in an empty segment are newly allocated or migrated by fsck (e.g. during quota rebuild), se->ckpt_valid_blocks remains 0. Subsequent calls to get_seg_vblocks() will treat the segment as completely empty, leading to false free segment detection or incorrect section reuse.

Fix this by maintaining se->ckpt_valid_blocks alongside se->ckpt_valid_map in update_block() and release_block().

Fixes 10dad5ed7ce1 ("f2fs-tools: support zoned ufs devices")
---
 fsck/fsck.c    | 4 +++-
 fsck/segment.c | 8 ++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
fsck/fsck.c +3 -1
index e47f7be..a56c16b 100644
@@ -3262,8 +3262,10 @@ static inline void release_block(struct f2fs_sb_info *sbi, u64 blkaddr,
 		offset = OFFSET_IN_SEG(sbi, blkaddr);
 		se->valid_blocks--;
 		f2fs_clear_bit(offset, (char *)se->cur_valid_map);
-		if (need_fsync_data_record(sbi))
+		if (need_fsync_data_record(sbi)) {
 			f2fs_clear_bit(offset, (char *)se->ckpt_valid_map);
+			se->ckpt_valid_blocks--;
+		}
 		se->dirty = 1;
 		f2fs_clear_sit_bitmap(sbi, blkaddr);
 	}
fsck/segment.c +6 -2
index 9f3fa0c..ee66a8e 100644
@@ -798,8 +798,10 @@ int update_block(struct f2fs_sb_info *sbi, void *buf, u32 *blkaddr,
 	}
 	se->valid_blocks--;
 	f2fs_clear_bit(offset, (char *)se->cur_valid_map);
-	if (need_fsync_data_record(sbi))
+	if (need_fsync_data_record(sbi)) {
 		f2fs_clear_bit(offset, (char *)se->ckpt_valid_map);
+		se->ckpt_valid_blocks--;
+	}
 	se->dirty = 1;
 	f2fs_clear_main_bitmap(sbi, old_blkaddr);
 	f2fs_clear_sit_bitmap(sbi, old_blkaddr);
@@ -821,8 +823,10 @@ int update_block(struct f2fs_sb_info *sbi, void *buf, u32 *blkaddr,
 	se->type = se->orig_type = type;
 	se->valid_blocks++;
 	f2fs_set_bit(offset, (char *)se->cur_valid_map);
-	if (need_fsync_data_record(sbi))
+	if (need_fsync_data_record(sbi)) {
 		f2fs_set_bit(offset, (char *)se->ckpt_valid_map);
+		se->ckpt_valid_blocks++;
+	}
 	se->dirty = 1;
 	f2fs_set_main_bitmap(sbi, new_blkaddr, type);
 	f2fs_set_sit_bitmap(sbi, new_blkaddr);
Signature · 8 lines
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel