Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3701122rdb; Wed, 27 Dec 2023 17:41:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG66yjmCHJHcLd8dLl2eYt70L9LwnnYLIP1CI2GKFcnd8LABIi5xZVio9p8E143DhjW0Tsl X-Received: by 2002:a05:6a00:9e:b0:6d9:b9b4:8ca with SMTP id c30-20020a056a00009e00b006d9b9b408camr2492916pfj.28.1703727703589; Wed, 27 Dec 2023 17:41:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703727703; cv=none; d=google.com; s=arc-20160816; b=iLkmSKkIlEJorTsvRJJIk8v/mt3ubvorF0+XlVuqs+V6UPhsGmgGM7bOC3SMtMXA0A qUUjFDZdB06gOh+HtV/cGJEhVvQdkhyfSom9vUot6b9/rQDXySa3lldQ66eJ6zITyMuK cOjIHU4zmTr8Wyb0nqlaxpsZrZmxwOXSRFDcKGNb2Yz+97hhZnQdpPk6BvFLRw6G7JXH 98v7zaqDR+RTlHyf7WhOPWOv/nFHW5tQ2D7gJafgSaFNhex3ZH6Te2vFgROnQpNLsF1+ 4Mi/YcoEVjmdsBjclNlwvFjQW9mMfwLSce3B3uRJJuYh0BfuyFydLtamug1o3QVP+StK VenQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=nbruqzexgkpNoKJ1ciJqG1RZYCz96bRUw1PF9gv5eVg=; fh=3kaVOPShTC55oj708yh1yJALapWuogKx6Yvc3sQq9zY=; b=uKYoONXkBx/X5KbPNYcHFlwHs4EFnMKsPnVVetsCOh8EyJ9q6oFfCQgGl/WE3nySrA 0eXj9xxvNkORypH9eUBVXfCyZelQGYwATS36fJg4h+4tDIrSQb/6mpEq2VemwzCQs+Ab YSf+Fv/oBf+lGFnu4PXXVP/yrRKs7J87WRvsi9Cjxr7qZ2PoO0/2EbZiBdN4/0M3XKHf QunsPy4DSneSAdnjYvIfqcnIyJuLL9GBPQYM8gqUgHwbOrG8gwBvesh1H9fhoM7ThBet fr7zusXNQ1w/IqxbloITHhOEydJIHeD4CU0QKvVjyiUVB83Sb9uBhLTq6uLGRRoKwuoY fhMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12363-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x66-20020a636345000000b005ce02ada455si8351255pgb.656.2023.12.27.17.41.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:41:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12363-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4088D281968 for ; Thu, 28 Dec 2023 01:41:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9812EDDC8; Thu, 28 Dec 2023 01:39:17 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E768D51B for ; Thu, 28 Dec 2023 01:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4T0rlC2hZTz1vqJh; Thu, 28 Dec 2023 09:39:03 +0800 (CST) Received: from kwepemm000013.china.huawei.com (unknown [7.193.23.81]) by mail.maildlp.com (Postfix) with ESMTPS id 9877F1A0195; Thu, 28 Dec 2023 09:38:58 +0800 (CST) Received: from huawei.com (10.175.127.227) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 28 Dec 2023 09:38:14 +0800 From: Zhihao Cheng To: , , , , CC: , Subject: [PATCH RFC 14/17] ubifs: repair: Clean up log and orphan area Date: Thu, 28 Dec 2023 09:41:09 +0800 Message-ID: <20231228014112.2836317-15-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231228014112.2836317-1-chengzhihao1@huawei.com> References: <20231228014112.2836317-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000013.china.huawei.com (7.193.23.81) This is the 12/13 step of repairing. Clean up log and orphan area, all nodes have been recovered, these two areas should be cleared, otherwise old content in journal/orphan could be replayed in next mounting. Signed-off-by: Zhihao Cheng --- fs/ubifs/repair.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/fs/ubifs/repair.c b/fs/ubifs/repair.c index 8d40cff26f7a..42124cda5d7d 100644 --- a/fs/ubifs/repair.c +++ b/fs/ubifs/repair.c @@ -2367,6 +2367,43 @@ int build_lpt(struct ubifs_info *c) return ubifs_create_lpt(c, c->repair->lpts, c->main_lebs, hash_lpt); } +/** + * clean_log - clean up log area. + * @c: UBIFS file-system description object + * + * This function cleans up log area, since there is no need to do recovery + * in next mounting. + */ +static int clean_log(struct ubifs_info *c) +{ + int lnum, err; + struct ubifs_cs_node *cs; + + for (lnum = UBIFS_LOG_LNUM; lnum <= c->log_last; lnum++) { + if (fatal_signal_pending(current)) + return -EINTR; + cond_resched(); + + err = ubifs_leb_unmap(c, lnum); + if (err) + return err; + } + + cs = kzalloc(ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size), GFP_KERNEL); + if (!cs) + return -ENOMEM; + + cs->ch.node_type = UBIFS_CS_NODE; + cs->cmt_no = cpu_to_le64(0); + + err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, 0); + kfree(cs); + if (err) + return err; + + return 0; +} + static int do_repair(struct ubifs_info *c) { int err = 0; @@ -2416,6 +2453,16 @@ static int do_repair(struct ubifs_info *c) /* Step 11. Build LPT. */ ubifs_msg(c, "Step 11: Build LPT"); err = build_lpt(c); + if (err) + goto out; + + /* Step 12. Clean up log & orphan. */ + ubifs_msg(c, "Step 12: Clean up log & orphan"); + err = clean_log(c); + if (err) + goto out; + + err = ubifs_clear_orphans(c); out: destroy_scanned_info(c, &si); -- 2.31.1