Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2338054rdg; Mon, 16 Oct 2023 00:38:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0osFFGkbHKb2lNTIYCY9VE9U+8uzFqt3YtR+Ee/7IjeuwAftWl+yEFewLum7HDgLudPKz X-Received: by 2002:a05:6a21:7881:b0:15e:a653:fed5 with SMTP id bf1-20020a056a21788100b0015ea653fed5mr43792355pzc.16.1697441883830; Mon, 16 Oct 2023 00:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697441883; cv=none; d=google.com; s=arc-20160816; b=ihVDBQUkpz3oCOfiaikY3y+C+c/Ek1xwH21BC85NWqlUyfFDEMynZp5l09+ms88dC+ 07BnHep7rvQjKvz9gG8aciigmJHnYLd+0G01BfYIZ0O0ByJf2pg9e00+aW7lwo/15SKv lE4Mg2Ke1ZY0PeO0PJ4qWbyZxITIp5ISi2omw2mpC7n9i2ZxHYI5dB/XpVibBKYHorG3 4dpS8+dDAWnrCk6ETQFX/BiZSLMeS6l/JunFPj+TizXxImGwRbzrpbnP2+03Boy5oj9X Fvss485GfQHCu8j0mppTgMuU7PgCgbtUc5+Td/+p8aBXcBASgxmZ/wnWmbDLNnbpYk2o MU9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=J8+QhPwObtMDJ/BcO8UcknpOxgJzt98jsZDPft6IZDg=; fh=uP2+s0SnWKHhrxZgbnrwyPtD8aJRoeJvs5DzXDI6h2Q=; b=d4GQDVPSoXa6Gl0iiCrRfjMcvBgmUpXl23Ph3LMNcCMayLVfNuQhsLBs8ci/x0+3HT aqG+BPsvcWq44HtglfunDS8MOw04ENyFHDbhlHHFpiN4TiYq1XyoS8/CXlbnnT2++t0y CKZ1r21EDDk1kOjLq933Jf03E9VoZBoyw03lBEqJSxDYc212QI8/RsG3nEXQTDvh6/yA lTVq1Gye6Br/BYPEL7SyJOr/01rfDqLD9Y1p9l/7tHYfRw4QGuAvbskSW2LsaAtPwOIX DNMU/MxI4hZT/hs9eKW47/wIAczQ93XuR1Dx+u8ESouKpVF1gM9Rj6vuvSRQEGbikSZe 27kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uKl0gLR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j23-20020a17090aeb1700b0027d0c3507eesi5592706pjz.32.2023.10.16.00.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uKl0gLR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DEA0480C778E; Mon, 16 Oct 2023 00:37:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231977AbjJPHhu (ORCPT + 99 others); Mon, 16 Oct 2023 03:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232087AbjJPHht (ORCPT ); Mon, 16 Oct 2023 03:37:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EED6EE1 for ; Mon, 16 Oct 2023 00:37:47 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55D3BC433C7; Mon, 16 Oct 2023 07:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697441867; bh=FNzUTuBfzvrUXizLUlXqjLaF57+7wKA7RX7E+mW/uVs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=uKl0gLR5aCbqsy4jq6YSzWsz0n0y3ptbS/D2PUkZCXzkW5lCvAgKT5xJGgGtLFDpp +7/na5QhVIk2t4dW+6d6Ea59iUAk6ISccysTCRNKY6YWrTFAKrn/57mMhBwLGAUXaS u7VXdfIEOmLEbPfGnbZYZ4EsqtyqBgn1lZEm5BAV1+CGwHbG4SHVRfkAF1QnHjDsL5 8IJYpd+qDzrHEYprTR5s+kA/B/j99qxa2b6eJr1vSXoMfmg8z9039dTN2+/GjHmm7m GMBGUt3pdt8BFGmET8k68JAeq2WLxFU2pzDzReA/pOq6Bo5egaObVUKQjgZ0p8UB7n GFCxhJ2h4Mhag== Message-ID: <1880a7c4-9ab9-8e6d-f1d4-c2172a99685c@kernel.org> Date: Mon, 16 Oct 2023 15:37:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH] f2fs: fix error path of __f2fs_build_free_nids Content-Language: en-US To: Zhiguo Niu , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, niuzhiguo84@gmail.com References: <1697194703-21371-1-git-send-email-zhiguo.niu@unisoc.com> From: Chao Yu In-Reply-To: <1697194703-21371-1-git-send-email-zhiguo.niu@unisoc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 16 Oct 2023 00:38:00 -0700 (PDT) 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 2001 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_FSCK. 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 *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