aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd/transaction.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jbd/transaction.c')
-rw-r--r--fs/jbd/transaction.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index 73242ba7c7b1..006f9ad838a2 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -56,7 +56,8 @@ get_transaction(journal_t *journal, transaction_t *transaction)
56 spin_lock_init(&transaction->t_handle_lock); 56 spin_lock_init(&transaction->t_handle_lock);
57 57
58 /* Set up the commit timer for the new transaction. */ 58 /* Set up the commit timer for the new transaction. */
59 journal->j_commit_timer.expires = round_jiffies(transaction->t_expires); 59 journal->j_commit_timer.expires =
60 round_jiffies_up(transaction->t_expires);
60 add_timer(&journal->j_commit_timer); 61 add_timer(&journal->j_commit_timer);
61 62
62 J_ASSERT(journal->j_running_transaction == NULL); 63 J_ASSERT(journal->j_running_transaction == NULL);
@@ -228,6 +229,8 @@ repeat_locked:
228 __log_space_left(journal)); 229 __log_space_left(journal));
229 spin_unlock(&transaction->t_handle_lock); 230 spin_unlock(&transaction->t_handle_lock);
230 spin_unlock(&journal->j_state_lock); 231 spin_unlock(&journal->j_state_lock);
232
233 lock_map_acquire(&handle->h_lockdep_map);
231out: 234out:
232 if (unlikely(new_transaction)) /* It's usually NULL */ 235 if (unlikely(new_transaction)) /* It's usually NULL */
233 kfree(new_transaction); 236 kfree(new_transaction);
@@ -292,9 +295,6 @@ handle_t *journal_start(journal_t *journal, int nblocks)
292 handle = ERR_PTR(err); 295 handle = ERR_PTR(err);
293 goto out; 296 goto out;
294 } 297 }
295
296 lock_map_acquire(&handle->h_lockdep_map);
297
298out: 298out:
299 return handle; 299 return handle;
300} 300}
@@ -416,6 +416,7 @@ int journal_restart(handle_t *handle, int nblocks)
416 __log_start_commit(journal, transaction->t_tid); 416 __log_start_commit(journal, transaction->t_tid);
417 spin_unlock(&journal->j_state_lock); 417 spin_unlock(&journal->j_state_lock);
418 418
419 lock_map_release(&handle->h_lockdep_map);
419 handle->h_buffer_credits = nblocks; 420 handle->h_buffer_credits = nblocks;
420 ret = start_this_handle(journal, handle); 421 ret = start_this_handle(journal, handle);
421 return ret; 422 return ret;
@@ -489,34 +490,15 @@ void journal_unlock_updates (journal_t *journal)
489 wake_up(&journal->j_wait_transaction_locked); 490 wake_up(&journal->j_wait_transaction_locked);
490} 491}
491 492
492/* 493static void warn_dirty_buffer(struct buffer_head *bh)
493 * Report any unexpected dirty buffers which turn up. Normally those
494 * indicate an error, but they can occur if the user is running (say)
495 * tune2fs to modify the live filesystem, so we need the option of
496 * continuing as gracefully as possible. #
497 *
498 * The caller should already hold the journal lock and
499 * j_list_lock spinlock: most callers will need those anyway
500 * in order to probe the buffer's journaling state safely.
501 */
502static void jbd_unexpected_dirty_buffer(struct journal_head *jh)
503{ 494{
504 int jlist; 495 char b[BDEVNAME_SIZE];
505
506 /* If this buffer is one which might reasonably be dirty
507 * --- ie. data, or not part of this journal --- then
508 * we're OK to leave it alone, but otherwise we need to
509 * move the dirty bit to the journal's own internal
510 * JBDDirty bit. */
511 jlist = jh->b_jlist;
512
513 if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
514 jlist == BJ_Shadow || jlist == BJ_Forget) {
515 struct buffer_head *bh = jh2bh(jh);
516 496
517 if (test_clear_buffer_dirty(bh)) 497 printk(KERN_WARNING
518 set_buffer_jbddirty(bh); 498 "JBD: Spotted dirty metadata buffer (dev = %s, blocknr = %llu). "
519 } 499 "There's a risk of filesystem corruption in case of system "
500 "crash.\n",
501 bdevname(bh->b_bdev, b), (unsigned long long)bh->b_blocknr);
520} 502}
521 503
522/* 504/*
@@ -583,14 +565,16 @@ repeat:
583 if (jh->b_next_transaction) 565 if (jh->b_next_transaction)
584 J_ASSERT_JH(jh, jh->b_next_transaction == 566 J_ASSERT_JH(jh, jh->b_next_transaction ==
585 transaction); 567 transaction);
568 warn_dirty_buffer(bh);
586 } 569 }
587 /* 570 /*
588 * In any case we need to clean the dirty flag and we must 571 * In any case we need to clean the dirty flag and we must
589 * do it under the buffer lock to be sure we don't race 572 * do it under the buffer lock to be sure we don't race
590 * with running write-out. 573 * with running write-out.
591 */ 574 */
592 JBUFFER_TRACE(jh, "Unexpected dirty buffer"); 575 JBUFFER_TRACE(jh, "Journalling dirty buffer");
593 jbd_unexpected_dirty_buffer(jh); 576 clear_buffer_dirty(bh);
577 set_buffer_jbddirty(bh);
594 } 578 }
595 579
596 unlock_buffer(bh); 580 unlock_buffer(bh);
@@ -826,6 +810,15 @@ int journal_get_create_access(handle_t *handle, struct buffer_head *bh)
826 J_ASSERT_JH(jh, buffer_locked(jh2bh(jh))); 810 J_ASSERT_JH(jh, buffer_locked(jh2bh(jh)));
827 811
828 if (jh->b_transaction == NULL) { 812 if (jh->b_transaction == NULL) {
813 /*
814 * Previous journal_forget() could have left the buffer
815 * with jbddirty bit set because it was being committed. When
816 * the commit finished, we've filed the buffer for
817 * checkpointing and marked it dirty. Now we are reallocating
818 * the buffer so the transaction freeing it must have
819 * committed and so it's safe to clear the dirty bit.
820 */
821 clear_buffer_dirty(jh2bh(jh));
829 jh->b_transaction = transaction; 822 jh->b_transaction = transaction;
830 823
831 /* first access by this transaction */ 824 /* first access by this transaction */
@@ -1782,8 +1775,13 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
1782 1775
1783 if (jh->b_cp_transaction) { 1776 if (jh->b_cp_transaction) {
1784 JBUFFER_TRACE(jh, "on running+cp transaction"); 1777 JBUFFER_TRACE(jh, "on running+cp transaction");
1778 /*
1779 * We don't want to write the buffer anymore, clear the
1780 * bit so that we don't confuse checks in
1781 * __journal_file_buffer
1782 */
1783 clear_buffer_dirty(bh);
1785 __journal_file_buffer(jh, transaction, BJ_Forget); 1784 __journal_file_buffer(jh, transaction, BJ_Forget);
1786 clear_buffer_jbddirty(bh);
1787 may_free = 0; 1785 may_free = 0;
1788 } else { 1786 } else {
1789 JBUFFER_TRACE(jh, "on running transaction"); 1787 JBUFFER_TRACE(jh, "on running transaction");
@@ -2041,12 +2039,17 @@ void __journal_file_buffer(struct journal_head *jh,
2041 if (jh->b_transaction && jh->b_jlist == jlist) 2039 if (jh->b_transaction && jh->b_jlist == jlist)
2042 return; 2040 return;
2043 2041
2044 /* The following list of buffer states needs to be consistent
2045 * with __jbd_unexpected_dirty_buffer()'s handling of dirty
2046 * state. */
2047
2048 if (jlist == BJ_Metadata || jlist == BJ_Reserved || 2042 if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
2049 jlist == BJ_Shadow || jlist == BJ_Forget) { 2043 jlist == BJ_Shadow || jlist == BJ_Forget) {
2044 /*
2045 * For metadata buffers, we track dirty bit in buffer_jbddirty
2046 * instead of buffer_dirty. We should not see a dirty bit set
2047 * here because we clear it in do_get_write_access but e.g.
2048 * tune2fs can modify the sb and set the dirty bit at any time
2049 * so we try to gracefully handle that.
2050 */
2051 if (buffer_dirty(bh))
2052 warn_dirty_buffer(bh);
2050 if (test_clear_buffer_dirty(bh) || 2053 if (test_clear_buffer_dirty(bh) ||
2051 test_clear_buffer_jbddirty(bh)) 2054 test_clear_buffer_jbddirty(bh))
2052 was_dirty = 1; 2055 was_dirty = 1;