From patchwork Wed Mar 15 01:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 69924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2084624wrd; Tue, 14 Mar 2023 18:47:58 -0700 (PDT) X-Google-Smtp-Source: AK7set/S9TIEg9s+/pZF1Nb04gKHZVnS59yVXJGkWAnUAyP1q5ZVxHC8P99NyfaC2VTH/fUE7EfV X-Received: by 2002:a05:6a21:78aa:b0:b8:723f:e21b with SMTP id bf42-20020a056a2178aa00b000b8723fe21bmr47282221pzc.3.1678844878585; Tue, 14 Mar 2023 18:47:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678844878; cv=none; d=google.com; s=arc-20160816; b=ZyG5VzWEY2b3WFkHzO9LM0Zo52ctKiLH0QvBQkBP2GqSEDGgLlHqWWJqcWWKc2Yg2t WqAj3OdiMUFFzJKRSqAts1RMz3eFUKOXCiDUGAODQmA1vERi6Nx2jlapInSSdSXSTuLS 2Fpny94pdFxZNITkHe11BOZjPthslKkYt/harWulTQdhGdwixngTOe8KHf1qUm7Edjl0 HUjzxCRSWebH9RtLcvTPl4+CREIXZy6IJharHneYiSoxXRvd7jov4E1exkyWGyxGKh8w NMN/b6T4PH7slcu+JEfeWBs5PqnW7DyjrtWWEb39omA1Yen730OqDDFic1Xy1ZmwJrcl V5LQ== 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=ojSaZqeXuWwV8D/Wj2w/l5Q8pmQToDYiEaZgcS961po=; b=jQlyglLJ0cd46Brv9gI5vVbyBBFeGzR9bD2ypj0YTOfoE5V60dn4jBcJlr3gcFfhJG /DrHFf+TigPA++Q+SDnMRbTnsyfipm5GVNNan1heK/tjn9x9uWn4SMWiBsfUICsxG1zc 1ZjvPB5T/JB4X+kL/hun9MyWSZNQm1wzYJg77hEHNqAfIlPG79JU3heygMm/QIv/kLVZ 6i9pQ6gs6WrEZsN1cuB1luedp8sCQWEw70FLUR+hJK2UT+a3xr4jZF2BFVnT0Di3Fbd+ NYpCJFA7BrpAn/bSDQQJ/OxKwFqRhqK73QzCui9FT+sKmffq4TFXX6fGngU5kABAgtNX yyWw== 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 p25-20020a634f59000000b004fc2dfedcd6si3592117pgl.213.2023.03.14.18.47.43; Tue, 14 Mar 2023 18:47:58 -0700 (PDT) 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 S229845AbjCOBdL (ORCPT + 99 others); Tue, 14 Mar 2023 21:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230143AbjCOBcx (ORCPT ); Tue, 14 Mar 2023 21:32:53 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C74C26CD6; Tue, 14 Mar 2023 18:32:23 -0700 (PDT) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PbtCJ728YzrSmT; Wed, 15 Mar 2023 09:31:24 +0800 (CST) 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.2507.21; Wed, 15 Mar 2023 09:32:17 +0800 From: Zhihao Cheng To: , , , CC: , , , Subject: [PATCH v3 4/6] jbd2: switch to check format version in superblock directly Date: Wed, 15 Mar 2023 09:31:26 +0800 Message-ID: <20230315013128.3911115-5-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230315013128.3911115-1-chengzhihao1@huawei.com> References: <20230315013128.3911115-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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?1760396447586772497?= X-GMAIL-MSGID: =?utf-8?q?1760396447586772497?= From: Zhang Yi We should only check and set extented features if journal format version is 2, and now we check the in memory copy of the superblock 'journal->j_format_version', which relys on the parameter initialization sequence, switch to use the h_blocktype in superblock cloud be more clear. Signed-off-by: Zhang Yi Signed-off-by: Zhihao Cheng Reviewed-by: Jan Kara --- fs/jbd2/journal.c | 16 +++++++--------- include/linux/jbd2.h | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 8ae419152ff6..8d5fe6738cc4 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -2062,10 +2062,12 @@ int jbd2_journal_load(journal_t *journal) return err; sb = journal->j_superblock; - /* If this is a V2 superblock, then we have to check the - * features flags on it. */ - if (journal->j_format_version >= 2) { + /* + * If this is a V2 superblock, then we have to check the + * features flags on it. + */ + if (jbd2_format_support_feature(journal)) { if ((sb->s_feature_ro_compat & ~cpu_to_be32(JBD2_KNOWN_ROCOMPAT_FEATURES)) || (sb->s_feature_incompat & @@ -2227,7 +2229,7 @@ int jbd2_journal_check_used_features(journal_t *journal, unsigned long compat, if (journal->j_format_version == 0 && journal_get_superblock(journal) != 0) return 0; - if (journal->j_format_version == 1) + if (!jbd2_format_support_feature(journal)) return 0; sb = journal->j_superblock; @@ -2257,11 +2259,7 @@ int jbd2_journal_check_available_features(journal_t *journal, unsigned long comp if (!compat && !ro && !incompat) return 1; - /* We can support any known requested features iff the - * superblock is in version 2. Otherwise we fail to support any - * extended sb features. */ - - if (journal->j_format_version != 2) + if (!jbd2_format_support_feature(journal)) return 0; if ((compat & JBD2_KNOWN_COMPAT_FEATURES) == compat && diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index a91cf9c7a94b..1ffcea5c024e 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1313,11 +1313,22 @@ struct journal_s rwsem_release(&j->j_trans_commit_map, _THIS_IP_); \ } while (0) +/* + * We can support any known requested features iff the + * superblock is not in version 1. Otherwise we fail to support any + * extended sb features. + */ +static inline bool jbd2_format_support_feature(journal_t *j) +{ + return j->j_superblock->s_header.h_blocktype != + cpu_to_be32(JBD2_SUPERBLOCK_V1); +} + /* journal feature predicate functions */ #define JBD2_FEATURE_COMPAT_FUNCS(name, flagname) \ static inline bool jbd2_has_feature_##name(journal_t *j) \ { \ - return ((j)->j_format_version >= 2 && \ + return (jbd2_format_support_feature(j) && \ ((j)->j_superblock->s_feature_compat & \ cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname)) != 0); \ } \ @@ -1335,7 +1346,7 @@ static inline void jbd2_clear_feature_##name(journal_t *j) \ #define JBD2_FEATURE_RO_COMPAT_FUNCS(name, flagname) \ static inline bool jbd2_has_feature_##name(journal_t *j) \ { \ - return ((j)->j_format_version >= 2 && \ + return (jbd2_format_support_feature(j) && \ ((j)->j_superblock->s_feature_ro_compat & \ cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname)) != 0); \ } \ @@ -1353,7 +1364,7 @@ static inline void jbd2_clear_feature_##name(journal_t *j) \ #define JBD2_FEATURE_INCOMPAT_FUNCS(name, flagname) \ static inline bool jbd2_has_feature_##name(journal_t *j) \ { \ - return ((j)->j_format_version >= 2 && \ + return (jbd2_format_support_feature(j) && \ ((j)->j_superblock->s_feature_incompat & \ cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname)) != 0); \ } \