Skip to content

Commit 3e5cf02

Browse files
zhangyi089tytso
authored andcommitted
jbd2: factor out journal initialization from journal_get_superblock()
Current journal_get_superblock() couple journal superblock checking and partial journal initialization, factor out initialization part from it to make things 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-6-chengzhihao1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 5cf036d commit 3e5cf02

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

fs/jbd2/journal.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,21 +1925,13 @@ static int journal_get_superblock(journal_t *journal)
19251925
goto out;
19261926
}
19271927

1928-
switch(be32_to_cpu(sb->s_header.h_blocktype)) {
1929-
case JBD2_SUPERBLOCK_V1:
1930-
journal->j_format_version = 1;
1931-
break;
1932-
case JBD2_SUPERBLOCK_V2:
1933-
journal->j_format_version = 2;
1934-
break;
1935-
default:
1928+
if (be32_to_cpu(sb->s_header.h_blocktype) != JBD2_SUPERBLOCK_V1 &&
1929+
be32_to_cpu(sb->s_header.h_blocktype) != JBD2_SUPERBLOCK_V2) {
19361930
printk(KERN_WARNING "JBD2: unrecognised superblock format ID\n");
19371931
goto out;
19381932
}
19391933

1940-
if (be32_to_cpu(sb->s_maxlen) < journal->j_total_len)
1941-
journal->j_total_len = be32_to_cpu(sb->s_maxlen);
1942-
else if (be32_to_cpu(sb->s_maxlen) > journal->j_total_len) {
1934+
if (be32_to_cpu(sb->s_maxlen) > journal->j_total_len) {
19431935
printk(KERN_WARNING "JBD2: journal file too short\n");
19441936
goto out;
19451937
}
@@ -1982,25 +1974,14 @@ static int journal_get_superblock(journal_t *journal)
19821974
journal->j_chksum_driver = NULL;
19831975
goto out;
19841976
}
1985-
}
1986-
1987-
if (jbd2_journal_has_csum_v2or3(journal)) {
19881977
/* Check superblock checksum */
19891978
if (sb->s_checksum != jbd2_superblock_csum(journal, sb)) {
19901979
printk(KERN_ERR "JBD2: journal checksum error\n");
19911980
err = -EFSBADCRC;
19921981
goto out;
19931982
}
1994-
1995-
/* Precompute checksum seed for all metadata */
1996-
journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
1997-
sizeof(sb->s_uuid));
19981983
}
1999-
2000-
journal->j_revoke_records_per_block =
2001-
journal_revoke_records_per_block(journal);
20021984
set_buffer_verified(bh);
2003-
20041985
return 0;
20051986

20061987
out:
@@ -2025,12 +2006,30 @@ static int load_superblock(journal_t *journal)
20252006

20262007
sb = journal->j_superblock;
20272008

2009+
switch (be32_to_cpu(sb->s_header.h_blocktype)) {
2010+
case JBD2_SUPERBLOCK_V1:
2011+
journal->j_format_version = 1;
2012+
break;
2013+
case JBD2_SUPERBLOCK_V2:
2014+
journal->j_format_version = 2;
2015+
break;
2016+
}
2017+
20282018
journal->j_tail_sequence = be32_to_cpu(sb->s_sequence);
20292019
journal->j_tail = be32_to_cpu(sb->s_start);
20302020
journal->j_first = be32_to_cpu(sb->s_first);
20312021
journal->j_errno = be32_to_cpu(sb->s_errno);
20322022
journal->j_last = be32_to_cpu(sb->s_maxlen);
20332023

2024+
if (be32_to_cpu(sb->s_maxlen) < journal->j_total_len)
2025+
journal->j_total_len = be32_to_cpu(sb->s_maxlen);
2026+
/* Precompute checksum seed for all metadata */
2027+
if (jbd2_journal_has_csum_v2or3(journal))
2028+
journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
2029+
sizeof(sb->s_uuid));
2030+
journal->j_revoke_records_per_block =
2031+
journal_revoke_records_per_block(journal);
2032+
20342033
if (jbd2_has_feature_fast_commit(journal)) {
20352034
journal->j_fc_last = be32_to_cpu(sb->s_maxlen);
20362035
num_fc_blocks = jbd2_journal_get_num_fc_blks(sb);
@@ -2226,8 +2225,7 @@ int jbd2_journal_check_used_features(journal_t *journal, unsigned long compat,
22262225
if (!compat && !ro && !incompat)
22272226
return 1;
22282227
/* Load journal superblock if it is not loaded yet. */
2229-
if (journal->j_format_version == 0 &&
2230-
journal_get_superblock(journal) != 0)
2228+
if (journal_get_superblock(journal))
22312229
return 0;
22322230
if (!jbd2_format_support_feature(journal))
22332231
return 0;

0 commit comments

Comments
 (0)