1 jbd2: factor out common descriptor block initialization
3 From: Jan Kara <jack@suse.cz>
5 Descriptor block header is initialized in several places. Factor out the
6 common code into jbd2_journal_get_descriptor_buffer().
8 Signed-off-by: Jan Kara <jack@suse.cz>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 fs/jbd2/commit.c | 16 +++++-----------
12 fs/jbd2/journal.c | 9 ++++++++-
13 fs/jbd2/revoke.c | 8 ++------
14 include/linux/jbd2.h | 2 +-
15 4 files changed, 16 insertions(+), 19 deletions(-)
17 diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
18 index ae4402d15d46..cf221f3d955a 100644
19 --- a/fs/jbd2/commit.c
20 +++ b/fs/jbd2/commit.c
21 @@ -131,14 +131,12 @@ static int journal_submit_commit_record(journal_t *journal,
22 if (is_journal_aborted(journal))
25 - bh = jbd2_journal_get_descriptor_buffer(journal);
26 + bh = jbd2_journal_get_descriptor_buffer(commit_transaction,
31 tmp = (struct commit_header *)bh->b_data;
32 - tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
33 - tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
34 - tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
35 tmp->h_commit_sec = cpu_to_be64(now.tv_sec);
36 tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec);
38 @@ -379,7 +377,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
42 - journal_header_t *header;
43 journal_block_tag_t *tag = NULL;
46 @@ -615,7 +612,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
48 jbd_debug(4, "JBD2: get descriptor\n");
50 - descriptor = jbd2_journal_get_descriptor_buffer(journal);
51 + descriptor = jbd2_journal_get_descriptor_buffer(
53 + JBD2_DESCRIPTOR_BLOCK);
55 jbd2_journal_abort(journal, -EIO);
57 @@ -624,11 +623,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
58 jbd_debug(4, "JBD2: got buffer %llu (%p)\n",
59 (unsigned long long)descriptor->b_blocknr,
61 - header = (journal_header_t *)descriptor->b_data;
62 - header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
63 - header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
64 - header->h_sequence = cpu_to_be32(commit_transaction->t_tid);
66 tagp = &descriptor->b_data[sizeof(journal_header_t)];
67 space_left = descriptor->b_size -
68 sizeof(journal_header_t);
69 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
70 index 81e622681c82..28d05bd9a588 100644
71 --- a/fs/jbd2/journal.c
72 +++ b/fs/jbd2/journal.c
73 @@ -805,10 +805,13 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
74 * But we don't bother doing that, so there will be coherency problems with
75 * mmaps of blockdevs which hold live JBD-controlled filesystems.
77 -struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
79 +jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type)
81 + journal_t *journal = transaction->t_journal;
82 struct buffer_head *bh;
83 unsigned long long blocknr;
84 + journal_header_t *header;
87 err = jbd2_journal_next_log_block(journal, &blocknr);
88 @@ -821,6 +824,10 @@ struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
91 memset(bh->b_data, 0, journal->j_blocksize);
92 + header = (journal_header_t *)bh->b_data;
93 + header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
94 + header->h_blocktype = cpu_to_be32(type);
95 + header->h_sequence = cpu_to_be32(transaction->t_tid);
96 set_buffer_uptodate(bh);
98 BUFFER_TRACE(bh, "return this buffer");
99 diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
100 index c839332be56b..d1ebb1d41d17 100644
101 --- a/fs/jbd2/revoke.c
102 +++ b/fs/jbd2/revoke.c
103 @@ -570,7 +570,6 @@ static void write_one_revoke_record(transaction_t *transaction,
105 struct buffer_head *descriptor;
107 - journal_header_t *header;
109 /* If we are already aborting, this all becomes a noop. We
110 still need to go round the loop in
111 @@ -600,13 +599,10 @@ static void write_one_revoke_record(transaction_t *transaction,
115 - descriptor = jbd2_journal_get_descriptor_buffer(journal);
116 + descriptor = jbd2_journal_get_descriptor_buffer(transaction,
117 + JBD2_REVOKE_BLOCK);
120 - header = (journal_header_t *)descriptor->b_data;
121 - header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
122 - header->h_blocktype = cpu_to_be32(JBD2_REVOKE_BLOCK);
123 - header->h_sequence = cpu_to_be32(transaction->t_tid);
125 /* Record it so that we can wait for IO completion later */
126 BUFFER_TRACE(descriptor, "file in log_bufs");
127 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
128 index 5716d9554e77..3649cb8d3a41 100644
129 --- a/include/linux/jbd2.h
130 +++ b/include/linux/jbd2.h
131 @@ -1137,7 +1137,7 @@ static inline void jbd2_unfile_log_bh(struct buffer_head *bh)
134 /* Log buffer allocation */
135 -struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal);
136 +struct buffer_head *jbd2_journal_get_descriptor_buffer(transaction_t *, int);
137 int jbd2_journal_next_log_block(journal_t *, unsigned long long *);
138 int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
139 unsigned long *block);
144 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
145 the body of a message to majordomo@vger.kernel.org
146 More majordomo info at http://vger.kernel.org/majordomo-info.html