* [f2fs-dev] [PATCH] fsck.f2fs: fix to maintain ckpt_valid_blocks correctly
@ 2026-09-09 5:06 Chao Yu via Linux-f2fs-devel
0 siblings, 0 replies; only message in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-09-09 5:06 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel
From: Chao Yu <chao@kernel.org>
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")
Signed-off-by: Chao Yu <chao@kernel.org>
---
fsck/fsck.c | 4 +++-
fsck/segment.c | 8 ++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/fsck/fsck.c b/fsck/fsck.c
index e47f7be..a56c16b 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -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);
}
diff --git a/fsck/segment.c b/fsck/segment.c
index 9f3fa0c..ee66a8e 100644
--- a/fsck/segment.c
+++ b/fsck/segment.c
@@ -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);
--
2.49.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-09 5:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09 5:06 [f2fs-dev] [PATCH] fsck.f2fs: fix to maintain ckpt_valid_blocks correctly Chao Yu via Linux-f2fs-devel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox