Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2428813rdg; Mon, 16 Oct 2023 04:28:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELXuD4BjodCoLEDwcuCnE0I1cEtC49kXPw7XmwSYfVFbEgBjaae8FvNHD17oPG9tj0gXoA X-Received: by 2002:a05:6a00:134c:b0:6b5:6c95:4671 with SMTP id k12-20020a056a00134c00b006b56c954671mr9288867pfu.34.1697455733622; Mon, 16 Oct 2023 04:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697455733; cv=none; d=google.com; s=arc-20160816; b=tJ718/RHXU885FFg4AUGlyukHj5zXhVoCIxWZIpteQejjVXCnRP582t4Kv61jomwjs UtGzPwnKpB2A/0O89GzoPpVBT3TS1R7av89/T6BNPzRUqkDe3ZJP0kRSaBxRD1CgLBwV 2j/fMYSs0qqDbmJ9XUXEp29WLlA6xSdNPIFuYptpPQIQknhr16J4YnVF4+VwqekFlSkl mRGfZ84SDOuI2EG4v3wM7te/gf5YaWYX+nyaXC1484hH4HtS3UDcfccm/OpsfVL65KQl Rz769aK/+tAK0nUwKG3afeS+mANmmA1cbB/fNv9u1QLM4qps0JV0qY8GF+ldr1yd0Bsp bK5A== 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=Lr6tYd/cdlc6A/j5Z06hla8YsgmiQ8kHtm5dtZ5WbsA=; fh=jjDTLTkAaPK3cTutO2P9ZECZUYkGOS1dcBtirQV26To=; b=xRmx8Jc0HHaCdHLQ7PgidBvIn7aSc6aRDGXthkLvxBjYl0BolCDkvt2faIT6OIr41R 7vA3RguWXKWNivEU1TXuHFa1nfuqHJuO/vh+VAkv0zJyzlcgWH/fqTViRyjDGkecEptj GWtD9LjoGEes69LKMkUsQFi3PYYIjo8dNIX6LmU6kHgm80Fk6wKQ182GUABZ8ELni3QG bMDXYELt3xqG0CiBlFKvZR8qtY3EsEVng23WZfEjl3yyb8ZkGEb9ekiXlkHKb3CQxB3D RZK65lq95/m7SEiVdi8q82aykbw6pjeZb2Ho48H9yIG8FSWxdxUFRA1RmNHvLXjJu8L1 WAwA== 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:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id l187-20020a6391c4000000b005a9f776c579si7981144pge.65.2023.10.16.04.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 04:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id CDCA080ACC7F; Mon, 16 Oct 2023 04:28:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233346AbjJPL2k (ORCPT + 99 others); Mon, 16 Oct 2023 07:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbjJPL2j (ORCPT ); Mon, 16 Oct 2023 07:28:39 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A8CE5 for ; Mon, 16 Oct 2023 04:28:35 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 39GBRuqv055664; Mon, 16 Oct 2023 19:27:56 +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 4S8F9Z5g4bz2KQZJ4; Mon, 16 Oct 2023 19:23:46 +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; Mon, 16 Oct 2023 19:27:54 +0800 From: Zhiguo Niu To: , CC: , , , Subject: [PATCH V2] f2fs: fix error path of __f2fs_build_free_nids Date: Mon, 16 Oct 2023 19:27:31 +0800 Message-ID: <1697455651-11124-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: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 39GBRuqv055664 X-Spam-Status: No, score=-0.8 required=5.0 tests=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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 04:28:51 -0700 (PDT) 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 --- changes of v2: Improve the patch according to Chao's suggestions. --- --- 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 ee2e1dd..248764b 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 a82a4bb..cf1adce 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, }; -- 1.9.1