fsck.f2fs: fix to maintain ckpt_valid_blocks correctly
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().
--- fsck/fsck.c | 4 +++- fsck/segment.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
fsck/fsck.c +3 -1
@@ -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
@@ -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