Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3487454ioo; Wed, 25 May 2022 01:32:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkZPRoa2cxP4xoYNUFIL+zn6Wkn8RqFubWMpWaqLhKfbjiK7ISy4GLYJa1yBxjxtMMyuIE X-Received: by 2002:a05:6402:1d48:b0:42b:6e02:5ece with SMTP id dz8-20020a0564021d4800b0042b6e025ecemr13505168edb.178.1653467542614; Wed, 25 May 2022 01:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653467542; cv=none; d=google.com; s=arc-20160816; b=vmAlCz/D5lXqmiz0FIl1TymTq18OCkL3fGaGJ7Wg0T1CVzhMa8SVuf8oXBjRwM2PRV QJt3szlsR74nUoa6bnpMeQyIPpfrZpaLGO7rttF7EJmva3Hf0cBgAS3B06QLyVMTYLXP VFFrUD5wrNmKYObwbKvsBW0WIXQCr5chJKFilIE8/XcK/iki0wHYkAvj6W8d1ruXpVWT SuIvkBKrNsg2OD01hI2ZnnBHXugCB5hRE5l6dF5lklF8Or7SxRqc+brYJTBu1uaRk/SL kRcz7D5izBg3U2dzRLMNcFTQC53cLU+th8NxNhiF5pqlCs91/p6hYzhY226MCEtUhHto Yj+A== 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 :message-id:date:subject:cc:to:from; bh=QEWPC1+VR37IU7LwjJhn1SHrDogzIExpjEbWLTVejXU=; b=vtLvMdsInfWWylzxUQE9RNoKKm5ZkYVsPUpLWsPuQZQf+nxSBeb+drTVl1/SqtJi3P wHTsr9t0mlbWmKY3cna0kFcsNE2nWBaqDNuHcwhl0yYUCW8paNkl8kR0bJcUXNDrscZY YrVtDqpSNpZ9qYzFDvB2YsrXvXEOWhYPhmJ/YZp4rSSRu9pvFRivp0LFVaROgBNl3Mz0 pTElB77JH62D37Jhc68RghUh8j7k4LMh3hsvT5JtHx0XnGeXe3/qTDIdv2Z4WhHiZICU gh4Z0Rh9yj4ZuLqe7498zjFyOpobhwTFEk8hQVA+UkJGWUVKdTm9ylVv/JhGWAbjrXte xy5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eq20-20020a056402299400b00428beb5a548si21418249edb.526.2022.05.25.01.31.52; Wed, 25 May 2022 01:32:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S236265AbiEYBPe (ORCPT + 99 others); Tue, 24 May 2022 21:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231764AbiEYBPd (ORCPT ); Tue, 24 May 2022 21:15:33 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEA3F6A40B; Tue, 24 May 2022 18:15:31 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L7Ckv6F75z1JC0c; Wed, 25 May 2022 09:13:59 +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_128_GCM_SHA256) id 15.1.2375.24; Wed, 25 May 2022 09:15:29 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next] ext4: fix super block checksum incorrect after mount Date: Wed, 25 May 2022 09:29:04 +0800 Message-ID: <20220525012904.1604737-1-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) 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,T_SCC_BODY_TEXT_LINE 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-ext4@vger.kernel.org We got issue as follows: [home]# mount /dev/sda test EXT4-fs (sda): warning: mounting fs with errors, running e2fsck is recommended [home]# dmesg EXT4-fs (sda): warning: mounting fs with errors, running e2fsck is recommended EXT4-fs (sda): Errors on filesystem, clearing orphan list. EXT4-fs (sda): recovery complete EXT4-fs (sda): mounted filesystem with ordered data mode. Quota mode: none. [home]# debugfs /dev/sda debugfs 1.46.5 (30-Dec-2021) Checksum errors in superblock! Retrying... Reason is ext4_orphan_cleanup will reset ‘s_last_orphan’ but not update super block checksum. To solve above issue, defer update super block checksum after ext4_orphan_cleanup. Signed-off-by: Ye Bin --- fs/ext4/super.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index f9a3ad683b4a..c47204029429 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5300,14 +5300,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) err = percpu_counter_init(&sbi->s_freeinodes_counter, freei, GFP_KERNEL); } - /* - * Update the checksum after updating free space/inode - * counters. Otherwise the superblock can have an incorrect - * checksum in the buffer cache until it is written out and - * e2fsprogs programs trying to open a file system immediately - * after it is mounted can fail. - */ - ext4_superblock_csum_set(sb); if (!err) err = percpu_counter_init(&sbi->s_dirs_counter, ext4_count_dirs(sb), GFP_KERNEL); @@ -5365,6 +5357,14 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; ext4_orphan_cleanup(sb, es); EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; + /* + * Update the checksum after updating free space/inode counters and + * ext4_orphan_cleanup. Otherwise the superblock can have an incorrect + * checksum in the buffer cache until it is written out and + * e2fsprogs programs trying to open a file system immediately + * after it is mounted can fail. + */ + ext4_superblock_csum_set(sb); if (needs_recovery) { ext4_msg(sb, KERN_INFO, "recovery complete"); err = ext4_mark_recovery_complete(sb, es); -- 2.31.1