From patchwork Wed Feb 1 11:46:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 1735486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=vmym=55=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6KKQ47myz23gY for ; Wed, 1 Feb 2023 22:23:06 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKQ0J6kz4xGq for ; Wed, 1 Feb 2023 22:23:06 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4P6KKQ0CN9z4xwq; Wed, 1 Feb 2023 22:23:06 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKQ05NQz4xGq for ; Wed, 1 Feb 2023 22:23:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjBALXE (ORCPT ); Wed, 1 Feb 2023 06:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjBALXA (ORCPT ); Wed, 1 Feb 2023 06:23:00 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19FAC3C1A; Wed, 1 Feb 2023 03:22:59 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4P6KK94q4lz4f3jYx; Wed, 1 Feb 2023 19:22:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgDn4R+NS9pj_j45Cg--.57546S5; Wed, 01 Feb 2023 19:22:55 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH 1/5] jbd2: introduce callback for recovery journal Date: Wed, 1 Feb 2023 19:46:47 +0800 Message-Id: <20230201114651.4090446-2-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201114651.4090446-1-yebin@huaweicloud.com> References: <20230201114651.4090446-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgDn4R+NS9pj_j45Cg--.57546S5 X-Coremail-Antispam: 1UD129KBjvJXoWrtryrCryxJrW7Aw4UWry7Awb_yoW8JrW8pa s5Cwn3CFW8uFy7Cr1fJa18AFWIv3yv9r4UGF98u3s0y347trZ2qaykGw15try5Ar43K3yj qr1UCrW3Cw1YkrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxUzoGQUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE 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 From: Ye Bin EXT4 file system's super block may submited by journal, however it maybe submited directly when do error handle and also other scene. So super block isn't uptodate in journal. So there is need to do some extra handle when recover journal. Signed-off-by: Ye Bin --- include/linux/jbd2.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 5962072a4b19..ab0e1a435a50 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1308,6 +1308,17 @@ struct journal_s struct buffer_head *bh, enum passtype pass, int off, tid_t expected_commit_id); + /* + * EXT4 file system's super block may submited by journal, however it + * maybe submited directly when do error handle. So super block isn't + * uptodate in journal. So there is need to do some extra handle when + * recover journal. + */ + void *j_replay_private_data; + int (*j_replay_prepare_callback)(struct journal_s *journal); + int (*j_replay_callback)(struct journal_s *journal, + struct buffer_head *bh); + void (*j_replay_end_callback)(struct journal_s *journal); }; #define jbd2_might_wait_for_commit(j) \ From patchwork Wed Feb 1 11:46:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 1735489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=vmym=55=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6KKX1Pj5z23jG for ; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKX0zrqz4xGq for ; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4P6KKX0xmMz4xwq; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKX0sRhz4xGq for ; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232470AbjBALXJ (ORCPT ); Wed, 1 Feb 2023 06:23:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbjBALXB (ORCPT ); Wed, 1 Feb 2023 06:23:01 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E2CD44A1; Wed, 1 Feb 2023 03:22:59 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4P6KK96zdfz4f3jHb; Wed, 1 Feb 2023 19:22:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgDn4R+NS9pj_j45Cg--.57546S6; Wed, 01 Feb 2023 19:22:56 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH 2/5] ext4: introudce helper for jounral recover handle Date: Wed, 1 Feb 2023 19:46:48 +0800 Message-Id: <20230201114651.4090446-3-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201114651.4090446-1-yebin@huaweicloud.com> References: <20230201114651.4090446-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgDn4R+NS9pj_j45Cg--.57546S6 X-Coremail-Antispam: 1UD129KBjvJXoWxAFy5KFyfGF13Jr43Zr13urg_yoW5tFy5pr WrCr1FyrW8u3Zruw43GrsrXF9Ivw40ka45Gry3CasIka47tryxAayktF1UCFWYqrWUWw1r X3Wjy3y8Gw15KrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2_MaUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE 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 From: Ye Bin Now, ext4 file system only need to handle super block when do recover journal. Signed-off-by: Ye Bin --- fs/ext4/ext4_jbd2.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/ext4_jbd2.h | 2 ++ fs/ext4/super.c | 1 + 3 files changed, 68 insertions(+) diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 77f318ec8abb..7c0f2bed0ec4 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -395,3 +395,68 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, } return err; } + +void ext4_replay_end_callback(struct journal_s *journal) +{ + kfree(journal->j_replay_private_data); + journal->j_replay_private_data = NULL; + journal->j_replay_callback = NULL; + journal->j_replay_end_callback = NULL; +} + +static int ext4_replay_callback(struct journal_s *journal, + struct buffer_head *bh) +{ + struct super_block *sb = journal->j_private; + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_super_block *es = sbi->s_es; + struct ext4_super_block *nes; + unsigned long offset; + + if (likely(sbi->s_sbh != bh)) + return 0; + + offset = (void*)es - (void*)sbi->s_sbh->b_data; + nes = (struct ext4_super_block*)(bh->b_data + offset); + /* + * If super block has error flag in journal record, there isn't need to + * cover error information, as in this case is errors=continue mode, + * error handle submit super block through journal. + */ + if (le16_to_cpu(nes->s_state) & EXT4_ERROR_FS) + return 0; + + memcpy(((char *)es) + EXT4_S_ERR_START, + journal->j_replay_private_data, EXT4_S_ERR_LEN); + if (sbi->s_mount_state & EXT4_ERROR_FS) + es->s_state |= cpu_to_le16(EXT4_ERROR_FS); + + return 0; +} + +static int ext4_replay_prepare_callback(struct journal_s *journal) +{ + struct super_block *sb = journal->j_private; + struct ext4_sb_info *sbi = EXT4_SB(sb); + char *private; + struct ext4_super_block *es = sbi->s_es; + + if (!(sbi->s_mount_state & EXT4_ERROR_FS)) + return 0; + + private = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL); + if (!private) + return -ENOMEM; + memcpy(private, ((char *)es) + EXT4_S_ERR_START, EXT4_S_ERR_LEN); + + journal->j_replay_private_data = private; + journal->j_replay_callback = ext4_replay_callback; + journal->j_replay_end_callback = ext4_replay_end_callback; + + return 0; +} + +void ext4_init_replay(journal_t *journal) +{ + journal->j_replay_prepare_callback = ext4_replay_prepare_callback; +} diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 0c77697d5e90..8dcc7ef5028c 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -513,4 +513,6 @@ static inline int ext4_should_dioread_nolock(struct inode *inode) return 1; } +void ext4_init_replay(journal_t *journal); + #endif /* _EXT4_JBD2_H */ diff --git a/fs/ext4/super.c b/fs/ext4/super.c index dc3907dff13a..ea0fea04907c 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5677,6 +5677,7 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) journal->j_commit_interval = sbi->s_commit_interval; journal->j_min_batch_time = sbi->s_min_batch_time; journal->j_max_batch_time = sbi->s_max_batch_time; + ext4_init_replay(journal); ext4_fc_init(sb, journal); write_lock(&journal->j_state_lock); From patchwork Wed Feb 1 11:46:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 1735490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=vmym=55=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6KKX4TwPz23gY for ; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKX44Gyz4xGq for ; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4P6KKX42MFz4xwq; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKX3ymrz4xGq for ; Wed, 1 Feb 2023 22:23:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232477AbjBALXL (ORCPT ); Wed, 1 Feb 2023 06:23:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbjBALXC (ORCPT ); Wed, 1 Feb 2023 06:23:02 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91AFF449E; Wed, 1 Feb 2023 03:22:59 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4P6KKB1KlDz4f3mJX; Wed, 1 Feb 2023 19:22:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgDn4R+NS9pj_j45Cg--.57546S7; Wed, 01 Feb 2023 19:22:56 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH 3/5] ext4: fix error flag covered by journal recovery Date: Wed, 1 Feb 2023 19:46:49 +0800 Message-Id: <20230201114651.4090446-4-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201114651.4090446-1-yebin@huaweicloud.com> References: <20230201114651.4090446-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgDn4R+NS9pj_j45Cg--.57546S7 X-Coremail-Antispam: 1UD129KBjvJXoWxur43Jw15Cw4kCw1fCr45Wrg_yoW5CFy5pr WrCrySyFWqvr17Awn3JF4DWFWYg340yFWUGrnF93Zayay5Jrn2v3y8t3WrtFy0qrWrKa4r JF1UJ3yUCw15KrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2PEfUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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 From: Ye Bin Super block in journal maybe not uptodate, when file system has error, we need set error information when do recover super block. Signed-off-by: Ye Bin --- fs/ext4/super.c | 38 ++++++++++++++++---------------------- fs/jbd2/recovery.c | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index ea0fea04907c..ab136d08d93d 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5887,7 +5887,7 @@ static int ext4_load_journal(struct super_block *sb, ext4_msg(sb, KERN_ERR, "journal device read-only, try mounting with '-o ro'"); err = -EROFS; - goto err_out; + goto out; } /* @@ -5904,7 +5904,7 @@ static int ext4_load_journal(struct super_block *sb, "unavailable, cannot proceed " "(try mounting with noload)"); err = -EROFS; - goto err_out; + goto out; } ext4_msg(sb, KERN_INFO, "write access will " "be enabled during recovery"); @@ -5917,29 +5917,21 @@ static int ext4_load_journal(struct super_block *sb, if (!ext4_has_feature_journal_needs_recovery(sb)) err = jbd2_journal_wipe(journal, !really_read_only); if (!err) { - char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL); - if (save) - memcpy(save, ((char *) es) + - EXT4_S_ERR_START, EXT4_S_ERR_LEN); - err = jbd2_journal_load(journal); - if (save) - memcpy(((char *) es) + EXT4_S_ERR_START, - save, EXT4_S_ERR_LEN); - kfree(save); + if (journal->j_replay_prepare_callback) + err = journal->j_replay_prepare_callback(journal); + if (!err) + err = jbd2_journal_load(journal); } if (err) { ext4_msg(sb, KERN_ERR, "error loading journal"); - goto err_out; + goto out; } EXT4_SB(sb)->s_journal = journal; err = ext4_clear_journal_err(sb, es); - if (err) { - EXT4_SB(sb)->s_journal = NULL; - jbd2_journal_destroy(journal); - return err; - } + if (err) + goto out; if (!really_read_only && journal_devnum && journal_devnum != le32_to_cpu(es->s_journal_dev)) { @@ -5948,11 +5940,13 @@ static int ext4_load_journal(struct super_block *sb, /* Make sure we flush the recovery flag to disk. */ ext4_commit_super(sb); } - - return 0; - -err_out: - jbd2_journal_destroy(journal); +out: + if (unlikely(journal->j_replay_end_callback)) + journal->j_replay_end_callback(journal); + if (err) { + EXT4_SB(sb)->s_journal = NULL; + jbd2_journal_destroy(journal); + } return err; } diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index 8286a9ec122f..8175d0a8d5f7 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -687,6 +687,20 @@ static int do_one_pass(journal_t *journal, *((__be32 *)nbh->b_data) = cpu_to_be32(JBD2_MAGIC_NUMBER); } + if (unlikely(journal->j_replay_callback)) { + err = journal->j_replay_callback( + journal, nbh); + if (err) { + printk(KERN_ERR + "JBD2: replay " + "call back " + "failed.\n"); + unlock_buffer(nbh); + brelse(obh); + brelse(nbh); + goto failed; + } + } BUFFER_TRACE(nbh, "marking dirty"); set_buffer_uptodate(nbh); From patchwork Wed Feb 1 11:46:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 1735491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=vmym=55=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6KKZ3KZQz23gY for ; Wed, 1 Feb 2023 22:23:14 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKZ38C9z4xwq for ; Wed, 1 Feb 2023 22:23:14 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4P6KKZ35Rlz4xyF; Wed, 1 Feb 2023 22:23:14 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKZ2z0vz4xwq for ; Wed, 1 Feb 2023 22:23:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231760AbjBALXM (ORCPT ); Wed, 1 Feb 2023 06:23:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbjBALXC (ORCPT ); Wed, 1 Feb 2023 06:23:02 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21FF96A63; Wed, 1 Feb 2023 03:23:00 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4P6KKB48Pcz4f3jYs; Wed, 1 Feb 2023 19:22:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgDn4R+NS9pj_j45Cg--.57546S8; Wed, 01 Feb 2023 19:22:56 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH 4/5] ext4: fix super block checksum error Date: Wed, 1 Feb 2023 19:46:50 +0800 Message-Id: <20230201114651.4090446-5-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201114651.4090446-1-yebin@huaweicloud.com> References: <20230201114651.4090446-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgDn4R+NS9pj_j45Cg--.57546S8 X-Coremail-Antispam: 1UD129KBjvdXoW7Jr18Jw4xWrWfZw4xJw1rCrg_yoW3KFX_Ga yxXw1rWr4fJa1Sg3W8Kr1Yv3W0grs2vF1rXa93AF1rXF1DXFs2qw4kurZF9rn8Wr4vqr45 Ar48K348Gr97WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbVAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbV WUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF 67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42 IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF 0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE 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 From: Ye Bin As commit("ext4: fix error flag covered by journal recovery") update error record when do journal recovery.There is need to recalculate super block checksum after update error record or will lead to super block checksum mismatch to data. Signed-off-by: Ye Bin --- fs/ext4/ext4_jbd2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 7c0f2bed0ec4..21f4f00429a1 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -430,6 +430,7 @@ static int ext4_replay_callback(struct journal_s *journal, journal->j_replay_private_data, EXT4_S_ERR_LEN); if (sbi->s_mount_state & EXT4_ERROR_FS) es->s_state |= cpu_to_le16(EXT4_ERROR_FS); + ext4_superblock_csum_set(sb); return 0; } From patchwork Wed Feb 1 11:46:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 1735488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=vmym=55=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6KKW4wyWz23gY for ; Wed, 1 Feb 2023 22:23:11 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKW4VQBz4xGq for ; Wed, 1 Feb 2023 22:23:11 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4P6KKW4SGXz4xwq; Wed, 1 Feb 2023 22:23:11 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P6KKW4NgXz4xGq for ; Wed, 1 Feb 2023 22:23:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232456AbjBALXH (ORCPT ); Wed, 1 Feb 2023 06:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231420AbjBALXB (ORCPT ); Wed, 1 Feb 2023 06:23:01 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9CF44EE8; Wed, 1 Feb 2023 03:22:59 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4P6KKB6w1vz4f3nTZ; Wed, 1 Feb 2023 19:22:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgDn4R+NS9pj_j45Cg--.57546S9; Wed, 01 Feb 2023 19:22:57 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH 5/5] ext4: make sure fs error flag setted before clear journal error Date: Wed, 1 Feb 2023 19:46:51 +0800 Message-Id: <20230201114651.4090446-6-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201114651.4090446-1-yebin@huaweicloud.com> References: <20230201114651.4090446-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgDn4R+NS9pj_j45Cg--.57546S9 X-Coremail-Antispam: 1UD129KBjvdXoWrtryDXF13GrW7XryxXryrZwb_yoWkXwbEq3 yxZan5Wrs3Ar1xK3WrCan8WwnYvws2vrnYqasayF15uryDXa4kCa4kWryfurn8urWrKrZ8 JF18ZFn7KFWkZjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbVAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbV WUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF 67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42 IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF 0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE 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 From: Ye Bin Now, jounral error number maybe cleared even though ext4_commit_super() failed. This may lead to error flag miss, then fsck will miss to check file system deeply. Signed-off-by: Ye Bin --- fs/ext4/super.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index ab136d08d93d..c36cc9708258 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6146,11 +6146,13 @@ static int ext4_clear_journal_err(struct super_block *sb, errstr = ext4_decode_error(sb, j_errno, nbuf); ext4_warning(sb, "Filesystem error recorded " "from previous mount: %s", errstr); - ext4_warning(sb, "Marking fs in need of filesystem check."); EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; es->s_state |= cpu_to_le16(EXT4_ERROR_FS); - ext4_commit_super(sb); + j_errno = ext4_commit_super(sb); + if (j_errno) + return j_errno; + ext4_warning(sb, "Marked fs in need of filesystem check."); jbd2_journal_clear_err(journal); jbd2_journal_update_sb_errno(journal);