summaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
authorZhiguo Niu <zhiguo.niu@unisoc.com>2023-10-16 13:27:31 +0200
committerJaegeuk Kim <jaegeuk@kernel.org>2023-10-16 21:52:39 +0200
commita5e80e18f268ea7c7a36bc4159de0deb3b5a2171 (patch)
tree508e86135da005caa3221fe3532a8a0aa975dbf5 /fs/f2fs
parentf2fs: Clean up errors in segment.h (diff)
downloadlinux-a5e80e18f268ea7c7a36bc4159de0deb3b5a2171.tar.xz
linux-a5e80e18f268ea7c7a36bc4159de0deb3b5a2171.zip
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 <zhiguo.niu@unisoc.com> Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/node.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index a2b2c6c7f66d..1c8bf56c834c 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2389,7 +2389,7 @@ static int scan_nat_page(struct f2fs_sb_info *sbi,
blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr);
if (blk_addr == NEW_ADDR)
- return -EINVAL;
+ return -EFSCORRUPTED;
if (blk_addr == NULL_ADDR) {
add_free_nid(sbi, start_nid, true, true);
@@ -2504,7 +2504,14 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi,
if (ret) {
f2fs_up_read(&nm_i->nat_tree_lock);
- f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
+
+ if (ret == -EFSCORRUPTED) {
+ f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_handle_error(sbi,
+ ERROR_INCONSISTENT_NAT);
+ }
+
return ret;
}
}