mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zhiguo Niu <zhiguo.niu@unisoc.com>, Chao Yu <chao@kernel.org>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Sasha Levin <sashal@kernel.org>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH AUTOSEL 6.6 13/18] f2fs: fix error path of __f2fs_build_free_nids
Date: Tue,  7 Nov 2023 18:22:07 -0500	[thread overview]
Message-ID: <20231107232231.3775605-13-sashal@kernel.org> (raw)
In-Reply-To: <20231107232231.3775605-1-sashal@kernel.org>

From: Zhiguo Niu <zhiguo.niu@unisoc.com>

[ Upstream commit a5e80e18f268ea7c7a36bc4159de0deb3b5a2171 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/f2fs/node.c          | 11 +++++++++--
 include/linux/f2fs_fs.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index ee2e1dd64f256..248764badcde8 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;
 			}
 		}
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index a82a4bb6ce68b..cf1adceb02697 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -104,6 +104,7 @@ enum f2fs_error {
 	ERROR_CORRUPTED_VERITY_XATTR,
 	ERROR_CORRUPTED_XATTR,
 	ERROR_INVALID_NODE_REFERENCE,
+	ERROR_INCONSISTENT_NAT,
 	ERROR_MAX,
 };
 
-- 
2.42.0


  parent reply	other threads:[~2023-11-07 23:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 23:21 [PATCH AUTOSEL 6.6 01/18] iio: adc: stm32-adc: harden against NULL pointer deref in stm32_adc_probe() Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 02/18] thunderbolt: Apply USB 3.x bandwidth quirk only in software connection manager Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 03/18] tty: vcc: Add check for kstrdup() in vcc_probe() Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 04/18] dt-bindings: phy: qcom,snps-eusb2-repeater: Add magic tuning overrides Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 05/18] phy: qualcomm: phy-qcom-eusb2-repeater: Use regmap_fields Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 06/18] phy: qualcomm: phy-qcom-eusb2-repeater: Zero out untouched tuning regs Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 07/18] usb: dwc3: core: configure TX/RX threshold for DWC3_IP Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 08/18] usb: pci-quirks: group AMD specific quirk code together Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 09/18] usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 10/18] usb: pci-quirks: handle HAS_IOPORT dependency for UHCI handoff Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 11/18] usb: ucsi: glink: use the connector orientation GPIO to provide switch events Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 12/18] soundwire: dmi-quirks: update HP Omen match Sasha Levin
2023-11-07 23:22 ` Sasha Levin [this message]
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 14/18] f2fs: fix error handling of __get_node_page Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 15/18] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 16/18] usb: gadget: f_ncm: Always set current gadget in ncm_bind() Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 17/18] 9p/trans_fd: Annotate data-racy writes to file::f_flags Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 18/18] 9p: v9fs_listxattr: fix %s null argument warning Sasha Levin

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=20231107232231.3775605-13-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zhiguo.niu@unisoc.com \
    /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

Powered by JetHome