Skip to content

Commit a5e80e1

Browse files
Zhiguo NiuJaegeuk Kim
authored andcommitted
f2fs: fix error path of __f2fs_build_free_nids
If NAT is corrupted, let scan_nat_page() return EFSCORRUPTED, so that, caller can set SBI_NEED_FSCK flag into checkpoint for later repair by fsck. Also, this patch introduces a new fscorrupted error flag, and in above scenario, it will persist the error flag into superblock synchronously to avoid it has no luck to trigger a checkpoint to record SBI_NEED_FSCK Signed-off-by: Zhiguo Niu <[email protected]> Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 3776843 commit a5e80e1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

fs/f2fs/node.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,7 @@ static int scan_nat_page(struct f2fs_sb_info *sbi,
23892389
blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr);
23902390

23912391
if (blk_addr == NEW_ADDR)
2392-
return -EINVAL;
2392+
return -EFSCORRUPTED;
23932393

23942394
if (blk_addr == NULL_ADDR) {
23952395
add_free_nid(sbi, start_nid, true, true);
@@ -2504,7 +2504,14 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi,
25042504

25052505
if (ret) {
25062506
f2fs_up_read(&nm_i->nat_tree_lock);
2507-
f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
2507+
2508+
if (ret == -EFSCORRUPTED) {
2509+
f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
2510+
set_sbi_flag(sbi, SBI_NEED_FSCK);
2511+
f2fs_handle_error(sbi,
2512+
ERROR_INCONSISTENT_NAT);
2513+
}
2514+
25082515
return ret;
25092516
}
25102517
}

include/linux/f2fs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ enum f2fs_error {
104104
ERROR_CORRUPTED_VERITY_XATTR,
105105
ERROR_CORRUPTED_XATTR,
106106
ERROR_INVALID_NODE_REFERENCE,
107+
ERROR_INCONSISTENT_NAT,
107108
ERROR_MAX,
108109
};
109110

0 commit comments

Comments
 (0)