diff options
author | Jan Kara <jack@suse.cz> | 2016-02-22 23:17:15 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2016-02-22 23:17:15 -0500 |
commit | 32ab671599a89534f37e97d146c27690e371b661 (patch) | |
tree | 6fe66460f49b278a6c7115fe2d3d03733c91bc2f | |
parent | 9bcf976cb8b86eb40e0c0b495a14e4cb967b9c6e (diff) |
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: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | fs/jbd2/commit.c | 16 | ||||
-rw-r--r-- | fs/jbd2/journal.c | 9 | ||||
-rw-r--r-- | fs/jbd2/revoke.c | 8 | ||||
-rw-r--r-- | include/linux/jbd2.h | 2 |
4 files changed, 16 insertions, 19 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index ae4402d15d46..cf221f3d955a 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c | |||
@@ -131,14 +131,12 @@ static int journal_submit_commit_record(journal_t *journal, | |||
131 | if (is_journal_aborted(journal)) | 131 | if (is_journal_aborted(journal)) |
132 | return 0; | 132 | return 0; |
133 | 133 | ||
134 | bh = jbd2_journal_get_descriptor_buffer(journal); | 134 | bh = jbd2_journal_get_descriptor_buffer(commit_transaction, |
135 | JBD2_COMMIT_BLOCK); | ||
135 | if (!bh) | 136 | if (!bh) |
136 | return 1; | 137 | return 1; |
137 | 138 | ||
138 | tmp = (struct commit_header *)bh->b_data; | 139 | tmp = (struct commit_header *)bh->b_data; |
139 | tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); | ||
140 | tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK); | ||
141 | tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid); | ||
142 | tmp->h_commit_sec = cpu_to_be64(now.tv_sec); | 140 | tmp->h_commit_sec = cpu_to_be64(now.tv_sec); |
143 | tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec); | 141 | tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec); |
144 | 142 | ||
@@ -379,7 +377,6 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
379 | ktime_t start_time; | 377 | ktime_t start_time; |
380 | u64 commit_time; | 378 | u64 commit_time; |
381 | char *tagp = NULL; | 379 | char *tagp = NULL; |
382 | journal_header_t *header; | ||
383 | journal_block_tag_t *tag = NULL; | 380 | journal_block_tag_t *tag = NULL; |
384 | int space_left = 0; | 381 | int space_left = 0; |
385 | int first_tag = 0; | 382 | int first_tag = 0; |
@@ -615,7 +612,9 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
615 | 612 | ||
616 | jbd_debug(4, "JBD2: get descriptor\n"); | 613 | jbd_debug(4, "JBD2: get descriptor\n"); |
617 | 614 | ||
618 | descriptor = jbd2_journal_get_descriptor_buffer(journal); | 615 | descriptor = jbd2_journal_get_descriptor_buffer( |
616 | commit_transaction, | ||
617 | JBD2_DESCRIPTOR_BLOCK); | ||
619 | if (!descriptor) { | 618 | if (!descriptor) { |
620 | jbd2_journal_abort(journal, -EIO); | 619 | jbd2_journal_abort(journal, -EIO); |
621 | continue; | 620 | continue; |
@@ -624,11 +623,6 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
624 | jbd_debug(4, "JBD2: got buffer %llu (%p)\n", | 623 | jbd_debug(4, "JBD2: got buffer %llu (%p)\n", |
625 | (unsigned long long)descriptor->b_blocknr, | 624 | (unsigned long long)descriptor->b_blocknr, |
626 | descriptor->b_data); | 625 | descriptor->b_data); |
627 | header = (journal_header_t *)descriptor->b_data; | ||
628 | header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); | ||
629 | header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK); | ||
630 | header->h_sequence = cpu_to_be32(commit_transaction->t_tid); | ||
631 | |||
632 | tagp = &descriptor->b_data[sizeof(journal_header_t)]; | 626 | tagp = &descriptor->b_data[sizeof(journal_header_t)]; |
633 | space_left = descriptor->b_size - | 627 | space_left = descriptor->b_size - |
634 | sizeof(journal_header_t); | 628 | sizeof(journal_header_t); |
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 81e622681c82..28d05bd9a588 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -805,10 +805,13 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr, | |||
805 | * But we don't bother doing that, so there will be coherency problems with | 805 | * But we don't bother doing that, so there will be coherency problems with |
806 | * mmaps of blockdevs which hold live JBD-controlled filesystems. | 806 | * mmaps of blockdevs which hold live JBD-controlled filesystems. |
807 | */ | 807 | */ |
808 | struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal) | 808 | struct buffer_head * |
809 | jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type) | ||
809 | { | 810 | { |
811 | journal_t *journal = transaction->t_journal; | ||
810 | struct buffer_head *bh; | 812 | struct buffer_head *bh; |
811 | unsigned long long blocknr; | 813 | unsigned long long blocknr; |
814 | journal_header_t *header; | ||
812 | int err; | 815 | int err; |
813 | 816 | ||
814 | err = jbd2_journal_next_log_block(journal, &blocknr); | 817 | err = jbd2_journal_next_log_block(journal, &blocknr); |
@@ -821,6 +824,10 @@ struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal) | |||
821 | return NULL; | 824 | return NULL; |
822 | lock_buffer(bh); | 825 | lock_buffer(bh); |
823 | memset(bh->b_data, 0, journal->j_blocksize); | 826 | memset(bh->b_data, 0, journal->j_blocksize); |
827 | header = (journal_header_t *)bh->b_data; | ||
828 | header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); | ||
829 | header->h_blocktype = cpu_to_be32(type); | ||
830 | header->h_sequence = cpu_to_be32(transaction->t_tid); | ||
824 | set_buffer_uptodate(bh); | 831 | set_buffer_uptodate(bh); |
825 | unlock_buffer(bh); | 832 | unlock_buffer(bh); |
826 | BUFFER_TRACE(bh, "return this buffer"); | 833 | BUFFER_TRACE(bh, "return this buffer"); |
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c index c839332be56b..d1ebb1d41d17 100644 --- a/fs/jbd2/revoke.c +++ b/fs/jbd2/revoke.c | |||
@@ -570,7 +570,6 @@ static void write_one_revoke_record(transaction_t *transaction, | |||
570 | int csum_size = 0; | 570 | int csum_size = 0; |
571 | struct buffer_head *descriptor; | 571 | struct buffer_head *descriptor; |
572 | int sz, offset; | 572 | int sz, offset; |
573 | journal_header_t *header; | ||
574 | 573 | ||
575 | /* If we are already aborting, this all becomes a noop. We | 574 | /* If we are already aborting, this all becomes a noop. We |
576 | still need to go round the loop in | 575 | still need to go round the loop in |
@@ -600,13 +599,10 @@ static void write_one_revoke_record(transaction_t *transaction, | |||
600 | } | 599 | } |
601 | 600 | ||
602 | if (!descriptor) { | 601 | if (!descriptor) { |
603 | descriptor = jbd2_journal_get_descriptor_buffer(journal); | 602 | descriptor = jbd2_journal_get_descriptor_buffer(transaction, |
603 | JBD2_REVOKE_BLOCK); | ||
604 | if (!descriptor) | 604 | if (!descriptor) |
605 | return; | 605 | return; |
606 | header = (journal_header_t *)descriptor->b_data; | ||
607 | header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); | ||
608 | header->h_blocktype = cpu_to_be32(JBD2_REVOKE_BLOCK); | ||
609 | header->h_sequence = cpu_to_be32(transaction->t_tid); | ||
610 | 606 | ||
611 | /* Record it so that we can wait for IO completion later */ | 607 | /* Record it so that we can wait for IO completion later */ |
612 | BUFFER_TRACE(descriptor, "file in log_bufs"); | 608 | BUFFER_TRACE(descriptor, "file in log_bufs"); |
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 5716d9554e77..3649cb8d3a41 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h | |||
@@ -1137,7 +1137,7 @@ static inline void jbd2_unfile_log_bh(struct buffer_head *bh) | |||
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | /* Log buffer allocation */ | 1139 | /* Log buffer allocation */ |
1140 | struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal); | 1140 | struct buffer_head *jbd2_journal_get_descriptor_buffer(transaction_t *, int); |
1141 | int jbd2_journal_next_log_block(journal_t *, unsigned long long *); | 1141 | int jbd2_journal_next_log_block(journal_t *, unsigned long long *); |
1142 | int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid, | 1142 | int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid, |
1143 | unsigned long *block); | 1143 | unsigned long *block); |