The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Zhiguo Niu <niuzhiguo84@gmail.com>
Cc: Zhiguo Niu <zhiguo.niu@unisoc.com>,
	jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: fix error path of __f2fs_build_free_nids
Date: Mon, 16 Oct 2023 17:17:06 +0800	[thread overview]
Message-ID: <2a777530-b90e-a70d-99bd-81d36b1323fc@kernel.org> (raw)
In-Reply-To: <CAHJ8P3J+Rnx4dUDGesdrtajDdP_SxDaM6yyYbHRt4ij_wVGhsg@mail.gmail.com>

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!

      parent reply	other threads:[~2023-10-16  9:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-13 10:58 [PATCH] f2fs: fix error path of __f2fs_build_free_nids Zhiguo Niu
2023-10-16  7:37 ` Chao Yu
2023-10-16  9:02   ` Zhiguo Niu
2023-10-16  9:06     ` Chao Yu
2023-10-16  9:16       ` Zhiguo Niu
2023-10-16  9:17     ` Chao Yu [this message]

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=2a777530-b90e-a70d-99bd-81d36b1323fc@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niuzhiguo84@gmail.com \
    --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