fsck.f2fs: skip roll-forward and block kernel fsync recovery on record_fsync_data() failure
RFC PATCH 1/1 fsck.f2fs: skip roll-forward and block kernel fsync recovery on record_fsync_data() failure
When record_fsync_data() fails mid-way, fsck aborts and leaves the image unrepairable. On the next mount the kernel still runs f2fs_recover_fsync_data() and walks the very fsync chain fsck could not traverse, recovering data against a broken chain.
Fix in two parts:
1. On non--ELOOP failures, skip roll-forward instead of aborting:
set c.bug_on/c.fix_on so fsck proceeds to repair the image.
2. Block the kernel from recovering against the broken chain: bump checkpoint_ver's low-32 by 1 in fix_checkpoint(), so is_recoverable_dnode() no longer matches the fsync dnode footers stamped with the pre-bump version. find_fsync_dnodes() returns empty, no recovery runs.
--- fsck/fsck.c | 3 +++ fsck/mount.c | 9 +++++++-- include/f2fs_fs.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-)
fsck/fsck.c +3 -0
@@ -2760,6 +2760,9 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi) flags |=CP_NOCRC_RECOVERY_FLAG ;set_cp (ckpt_flags, flags); +if (c.fsync_record_failed) +set_cp (checkpoint_ver,get_cp (checkpoint_ver) +1 ); +set_cp (free_segment_count,get_free_segments (sbi));set_cp (valid_block_count, fsck->chk.valid_blk_cnt);set_cp (valid_node_count, fsck->chk.valid_node_cnt);
fsck/mount.c +7 -2
@@ -4249,8 +4249,13 @@ out: ret =record_fsync_data (sbi);if (ret) {ERR_MSG ("record_fsync_data failed\n" ); -if (ret != -ELOOP ) -return -1 ; +if (ret != -ELOOP ) { +ERR_MSG ("skip roll-forward\n" ); + c.bug_on =1 ; + c.roll_forward =0 ; + c.fix_on =1 ; + c.fsync_record_failed =1 ; + } }if (!f2fs_should_proceed (sb,get_cp (ckpt_flags)))
include/f2fs_fs.h +1 -0
@@ -1596,6 +1596,7 @@ struct f2fs_configuration {unsigned int quota_bits;/* quota bits */ time_t fixed_time;int roll_forward; +int fsync_record_failed;bool need_fsync;bool need_whint;int whint;
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel