Skip to content

Commit 5cf036d

Browse files
zhangyi089tytso
authored andcommitted
jbd2: switch to check format version in superblock directly
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 <yi.zhang@huawei.com> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230315013128.3911115-5-chengzhihao1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 5c5bd1f commit 5cf036d

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

fs/jbd2/journal.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,10 +2062,12 @@ int jbd2_journal_load(journal_t *journal)
20622062
return err;
20632063

20642064
sb = journal->j_superblock;
2065-
/* If this is a V2 superblock, then we have to check the
2066-
* features flags on it. */
20672065

2068-
if (journal->j_format_version >= 2) {
2066+
/*
2067+
* If this is a V2 superblock, then we have to check the
2068+
* features flags on it.
2069+
*/
2070+
if (jbd2_format_support_feature(journal)) {
20692071
if ((sb->s_feature_ro_compat &
20702072
~cpu_to_be32(JBD2_KNOWN_ROCOMPAT_FEATURES)) ||
20712073
(sb->s_feature_incompat &
@@ -2227,7 +2229,7 @@ int jbd2_journal_check_used_features(journal_t *journal, unsigned long compat,
22272229
if (journal->j_format_version == 0 &&
22282230
journal_get_superblock(journal) != 0)
22292231
return 0;
2230-
if (journal->j_format_version == 1)
2232+
if (!jbd2_format_support_feature(journal))
22312233
return 0;
22322234

22332235
sb = journal->j_superblock;
@@ -2257,11 +2259,7 @@ int jbd2_journal_check_available_features(journal_t *journal, unsigned long comp
22572259
if (!compat && !ro && !incompat)
22582260
return 1;
22592261

2260-
/* We can support any known requested features iff the
2261-
* superblock is in version 2. Otherwise we fail to support any
2262-
* extended sb features. */
2263-
2264-
if (journal->j_format_version != 2)
2262+
if (!jbd2_format_support_feature(journal))
22652263
return 0;
22662264

22672265
if ((compat & JBD2_KNOWN_COMPAT_FEATURES) == compat &&

include/linux/jbd2.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,11 +1313,22 @@ struct journal_s
13131313
rwsem_release(&j->j_trans_commit_map, _THIS_IP_); \
13141314
} while (0)
13151315

1316+
/*
1317+
* We can support any known requested features iff the
1318+
* superblock is not in version 1. Otherwise we fail to support any
1319+
* extended sb features.
1320+
*/
1321+
static inline bool jbd2_format_support_feature(journal_t *j)
1322+
{
1323+
return j->j_superblock->s_header.h_blocktype !=
1324+
cpu_to_be32(JBD2_SUPERBLOCK_V1);
1325+
}
1326+
13161327
/* journal feature predicate functions */
13171328
#define JBD2_FEATURE_COMPAT_FUNCS(name, flagname) \
13181329
static inline bool jbd2_has_feature_##name(journal_t *j) \
13191330
{ \
1320-
return ((j)->j_format_version >= 2 && \
1331+
return (jbd2_format_support_feature(j) && \
13211332
((j)->j_superblock->s_feature_compat & \
13221333
cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname)) != 0); \
13231334
} \
@@ -1335,7 +1346,7 @@ static inline void jbd2_clear_feature_##name(journal_t *j) \
13351346
#define JBD2_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
13361347
static inline bool jbd2_has_feature_##name(journal_t *j) \
13371348
{ \
1338-
return ((j)->j_format_version >= 2 && \
1349+
return (jbd2_format_support_feature(j) && \
13391350
((j)->j_superblock->s_feature_ro_compat & \
13401351
cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname)) != 0); \
13411352
} \
@@ -1353,7 +1364,7 @@ static inline void jbd2_clear_feature_##name(journal_t *j) \
13531364
#define JBD2_FEATURE_INCOMPAT_FUNCS(name, flagname) \
13541365
static inline bool jbd2_has_feature_##name(journal_t *j) \
13551366
{ \
1356-
return ((j)->j_format_version >= 2 && \
1367+
return (jbd2_format_support_feature(j) && \
13571368
((j)->j_superblock->s_feature_incompat & \
13581369
cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname)) != 0); \
13591370
} \

0 commit comments

Comments
 (0)