Commit 32ab6715 authored by Jan Kara's avatar Jan Kara Committed by Theodore Ts'o

jbd2: factor out common descriptor block initialization

Descriptor block header is initialized in several places. Factor out the
common code into jbd2_journal_get_descriptor_buffer().
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 9bcf976c
...@@ -131,14 +131,12 @@ static int journal_submit_commit_record(journal_t *journal, ...@@ -131,14 +131,12 @@ static int journal_submit_commit_record(journal_t *journal,
if (is_journal_aborted(journal)) if (is_journal_aborted(journal))
return 0; return 0;
bh = jbd2_journal_get_descriptor_buffer(journal); bh = jbd2_journal_get_descriptor_buffer(commit_transaction,
JBD2_COMMIT_BLOCK);
if (!bh) if (!bh)
return 1; return 1;
tmp = (struct commit_header *)bh->b_data; tmp = (struct commit_header *)bh->b_data;
tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
tmp->h_commit_sec = cpu_to_be64(now.tv_sec); tmp->h_commit_sec = cpu_to_be64(now.tv_sec);
tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec); tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec);
...@@ -379,7 +377,6 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -379,7 +377,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
ktime_t start_time; ktime_t start_time;
u64 commit_time; u64 commit_time;
char *tagp = NULL; char *tagp = NULL;
journal_header_t *header;
journal_block_tag_t *tag = NULL; journal_block_tag_t *tag = NULL;
int space_left = 0; int space_left = 0;
int first_tag = 0; int first_tag = 0;
...@@ -615,7 +612,9 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -615,7 +612,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
jbd_debug(4, "JBD2: get descriptor\n"); jbd_debug(4, "JBD2: get descriptor\n");
descriptor = jbd2_journal_get_descriptor_buffer(journal); descriptor = jbd2_journal_get_descriptor_buffer(
commit_transaction,
JBD2_DESCRIPTOR_BLOCK);
if (!descriptor) { if (!descriptor) {
jbd2_journal_abort(journal, -EIO); jbd2_journal_abort(journal, -EIO);
continue; continue;
...@@ -624,11 +623,6 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -624,11 +623,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
jbd_debug(4, "JBD2: got buffer %llu (%p)\n", jbd_debug(4, "JBD2: got buffer %llu (%p)\n",
(unsigned long long)descriptor->b_blocknr, (unsigned long long)descriptor->b_blocknr,
descriptor->b_data); descriptor->b_data);
header = (journal_header_t *)descriptor->b_data;
header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
header->h_sequence = cpu_to_be32(commit_transaction->t_tid);
tagp = &descriptor->b_data[sizeof(journal_header_t)]; tagp = &descriptor->b_data[sizeof(journal_header_t)];
space_left = descriptor->b_size - space_left = descriptor->b_size -
sizeof(journal_header_t); sizeof(journal_header_t);
......
...@@ -805,10 +805,13 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr, ...@@ -805,10 +805,13 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
* But we don't bother doing that, so there will be coherency problems with * But we don't bother doing that, so there will be coherency problems with
* mmaps of blockdevs which hold live JBD-controlled filesystems. * mmaps of blockdevs which hold live JBD-controlled filesystems.
*/ */
struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal) struct buffer_head *
jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type)
{ {
journal_t *journal = transaction->t_journal;
struct buffer_head *bh; struct buffer_head *bh;
unsigned long long blocknr; unsigned long long blocknr;
journal_header_t *header;
int err; int err;
err = jbd2_journal_next_log_block(journal, &blocknr); err = jbd2_journal_next_log_block(journal, &blocknr);
...@@ -821,6 +824,10 @@ struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal) ...@@ -821,6 +824,10 @@ struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
return NULL; return NULL;
lock_buffer(bh); lock_buffer(bh);
memset(bh->b_data, 0, journal->j_blocksize); memset(bh->b_data, 0, journal->j_blocksize);
header = (journal_header_t *)bh->b_data;
header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
header->h_blocktype = cpu_to_be32(type);
header->h_sequence = cpu_to_be32(transaction->t_tid);
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
unlock_buffer(bh); unlock_buffer(bh);
BUFFER_TRACE(bh, "return this buffer"); BUFFER_TRACE(bh, "return this buffer");
......
...@@ -570,7 +570,6 @@ static void write_one_revoke_record(transaction_t *transaction, ...@@ -570,7 +570,6 @@ static void write_one_revoke_record(transaction_t *transaction,
int csum_size = 0; int csum_size = 0;
struct buffer_head *descriptor; struct buffer_head *descriptor;
int sz, offset; int sz, offset;
journal_header_t *header;
/* If we are already aborting, this all becomes a noop. We /* If we are already aborting, this all becomes a noop. We
still need to go round the loop in still need to go round the loop in
...@@ -600,13 +599,10 @@ static void write_one_revoke_record(transaction_t *transaction, ...@@ -600,13 +599,10 @@ static void write_one_revoke_record(transaction_t *transaction,
} }
if (!descriptor) { if (!descriptor) {
descriptor = jbd2_journal_get_descriptor_buffer(journal); descriptor = jbd2_journal_get_descriptor_buffer(transaction,
JBD2_REVOKE_BLOCK);
if (!descriptor) if (!descriptor)
return; return;
header = (journal_header_t *)descriptor->b_data;
header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
header->h_blocktype = cpu_to_be32(JBD2_REVOKE_BLOCK);
header->h_sequence = cpu_to_be32(transaction->t_tid);
/* Record it so that we can wait for IO completion later */ /* Record it so that we can wait for IO completion later */
BUFFER_TRACE(descriptor, "file in log_bufs"); BUFFER_TRACE(descriptor, "file in log_bufs");
......
...@@ -1137,7 +1137,7 @@ static inline void jbd2_unfile_log_bh(struct buffer_head *bh) ...@@ -1137,7 +1137,7 @@ static inline void jbd2_unfile_log_bh(struct buffer_head *bh)
} }
/* Log buffer allocation */ /* Log buffer allocation */
struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal); struct buffer_head *jbd2_journal_get_descriptor_buffer(transaction_t *, int);
int jbd2_journal_next_log_block(journal_t *, unsigned long long *); int jbd2_journal_next_log_block(journal_t *, unsigned long long *);
int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid, int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
unsigned long *block); unsigned long *block);
......
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