diff options
Diffstat (limited to 'fs/jbd2/commit.c')
-rw-r--r-- | fs/jbd2/commit.c | 184 |
1 files changed, 77 insertions, 107 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 0f53946f13c1..559bec1a37b4 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c | |||
@@ -30,15 +30,22 @@ | |||
30 | #include <trace/events/jbd2.h> | 30 | #include <trace/events/jbd2.h> |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Default IO end handler for temporary BJ_IO buffer_heads. | 33 | * IO end handler for temporary buffer_heads handling writes to the journal. |
34 | */ | 34 | */ |
35 | static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate) | 35 | static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate) |
36 | { | 36 | { |
37 | struct buffer_head *orig_bh = bh->b_private; | ||
38 | |||
37 | BUFFER_TRACE(bh, ""); | 39 | BUFFER_TRACE(bh, ""); |
38 | if (uptodate) | 40 | if (uptodate) |
39 | set_buffer_uptodate(bh); | 41 | set_buffer_uptodate(bh); |
40 | else | 42 | else |
41 | clear_buffer_uptodate(bh); | 43 | clear_buffer_uptodate(bh); |
44 | if (orig_bh) { | ||
45 | clear_bit_unlock(BH_Shadow, &orig_bh->b_state); | ||
46 | smp_mb__after_clear_bit(); | ||
47 | wake_up_bit(&orig_bh->b_state, BH_Shadow); | ||
48 | } | ||
42 | unlock_buffer(bh); | 49 | unlock_buffer(bh); |
43 | } | 50 | } |
44 | 51 | ||
@@ -85,8 +92,7 @@ nope: | |||
85 | __brelse(bh); | 92 | __brelse(bh); |
86 | } | 93 | } |
87 | 94 | ||
88 | static void jbd2_commit_block_csum_set(journal_t *j, | 95 | static void jbd2_commit_block_csum_set(journal_t *j, struct buffer_head *bh) |
89 | struct journal_head *descriptor) | ||
90 | { | 96 | { |
91 | struct commit_header *h; | 97 | struct commit_header *h; |
92 | __u32 csum; | 98 | __u32 csum; |
@@ -94,12 +100,11 @@ static void jbd2_commit_block_csum_set(journal_t *j, | |||
94 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) | 100 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) |
95 | return; | 101 | return; |
96 | 102 | ||
97 | h = (struct commit_header *)(jh2bh(descriptor)->b_data); | 103 | h = (struct commit_header *)(bh->b_data); |
98 | h->h_chksum_type = 0; | 104 | h->h_chksum_type = 0; |
99 | h->h_chksum_size = 0; | 105 | h->h_chksum_size = 0; |
100 | h->h_chksum[0] = 0; | 106 | h->h_chksum[0] = 0; |
101 | csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data, | 107 | csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize); |
102 | j->j_blocksize); | ||
103 | h->h_chksum[0] = cpu_to_be32(csum); | 108 | h->h_chksum[0] = cpu_to_be32(csum); |
104 | } | 109 | } |
105 | 110 | ||
@@ -116,7 +121,6 @@ static int journal_submit_commit_record(journal_t *journal, | |||
116 | struct buffer_head **cbh, | 121 | struct buffer_head **cbh, |
117 | __u32 crc32_sum) | 122 | __u32 crc32_sum) |
118 | { | 123 | { |
119 | struct journal_head *descriptor; | ||
120 | struct commit_header *tmp; | 124 | struct commit_header *tmp; |
121 | struct buffer_head *bh; | 125 | struct buffer_head *bh; |
122 | int ret; | 126 | int ret; |
@@ -127,12 +131,10 @@ static int journal_submit_commit_record(journal_t *journal, | |||
127 | if (is_journal_aborted(journal)) | 131 | if (is_journal_aborted(journal)) |
128 | return 0; | 132 | return 0; |
129 | 133 | ||
130 | descriptor = jbd2_journal_get_descriptor_buffer(journal); | 134 | bh = jbd2_journal_get_descriptor_buffer(journal); |
131 | if (!descriptor) | 135 | if (!bh) |
132 | return 1; | 136 | return 1; |
133 | 137 | ||
134 | bh = jh2bh(descriptor); | ||
135 | |||
136 | tmp = (struct commit_header *)bh->b_data; | 138 | tmp = (struct commit_header *)bh->b_data; |
137 | tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); | 139 | tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); |
138 | tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK); | 140 | tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK); |
@@ -146,9 +148,9 @@ static int journal_submit_commit_record(journal_t *journal, | |||
146 | tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE; | 148 | tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE; |
147 | tmp->h_chksum[0] = cpu_to_be32(crc32_sum); | 149 | tmp->h_chksum[0] = cpu_to_be32(crc32_sum); |
148 | } | 150 | } |
149 | jbd2_commit_block_csum_set(journal, descriptor); | 151 | jbd2_commit_block_csum_set(journal, bh); |
150 | 152 | ||
151 | JBUFFER_TRACE(descriptor, "submit commit block"); | 153 | BUFFER_TRACE(bh, "submit commit block"); |
152 | lock_buffer(bh); | 154 | lock_buffer(bh); |
153 | clear_buffer_dirty(bh); | 155 | clear_buffer_dirty(bh); |
154 | set_buffer_uptodate(bh); | 156 | set_buffer_uptodate(bh); |
@@ -180,7 +182,6 @@ static int journal_wait_on_commit_record(journal_t *journal, | |||
180 | if (unlikely(!buffer_uptodate(bh))) | 182 | if (unlikely(!buffer_uptodate(bh))) |
181 | ret = -EIO; | 183 | ret = -EIO; |
182 | put_bh(bh); /* One for getblk() */ | 184 | put_bh(bh); /* One for getblk() */ |
183 | jbd2_journal_put_journal_head(bh2jh(bh)); | ||
184 | 185 | ||
185 | return ret; | 186 | return ret; |
186 | } | 187 | } |
@@ -321,7 +322,7 @@ static void write_tag_block(int tag_bytes, journal_block_tag_t *tag, | |||
321 | } | 322 | } |
322 | 323 | ||
323 | static void jbd2_descr_block_csum_set(journal_t *j, | 324 | static void jbd2_descr_block_csum_set(journal_t *j, |
324 | struct journal_head *descriptor) | 325 | struct buffer_head *bh) |
325 | { | 326 | { |
326 | struct jbd2_journal_block_tail *tail; | 327 | struct jbd2_journal_block_tail *tail; |
327 | __u32 csum; | 328 | __u32 csum; |
@@ -329,12 +330,10 @@ static void jbd2_descr_block_csum_set(journal_t *j, | |||
329 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) | 330 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) |
330 | return; | 331 | return; |
331 | 332 | ||
332 | tail = (struct jbd2_journal_block_tail *) | 333 | tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize - |
333 | (jh2bh(descriptor)->b_data + j->j_blocksize - | ||
334 | sizeof(struct jbd2_journal_block_tail)); | 334 | sizeof(struct jbd2_journal_block_tail)); |
335 | tail->t_checksum = 0; | 335 | tail->t_checksum = 0; |
336 | csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data, | 336 | csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize); |
337 | j->j_blocksize); | ||
338 | tail->t_checksum = cpu_to_be32(csum); | 337 | tail->t_checksum = cpu_to_be32(csum); |
339 | } | 338 | } |
340 | 339 | ||
@@ -343,20 +342,21 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, | |||
343 | { | 342 | { |
344 | struct page *page = bh->b_page; | 343 | struct page *page = bh->b_page; |
345 | __u8 *addr; | 344 | __u8 *addr; |
346 | __u32 csum; | 345 | __u32 csum32; |
347 | 346 | ||
348 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) | 347 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) |
349 | return; | 348 | return; |
350 | 349 | ||
351 | sequence = cpu_to_be32(sequence); | 350 | sequence = cpu_to_be32(sequence); |
352 | addr = kmap_atomic(page); | 351 | addr = kmap_atomic(page); |
353 | csum = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence, | 352 | csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence, |
354 | sizeof(sequence)); | 353 | sizeof(sequence)); |
355 | csum = jbd2_chksum(j, csum, addr + offset_in_page(bh->b_data), | 354 | csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data), |
356 | bh->b_size); | 355 | bh->b_size); |
357 | kunmap_atomic(addr); | 356 | kunmap_atomic(addr); |
358 | 357 | ||
359 | tag->t_checksum = cpu_to_be32(csum); | 358 | /* We only have space to store the lower 16 bits of the crc32c. */ |
359 | tag->t_checksum = cpu_to_be16(csum32); | ||
360 | } | 360 | } |
361 | /* | 361 | /* |
362 | * jbd2_journal_commit_transaction | 362 | * jbd2_journal_commit_transaction |
@@ -368,7 +368,8 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
368 | { | 368 | { |
369 | struct transaction_stats_s stats; | 369 | struct transaction_stats_s stats; |
370 | transaction_t *commit_transaction; | 370 | transaction_t *commit_transaction; |
371 | struct journal_head *jh, *new_jh, *descriptor; | 371 | struct journal_head *jh; |
372 | struct buffer_head *descriptor; | ||
372 | struct buffer_head **wbuf = journal->j_wbuf; | 373 | struct buffer_head **wbuf = journal->j_wbuf; |
373 | int bufs; | 374 | int bufs; |
374 | int flags; | 375 | int flags; |
@@ -392,6 +393,8 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
392 | tid_t first_tid; | 393 | tid_t first_tid; |
393 | int update_tail; | 394 | int update_tail; |
394 | int csum_size = 0; | 395 | int csum_size = 0; |
396 | LIST_HEAD(io_bufs); | ||
397 | LIST_HEAD(log_bufs); | ||
395 | 398 | ||
396 | if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) | 399 | if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) |
397 | csum_size = sizeof(struct jbd2_journal_block_tail); | 400 | csum_size = sizeof(struct jbd2_journal_block_tail); |
@@ -424,13 +427,13 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
424 | J_ASSERT(journal->j_committing_transaction == NULL); | 427 | J_ASSERT(journal->j_committing_transaction == NULL); |
425 | 428 | ||
426 | commit_transaction = journal->j_running_transaction; | 429 | commit_transaction = journal->j_running_transaction; |
427 | J_ASSERT(commit_transaction->t_state == T_RUNNING); | ||
428 | 430 | ||
429 | trace_jbd2_start_commit(journal, commit_transaction); | 431 | trace_jbd2_start_commit(journal, commit_transaction); |
430 | jbd_debug(1, "JBD2: starting commit of transaction %d\n", | 432 | jbd_debug(1, "JBD2: starting commit of transaction %d\n", |
431 | commit_transaction->t_tid); | 433 | commit_transaction->t_tid); |
432 | 434 | ||
433 | write_lock(&journal->j_state_lock); | 435 | write_lock(&journal->j_state_lock); |
436 | J_ASSERT(commit_transaction->t_state == T_RUNNING); | ||
434 | commit_transaction->t_state = T_LOCKED; | 437 | commit_transaction->t_state = T_LOCKED; |
435 | 438 | ||
436 | trace_jbd2_commit_locking(journal, commit_transaction); | 439 | trace_jbd2_commit_locking(journal, commit_transaction); |
@@ -520,6 +523,12 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
520 | */ | 523 | */ |
521 | jbd2_journal_switch_revoke_table(journal); | 524 | jbd2_journal_switch_revoke_table(journal); |
522 | 525 | ||
526 | /* | ||
527 | * Reserved credits cannot be claimed anymore, free them | ||
528 | */ | ||
529 | atomic_sub(atomic_read(&journal->j_reserved_credits), | ||
530 | &commit_transaction->t_outstanding_credits); | ||
531 | |||
523 | trace_jbd2_commit_flushing(journal, commit_transaction); | 532 | trace_jbd2_commit_flushing(journal, commit_transaction); |
524 | stats.run.rs_flushing = jiffies; | 533 | stats.run.rs_flushing = jiffies; |
525 | stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked, | 534 | stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked, |
@@ -533,7 +542,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
533 | wake_up(&journal->j_wait_transaction_locked); | 542 | wake_up(&journal->j_wait_transaction_locked); |
534 | write_unlock(&journal->j_state_lock); | 543 | write_unlock(&journal->j_state_lock); |
535 | 544 | ||
536 | jbd_debug(3, "JBD2: commit phase 2\n"); | 545 | jbd_debug(3, "JBD2: commit phase 2a\n"); |
537 | 546 | ||
538 | /* | 547 | /* |
539 | * Now start flushing things to disk, in the order they appear | 548 | * Now start flushing things to disk, in the order they appear |
@@ -545,10 +554,10 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
545 | 554 | ||
546 | blk_start_plug(&plug); | 555 | blk_start_plug(&plug); |
547 | jbd2_journal_write_revoke_records(journal, commit_transaction, | 556 | jbd2_journal_write_revoke_records(journal, commit_transaction, |
548 | WRITE_SYNC); | 557 | &log_bufs, WRITE_SYNC); |
549 | blk_finish_plug(&plug); | 558 | blk_finish_plug(&plug); |
550 | 559 | ||
551 | jbd_debug(3, "JBD2: commit phase 2\n"); | 560 | jbd_debug(3, "JBD2: commit phase 2b\n"); |
552 | 561 | ||
553 | /* | 562 | /* |
554 | * Way to go: we have now written out all of the data for a | 563 | * Way to go: we have now written out all of the data for a |
@@ -571,8 +580,8 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
571 | atomic_read(&commit_transaction->t_outstanding_credits)); | 580 | atomic_read(&commit_transaction->t_outstanding_credits)); |
572 | 581 | ||
573 | err = 0; | 582 | err = 0; |
574 | descriptor = NULL; | ||
575 | bufs = 0; | 583 | bufs = 0; |
584 | descriptor = NULL; | ||
576 | blk_start_plug(&plug); | 585 | blk_start_plug(&plug); |
577 | while (commit_transaction->t_buffers) { | 586 | while (commit_transaction->t_buffers) { |
578 | 587 | ||
@@ -604,8 +613,6 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
604 | record the metadata buffer. */ | 613 | record the metadata buffer. */ |
605 | 614 | ||
606 | if (!descriptor) { | 615 | if (!descriptor) { |
607 | struct buffer_head *bh; | ||
608 | |||
609 | J_ASSERT (bufs == 0); | 616 | J_ASSERT (bufs == 0); |
610 | 617 | ||
611 | jbd_debug(4, "JBD2: get descriptor\n"); | 618 | jbd_debug(4, "JBD2: get descriptor\n"); |
@@ -616,26 +623,26 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
616 | continue; | 623 | continue; |
617 | } | 624 | } |
618 | 625 | ||
619 | bh = jh2bh(descriptor); | ||
620 | jbd_debug(4, "JBD2: got buffer %llu (%p)\n", | 626 | jbd_debug(4, "JBD2: got buffer %llu (%p)\n", |
621 | (unsigned long long)bh->b_blocknr, bh->b_data); | 627 | (unsigned long long)descriptor->b_blocknr, |
622 | header = (journal_header_t *)&bh->b_data[0]; | 628 | descriptor->b_data); |
629 | header = (journal_header_t *)descriptor->b_data; | ||
623 | header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); | 630 | header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER); |
624 | header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK); | 631 | header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK); |
625 | header->h_sequence = cpu_to_be32(commit_transaction->t_tid); | 632 | header->h_sequence = cpu_to_be32(commit_transaction->t_tid); |
626 | 633 | ||
627 | tagp = &bh->b_data[sizeof(journal_header_t)]; | 634 | tagp = &descriptor->b_data[sizeof(journal_header_t)]; |
628 | space_left = bh->b_size - sizeof(journal_header_t); | 635 | space_left = descriptor->b_size - |
636 | sizeof(journal_header_t); | ||
629 | first_tag = 1; | 637 | first_tag = 1; |
630 | set_buffer_jwrite(bh); | 638 | set_buffer_jwrite(descriptor); |
631 | set_buffer_dirty(bh); | 639 | set_buffer_dirty(descriptor); |
632 | wbuf[bufs++] = bh; | 640 | wbuf[bufs++] = descriptor; |
633 | 641 | ||
634 | /* Record it so that we can wait for IO | 642 | /* Record it so that we can wait for IO |
635 | completion later */ | 643 | completion later */ |
636 | BUFFER_TRACE(bh, "ph3: file as descriptor"); | 644 | BUFFER_TRACE(descriptor, "ph3: file as descriptor"); |
637 | jbd2_journal_file_buffer(descriptor, commit_transaction, | 645 | jbd2_file_log_bh(&log_bufs, descriptor); |
638 | BJ_LogCtl); | ||
639 | } | 646 | } |
640 | 647 | ||
641 | /* Where is the buffer to be written? */ | 648 | /* Where is the buffer to be written? */ |
@@ -658,29 +665,22 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
658 | 665 | ||
659 | /* Bump b_count to prevent truncate from stumbling over | 666 | /* Bump b_count to prevent truncate from stumbling over |
660 | the shadowed buffer! @@@ This can go if we ever get | 667 | the shadowed buffer! @@@ This can go if we ever get |
661 | rid of the BJ_IO/BJ_Shadow pairing of buffers. */ | 668 | rid of the shadow pairing of buffers. */ |
662 | atomic_inc(&jh2bh(jh)->b_count); | 669 | atomic_inc(&jh2bh(jh)->b_count); |
663 | 670 | ||
664 | /* Make a temporary IO buffer with which to write it out | ||
665 | (this will requeue both the metadata buffer and the | ||
666 | temporary IO buffer). new_bh goes on BJ_IO*/ | ||
667 | |||
668 | set_bit(BH_JWrite, &jh2bh(jh)->b_state); | ||
669 | /* | 671 | /* |
670 | * akpm: jbd2_journal_write_metadata_buffer() sets | 672 | * Make a temporary IO buffer with which to write it out |
671 | * new_bh->b_transaction to commit_transaction. | 673 | * (this will requeue the metadata buffer to BJ_Shadow). |
672 | * We need to clean this up before we release new_bh | ||
673 | * (which is of type BJ_IO) | ||
674 | */ | 674 | */ |
675 | set_bit(BH_JWrite, &jh2bh(jh)->b_state); | ||
675 | JBUFFER_TRACE(jh, "ph3: write metadata"); | 676 | JBUFFER_TRACE(jh, "ph3: write metadata"); |
676 | flags = jbd2_journal_write_metadata_buffer(commit_transaction, | 677 | flags = jbd2_journal_write_metadata_buffer(commit_transaction, |
677 | jh, &new_jh, blocknr); | 678 | jh, &wbuf[bufs], blocknr); |
678 | if (flags < 0) { | 679 | if (flags < 0) { |
679 | jbd2_journal_abort(journal, flags); | 680 | jbd2_journal_abort(journal, flags); |
680 | continue; | 681 | continue; |
681 | } | 682 | } |
682 | set_bit(BH_JWrite, &jh2bh(new_jh)->b_state); | 683 | jbd2_file_log_bh(&io_bufs, wbuf[bufs]); |
683 | wbuf[bufs++] = jh2bh(new_jh); | ||
684 | 684 | ||
685 | /* Record the new block's tag in the current descriptor | 685 | /* Record the new block's tag in the current descriptor |
686 | buffer */ | 686 | buffer */ |
@@ -694,10 +694,11 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
694 | tag = (journal_block_tag_t *) tagp; | 694 | tag = (journal_block_tag_t *) tagp; |
695 | write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr); | 695 | write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr); |
696 | tag->t_flags = cpu_to_be16(tag_flag); | 696 | tag->t_flags = cpu_to_be16(tag_flag); |
697 | jbd2_block_tag_csum_set(journal, tag, jh2bh(new_jh), | 697 | jbd2_block_tag_csum_set(journal, tag, wbuf[bufs], |
698 | commit_transaction->t_tid); | 698 | commit_transaction->t_tid); |
699 | tagp += tag_bytes; | 699 | tagp += tag_bytes; |
700 | space_left -= tag_bytes; | 700 | space_left -= tag_bytes; |
701 | bufs++; | ||
701 | 702 | ||
702 | if (first_tag) { | 703 | if (first_tag) { |
703 | memcpy (tagp, journal->j_uuid, 16); | 704 | memcpy (tagp, journal->j_uuid, 16); |
@@ -809,7 +810,7 @@ start_journal_io: | |||
809 | the log. Before we can commit it, wait for the IO so far to | 810 | the log. Before we can commit it, wait for the IO so far to |
810 | complete. Control buffers being written are on the | 811 | complete. Control buffers being written are on the |
811 | transaction's t_log_list queue, and metadata buffers are on | 812 | transaction's t_log_list queue, and metadata buffers are on |
812 | the t_iobuf_list queue. | 813 | the io_bufs list. |
813 | 814 | ||
814 | Wait for the buffers in reverse order. That way we are | 815 | Wait for the buffers in reverse order. That way we are |
815 | less likely to be woken up until all IOs have completed, and | 816 | less likely to be woken up until all IOs have completed, and |
@@ -818,47 +819,33 @@ start_journal_io: | |||
818 | 819 | ||
819 | jbd_debug(3, "JBD2: commit phase 3\n"); | 820 | jbd_debug(3, "JBD2: commit phase 3\n"); |
820 | 821 | ||
821 | /* | 822 | while (!list_empty(&io_bufs)) { |
822 | * akpm: these are BJ_IO, and j_list_lock is not needed. | 823 | struct buffer_head *bh = list_entry(io_bufs.prev, |
823 | * See __journal_try_to_free_buffer. | 824 | struct buffer_head, |
824 | */ | 825 | b_assoc_buffers); |
825 | wait_for_iobuf: | ||
826 | while (commit_transaction->t_iobuf_list != NULL) { | ||
827 | struct buffer_head *bh; | ||
828 | 826 | ||
829 | jh = commit_transaction->t_iobuf_list->b_tprev; | 827 | wait_on_buffer(bh); |
830 | bh = jh2bh(jh); | 828 | cond_resched(); |
831 | if (buffer_locked(bh)) { | ||
832 | wait_on_buffer(bh); | ||
833 | goto wait_for_iobuf; | ||
834 | } | ||
835 | if (cond_resched()) | ||
836 | goto wait_for_iobuf; | ||
837 | 829 | ||
838 | if (unlikely(!buffer_uptodate(bh))) | 830 | if (unlikely(!buffer_uptodate(bh))) |
839 | err = -EIO; | 831 | err = -EIO; |
840 | 832 | jbd2_unfile_log_bh(bh); | |
841 | clear_buffer_jwrite(bh); | ||
842 | |||
843 | JBUFFER_TRACE(jh, "ph4: unfile after journal write"); | ||
844 | jbd2_journal_unfile_buffer(journal, jh); | ||
845 | 833 | ||
846 | /* | 834 | /* |
847 | * ->t_iobuf_list should contain only dummy buffer_heads | 835 | * The list contains temporary buffer heads created by |
848 | * which were created by jbd2_journal_write_metadata_buffer(). | 836 | * jbd2_journal_write_metadata_buffer(). |
849 | */ | 837 | */ |
850 | BUFFER_TRACE(bh, "dumping temporary bh"); | 838 | BUFFER_TRACE(bh, "dumping temporary bh"); |
851 | jbd2_journal_put_journal_head(jh); | ||
852 | __brelse(bh); | 839 | __brelse(bh); |
853 | J_ASSERT_BH(bh, atomic_read(&bh->b_count) == 0); | 840 | J_ASSERT_BH(bh, atomic_read(&bh->b_count) == 0); |
854 | free_buffer_head(bh); | 841 | free_buffer_head(bh); |
855 | 842 | ||
856 | /* We also have to unlock and free the corresponding | 843 | /* We also have to refile the corresponding shadowed buffer */ |
857 | shadowed buffer */ | ||
858 | jh = commit_transaction->t_shadow_list->b_tprev; | 844 | jh = commit_transaction->t_shadow_list->b_tprev; |
859 | bh = jh2bh(jh); | 845 | bh = jh2bh(jh); |
860 | clear_bit(BH_JWrite, &bh->b_state); | 846 | clear_buffer_jwrite(bh); |
861 | J_ASSERT_BH(bh, buffer_jbddirty(bh)); | 847 | J_ASSERT_BH(bh, buffer_jbddirty(bh)); |
848 | J_ASSERT_BH(bh, !buffer_shadow(bh)); | ||
862 | 849 | ||
863 | /* The metadata is now released for reuse, but we need | 850 | /* The metadata is now released for reuse, but we need |
864 | to remember it against this transaction so that when | 851 | to remember it against this transaction so that when |
@@ -866,14 +853,6 @@ wait_for_iobuf: | |||
866 | required. */ | 853 | required. */ |
867 | JBUFFER_TRACE(jh, "file as BJ_Forget"); | 854 | JBUFFER_TRACE(jh, "file as BJ_Forget"); |
868 | jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget); | 855 | jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget); |
869 | /* | ||
870 | * Wake up any transactions which were waiting for this IO to | ||
871 | * complete. The barrier must be here so that changes by | ||
872 | * jbd2_journal_file_buffer() take effect before wake_up_bit() | ||
873 | * does the waitqueue check. | ||
874 | */ | ||
875 | smp_mb(); | ||
876 | wake_up_bit(&bh->b_state, BH_Unshadow); | ||
877 | JBUFFER_TRACE(jh, "brelse shadowed buffer"); | 856 | JBUFFER_TRACE(jh, "brelse shadowed buffer"); |
878 | __brelse(bh); | 857 | __brelse(bh); |
879 | } | 858 | } |
@@ -883,26 +862,19 @@ wait_for_iobuf: | |||
883 | jbd_debug(3, "JBD2: commit phase 4\n"); | 862 | jbd_debug(3, "JBD2: commit phase 4\n"); |
884 | 863 | ||
885 | /* Here we wait for the revoke record and descriptor record buffers */ | 864 | /* Here we wait for the revoke record and descriptor record buffers */ |
886 | wait_for_ctlbuf: | 865 | while (!list_empty(&log_bufs)) { |
887 | while (commit_transaction->t_log_list != NULL) { | ||
888 | struct buffer_head *bh; | 866 | struct buffer_head *bh; |
889 | 867 | ||
890 | jh = commit_transaction->t_log_list->b_tprev; | 868 | bh = list_entry(log_bufs.prev, struct buffer_head, b_assoc_buffers); |
891 | bh = jh2bh(jh); | 869 | wait_on_buffer(bh); |
892 | if (buffer_locked(bh)) { | 870 | cond_resched(); |
893 | wait_on_buffer(bh); | ||
894 | goto wait_for_ctlbuf; | ||
895 | } | ||
896 | if (cond_resched()) | ||
897 | goto wait_for_ctlbuf; | ||
898 | 871 | ||
899 | if (unlikely(!buffer_uptodate(bh))) | 872 | if (unlikely(!buffer_uptodate(bh))) |
900 | err = -EIO; | 873 | err = -EIO; |
901 | 874 | ||
902 | BUFFER_TRACE(bh, "ph5: control buffer writeout done: unfile"); | 875 | BUFFER_TRACE(bh, "ph5: control buffer writeout done: unfile"); |
903 | clear_buffer_jwrite(bh); | 876 | clear_buffer_jwrite(bh); |
904 | jbd2_journal_unfile_buffer(journal, jh); | 877 | jbd2_unfile_log_bh(bh); |
905 | jbd2_journal_put_journal_head(jh); | ||
906 | __brelse(bh); /* One for getblk */ | 878 | __brelse(bh); /* One for getblk */ |
907 | /* AKPM: bforget here */ | 879 | /* AKPM: bforget here */ |
908 | } | 880 | } |
@@ -952,9 +924,7 @@ wait_for_iobuf: | |||
952 | J_ASSERT(list_empty(&commit_transaction->t_inode_list)); | 924 | J_ASSERT(list_empty(&commit_transaction->t_inode_list)); |
953 | J_ASSERT(commit_transaction->t_buffers == NULL); | 925 | J_ASSERT(commit_transaction->t_buffers == NULL); |
954 | J_ASSERT(commit_transaction->t_checkpoint_list == NULL); | 926 | J_ASSERT(commit_transaction->t_checkpoint_list == NULL); |
955 | J_ASSERT(commit_transaction->t_iobuf_list == NULL); | ||
956 | J_ASSERT(commit_transaction->t_shadow_list == NULL); | 927 | J_ASSERT(commit_transaction->t_shadow_list == NULL); |
957 | J_ASSERT(commit_transaction->t_log_list == NULL); | ||
958 | 928 | ||
959 | restart_loop: | 929 | restart_loop: |
960 | /* | 930 | /* |