Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2373345rdg; Mon, 16 Oct 2023 02:16:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6Nd9C3XXILO/MxW4lqNk/RAWeeuke6lARKe8MsRRBTDCYvX+mkEZbMR3QaUJm67CVGR4Q X-Received: by 2002:a05:6a00:1ac7:b0:6b2:5d32:57d with SMTP id f7-20020a056a001ac700b006b25d32057dmr10115763pfv.5.1697447807428; Mon, 16 Oct 2023 02:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697447807; cv=none; d=google.com; s=arc-20160816; b=pnwznNoJc66hTIunPvquFY75+DTob4gbcwRf2/2zvLF0hxMBp9RFyrX7o53gyjoJPV QO2Yti9Ff5+YNTmblLQ/IOsF250MpwCH/yePeUc/KIktNED1k0YTsVMUOanfg8+pCy/2 jNXVRjcygLN7r3koqb3zarBoauZSaSZHh5xXMadwEfHcMzq0PB1hilUngIFdhsrXqNNL noMi/JwaKRqQhuk4QlNZCF+EGeQwf87O/tMnxn3Jnc0YegDI6Ugcg942CPyRikLNSY1o HQ0pLj3mFiZjt9UKB0WyIO3l+jx0s3cp5VBtTbl03n+YqFzyHKoZ6+d167gH7P1Q7A34 Rdfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=3FwdJg2ESwHU12LbRl+SXH4clXzUSlhz/qOQqxgChOg=; fh=dcDW83Ixmwu6BqsNFYUyZ75LnUA9sKISy3tIW7wDjqg=; b=nuXxD3AWRHLt2wOpaNOiZZGJxepe+35tBLRfUsXWDHvKmFMMajQD2GOY7sBqYtJBTU r5fXpUY3SlGmFA9LjxOLCgAwW+Prh9fUU+77PfQ9zZ9Hmncf5YSQJnIuq+Ld0PZF9ZMQ ERvQCqjU4ZqpIw7tX3Mcv5E2z+s0Ru/EhtYTGHvZwEump62C7p+dRRIRcOYdG1zLsZdq PLAHMmFsapkw0HLBvCOR9NrQ1uVJ2tFLDCkViaoAclPMQAOi9RGWWZYmIa2xNZYjfyaP uNdRi68nn8WuAW6uvbaiNR7smnt7OnFfOPANmhqH1gJd7jwEyWAS9D8uaNHG0yyMVPn/ 8GKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Udg3+Ne+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bo12-20020a056a000e8c00b0068c0300a3f7si14758278pfb.279.2023.10.16.02.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 02:16:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Udg3+Ne+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0ED3480697F7; Mon, 16 Oct 2023 02:16:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230406AbjJPJQe (ORCPT + 99 others); Mon, 16 Oct 2023 05:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232455AbjJPJQd (ORCPT ); Mon, 16 Oct 2023 05:16:33 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEE88AB for ; Mon, 16 Oct 2023 02:16:31 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-53db3811d8fso8795934a12.1 for ; Mon, 16 Oct 2023 02:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697447790; x=1698052590; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3FwdJg2ESwHU12LbRl+SXH4clXzUSlhz/qOQqxgChOg=; b=Udg3+Ne+n4eqVERo5Kpy/FKQ5xkvI65GKvlMnLyfK3QdJE5G0cjP4pwaGEse+nQGaU 5cgJTs8TPRjuSPY5a3iyVbmfiWUaIOTGveQ0kSsBIargMzYyAEiIptR38AD5CkJEwjPs wug2DEBb9K6qwLpnq6D5mTk954Tg8vbJfRby28bcdB3LsDDW7ju5c1eqY9yH7E0O7NIU GuX5YTxW+UGkYJ3Vra9azTB9G3E9E0DCVbKBGCXZqtYfv4NEF6sfxytEDB5hgTmwkW/J jg/Hqjh07hwf47rc1I8o82PgpdQx2cWu0Jy7gG35AGHiqZw1rT2Sm23IsL6tJrOBJBwG uEFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697447790; x=1698052590; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3FwdJg2ESwHU12LbRl+SXH4clXzUSlhz/qOQqxgChOg=; b=LScSHoFjs8jGqyyqUI/PqxKSeYQOI4yWQmsSjaNPZX8AV2bHQM07sf22uP/2Fthzym 5IXOSzON/AIp1cdvkMq4QrvYKJYvNpyVlteLePSZxFuLom4vc3PasRmpo9nnlFEQxt7I +6AWiodkOagRC5HN4GUJzBrLd199XNfAIt3m5qjpr4Xpovv6uFGExuwosvzOvBj4Kt49 fA8tKqMa8Hey7ok0uGQIWHaf9IL3PoP9x5jzgR7AGDKzJEHDgT7ExpvActD501+hSDV2 qMqgtOts4r0oqe9R7PeG8lFXsEBntovigv2eOrhlptFd8aWLDbI34ccEwCULkZss9RdW Orzg== X-Gm-Message-State: AOJu0Ywwcye5gkNrONotQigaw+Lhcq3TnZNGsgwbXhwEp5dCDGesu40f 7UWjTshPa+E+SOHFMOnbmjHcvWBxymiP9kFmx4o= X-Received: by 2002:a50:c8ca:0:b0:530:ec02:babd with SMTP id k10-20020a50c8ca000000b00530ec02babdmr5868072edh.9.1697447790261; Mon, 16 Oct 2023 02:16:30 -0700 (PDT) MIME-Version: 1.0 References: <1697194703-21371-1-git-send-email-zhiguo.niu@unisoc.com> <1880a7c4-9ab9-8e6d-f1d4-c2172a99685c@kernel.org> <4409f648-40f6-c28a-ebe0-d2c69ecd11fc@kernel.org> In-Reply-To: <4409f648-40f6-c28a-ebe0-d2c69ecd11fc@kernel.org> From: Zhiguo Niu Date: Mon, 16 Oct 2023 17:16:18 +0800 Message-ID: Subject: Re: [PATCH] f2fs: fix error path of __f2fs_build_free_nids To: Chao Yu Cc: Zhiguo Niu , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 16 Oct 2023 02:16:45 -0700 (PDT) Dear Chao, On Mon, Oct 16, 2023 at 5:07=E2=80=AFPM Chao Yu wrote: > > Zhiguo, > > On 2023/10/16 17:02, Zhiguo Niu wrote: > > Dear Chao, > > > > On Mon, Oct 16, 2023 at 3:37=E2=80=AFPM Chao Yu 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 > >> > >> Hi Zhiguo, > >> > >> Can you please check below update? > >> > >> From 9a3459d2d62a12f8708d72aa7808a1def9f9d92f Mon Sep 17 00:00:00 20= 01 > >> From: Zhiguo Niu > >> 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_FSC= K. > >> > >> Signed-off-by: Zhiguo Niu > >> Signed-off-by: Chao Yu > >> --- > >> 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 *sb= i, > >> blk_addr =3D le32_to_cpu(nat_blk->entries[i].block_ad= dr); > >> > >> if (blk_addr =3D=3D NEW_ADDR) > >> - return -EINVAL; > >> + return -EFSCORRUPTED; > >> > >> if (blk_addr =3D=3D NULL_ADDR) { > >> add_free_nid(sbi, start_nid, true, true); > >> @@ -2504,7 +2504,14 @@ static int __f2fs_build_free_nids(struct f2fs_s= b_info *sbi, > >> > >> if (ret) { > >> f2fs_up_read(&nm_i->nat_tree_lock); > >> - f2fs_err(sbi, "NAT is corrupt, run fsc= k to fix it"); > >> + > >> + if (ret =3D=3D -EFSCORRUPTED) { > >> + f2fs_err(sbi, "NAT is corrupt,= run fsck to fix it"); > >> + set_sbi_flag(sbi, SBI_NEED_FSC= K); > >> + f2fs_handle_error(sbi, > >> + ERROR_INCONSIS= TENT_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 =3D -EINVAL; > > err =3D -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!