From patchwork Fri Nov 18 09:02:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 22194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp69933wrr; Fri, 18 Nov 2022 00:46:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7D7MCJNc5iYLdHP9G77uNvR/45TDLffR421Dg7TJzmtObhLB5Fp3Ybku24cV4R40U7D63l X-Received: by 2002:a17:902:7615:b0:188:d4ea:251f with SMTP id k21-20020a170902761500b00188d4ea251fmr6640067pll.36.1668761162914; Fri, 18 Nov 2022 00:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668761162; cv=none; d=google.com; s=arc-20160816; b=m1sDDQkwsHol8CrpUFIhtrtnzT9DUzP4SIctglDDH7PrUjEfHo+EK+o4sQ+hnoXHCs 2lLrL6sXiDUvCU8NnoDX9jZB0Ipr/uUpHQ8YT/YwIaSVU0sobP7fjaAlSAdPLD2LAH57 vMbOhfHRvS07hx0+7sIap5t3C25KiX07mUujUfNve45XyNIcOTND8VE4wm32iDs9P/eZ CEP3A///0mDySe28+M+RtdM3ilaQBkxAa/0pr/tceUmhlQ1a8AmZ/RCN7ZnftNqDhhEX 5byj7oi5s5rJffztxp04RSDDyrV4160cv9KsqJl797SPEpEpLBrd79VMDa4UdplKx8qB 3Kww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZburDoNd4tfjiJmTYdrqP+POXwnWwJjKEW8FbXdVc/w=; b=LIZaG5+kXgljiTEhG+Q4WSOXbHjBHqnR9Ng4KlP24gz+dkPnzRv4OYaa9H4lPdZcOx ykK1Wn7So6XRzk18RienzWsW4LiQ7FkJevJPyZXcA3LOgZj7TzcEveE5rqjynYkQcRp4 jUqbT/EcrloxLXGbpCx7csZdwJqZovwZyC2Z+InDCBMvYCJMsxZ7OsoxIWhjUxG3p8Kr nYSZVWLkcJ79A4T8Hq/peynL/Dtfn2d1pwyQy2A/6bHVBQoLtcu2MRgbrQ7tfBsWtkfT KZXRoyY7BiRSHKRmh3acgA5YqhcV8UOfBr1IGfwl8pEVaVQZOp9s/aK/ZY1kTKLo9zNm 2XOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w125-20020a636283000000b0042bc6e8d3f7si3369414pgb.642.2022.11.18.00.45.50; Fri, 18 Nov 2022 00:46:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241259AbiKRIlY (ORCPT + 99 others); Fri, 18 Nov 2022 03:41:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241099AbiKRIlV (ORCPT ); Fri, 18 Nov 2022 03:41:21 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7186F63CF8 for ; Fri, 18 Nov 2022 00:41:20 -0800 (PST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4ND9Gk3y40zHw1N; Fri, 18 Nov 2022 16:40:46 +0800 (CST) Received: from kwepemm600013.china.huawei.com (7.193.23.68) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 18 Nov 2022 16:41:18 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 18 Nov 2022 16:41:18 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 1/2] ubifs: Re-statistic cleaned znode count if commit failed Date: Fri, 18 Nov 2022 17:02:35 +0800 Message-ID: <20221118090236.664244-2-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221118090236.664244-1-chengzhihao1@huawei.com> References: <20221118090236.664244-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749822905285123466?= X-GMAIL-MSGID: =?utf-8?q?1749822905285123466?= Dirty znodes will be written on flash in committing process with following states: process A | znode state ------------------------------------------------------ do_commit | DIRTY_ZNODE ubifs_tnc_start_commit | DIRTY_ZNODE get_znodes_to_commit | DIRTY_ZNODE | COW_ZNODE layout_commit | DIRTY_ZNODE | COW_ZNODE fill_gap | 0 write master | 0 or OBSOLETE_ZNODE process B | znode state ------------------------------------------------------ do_commit | DIRTY_ZNODE[1] ubifs_tnc_start_commit | DIRTY_ZNODE get_znodes_to_commit | DIRTY_ZNODE | COW_ZNODE ubifs_tnc_end_commit | DIRTY_ZNODE | COW_ZNODE write_index | 0 write master | 0 or OBSOLETE_ZNODE[2] or | DIRTY_ZNODE[3] [1] znode is dirtied without concurrent committing process [2] znode is copied up (re-dirtied by other process) before cleaned up in committing process [3] znode is re-dirtied after cleaned up in committing process Currently, the clean znode count is updated in free_obsolete_znodes(), which is called only in normal path. If do_commit failed, clean znode count won't be updated, which triggers a failure ubifs assertion[4] in ubifs_tnc_close(): ubifs_assert_failed [ubifs]: UBIFS assert failed: freed == n [4] Commit 380347e9ca7682 ("UBIFS: Add an assertion for clean_zn_cnt"). Fix it by re-statisticing cleaned znode count in tnc_destroy_cnext(). Fetch a reproducer in [Link]. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216704 Fixes: 1e51764a3c2a ("UBIFS: add new flash file system") Signed-off-by: Zhihao Cheng --- fs/ubifs/tnc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index 488f3da7a6c6..2df56bbc6865 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c @@ -3053,6 +3053,21 @@ static void tnc_destroy_cnext(struct ubifs_info *c) cnext = cnext->cnext; if (ubifs_zn_obsolete(znode)) kfree(znode); + else if (!ubifs_zn_cow(znode)) { + /* + * Don't forget to update clean znode count after + * committing failed, because ubifs will check this + * count while closing tnc. Non-obsolete znode could + * be re-dirtied during committing process, so dirty + * flag is untrustable. The flag 'COW_ZNODE' is set + * for each dirty znode before committing, and it is + * cleared as long as the znode become clean, so we + * can statistic clean znode count according to this + * flag. + */ + atomic_long_inc(&c->clean_zn_cnt); + atomic_long_inc(&ubifs_clean_zn_cnt); + } } while (cnext && cnext != c->cnext); }