Commit 9bd23c31 authored by Harshad Shirwadkar's avatar Harshad Shirwadkar Committed by Theodore Ts'o

jbd2: add a helper to find out number of fast commit blocks

Add a helper to read number of fast commit blocks from jbd2 superblock
and also rename the JBD2_MIN_FC_BLKS to
JBD2_DEFAULT_FAST_COMMIT_BLOCKS since this constant is just the
default number of fast commit blocks to use in case number of fast
commit blocks isn't set in jbd2 superblock.
Signed-off-by: default avatarHarshad Shirwadkar <harshadshirwadkar@gmail.com>
Link: https://lore.kernel.org/r/20201120202232.2240293-2-harshadshirwadkar@gmail.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 941ba122
...@@ -1869,9 +1869,7 @@ static int load_superblock(journal_t *journal) ...@@ -1869,9 +1869,7 @@ static int load_superblock(journal_t *journal)
if (jbd2_has_feature_fast_commit(journal)) { if (jbd2_has_feature_fast_commit(journal)) {
journal->j_fc_last = be32_to_cpu(sb->s_maxlen); journal->j_fc_last = be32_to_cpu(sb->s_maxlen);
num_fc_blocks = be32_to_cpu(sb->s_num_fc_blks); num_fc_blocks = jbd2_journal_get_num_fc_blks(sb);
if (!num_fc_blocks)
num_fc_blocks = JBD2_MIN_FC_BLOCKS;
if (journal->j_last - num_fc_blocks >= JBD2_MIN_JOURNAL_BLOCKS) if (journal->j_last - num_fc_blocks >= JBD2_MIN_JOURNAL_BLOCKS)
journal->j_last = journal->j_fc_last - num_fc_blocks; journal->j_last = journal->j_fc_last - num_fc_blocks;
journal->j_fc_first = journal->j_last + 1; journal->j_fc_first = journal->j_last + 1;
...@@ -2102,9 +2100,7 @@ jbd2_journal_initialize_fast_commit(journal_t *journal) ...@@ -2102,9 +2100,7 @@ jbd2_journal_initialize_fast_commit(journal_t *journal)
journal_superblock_t *sb = journal->j_superblock; journal_superblock_t *sb = journal->j_superblock;
unsigned long long num_fc_blks; unsigned long long num_fc_blks;
num_fc_blks = be32_to_cpu(sb->s_num_fc_blks); num_fc_blks = jbd2_journal_get_num_fc_blks(sb);
if (num_fc_blks == 0)
num_fc_blks = JBD2_MIN_FC_BLOCKS;
if (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS) if (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS)
return -ENOSPC; return -ENOSPC;
......
...@@ -68,7 +68,7 @@ extern void *jbd2_alloc(size_t size, gfp_t flags); ...@@ -68,7 +68,7 @@ extern void *jbd2_alloc(size_t size, gfp_t flags);
extern void jbd2_free(void *ptr, size_t size); extern void jbd2_free(void *ptr, size_t size);
#define JBD2_MIN_JOURNAL_BLOCKS 1024 #define JBD2_MIN_JOURNAL_BLOCKS 1024
#define JBD2_MIN_FC_BLOCKS 256 #define JBD2_DEFAULT_FAST_COMMIT_BLOCKS 256
#ifdef __KERNEL__ #ifdef __KERNEL__
...@@ -1692,6 +1692,13 @@ static inline int jbd2_journal_has_csum_v2or3(journal_t *journal) ...@@ -1692,6 +1692,13 @@ static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
return journal->j_chksum_driver != NULL; return journal->j_chksum_driver != NULL;
} }
static inline int jbd2_journal_get_num_fc_blks(journal_superblock_t *jsb)
{
int num_fc_blocks = be32_to_cpu(jsb->s_num_fc_blks);
return num_fc_blocks ? num_fc_blocks : JBD2_DEFAULT_FAST_COMMIT_BLOCKS;
}
/* /*
* Return number of free blocks in the log. Must be called under j_state_lock. * Return number of free blocks in the log. Must be called under j_state_lock.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment