Message ID | 1697194703-21371-1-git-send-email-zhiguo.niu@unisoc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1803869vqb; Fri, 13 Oct 2023 03:59:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOaKRnxmb7Mbv4ELcLPvARiGGkCLi/dgk/bOS98sz8FmD3casNpmseiRLjQI+SnBHkaR1g X-Received: by 2002:a05:6e02:2185:b0:357:5188:1f83 with SMTP id j5-20020a056e02218500b0035751881f83mr7371162ila.1.1697194788804; Fri, 13 Oct 2023 03:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697194788; cv=none; d=google.com; s=arc-20160816; b=xopdrQrn+zyFnFy+VQYIOSVMWndgmviddsJlF/fim6IpaE7YyE54ImfiExEhsZq4I5 vS7jYmujZkEbWwB+9Ijfkh0MeKrEqow/52Cc5jBb89CxdvuZbhZB5eA6Hv6hG8l7m4Ou E7GZIzzVKO/cQmNSxa774uHErPZnQ3eZO5eNhp+cVdkSPDgMZc+pfm4VT3ArpANbRoc3 nKDOhYpzaecTdbUX+yKkAjaJzkf85LIZlaWdpUCFXjVEMoxgCwi8oqhandeKTDWLGKOX KgAZ8WYWE+1Hld5KtEDrCTd0MmbpTjWand2i71AJ+fZNlA5oWK6txg597tdjX5nWmRCD nYZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=Mogbi/2oqpyAyBS1J5rCe6n6lYblpP0L0ZK8pevYaPE=; fh=jjDTLTkAaPK3cTutO2P9ZECZUYkGOS1dcBtirQV26To=; b=UQnLFAWrnZh/L720S9V3n3yC8hqtkP2mMwELrTK+T3umgeTMG5/RspMeyPKAmO6ipb rS60S5HTHCxDCibutIdy/ZAhVh5t5j4PtSAQW+hwAuhBmkh0HyarmPsf+V/rPbTuJJjf fpzG4psDDeMWXDfkObUvSZckFBaeBEIuSEaX38QAHlqFiZf7SeuAs3ZamqrhjxwR75pp xQ9Xrhjjxo8EQ4VpJ3fdI4O0K3sSF86rGmNS4TK3z/Tu8afu8uuupoxsDL8EYVXKzzGn uHS7yIyq9cS6V8s1aN5YPXYWyftE7s7vXDsHzkPx1rQr+1DZyMaJ5ipuiVJOKRe3aEiK 5VlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w14-20020a63d74e000000b0056a670ebd6fsi4445813pgi.669.2023.10.13.03.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 03:59:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CA10682FABC1; Fri, 13 Oct 2023 03:59:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbjJMK7o (ORCPT <rfc822;rua109.linux@gmail.com> + 19 others); Fri, 13 Oct 2023 06:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjJMK7m (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 13 Oct 2023 06:59:42 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A39F83 for <linux-kernel@vger.kernel.org>; Fri, 13 Oct 2023 03:59:39 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 39DAworm019695; Fri, 13 Oct 2023 18:58:50 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4S6NgW2XMhz2KWZZn; Fri, 13 Oct 2023 18:54:47 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 13 Oct 2023 18:58:49 +0800 From: Zhiguo Niu <zhiguo.niu@unisoc.com> To: <jaegeuk@kernel.org>, <chao@kernel.org> CC: <linux-f2fs-devel@lists.sourceforge.net>, <linux-kernel@vger.kernel.org>, <niuzhiguo84@gmail.com>, <zhiguo.niu@unisoc.com> Subject: [PATCH] f2fs: fix error path of __f2fs_build_free_nids Date: Fri, 13 Oct 2023 18:58:23 +0800 Message-ID: <1697194703-21371-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.73.87] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 39DAworm019695 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 13 Oct 2023 03:59:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779637722915802053 X-GMAIL-MSGID: 1779637722915802053 |
Series |
f2fs: fix error path of __f2fs_build_free_nids
|
|
Commit Message
Zhiguo Niu
Oct. 13, 2023, 10:58 a.m. UTC
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@unisoc.com>
---
fs/f2fs/node.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On 2023/10/13 18:58, Zhiguo Niu wrote: > 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@unisoc.com> Hi Zhiguo, Can you please check below update? From 9a3459d2d62a12f8708d72aa7808a1def9f9d92f Mon Sep 17 00:00:00 2001 From: Zhiguo Niu <zhiguo.niu@unisoc.com> Date: Fri, 13 Oct 2023 18:58:23 +0800 Subject: [PATCH] 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> --- 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 a2b2c6c7f66d..57d9dd3a43bc 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 07ed69c2840d..039fe0ce8d83 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, };
Dear Chao, On Mon, Oct 16, 2023 at 3:37 PM Chao Yu <chao@kernel.org> wrote: > > On 2023/10/13 18:58, Zhiguo Niu wrote: > > 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@unisoc.com> > > Hi Zhiguo, > > Can you please check below update? > > From 9a3459d2d62a12f8708d72aa7808a1def9f9d92f Mon Sep 17 00:00:00 2001 > From: Zhiguo Niu <zhiguo.niu@unisoc.com> > Date: Fri, 13 Oct 2023 18:58:23 +0800 > Subject: [PATCH] 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> > --- > 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 a2b2c6c7f66d..57d9dd3a43bc 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 07ed69c2840d..039fe0ce8d83 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.40.1 Thank you for your updates and these updates are more reasonable based on the latest code. In addition, I also modified the following code after I checked the related flow of f2fs_handle_error. ERROR_INCONSISTENT_FOOTER is reused here, any suggestions for this? diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index d9e6087..94f5c7f 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1467,6 +1467,7 @@ static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid, ofs_of_node(page), cpver_of_node(page), next_blkaddr_of_node(page)); set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER); err = -EINVAL; out_err: ClearPageUptodate(page); If you have no other suggestions, I will update the "PATCH V2" Thanks!
Zhiguo, On 2023/10/16 17:02, Zhiguo Niu wrote: > Dear Chao, > > On Mon, Oct 16, 2023 at 3:37 PM Chao Yu <chao@kernel.org> wrote: >> >> On 2023/10/13 18:58, Zhiguo Niu wrote: >>> 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@unisoc.com> >> >> Hi Zhiguo, >> >> Can you please check below update? >> >> From 9a3459d2d62a12f8708d72aa7808a1def9f9d92f Mon Sep 17 00:00:00 2001 >> From: Zhiguo Niu <zhiguo.niu@unisoc.com> >> Date: Fri, 13 Oct 2023 18:58:23 +0800 >> Subject: [PATCH] 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> >> --- >> 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 a2b2c6c7f66d..57d9dd3a43bc 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 07ed69c2840d..039fe0ce8d83 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.40.1 > > Thank you for your updates and these updates are more reasonable based > on the latest code. > In addition, I also modified the following code after I checked the > related flow of f2fs_handle_error. > ERROR_INCONSISTENT_FOOTER is reused here, any suggestions for this? > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > index d9e6087..94f5c7f 100644 > --- a/fs/f2fs/node.c > +++ b/fs/f2fs/node.c > @@ -1467,6 +1467,7 @@ static struct page *__get_node_page(struct > f2fs_sb_info *sbi, pgoff_t nid, > ofs_of_node(page), cpver_of_node(page), > next_blkaddr_of_node(page)); > set_sbi_flag(sbi, SBI_NEED_FSCK); > + f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER); > err = -EINVAL; err = -EFSCORRUPTED; > out_err: > ClearPageUptodate(page); > > If you have no other suggestions, I will update the "PATCH V2" How about changing above code in separated patch? Thanks, > Thanks!
Dear Chao, On Mon, Oct 16, 2023 at 5:07 PM Chao Yu <chao@kernel.org> wrote: > > Zhiguo, > > On 2023/10/16 17:02, Zhiguo Niu wrote: > > Dear Chao, > > > > On Mon, Oct 16, 2023 at 3:37 PM Chao Yu <chao@kernel.org> wrote: > >> > >> On 2023/10/13 18:58, Zhiguo Niu wrote: > >>> 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@unisoc.com> > >> > >> Hi Zhiguo, > >> > >> Can you please check below update? > >> > >> From 9a3459d2d62a12f8708d72aa7808a1def9f9d92f Mon Sep 17 00:00:00 2001 > >> From: Zhiguo Niu <zhiguo.niu@unisoc.com> > >> Date: Fri, 13 Oct 2023 18:58:23 +0800 > >> Subject: [PATCH] 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> > >> --- > >> 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 a2b2c6c7f66d..57d9dd3a43bc 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 07ed69c2840d..039fe0ce8d83 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.40.1 > > > > Thank you for your updates and these updates are more reasonable based > > on the latest code. > > In addition, I also modified the following code after I checked the > > related flow of f2fs_handle_error. > > ERROR_INCONSISTENT_FOOTER is reused here, any suggestions for this? > > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > > index d9e6087..94f5c7f 100644 > > --- a/fs/f2fs/node.c > > +++ b/fs/f2fs/node.c > > @@ -1467,6 +1467,7 @@ static struct page *__get_node_page(struct > > f2fs_sb_info *sbi, pgoff_t nid, > > ofs_of_node(page), cpver_of_node(page), > > next_blkaddr_of_node(page)); > > set_sbi_flag(sbi, SBI_NEED_FSCK); > > + f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER); > > err = -EINVAL; > > err = -EFSCORRUPTED; > > > out_err: > > ClearPageUptodate(page); > > > > If you have no other suggestions, I will update the "PATCH V2" > > How about changing above code in separated patch? OK, I will do this as your suggestions. Thanks! > > Thanks, > > > Thanks!
On 2023/10/16 17:02, Zhiguo Niu wrote: > Dear Chao, > > On Mon, Oct 16, 2023 at 3:37 PM Chao Yu <chao@kernel.org> wrote: >> >> On 2023/10/13 18:58, Zhiguo Niu wrote: >>> 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@unisoc.com> >> >> Hi Zhiguo, >> >> Can you please check below update? >> >> From 9a3459d2d62a12f8708d72aa7808a1def9f9d92f Mon Sep 17 00:00:00 2001 >> From: Zhiguo Niu <zhiguo.niu@unisoc.com> >> Date: Fri, 13 Oct 2023 18:58:23 +0800 >> Subject: [PATCH] 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. Zhiguo, If you have no more comments, I guess you can resend this one as v2. Thanks, >> >> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> >> Signed-off-by: Chao Yu <chao@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 a2b2c6c7f66d..57d9dd3a43bc 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 07ed69c2840d..039fe0ce8d83 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.40.1 > > Thank you for your updates and these updates are more reasonable based > on the latest code. > In addition, I also modified the following code after I checked the > related flow of f2fs_handle_error. > ERROR_INCONSISTENT_FOOTER is reused here, any suggestions for this? > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > index d9e6087..94f5c7f 100644 > --- a/fs/f2fs/node.c > +++ b/fs/f2fs/node.c > @@ -1467,6 +1467,7 @@ static struct page *__get_node_page(struct > f2fs_sb_info *sbi, pgoff_t nid, > ofs_of_node(page), cpver_of_node(page), > next_blkaddr_of_node(page)); > set_sbi_flag(sbi, SBI_NEED_FSCK); > + f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER); > err = -EINVAL; > out_err: > ClearPageUptodate(page); > > If you have no other suggestions, I will update the "PATCH V2" > Thanks!
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; } }