From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] fsck.f2fs: fix to maintain ckpt_valid_blocks correctly
Date: Wed, 9 Sep 2026 13:06:04 +0800 [thread overview]
Message-ID: <20260909050604.3513016-1-chao@kernel.org> (raw)
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
reply other threads:[~2026-09-09 5:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260909050604.3513016-1-chao@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox