Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1935978lqz; Tue, 2 Apr 2024 02:09:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfHuy886IL0gLHahb+hrldeE9DdqeM9DnLFW3vG2JdisSATfbBaFWS8vNpOuh+sZ3MVGkiE5zMcbb57G4M2l85I9WyBQ4IMWJwITUoeg== X-Google-Smtp-Source: AGHT+IH3VeN8C2U1cxKzh0AO/776JJxZbO/I02Z8BUQEWVB9y1OafXN2cL667eh8c/o3o5Iq8QFw X-Received: by 2002:a05:6808:219b:b0:3c3:bf34:60fb with SMTP id be27-20020a056808219b00b003c3bf3460fbmr12789079oib.51.1712048949697; Tue, 02 Apr 2024 02:09:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712048949; cv=pass; d=google.com; s=arc-20160816; b=DJJLoR/rEgeJ1GdqkHcxpnLIUs0ScA4AuzOdXJ29WfqWGrZPsN6Lr6G2mtUAq5pWPE pqy2ZlbC8Dn2ItVoAV6VGvcltiDHccFPUuwZZ6wsfU3fphxakKRzVxAAG9m6oH7w3kkb NawxvHbasrFSpkSedavHsBtVC/GNtUZgt7JJPyzue2KVFvepsmHoAgZkL/0Cd6+QicRR Hmj37IyLOm5ngPXJ036ur9ubUuRf2QJ0X/RsN5vZ+M9laiLPFoIDSbvLDV6358rrVF6K 2DdAtjI/c7zrS2KM1/TrjhC0VzZ24OGiZymxOxG0NWO2olpBvlMTVByWFqUc7aQinPwT +stA== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from; bh=omIoBPY1TpJ5cBfc773iQkTr8YwqmynUyBtPbiTonNA=; fh=0YRSAtnrSRvhtzUzSfhpD62rtNa0OOsDCBO4xMqK++A=; b=FLTGxu/e+BHPxMJcHMK2FvcimKbPQ9fxI6nLtcesTIZ/HsbftM4/srCmTZJLsIVOv0 3BHQDKBG+/CEc1TgIfC9DdEl7Um6L/HzeBX01hxQF6plFCKQuaVHpeyuxmgmZ5pB5aAi d8Fn6KyV81reKG4R7eoP4rh4QZtjEp+T+kw1nNYWj6JnVS+cHZzWGKI13hudQlSbmDHe DxWw7+OzTBIcvVCnp2/hVOL9HtKvyB5u8s/mOXBAM7kLj0hhl1CV3/jjgqCaqlIRiA1d H+JXOd+w1lSFBTREFIJjMYKLHY5nniRGklM8PhnZFbYfyo8OBdeT8dQrr1oOIIvNgWFn g1kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1820-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c2-20020ac87d82000000b004317c2d1565si11525086qtd.327.2024.04.02.02.09.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 02:09:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1820-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1820-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1820-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1BB7E1C214F9 for ; Tue, 2 Apr 2024 09:09:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F07356B8E; Tue, 2 Apr 2024 09:09:04 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 597CC1E525; Tue, 2 Apr 2024 09:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712048944; cv=none; b=t1n++FA2iWoV8IZak8xSEBPKAhpyGoBZi51FUEqG07YL6C2iASWFFaHJ+hOO6nYPtoXpeF8O2LdYkbOIJ0JSnWAc9Ver0h/oyrMFDw/4+DqTVlpWMCOOoYbKls6IBH8DB3xeNEFYE0e9Or3n8i0fIwhNUPB/9xLWfqaSAfgw7vM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712048944; c=relaxed/simple; bh=y84DH1FpxfRn08U5oPYikSNOXDDr/iVJd9EcIchY8d8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=W9tp1ylXVBANuweyyt2opn8344QW1s3s4+D2jC6CWtaV5XBcVbch1s+A7FNQCGeRrXVmFMxvWhcgS/k9daAiXA0go5fFtX0czWB7hiKowbe3kTHJY1MQrE2crif80aSoGO6tBmdDof3zg438SeKwSN0DH4u4mbtE09maHzMCEBc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 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.163]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4V826s3MxGz1R9bj; Tue, 2 Apr 2024 17:06:13 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 8A5BF18002D; Tue, 2 Apr 2024 17:08:58 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 2 Apr 2024 17:08:58 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH] jbd2: avoid mount failed when commit block is partial submitted Date: Tue, 2 Apr 2024 17:09:51 +0800 Message-ID: <20240402090951.527619-1-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) We encountered a problem that the file system could not be mounted in the power-off scenario. The analysis of the file system mirror shows that only part of the data is written to the last commit block. To solve above issue, if commit block checksum is incorrect, check the next block if has valid magic and transaction ID. If next block hasn't valid magic or transaction ID then just drop the last transaction ignore checksum error. Theoretically, the transaction ID maybe occur loopback, which may cause the mounting failure. Signed-off-by: Ye Bin --- fs/jbd2/recovery.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index 1f7664984d6e..0a09f1a5fd1e 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -463,6 +463,41 @@ static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, return tag->t_checksum == cpu_to_be16(csum32); } +static int check_incomplete_commit(journal_t *journal, unsigned long next_block, + unsigned int next_commit_ID) +{ + journal_header_t *tmp; + struct buffer_head *bh; + int err = 0; + + err = jread(&bh, journal, next_block); + if (err) + return err; + + tmp = (journal_header_t *)bh->b_data; + /* + * If the next block does not contain consecutive transactions, it can + * be considered that the checksum error of the current commit block + * is caused by incomplete commit. Ignore the checksum error and drop + * the last transaction. + */ + if (tmp->h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER) || + be32_to_cpu(tmp->h_sequence) != next_commit_ID) { + jbd2_debug("JBD2: will drop incomplete transaction %u commit block %lu\n", + next_commit_ID - 1, next_block - 1); + goto out; + } + + pr_err("JBD2: potential continuous transaction detected %u at %lu, " + "likely invalid checksum in transaction %u\n", + next_commit_ID, next_block, next_commit_ID - 1); + + err = -EFSBADCRC; +out: + brelse(bh); + return err; +} + static int do_one_pass(journal_t *journal, struct recovery_info *info, enum passtype pass) { @@ -810,6 +845,10 @@ static int do_one_pass(journal_t *journal, if (pass == PASS_SCAN && !jbd2_commit_block_csum_verify(journal, bh->b_data)) { + if (!check_incomplete_commit(journal, + next_log_block, + next_commit_ID + 1)) + goto ignore_crc_mismatch; chksum_error: if (commit_time < last_trans_commit_time) goto ignore_crc_mismatch; -- 2.31.1