aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2016-04-18 05:18:55 -0400
committerJiri Kosina <jkosina@suse.cz>2016-04-18 05:18:55 -0400
commit9938b04472d5c59f8bd8152a548533a8599596a2 (patch)
tree0fc8318100878c5e446076613ec02a97aa179119 /fs/jbd2
parentbd7ced98812dbb906950d8b0ec786f14f631cede (diff)
parentc3b46c73264b03000d1e18b22f5caf63332547c9 (diff)
Merge branch 'master' into for-next
Sync with Linus' tree so that patches against newer codebase can be applied. Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'fs/jbd2')
-rw-r--r--fs/jbd2/commit.c53
-rw-r--r--fs/jbd2/journal.c45
-rw-r--r--fs/jbd2/recovery.c31
-rw-r--r--fs/jbd2/revoke.c60
-rw-r--r--fs/jbd2/transaction.c48
5 files changed, 96 insertions, 141 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 36345fefa3ff..2ad98d6e19f4 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -81,11 +81,11 @@ static void release_buffer_page(struct buffer_head *bh)
81 if (!trylock_page(page)) 81 if (!trylock_page(page))
82 goto nope; 82 goto nope;
83 83
84 page_cache_get(page); 84 get_page(page);
85 __brelse(bh); 85 __brelse(bh);
86 try_to_free_buffers(page); 86 try_to_free_buffers(page);
87 unlock_page(page); 87 unlock_page(page);
88 page_cache_release(page); 88 put_page(page);
89 return; 89 return;
90 90
91nope: 91nope:
@@ -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
@@ -222,7 +220,7 @@ static int journal_submit_data_buffers(journal_t *journal,
222 spin_lock(&journal->j_list_lock); 220 spin_lock(&journal->j_list_lock);
223 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) { 221 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
224 mapping = jinode->i_vfs_inode->i_mapping; 222 mapping = jinode->i_vfs_inode->i_mapping;
225 set_bit(__JI_COMMIT_RUNNING, &jinode->i_flags); 223 jinode->i_flags |= JI_COMMIT_RUNNING;
226 spin_unlock(&journal->j_list_lock); 224 spin_unlock(&journal->j_list_lock);
227 /* 225 /*
228 * submit the inode data buffers. We use writepage 226 * submit the inode data buffers. We use writepage
@@ -236,8 +234,8 @@ static int journal_submit_data_buffers(journal_t *journal,
236 ret = err; 234 ret = err;
237 spin_lock(&journal->j_list_lock); 235 spin_lock(&journal->j_list_lock);
238 J_ASSERT(jinode->i_transaction == commit_transaction); 236 J_ASSERT(jinode->i_transaction == commit_transaction);
239 clear_bit(__JI_COMMIT_RUNNING, &jinode->i_flags); 237 jinode->i_flags &= ~JI_COMMIT_RUNNING;
240 smp_mb__after_atomic(); 238 smp_mb();
241 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); 239 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
242 } 240 }
243 spin_unlock(&journal->j_list_lock); 241 spin_unlock(&journal->j_list_lock);
@@ -258,7 +256,7 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
258 /* For locking, see the comment in journal_submit_data_buffers() */ 256 /* For locking, see the comment in journal_submit_data_buffers() */
259 spin_lock(&journal->j_list_lock); 257 spin_lock(&journal->j_list_lock);
260 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) { 258 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
261 set_bit(__JI_COMMIT_RUNNING, &jinode->i_flags); 259 jinode->i_flags |= JI_COMMIT_RUNNING;
262 spin_unlock(&journal->j_list_lock); 260 spin_unlock(&journal->j_list_lock);
263 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping); 261 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
264 if (err) { 262 if (err) {
@@ -274,8 +272,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
274 ret = err; 272 ret = err;
275 } 273 }
276 spin_lock(&journal->j_list_lock); 274 spin_lock(&journal->j_list_lock);
277 clear_bit(__JI_COMMIT_RUNNING, &jinode->i_flags); 275 jinode->i_flags &= ~JI_COMMIT_RUNNING;
278 smp_mb__after_atomic(); 276 smp_mb();
279 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); 277 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
280 } 278 }
281 279
@@ -319,22 +317,6 @@ static void write_tag_block(journal_t *j, journal_block_tag_t *tag,
319 tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1); 317 tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
320} 318}
321 319
322static void jbd2_descr_block_csum_set(journal_t *j,
323 struct buffer_head *bh)
324{
325 struct jbd2_journal_block_tail *tail;
326 __u32 csum;
327
328 if (!jbd2_journal_has_csum_v2or3(j))
329 return;
330
331 tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
332 sizeof(struct jbd2_journal_block_tail));
333 tail->t_checksum = 0;
334 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
335 tail->t_checksum = cpu_to_be32(csum);
336}
337
338static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, 320static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
339 struct buffer_head *bh, __u32 sequence) 321 struct buffer_head *bh, __u32 sequence)
340{ 322{
@@ -379,7 +361,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
379 ktime_t start_time; 361 ktime_t start_time;
380 u64 commit_time; 362 u64 commit_time;
381 char *tagp = NULL; 363 char *tagp = NULL;
382 journal_header_t *header;
383 journal_block_tag_t *tag = NULL; 364 journal_block_tag_t *tag = NULL;
384 int space_left = 0; 365 int space_left = 0;
385 int first_tag = 0; 366 int first_tag = 0;
@@ -554,8 +535,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
554 jbd2_journal_abort(journal, err); 535 jbd2_journal_abort(journal, err);
555 536
556 blk_start_plug(&plug); 537 blk_start_plug(&plug);
557 jbd2_journal_write_revoke_records(journal, commit_transaction, 538 jbd2_journal_write_revoke_records(commit_transaction, &log_bufs);
558 &log_bufs, WRITE_SYNC);
559 539
560 jbd_debug(3, "JBD2: commit phase 2b\n"); 540 jbd_debug(3, "JBD2: commit phase 2b\n");
561 541
@@ -616,7 +596,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
616 596
617 jbd_debug(4, "JBD2: get descriptor\n"); 597 jbd_debug(4, "JBD2: get descriptor\n");
618 598
619 descriptor = jbd2_journal_get_descriptor_buffer(journal); 599 descriptor = jbd2_journal_get_descriptor_buffer(
600 commit_transaction,
601 JBD2_DESCRIPTOR_BLOCK);
620 if (!descriptor) { 602 if (!descriptor) {
621 jbd2_journal_abort(journal, -EIO); 603 jbd2_journal_abort(journal, -EIO);
622 continue; 604 continue;
@@ -625,11 +607,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
625 jbd_debug(4, "JBD2: got buffer %llu (%p)\n", 607 jbd_debug(4, "JBD2: got buffer %llu (%p)\n",
626 (unsigned long long)descriptor->b_blocknr, 608 (unsigned long long)descriptor->b_blocknr,
627 descriptor->b_data); 609 descriptor->b_data);
628 header = (journal_header_t *)descriptor->b_data;
629 header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
630 header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
631 header->h_sequence = cpu_to_be32(commit_transaction->t_tid);
632
633 tagp = &descriptor->b_data[sizeof(journal_header_t)]; 610 tagp = &descriptor->b_data[sizeof(journal_header_t)];
634 space_left = descriptor->b_size - 611 space_left = descriptor->b_size -
635 sizeof(journal_header_t); 612 sizeof(journal_header_t);
@@ -721,7 +698,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
721 698
722 tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG); 699 tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
723 700
724 jbd2_descr_block_csum_set(journal, descriptor); 701 jbd2_descriptor_block_csum_set(journal, descriptor);
725start_journal_io: 702start_journal_io:
726 for (i = 0; i < bufs; i++) { 703 for (i = 0; i < bufs; i++) {
727 struct buffer_head *bh = wbuf[i]; 704 struct buffer_head *bh = wbuf[i];
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 81e622681c82..435f0b26ac20 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 */
808struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal) 808struct buffer_head *
809jbd2_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,12 +824,31 @@ 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");
827 return bh; 834 return bh;
828} 835}
829 836
837void jbd2_descriptor_block_csum_set(journal_t *j, struct buffer_head *bh)
838{
839 struct jbd2_journal_block_tail *tail;
840 __u32 csum;
841
842 if (!jbd2_journal_has_csum_v2or3(j))
843 return;
844
845 tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
846 sizeof(struct jbd2_journal_block_tail));
847 tail->t_checksum = 0;
848 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
849 tail->t_checksum = cpu_to_be32(csum);
850}
851
830/* 852/*
831 * Return tid of the oldest transaction in the journal and block in the journal 853 * Return tid of the oldest transaction in the journal and block in the journal
832 * where the transaction starts. 854 * where the transaction starts.
@@ -1408,11 +1430,12 @@ out:
1408/** 1430/**
1409 * jbd2_mark_journal_empty() - Mark on disk journal as empty. 1431 * jbd2_mark_journal_empty() - Mark on disk journal as empty.
1410 * @journal: The journal to update. 1432 * @journal: The journal to update.
1433 * @write_op: With which operation should we write the journal sb
1411 * 1434 *
1412 * Update a journal's dynamic superblock fields to show that journal is empty. 1435 * Update a journal's dynamic superblock fields to show that journal is empty.
1413 * Write updated superblock to disk waiting for IO to complete. 1436 * Write updated superblock to disk waiting for IO to complete.
1414 */ 1437 */
1415static void jbd2_mark_journal_empty(journal_t *journal) 1438static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
1416{ 1439{
1417 journal_superblock_t *sb = journal->j_superblock; 1440 journal_superblock_t *sb = journal->j_superblock;
1418 1441
@@ -1430,7 +1453,7 @@ static void jbd2_mark_journal_empty(journal_t *journal)
1430 sb->s_start = cpu_to_be32(0); 1453 sb->s_start = cpu_to_be32(0);
1431 read_unlock(&journal->j_state_lock); 1454 read_unlock(&journal->j_state_lock);
1432 1455
1433 jbd2_write_superblock(journal, WRITE_FUA); 1456 jbd2_write_superblock(journal, write_op);
1434 1457
1435 /* Log is no longer empty */ 1458 /* Log is no longer empty */
1436 write_lock(&journal->j_state_lock); 1459 write_lock(&journal->j_state_lock);
@@ -1716,7 +1739,13 @@ int jbd2_journal_destroy(journal_t *journal)
1716 if (journal->j_sb_buffer) { 1739 if (journal->j_sb_buffer) {
1717 if (!is_journal_aborted(journal)) { 1740 if (!is_journal_aborted(journal)) {
1718 mutex_lock(&journal->j_checkpoint_mutex); 1741 mutex_lock(&journal->j_checkpoint_mutex);
1719 jbd2_mark_journal_empty(journal); 1742
1743 write_lock(&journal->j_state_lock);
1744 journal->j_tail_sequence =
1745 ++journal->j_transaction_sequence;
1746 write_unlock(&journal->j_state_lock);
1747
1748 jbd2_mark_journal_empty(journal, WRITE_FLUSH_FUA);
1720 mutex_unlock(&journal->j_checkpoint_mutex); 1749 mutex_unlock(&journal->j_checkpoint_mutex);
1721 } else 1750 } else
1722 err = -EIO; 1751 err = -EIO;
@@ -1975,7 +2004,7 @@ int jbd2_journal_flush(journal_t *journal)
1975 * the magic code for a fully-recovered superblock. Any future 2004 * the magic code for a fully-recovered superblock. Any future
1976 * commits of data to the journal will restore the current 2005 * commits of data to the journal will restore the current
1977 * s_start value. */ 2006 * s_start value. */
1978 jbd2_mark_journal_empty(journal); 2007 jbd2_mark_journal_empty(journal, WRITE_FUA);
1979 mutex_unlock(&journal->j_checkpoint_mutex); 2008 mutex_unlock(&journal->j_checkpoint_mutex);
1980 write_lock(&journal->j_state_lock); 2009 write_lock(&journal->j_state_lock);
1981 J_ASSERT(!journal->j_running_transaction); 2010 J_ASSERT(!journal->j_running_transaction);
@@ -2021,7 +2050,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)
2021 if (write) { 2050 if (write) {
2022 /* Lock to make assertions happy... */ 2051 /* Lock to make assertions happy... */
2023 mutex_lock(&journal->j_checkpoint_mutex); 2052 mutex_lock(&journal->j_checkpoint_mutex);
2024 jbd2_mark_journal_empty(journal); 2053 jbd2_mark_journal_empty(journal, WRITE_FUA);
2025 mutex_unlock(&journal->j_checkpoint_mutex); 2054 mutex_unlock(&journal->j_checkpoint_mutex);
2026 } 2055 }
2027 2056
@@ -2192,7 +2221,7 @@ void jbd2_journal_ack_err(journal_t *journal)
2192 2221
2193int jbd2_journal_blocks_per_page(struct inode *inode) 2222int jbd2_journal_blocks_per_page(struct inode *inode)
2194{ 2223{
2195 return 1 << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); 2224 return 1 << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);
2196} 2225}
2197 2226
2198/* 2227/*
@@ -2565,7 +2594,7 @@ void jbd2_journal_release_jbd_inode(journal_t *journal,
2565restart: 2594restart:
2566 spin_lock(&journal->j_list_lock); 2595 spin_lock(&journal->j_list_lock);
2567 /* Is commit writing out inode - we have to wait */ 2596 /* Is commit writing out inode - we have to wait */
2568 if (test_bit(__JI_COMMIT_RUNNING, &jinode->i_flags)) { 2597 if (jinode->i_flags & JI_COMMIT_RUNNING) {
2569 wait_queue_head_t *wq; 2598 wait_queue_head_t *wq;
2570 DEFINE_WAIT_BIT(wait, &jinode->i_flags, __JI_COMMIT_RUNNING); 2599 DEFINE_WAIT_BIT(wait, &jinode->i_flags, __JI_COMMIT_RUNNING);
2571 wq = bit_waitqueue(&jinode->i_flags, __JI_COMMIT_RUNNING); 2600 wq = bit_waitqueue(&jinode->i_flags, __JI_COMMIT_RUNNING);
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 76579c28edc7..805bc6bcd8ab 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -174,8 +174,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
174 return 0; 174 return 0;
175} 175}
176 176
177static int jbd2_descr_block_csum_verify(journal_t *j, 177static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf)
178 void *buf)
179{ 178{
180 struct jbd2_journal_block_tail *tail; 179 struct jbd2_journal_block_tail *tail;
181 __be32 provided; 180 __be32 provided;
@@ -522,8 +521,8 @@ static int do_one_pass(journal_t *journal,
522 descr_csum_size = 521 descr_csum_size =
523 sizeof(struct jbd2_journal_block_tail); 522 sizeof(struct jbd2_journal_block_tail);
524 if (descr_csum_size > 0 && 523 if (descr_csum_size > 0 &&
525 !jbd2_descr_block_csum_verify(journal, 524 !jbd2_descriptor_block_csum_verify(journal,
526 bh->b_data)) { 525 bh->b_data)) {
527 printk(KERN_ERR "JBD2: Invalid checksum " 526 printk(KERN_ERR "JBD2: Invalid checksum "
528 "recovering block %lu in log\n", 527 "recovering block %lu in log\n",
529 next_log_block); 528 next_log_block);
@@ -811,26 +810,6 @@ static int do_one_pass(journal_t *journal,
811 return err; 810 return err;
812} 811}
813 812
814static int jbd2_revoke_block_csum_verify(journal_t *j,
815 void *buf)
816{
817 struct jbd2_journal_revoke_tail *tail;
818 __be32 provided;
819 __u32 calculated;
820
821 if (!jbd2_journal_has_csum_v2or3(j))
822 return 1;
823
824 tail = (struct jbd2_journal_revoke_tail *)(buf + j->j_blocksize -
825 sizeof(struct jbd2_journal_revoke_tail));
826 provided = tail->r_checksum;
827 tail->r_checksum = 0;
828 calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
829 tail->r_checksum = provided;
830
831 return provided == cpu_to_be32(calculated);
832}
833
834/* Scan a revoke record, marking all blocks mentioned as revoked. */ 813/* Scan a revoke record, marking all blocks mentioned as revoked. */
835 814
836static int scan_revoke_records(journal_t *journal, struct buffer_head *bh, 815static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
@@ -846,11 +825,11 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
846 offset = sizeof(jbd2_journal_revoke_header_t); 825 offset = sizeof(jbd2_journal_revoke_header_t);
847 rcount = be32_to_cpu(header->r_count); 826 rcount = be32_to_cpu(header->r_count);
848 827
849 if (!jbd2_revoke_block_csum_verify(journal, header)) 828 if (!jbd2_descriptor_block_csum_verify(journal, header))
850 return -EFSBADCRC; 829 return -EFSBADCRC;
851 830
852 if (jbd2_journal_has_csum_v2or3(journal)) 831 if (jbd2_journal_has_csum_v2or3(journal))
853 csum_size = sizeof(struct jbd2_journal_revoke_tail); 832 csum_size = sizeof(struct jbd2_journal_block_tail);
854 if (rcount > journal->j_blocksize - csum_size) 833 if (rcount > journal->j_blocksize - csum_size)
855 return -EINVAL; 834 return -EINVAL;
856 max = rcount; 835 max = rcount;
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 705ae577882b..91171dc352cb 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -122,11 +122,11 @@ struct jbd2_revoke_table_s
122 122
123 123
124#ifdef __KERNEL__ 124#ifdef __KERNEL__
125static void write_one_revoke_record(journal_t *, transaction_t *, 125static void write_one_revoke_record(transaction_t *,
126 struct list_head *, 126 struct list_head *,
127 struct buffer_head **, int *, 127 struct buffer_head **, int *,
128 struct jbd2_revoke_record_s *, int); 128 struct jbd2_revoke_record_s *);
129static void flush_descriptor(journal_t *, struct buffer_head *, int, int); 129static void flush_descriptor(journal_t *, struct buffer_head *, int);
130#endif 130#endif
131 131
132/* Utility functions to maintain the revoke table */ 132/* Utility functions to maintain the revoke table */
@@ -519,11 +519,10 @@ void jbd2_journal_switch_revoke_table(journal_t *journal)
519 * Write revoke records to the journal for all entries in the current 519 * Write revoke records to the journal for all entries in the current
520 * revoke hash, deleting the entries as we go. 520 * revoke hash, deleting the entries as we go.
521 */ 521 */
522void jbd2_journal_write_revoke_records(journal_t *journal, 522void jbd2_journal_write_revoke_records(transaction_t *transaction,
523 transaction_t *transaction, 523 struct list_head *log_bufs)
524 struct list_head *log_bufs,
525 int write_op)
526{ 524{
525 journal_t *journal = transaction->t_journal;
527 struct buffer_head *descriptor; 526 struct buffer_head *descriptor;
528 struct jbd2_revoke_record_s *record; 527 struct jbd2_revoke_record_s *record;
529 struct jbd2_revoke_table_s *revoke; 528 struct jbd2_revoke_table_s *revoke;
@@ -544,16 +543,15 @@ void jbd2_journal_write_revoke_records(journal_t *journal,
544 while (!list_empty(hash_list)) { 543 while (!list_empty(hash_list)) {
545 record = (struct jbd2_revoke_record_s *) 544 record = (struct jbd2_revoke_record_s *)
546 hash_list->next; 545 hash_list->next;
547 write_one_revoke_record(journal, transaction, log_bufs, 546 write_one_revoke_record(transaction, log_bufs,
548 &descriptor, &offset, 547 &descriptor, &offset, record);
549 record, write_op);
550 count++; 548 count++;
551 list_del(&record->hash); 549 list_del(&record->hash);
552 kmem_cache_free(jbd2_revoke_record_cache, record); 550 kmem_cache_free(jbd2_revoke_record_cache, record);
553 } 551 }
554 } 552 }
555 if (descriptor) 553 if (descriptor)
556 flush_descriptor(journal, descriptor, offset, write_op); 554 flush_descriptor(journal, descriptor, offset);
557 jbd_debug(1, "Wrote %d revoke records\n", count); 555 jbd_debug(1, "Wrote %d revoke records\n", count);
558} 556}
559 557
@@ -562,18 +560,16 @@ void jbd2_journal_write_revoke_records(journal_t *journal,
562 * block if the old one is full or if we have not already created one. 560 * block if the old one is full or if we have not already created one.
563 */ 561 */
564 562
565static void write_one_revoke_record(journal_t *journal, 563static void write_one_revoke_record(transaction_t *transaction,
566 transaction_t *transaction,
567 struct list_head *log_bufs, 564 struct list_head *log_bufs,
568 struct buffer_head **descriptorp, 565 struct buffer_head **descriptorp,
569 int *offsetp, 566 int *offsetp,
570 struct jbd2_revoke_record_s *record, 567 struct jbd2_revoke_record_s *record)
571 int write_op)
572{ 568{
569 journal_t *journal = transaction->t_journal;
573 int csum_size = 0; 570 int csum_size = 0;
574 struct buffer_head *descriptor; 571 struct buffer_head *descriptor;
575 int sz, offset; 572 int sz, offset;
576 journal_header_t *header;
577 573
578 /* If we are already aborting, this all becomes a noop. We 574 /* If we are already aborting, this all becomes a noop. We
579 still need to go round the loop in 575 still need to go round the loop in
@@ -587,7 +583,7 @@ static void write_one_revoke_record(journal_t *journal,
587 583
588 /* Do we need to leave space at the end for a checksum? */ 584 /* Do we need to leave space at the end for a checksum? */
589 if (jbd2_journal_has_csum_v2or3(journal)) 585 if (jbd2_journal_has_csum_v2or3(journal))
590 csum_size = sizeof(struct jbd2_journal_revoke_tail); 586 csum_size = sizeof(struct jbd2_journal_block_tail);
591 587
592 if (jbd2_has_feature_64bit(journal)) 588 if (jbd2_has_feature_64bit(journal))
593 sz = 8; 589 sz = 8;
@@ -597,19 +593,16 @@ static void write_one_revoke_record(journal_t *journal,
597 /* Make sure we have a descriptor with space left for the record */ 593 /* Make sure we have a descriptor with space left for the record */
598 if (descriptor) { 594 if (descriptor) {
599 if (offset + sz > journal->j_blocksize - csum_size) { 595 if (offset + sz > journal->j_blocksize - csum_size) {
600 flush_descriptor(journal, descriptor, offset, write_op); 596 flush_descriptor(journal, descriptor, offset);
601 descriptor = NULL; 597 descriptor = NULL;
602 } 598 }
603 } 599 }
604 600
605 if (!descriptor) { 601 if (!descriptor) {
606 descriptor = jbd2_journal_get_descriptor_buffer(journal); 602 descriptor = jbd2_journal_get_descriptor_buffer(transaction,
603 JBD2_REVOKE_BLOCK);
607 if (!descriptor) 604 if (!descriptor)
608 return; 605 return;
609 header = (journal_header_t *)descriptor->b_data;
610 header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
611 header->h_blocktype = cpu_to_be32(JBD2_REVOKE_BLOCK);
612 header->h_sequence = cpu_to_be32(transaction->t_tid);
613 606
614 /* Record it so that we can wait for IO completion later */ 607 /* Record it so that we can wait for IO completion later */
615 BUFFER_TRACE(descriptor, "file in log_bufs"); 608 BUFFER_TRACE(descriptor, "file in log_bufs");
@@ -630,21 +623,6 @@ static void write_one_revoke_record(journal_t *journal,
630 *offsetp = offset; 623 *offsetp = offset;
631} 624}
632 625
633static void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
634{
635 struct jbd2_journal_revoke_tail *tail;
636 __u32 csum;
637
638 if (!jbd2_journal_has_csum_v2or3(j))
639 return;
640
641 tail = (struct jbd2_journal_revoke_tail *)(bh->b_data + j->j_blocksize -
642 sizeof(struct jbd2_journal_revoke_tail));
643 tail->r_checksum = 0;
644 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
645 tail->r_checksum = cpu_to_be32(csum);
646}
647
648/* 626/*
649 * Flush a revoke descriptor out to the journal. If we are aborting, 627 * Flush a revoke descriptor out to the journal. If we are aborting,
650 * this is a noop; otherwise we are generating a buffer which needs to 628 * this is a noop; otherwise we are generating a buffer which needs to
@@ -654,7 +632,7 @@ static void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
654 632
655static void flush_descriptor(journal_t *journal, 633static void flush_descriptor(journal_t *journal,
656 struct buffer_head *descriptor, 634 struct buffer_head *descriptor,
657 int offset, int write_op) 635 int offset)
658{ 636{
659 jbd2_journal_revoke_header_t *header; 637 jbd2_journal_revoke_header_t *header;
660 638
@@ -665,12 +643,12 @@ static void flush_descriptor(journal_t *journal,
665 643
666 header = (jbd2_journal_revoke_header_t *)descriptor->b_data; 644 header = (jbd2_journal_revoke_header_t *)descriptor->b_data;
667 header->r_count = cpu_to_be32(offset); 645 header->r_count = cpu_to_be32(offset);
668 jbd2_revoke_csum_set(journal, descriptor); 646 jbd2_descriptor_block_csum_set(journal, descriptor);
669 647
670 set_buffer_jwrite(descriptor); 648 set_buffer_jwrite(descriptor);
671 BUFFER_TRACE(descriptor, "write"); 649 BUFFER_TRACE(descriptor, "write");
672 set_buffer_dirty(descriptor); 650 set_buffer_dirty(descriptor);
673 write_dirty_buffer(descriptor, write_op); 651 write_dirty_buffer(descriptor, WRITE_SYNC);
674} 652}
675#endif 653#endif
676 654
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 98d04c5fe3d2..2c56c3e32194 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -764,13 +764,11 @@ void jbd2_journal_unlock_updates (journal_t *journal)
764 764
765static void warn_dirty_buffer(struct buffer_head *bh) 765static void warn_dirty_buffer(struct buffer_head *bh)
766{ 766{
767 char b[BDEVNAME_SIZE];
768
769 printk(KERN_WARNING 767 printk(KERN_WARNING
770 "JBD2: Spotted dirty metadata buffer (dev = %s, blocknr = %llu). " 768 "JBD2: Spotted dirty metadata buffer (dev = %pg, blocknr = %llu). "
771 "There's a risk of filesystem corruption in case of system " 769 "There's a risk of filesystem corruption in case of system "
772 "crash.\n", 770 "crash.\n",
773 bdevname(bh->b_bdev, b), (unsigned long long)bh->b_blocknr); 771 bh->b_bdev, (unsigned long long)bh->b_blocknr);
774} 772}
775 773
776/* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */ 774/* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */
@@ -968,14 +966,8 @@ repeat:
968 if (!frozen_buffer) { 966 if (!frozen_buffer) {
969 JBUFFER_TRACE(jh, "allocate memory for buffer"); 967 JBUFFER_TRACE(jh, "allocate memory for buffer");
970 jbd_unlock_bh_state(bh); 968 jbd_unlock_bh_state(bh);
971 frozen_buffer = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS); 969 frozen_buffer = jbd2_alloc(jh2bh(jh)->b_size,
972 if (!frozen_buffer) { 970 GFP_NOFS | __GFP_NOFAIL);
973 printk(KERN_ERR "%s: OOM for frozen_buffer\n",
974 __func__);
975 JBUFFER_TRACE(jh, "oom!");
976 error = -ENOMEM;
977 goto out;
978 }
979 goto repeat; 971 goto repeat;
980 } 972 }
981 jh->b_frozen_data = frozen_buffer; 973 jh->b_frozen_data = frozen_buffer;
@@ -1009,7 +1001,8 @@ out:
1009} 1001}
1010 1002
1011/* Fast check whether buffer is already attached to the required transaction */ 1003/* Fast check whether buffer is already attached to the required transaction */
1012static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh) 1004static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh,
1005 bool undo)
1013{ 1006{
1014 struct journal_head *jh; 1007 struct journal_head *jh;
1015 bool ret = false; 1008 bool ret = false;
@@ -1036,6 +1029,9 @@ static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh)
1036 jh = READ_ONCE(bh->b_private); 1029 jh = READ_ONCE(bh->b_private);
1037 if (!jh) 1030 if (!jh)
1038 goto out; 1031 goto out;
1032 /* For undo access buffer must have data copied */
1033 if (undo && !jh->b_committed_data)
1034 goto out;
1039 if (jh->b_transaction != handle->h_transaction && 1035 if (jh->b_transaction != handle->h_transaction &&
1040 jh->b_next_transaction != handle->h_transaction) 1036 jh->b_next_transaction != handle->h_transaction)
1041 goto out; 1037 goto out;
@@ -1073,7 +1069,7 @@ int jbd2_journal_get_write_access(handle_t *handle, struct buffer_head *bh)
1073 struct journal_head *jh; 1069 struct journal_head *jh;
1074 int rc; 1070 int rc;
1075 1071
1076 if (jbd2_write_access_granted(handle, bh)) 1072 if (jbd2_write_access_granted(handle, bh, false))
1077 return 0; 1073 return 0;
1078 1074
1079 jh = jbd2_journal_add_journal_head(bh); 1075 jh = jbd2_journal_add_journal_head(bh);
@@ -1210,7 +1206,7 @@ int jbd2_journal_get_undo_access(handle_t *handle, struct buffer_head *bh)
1210 char *committed_data = NULL; 1206 char *committed_data = NULL;
1211 1207
1212 JBUFFER_TRACE(jh, "entry"); 1208 JBUFFER_TRACE(jh, "entry");
1213 if (jbd2_write_access_granted(handle, bh)) 1209 if (jbd2_write_access_granted(handle, bh, true))
1214 return 0; 1210 return 0;
1215 1211
1216 jh = jbd2_journal_add_journal_head(bh); 1212 jh = jbd2_journal_add_journal_head(bh);
@@ -1224,15 +1220,9 @@ int jbd2_journal_get_undo_access(handle_t *handle, struct buffer_head *bh)
1224 goto out; 1220 goto out;
1225 1221
1226repeat: 1222repeat:
1227 if (!jh->b_committed_data) { 1223 if (!jh->b_committed_data)
1228 committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS); 1224 committed_data = jbd2_alloc(jh2bh(jh)->b_size,
1229 if (!committed_data) { 1225 GFP_NOFS|__GFP_NOFAIL);
1230 printk(KERN_ERR "%s: No memory for committed data\n",
1231 __func__);
1232 err = -ENOMEM;
1233 goto out;
1234 }
1235 }
1236 1226
1237 jbd_lock_bh_state(bh); 1227 jbd_lock_bh_state(bh);
1238 if (!jh->b_committed_data) { 1228 if (!jh->b_committed_data) {
@@ -1937,8 +1927,8 @@ out:
1937 * @journal: journal for operation 1927 * @journal: journal for operation
1938 * @page: to try and free 1928 * @page: to try and free
1939 * @gfp_mask: we use the mask to detect how hard should we try to release 1929 * @gfp_mask: we use the mask to detect how hard should we try to release
1940 * buffers. If __GFP_WAIT and __GFP_FS is set, we wait for commit code to 1930 * buffers. If __GFP_DIRECT_RECLAIM and __GFP_FS is set, we wait for commit
1941 * release the buffers. 1931 * code to release the buffers.
1942 * 1932 *
1943 * 1933 *
1944 * For all the buffers on this page, 1934 * For all the buffers on this page,
@@ -2152,6 +2142,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,
2152 2142
2153 if (!buffer_dirty(bh)) { 2143 if (!buffer_dirty(bh)) {
2154 /* bdflush has written it. We can drop it now */ 2144 /* bdflush has written it. We can drop it now */
2145 __jbd2_journal_remove_checkpoint(jh);
2155 goto zap_buffer; 2146 goto zap_buffer;
2156 } 2147 }
2157 2148
@@ -2181,6 +2172,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,
2181 /* The orphan record's transaction has 2172 /* The orphan record's transaction has
2182 * committed. We can cleanse this buffer */ 2173 * committed. We can cleanse this buffer */
2183 clear_buffer_jbddirty(bh); 2174 clear_buffer_jbddirty(bh);
2175 __jbd2_journal_remove_checkpoint(jh);
2184 goto zap_buffer; 2176 goto zap_buffer;
2185 } 2177 }
2186 } 2178 }
@@ -2271,7 +2263,7 @@ int jbd2_journal_invalidatepage(journal_t *journal,
2271 struct buffer_head *head, *bh, *next; 2263 struct buffer_head *head, *bh, *next;
2272 unsigned int stop = offset + length; 2264 unsigned int stop = offset + length;
2273 unsigned int curr_off = 0; 2265 unsigned int curr_off = 0;
2274 int partial_page = (offset || length < PAGE_CACHE_SIZE); 2266 int partial_page = (offset || length < PAGE_SIZE);
2275 int may_free = 1; 2267 int may_free = 1;
2276 int ret = 0; 2268 int ret = 0;
2277 2269
@@ -2280,7 +2272,7 @@ int jbd2_journal_invalidatepage(journal_t *journal,
2280 if (!page_has_buffers(page)) 2272 if (!page_has_buffers(page))
2281 return 0; 2273 return 0;
2282 2274
2283 BUG_ON(stop > PAGE_CACHE_SIZE || stop < length); 2275 BUG_ON(stop > PAGE_SIZE || stop < length);
2284 2276
2285 /* We will potentially be playing with lists other than just the 2277 /* We will potentially be playing with lists other than just the
2286 * data lists (especially for journaled data mode), so be 2278 * data lists (especially for journaled data mode), so be