[PATCH] f2fs: fix error path of __f2fs_build_free_nids

From: Zhiguo Niu
Date: Fri Oct 13 2023 - 06:59:46 EST


SBI_NEED_FSCK should be set for fsck has a chance to
repair in case of scan_nat_page fail in run time.

Signed-off-by: Zhiguo Niu <zhiguo.niu@xxxxxxxxxx>
---
fs/f2fs/node.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index ee2e1dd..d9e6087 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2499,12 +2499,15 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi,
ret = PTR_ERR(page);
} else {
ret = scan_nat_page(sbi, page, nid);
+ if (ret && !mount) {
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
+ }
f2fs_put_page(page, 1);
}

if (ret) {
f2fs_up_read(&nm_i->nat_tree_lock);
- f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
return ret;
}
}
--
1.9.1