From patchwork Fri Mar 10 12:52:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 67385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp857122wrd; Fri, 10 Mar 2023 05:03:00 -0800 (PST) X-Google-Smtp-Source: AK7set/jRgl07T0weI1PRDPZTyEsN5MBZ0pTi99nAsH7bBFLEjxwQZK6zqQVGg0pJaGGBQv17PFi X-Received: by 2002:a17:902:d506:b0:19e:2717:3de9 with SMTP id b6-20020a170902d50600b0019e27173de9mr31795117plg.52.1678453379772; Fri, 10 Mar 2023 05:02:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678453379; cv=none; d=google.com; s=arc-20160816; b=oW/Z1nbX8fvA+CC5vi6wXIh0ul9goX6shOn205SQ48ifbsAp2+/8PfmmPcdz1A05yy q1ZezayDMFCBamo/xjokHMCpVuiztVXjsklOWH8LfBdjLBxKe/dW5B/vVr61nfj/qjFL 5tP7L1P+zAHEIfTtQ3d395F6TlsuLFzjvmiQDge3bqgJmOknf5DjReDZ13QM+ALbzEKM Fuq8FOo8onX+Px6zFLViHTObpEO0C91q0L+E/bIqxvvbeD6hslTJkkjbjw+5Mhn2lI7C N72HEn51bzB42CvGw+EmpwGPH9Kpd5hnF/jR6dF9vbjrL6abJmfHl03mIg3q5bNZAuIQ /i+Q== 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=Td0nMLfuepwMC8pPH1SytHoONl4ekVV4sCgwly4wkgM=; b=zQdi71ynsRAFdRce2x/fr5kZsG3TiAuXfPuJTMuwHtolvhdQzR9HhiI8bfeKs7a70N 4/C432Dge/D9nfromS3BMroPpzNEUtwAeQCvWtZZoV2LFu9FI11Oe2+qxsZ20/FVnAjq 7X8hMSxMHqzFFgOK91zasGvV+bjfWihLpfN1OznPWmqJkTzgVrGtW2adIWXz9p/Wce7W UmexefKfuLTfNrLB0May4OHUKqp1nOGSIMyFI80uZ0JuuBZysyHfKfDvPlauaKKvsNEX nsxbd/jE9Rcs9f2iBXqHl8xea97XACTPXlojep/IpnaKqRdPViiWd6iYnVR/VKsCsV1c 1VOg== 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 iz15-20020a170902ef8f00b0019e69b5fa9esi2016642plb.521.2023.03.10.05.02.46; Fri, 10 Mar 2023 05:02:59 -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 S230350AbjCJMxM (ORCPT + 99 others); Fri, 10 Mar 2023 07:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbjCJMxA (ORCPT ); Fri, 10 Mar 2023 07:53:00 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA29810DE5C; Fri, 10 Mar 2023 04:52:53 -0800 (PST) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PY5VJ2FTJzSkkm; Fri, 10 Mar 2023 20:49:44 +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; Fri, 10 Mar 2023 20:52:51 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 3/5] jbd2: switch to check format version in superblock directly Date: Fri, 10 Mar 2023 20:52:04 +0800 Message-ID: <20230310125206.2867822-4-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230310125206.2867822-1-chengzhihao1@huawei.com> References: <20230310125206.2867822-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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?1759985931221586384?= X-GMAIL-MSGID: =?utf-8?q?1759985931221586384?= 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 e80c781731f8..b991d5c21d16 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -2059,10 +2059,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 & @@ -2224,7 +2226,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; @@ -2254,11 +2256,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 ad7bb6861143..7095c0f17ad0 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1305,11 +1305,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); \ } \ @@ -1327,7 +1338,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); \ } \ @@ -1345,7 +1356,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); \ } \