diff options
Diffstat (limited to 'fs/jbd2/transaction.c')
-rw-r--r-- | fs/jbd2/transaction.c | 123 |
1 files changed, 69 insertions, 54 deletions
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index f3479d6e0a83..2d7109414cdd 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | 31 | ||
32 | static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh); | 32 | static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh); |
33 | static void __jbd2_journal_unfile_buffer(struct journal_head *jh); | ||
33 | 34 | ||
34 | /* | 35 | /* |
35 | * jbd2_get_transaction: obtain a new transaction_t object. | 36 | * jbd2_get_transaction: obtain a new transaction_t object. |
@@ -82,7 +83,7 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction) | |||
82 | */ | 83 | */ |
83 | 84 | ||
84 | /* | 85 | /* |
85 | * Update transiaction's maximum wait time, if debugging is enabled. | 86 | * Update transaction's maximum wait time, if debugging is enabled. |
86 | * | 87 | * |
87 | * In order for t_max_wait to be reliable, it must be protected by a | 88 | * In order for t_max_wait to be reliable, it must be protected by a |
88 | * lock. But doing so will mean that start_this_handle() can not be | 89 | * lock. But doing so will mean that start_this_handle() can not be |
@@ -91,11 +92,10 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction) | |||
91 | * means that maximum wait time reported by the jbd2_run_stats | 92 | * means that maximum wait time reported by the jbd2_run_stats |
92 | * tracepoint will always be zero. | 93 | * tracepoint will always be zero. |
93 | */ | 94 | */ |
94 | static inline void update_t_max_wait(transaction_t *transaction) | 95 | static inline void update_t_max_wait(transaction_t *transaction, |
96 | unsigned long ts) | ||
95 | { | 97 | { |
96 | #ifdef CONFIG_JBD2_DEBUG | 98 | #ifdef CONFIG_JBD2_DEBUG |
97 | unsigned long ts = jiffies; | ||
98 | |||
99 | if (jbd2_journal_enable_debug && | 99 | if (jbd2_journal_enable_debug && |
100 | time_after(transaction->t_start, ts)) { | 100 | time_after(transaction->t_start, ts)) { |
101 | ts = jbd2_time_diff(ts, transaction->t_start); | 101 | ts = jbd2_time_diff(ts, transaction->t_start); |
@@ -117,10 +117,11 @@ static inline void update_t_max_wait(transaction_t *transaction) | |||
117 | static int start_this_handle(journal_t *journal, handle_t *handle, | 117 | static int start_this_handle(journal_t *journal, handle_t *handle, |
118 | int gfp_mask) | 118 | int gfp_mask) |
119 | { | 119 | { |
120 | transaction_t *transaction; | 120 | transaction_t *transaction, *new_transaction = NULL; |
121 | int needed; | 121 | tid_t tid; |
122 | int nblocks = handle->h_buffer_credits; | 122 | int needed, need_to_start; |
123 | transaction_t *new_transaction = NULL; | 123 | int nblocks = handle->h_buffer_credits; |
124 | unsigned long ts = jiffies; | ||
124 | 125 | ||
125 | if (nblocks > journal->j_max_transaction_buffers) { | 126 | if (nblocks > journal->j_max_transaction_buffers) { |
126 | printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n", | 127 | printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n", |
@@ -156,6 +157,7 @@ alloc_transaction: | |||
156 | */ | 157 | */ |
157 | repeat: | 158 | repeat: |
158 | read_lock(&journal->j_state_lock); | 159 | read_lock(&journal->j_state_lock); |
160 | BUG_ON(journal->j_flags & JBD2_UNMOUNT); | ||
159 | if (is_journal_aborted(journal) || | 161 | if (is_journal_aborted(journal) || |
160 | (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) { | 162 | (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) { |
161 | read_unlock(&journal->j_state_lock); | 163 | read_unlock(&journal->j_state_lock); |
@@ -221,8 +223,11 @@ repeat: | |||
221 | atomic_sub(nblocks, &transaction->t_outstanding_credits); | 223 | atomic_sub(nblocks, &transaction->t_outstanding_credits); |
222 | prepare_to_wait(&journal->j_wait_transaction_locked, &wait, | 224 | prepare_to_wait(&journal->j_wait_transaction_locked, &wait, |
223 | TASK_UNINTERRUPTIBLE); | 225 | TASK_UNINTERRUPTIBLE); |
224 | __jbd2_log_start_commit(journal, transaction->t_tid); | 226 | tid = transaction->t_tid; |
227 | need_to_start = !tid_geq(journal->j_commit_request, tid); | ||
225 | read_unlock(&journal->j_state_lock); | 228 | read_unlock(&journal->j_state_lock); |
229 | if (need_to_start) | ||
230 | jbd2_log_start_commit(journal, tid); | ||
226 | schedule(); | 231 | schedule(); |
227 | finish_wait(&journal->j_wait_transaction_locked, &wait); | 232 | finish_wait(&journal->j_wait_transaction_locked, &wait); |
228 | goto repeat; | 233 | goto repeat; |
@@ -250,7 +255,7 @@ repeat: | |||
250 | * the committing transaction. Really, we only need to give it | 255 | * the committing transaction. Really, we only need to give it |
251 | * committing_transaction->t_outstanding_credits plus "enough" for | 256 | * committing_transaction->t_outstanding_credits plus "enough" for |
252 | * the log control blocks. | 257 | * the log control blocks. |
253 | * Also, this test is inconsitent with the matching one in | 258 | * Also, this test is inconsistent with the matching one in |
254 | * jbd2_journal_extend(). | 259 | * jbd2_journal_extend(). |
255 | */ | 260 | */ |
256 | if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) { | 261 | if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) { |
@@ -267,7 +272,7 @@ repeat: | |||
267 | /* OK, account for the buffers that this operation expects to | 272 | /* OK, account for the buffers that this operation expects to |
268 | * use and add the handle to the running transaction. | 273 | * use and add the handle to the running transaction. |
269 | */ | 274 | */ |
270 | update_t_max_wait(transaction); | 275 | update_t_max_wait(transaction, ts); |
271 | handle->h_transaction = transaction; | 276 | handle->h_transaction = transaction; |
272 | atomic_inc(&transaction->t_updates); | 277 | atomic_inc(&transaction->t_updates); |
273 | atomic_inc(&transaction->t_handle_count); | 278 | atomic_inc(&transaction->t_handle_count); |
@@ -312,7 +317,8 @@ static handle_t *new_handle(int nblocks) | |||
312 | * This function is visible to journal users (like ext3fs), so is not | 317 | * This function is visible to journal users (like ext3fs), so is not |
313 | * called with the journal already locked. | 318 | * called with the journal already locked. |
314 | * | 319 | * |
315 | * Return a pointer to a newly allocated handle, or NULL on failure | 320 | * Return a pointer to a newly allocated handle, or an ERR_PTR() value |
321 | * on failure. | ||
316 | */ | 322 | */ |
317 | handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int gfp_mask) | 323 | handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int gfp_mask) |
318 | { | 324 | { |
@@ -339,9 +345,7 @@ handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int gfp_mask) | |||
339 | jbd2_free_handle(handle); | 345 | jbd2_free_handle(handle); |
340 | current->journal_info = NULL; | 346 | current->journal_info = NULL; |
341 | handle = ERR_PTR(err); | 347 | handle = ERR_PTR(err); |
342 | goto out; | ||
343 | } | 348 | } |
344 | out: | ||
345 | return handle; | 349 | return handle; |
346 | } | 350 | } |
347 | EXPORT_SYMBOL(jbd2__journal_start); | 351 | EXPORT_SYMBOL(jbd2__journal_start); |
@@ -443,7 +447,8 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, int gfp_mask) | |||
443 | { | 447 | { |
444 | transaction_t *transaction = handle->h_transaction; | 448 | transaction_t *transaction = handle->h_transaction; |
445 | journal_t *journal = transaction->t_journal; | 449 | journal_t *journal = transaction->t_journal; |
446 | int ret; | 450 | tid_t tid; |
451 | int need_to_start, ret; | ||
447 | 452 | ||
448 | /* If we've had an abort of any type, don't even think about | 453 | /* If we've had an abort of any type, don't even think about |
449 | * actually doing the restart! */ | 454 | * actually doing the restart! */ |
@@ -466,8 +471,11 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, int gfp_mask) | |||
466 | spin_unlock(&transaction->t_handle_lock); | 471 | spin_unlock(&transaction->t_handle_lock); |
467 | 472 | ||
468 | jbd_debug(2, "restarting handle %p\n", handle); | 473 | jbd_debug(2, "restarting handle %p\n", handle); |
469 | __jbd2_log_start_commit(journal, transaction->t_tid); | 474 | tid = transaction->t_tid; |
475 | need_to_start = !tid_geq(journal->j_commit_request, tid); | ||
470 | read_unlock(&journal->j_state_lock); | 476 | read_unlock(&journal->j_state_lock); |
477 | if (need_to_start) | ||
478 | jbd2_log_start_commit(journal, tid); | ||
471 | 479 | ||
472 | lock_map_release(&handle->h_lockdep_map); | 480 | lock_map_release(&handle->h_lockdep_map); |
473 | handle->h_buffer_credits = nblocks; | 481 | handle->h_buffer_credits = nblocks; |
@@ -588,7 +596,7 @@ do_get_write_access(handle_t *handle, struct journal_head *jh, | |||
588 | transaction = handle->h_transaction; | 596 | transaction = handle->h_transaction; |
589 | journal = transaction->t_journal; | 597 | journal = transaction->t_journal; |
590 | 598 | ||
591 | jbd_debug(5, "buffer_head %p, force_copy %d\n", jh, force_copy); | 599 | jbd_debug(5, "journal_head %p, force_copy %d\n", jh, force_copy); |
592 | 600 | ||
593 | JBUFFER_TRACE(jh, "entry"); | 601 | JBUFFER_TRACE(jh, "entry"); |
594 | repeat: | 602 | repeat: |
@@ -757,7 +765,6 @@ repeat: | |||
757 | if (!jh->b_transaction) { | 765 | if (!jh->b_transaction) { |
758 | JBUFFER_TRACE(jh, "no transaction"); | 766 | JBUFFER_TRACE(jh, "no transaction"); |
759 | J_ASSERT_JH(jh, !jh->b_next_transaction); | 767 | J_ASSERT_JH(jh, !jh->b_next_transaction); |
760 | jh->b_transaction = transaction; | ||
761 | JBUFFER_TRACE(jh, "file as BJ_Reserved"); | 768 | JBUFFER_TRACE(jh, "file as BJ_Reserved"); |
762 | spin_lock(&journal->j_list_lock); | 769 | spin_lock(&journal->j_list_lock); |
763 | __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved); | 770 | __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved); |
@@ -773,7 +780,7 @@ done: | |||
773 | J_EXPECT_JH(jh, buffer_uptodate(jh2bh(jh)), | 780 | J_EXPECT_JH(jh, buffer_uptodate(jh2bh(jh)), |
774 | "Possible IO failure.\n"); | 781 | "Possible IO failure.\n"); |
775 | page = jh2bh(jh)->b_page; | 782 | page = jh2bh(jh)->b_page; |
776 | offset = ((unsigned long) jh2bh(jh)->b_data) & ~PAGE_MASK; | 783 | offset = offset_in_page(jh2bh(jh)->b_data); |
777 | source = kmap_atomic(page, KM_USER0); | 784 | source = kmap_atomic(page, KM_USER0); |
778 | /* Fire data frozen trigger just before we copy the data */ | 785 | /* Fire data frozen trigger just before we copy the data */ |
779 | jbd2_buffer_frozen_trigger(jh, source + offset, | 786 | jbd2_buffer_frozen_trigger(jh, source + offset, |
@@ -807,7 +814,6 @@ out: | |||
807 | * int jbd2_journal_get_write_access() - notify intent to modify a buffer for metadata (not data) update. | 814 | * int jbd2_journal_get_write_access() - notify intent to modify a buffer for metadata (not data) update. |
808 | * @handle: transaction to add buffer modifications to | 815 | * @handle: transaction to add buffer modifications to |
809 | * @bh: bh to be used for metadata writes | 816 | * @bh: bh to be used for metadata writes |
810 | * @credits: variable that will receive credits for the buffer | ||
811 | * | 817 | * |
812 | * Returns an error code or 0 on success. | 818 | * Returns an error code or 0 on success. |
813 | * | 819 | * |
@@ -889,8 +895,6 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh) | |||
889 | * committed and so it's safe to clear the dirty bit. | 895 | * committed and so it's safe to clear the dirty bit. |
890 | */ | 896 | */ |
891 | clear_buffer_dirty(jh2bh(jh)); | 897 | clear_buffer_dirty(jh2bh(jh)); |
892 | jh->b_transaction = transaction; | ||
893 | |||
894 | /* first access by this transaction */ | 898 | /* first access by this transaction */ |
895 | jh->b_modified = 0; | 899 | jh->b_modified = 0; |
896 | 900 | ||
@@ -915,8 +919,8 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh) | |||
915 | */ | 919 | */ |
916 | JBUFFER_TRACE(jh, "cancelling revoke"); | 920 | JBUFFER_TRACE(jh, "cancelling revoke"); |
917 | jbd2_journal_cancel_revoke(handle, jh); | 921 | jbd2_journal_cancel_revoke(handle, jh); |
918 | jbd2_journal_put_journal_head(jh); | ||
919 | out: | 922 | out: |
923 | jbd2_journal_put_journal_head(jh); | ||
920 | return err; | 924 | return err; |
921 | } | 925 | } |
922 | 926 | ||
@@ -925,7 +929,6 @@ out: | |||
925 | * non-rewindable consequences | 929 | * non-rewindable consequences |
926 | * @handle: transaction | 930 | * @handle: transaction |
927 | * @bh: buffer to undo | 931 | * @bh: buffer to undo |
928 | * @credits: store the number of taken credits here (if not NULL) | ||
929 | * | 932 | * |
930 | * Sometimes there is a need to distinguish between metadata which has | 933 | * Sometimes there is a need to distinguish between metadata which has |
931 | * been committed to disk and that which has not. The ext3fs code uses | 934 | * been committed to disk and that which has not. The ext3fs code uses |
@@ -1225,8 +1228,6 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) | |||
1225 | __jbd2_journal_file_buffer(jh, transaction, BJ_Forget); | 1228 | __jbd2_journal_file_buffer(jh, transaction, BJ_Forget); |
1226 | } else { | 1229 | } else { |
1227 | __jbd2_journal_unfile_buffer(jh); | 1230 | __jbd2_journal_unfile_buffer(jh); |
1228 | jbd2_journal_remove_journal_head(bh); | ||
1229 | __brelse(bh); | ||
1230 | if (!buffer_jbd(bh)) { | 1231 | if (!buffer_jbd(bh)) { |
1231 | spin_unlock(&journal->j_list_lock); | 1232 | spin_unlock(&journal->j_list_lock); |
1232 | jbd_unlock_bh_state(bh); | 1233 | jbd_unlock_bh_state(bh); |
@@ -1397,7 +1398,7 @@ int jbd2_journal_stop(handle_t *handle) | |||
1397 | 1398 | ||
1398 | /* | 1399 | /* |
1399 | * Once we drop t_updates, if it goes to zero the transaction | 1400 | * Once we drop t_updates, if it goes to zero the transaction |
1400 | * could start commiting on us and eventually disappear. So | 1401 | * could start committing on us and eventually disappear. So |
1401 | * once we do this, we must not dereference transaction | 1402 | * once we do this, we must not dereference transaction |
1402 | * pointer again. | 1403 | * pointer again. |
1403 | */ | 1404 | */ |
@@ -1549,19 +1550,32 @@ void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh) | |||
1549 | mark_buffer_dirty(bh); /* Expose it to the VM */ | 1550 | mark_buffer_dirty(bh); /* Expose it to the VM */ |
1550 | } | 1551 | } |
1551 | 1552 | ||
1552 | void __jbd2_journal_unfile_buffer(struct journal_head *jh) | 1553 | /* |
1554 | * Remove buffer from all transactions. | ||
1555 | * | ||
1556 | * Called with bh_state lock and j_list_lock | ||
1557 | * | ||
1558 | * jh and bh may be already freed when this function returns. | ||
1559 | */ | ||
1560 | static void __jbd2_journal_unfile_buffer(struct journal_head *jh) | ||
1553 | { | 1561 | { |
1554 | __jbd2_journal_temp_unlink_buffer(jh); | 1562 | __jbd2_journal_temp_unlink_buffer(jh); |
1555 | jh->b_transaction = NULL; | 1563 | jh->b_transaction = NULL; |
1564 | jbd2_journal_put_journal_head(jh); | ||
1556 | } | 1565 | } |
1557 | 1566 | ||
1558 | void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) | 1567 | void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) |
1559 | { | 1568 | { |
1560 | jbd_lock_bh_state(jh2bh(jh)); | 1569 | struct buffer_head *bh = jh2bh(jh); |
1570 | |||
1571 | /* Get reference so that buffer cannot be freed before we unlock it */ | ||
1572 | get_bh(bh); | ||
1573 | jbd_lock_bh_state(bh); | ||
1561 | spin_lock(&journal->j_list_lock); | 1574 | spin_lock(&journal->j_list_lock); |
1562 | __jbd2_journal_unfile_buffer(jh); | 1575 | __jbd2_journal_unfile_buffer(jh); |
1563 | spin_unlock(&journal->j_list_lock); | 1576 | spin_unlock(&journal->j_list_lock); |
1564 | jbd_unlock_bh_state(jh2bh(jh)); | 1577 | jbd_unlock_bh_state(bh); |
1578 | __brelse(bh); | ||
1565 | } | 1579 | } |
1566 | 1580 | ||
1567 | /* | 1581 | /* |
@@ -1588,8 +1602,6 @@ __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh) | |||
1588 | if (jh->b_jlist == BJ_None) { | 1602 | if (jh->b_jlist == BJ_None) { |
1589 | JBUFFER_TRACE(jh, "remove from checkpoint list"); | 1603 | JBUFFER_TRACE(jh, "remove from checkpoint list"); |
1590 | __jbd2_journal_remove_checkpoint(jh); | 1604 | __jbd2_journal_remove_checkpoint(jh); |
1591 | jbd2_journal_remove_journal_head(bh); | ||
1592 | __brelse(bh); | ||
1593 | } | 1605 | } |
1594 | } | 1606 | } |
1595 | spin_unlock(&journal->j_list_lock); | 1607 | spin_unlock(&journal->j_list_lock); |
@@ -1652,7 +1664,6 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, | |||
1652 | /* | 1664 | /* |
1653 | * We take our own ref against the journal_head here to avoid | 1665 | * We take our own ref against the journal_head here to avoid |
1654 | * having to add tons of locking around each instance of | 1666 | * having to add tons of locking around each instance of |
1655 | * jbd2_journal_remove_journal_head() and | ||
1656 | * jbd2_journal_put_journal_head(). | 1667 | * jbd2_journal_put_journal_head(). |
1657 | */ | 1668 | */ |
1658 | jh = jbd2_journal_grab_journal_head(bh); | 1669 | jh = jbd2_journal_grab_journal_head(bh); |
@@ -1690,10 +1701,9 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction) | |||
1690 | int may_free = 1; | 1701 | int may_free = 1; |
1691 | struct buffer_head *bh = jh2bh(jh); | 1702 | struct buffer_head *bh = jh2bh(jh); |
1692 | 1703 | ||
1693 | __jbd2_journal_unfile_buffer(jh); | ||
1694 | |||
1695 | if (jh->b_cp_transaction) { | 1704 | if (jh->b_cp_transaction) { |
1696 | JBUFFER_TRACE(jh, "on running+cp transaction"); | 1705 | JBUFFER_TRACE(jh, "on running+cp transaction"); |
1706 | __jbd2_journal_temp_unlink_buffer(jh); | ||
1697 | /* | 1707 | /* |
1698 | * We don't want to write the buffer anymore, clear the | 1708 | * We don't want to write the buffer anymore, clear the |
1699 | * bit so that we don't confuse checks in | 1709 | * bit so that we don't confuse checks in |
@@ -1704,8 +1714,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction) | |||
1704 | may_free = 0; | 1714 | may_free = 0; |
1705 | } else { | 1715 | } else { |
1706 | JBUFFER_TRACE(jh, "on running transaction"); | 1716 | JBUFFER_TRACE(jh, "on running transaction"); |
1707 | jbd2_journal_remove_journal_head(bh); | 1717 | __jbd2_journal_unfile_buffer(jh); |
1708 | __brelse(bh); | ||
1709 | } | 1718 | } |
1710 | return may_free; | 1719 | return may_free; |
1711 | } | 1720 | } |
@@ -1983,6 +1992,8 @@ void __jbd2_journal_file_buffer(struct journal_head *jh, | |||
1983 | 1992 | ||
1984 | if (jh->b_transaction) | 1993 | if (jh->b_transaction) |
1985 | __jbd2_journal_temp_unlink_buffer(jh); | 1994 | __jbd2_journal_temp_unlink_buffer(jh); |
1995 | else | ||
1996 | jbd2_journal_grab_journal_head(bh); | ||
1986 | jh->b_transaction = transaction; | 1997 | jh->b_transaction = transaction; |
1987 | 1998 | ||
1988 | switch (jlist) { | 1999 | switch (jlist) { |
@@ -2034,9 +2045,10 @@ void jbd2_journal_file_buffer(struct journal_head *jh, | |||
2034 | * already started to be used by a subsequent transaction, refile the | 2045 | * already started to be used by a subsequent transaction, refile the |
2035 | * buffer on that transaction's metadata list. | 2046 | * buffer on that transaction's metadata list. |
2036 | * | 2047 | * |
2037 | * Called under journal->j_list_lock | 2048 | * Called under j_list_lock |
2038 | * | ||
2039 | * Called under jbd_lock_bh_state(jh2bh(jh)) | 2049 | * Called under jbd_lock_bh_state(jh2bh(jh)) |
2050 | * | ||
2051 | * jh and bh may be already free when this function returns | ||
2040 | */ | 2052 | */ |
2041 | void __jbd2_journal_refile_buffer(struct journal_head *jh) | 2053 | void __jbd2_journal_refile_buffer(struct journal_head *jh) |
2042 | { | 2054 | { |
@@ -2060,6 +2072,11 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) | |||
2060 | 2072 | ||
2061 | was_dirty = test_clear_buffer_jbddirty(bh); | 2073 | was_dirty = test_clear_buffer_jbddirty(bh); |
2062 | __jbd2_journal_temp_unlink_buffer(jh); | 2074 | __jbd2_journal_temp_unlink_buffer(jh); |
2075 | /* | ||
2076 | * We set b_transaction here because b_next_transaction will inherit | ||
2077 | * our jh reference and thus __jbd2_journal_file_buffer() must not | ||
2078 | * take a new one. | ||
2079 | */ | ||
2063 | jh->b_transaction = jh->b_next_transaction; | 2080 | jh->b_transaction = jh->b_next_transaction; |
2064 | jh->b_next_transaction = NULL; | 2081 | jh->b_next_transaction = NULL; |
2065 | if (buffer_freed(bh)) | 2082 | if (buffer_freed(bh)) |
@@ -2076,30 +2093,21 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) | |||
2076 | } | 2093 | } |
2077 | 2094 | ||
2078 | /* | 2095 | /* |
2079 | * For the unlocked version of this call, also make sure that any | 2096 | * __jbd2_journal_refile_buffer() with necessary locking added. We take our |
2080 | * hanging journal_head is cleaned up if necessary. | 2097 | * bh reference so that we can safely unlock bh. |
2081 | * | 2098 | * |
2082 | * __jbd2_journal_refile_buffer is usually called as part of a single locked | 2099 | * The jh and bh may be freed by this call. |
2083 | * operation on a buffer_head, in which the caller is probably going to | ||
2084 | * be hooking the journal_head onto other lists. In that case it is up | ||
2085 | * to the caller to remove the journal_head if necessary. For the | ||
2086 | * unlocked jbd2_journal_refile_buffer call, the caller isn't going to be | ||
2087 | * doing anything else to the buffer so we need to do the cleanup | ||
2088 | * ourselves to avoid a jh leak. | ||
2089 | * | ||
2090 | * *** The journal_head may be freed by this call! *** | ||
2091 | */ | 2100 | */ |
2092 | void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh) | 2101 | void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh) |
2093 | { | 2102 | { |
2094 | struct buffer_head *bh = jh2bh(jh); | 2103 | struct buffer_head *bh = jh2bh(jh); |
2095 | 2104 | ||
2105 | /* Get reference so that buffer cannot be freed before we unlock it */ | ||
2106 | get_bh(bh); | ||
2096 | jbd_lock_bh_state(bh); | 2107 | jbd_lock_bh_state(bh); |
2097 | spin_lock(&journal->j_list_lock); | 2108 | spin_lock(&journal->j_list_lock); |
2098 | |||
2099 | __jbd2_journal_refile_buffer(jh); | 2109 | __jbd2_journal_refile_buffer(jh); |
2100 | jbd_unlock_bh_state(bh); | 2110 | jbd_unlock_bh_state(bh); |
2101 | jbd2_journal_remove_journal_head(bh); | ||
2102 | |||
2103 | spin_unlock(&journal->j_list_lock); | 2111 | spin_unlock(&journal->j_list_lock); |
2104 | __brelse(bh); | 2112 | __brelse(bh); |
2105 | } | 2113 | } |
@@ -2141,6 +2149,13 @@ int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode) | |||
2141 | jinode->i_next_transaction == transaction) | 2149 | jinode->i_next_transaction == transaction) |
2142 | goto done; | 2150 | goto done; |
2143 | 2151 | ||
2152 | /* | ||
2153 | * We only ever set this variable to 1 so the test is safe. Since | ||
2154 | * t_need_data_flush is likely to be set, we do the test to save some | ||
2155 | * cacheline bouncing | ||
2156 | */ | ||
2157 | if (!transaction->t_need_data_flush) | ||
2158 | transaction->t_need_data_flush = 1; | ||
2144 | /* On some different transaction's list - should be | 2159 | /* On some different transaction's list - should be |
2145 | * the committing one */ | 2160 | * the committing one */ |
2146 | if (jinode->i_transaction) { | 2161 | if (jinode->i_transaction) { |