diff options
Diffstat (limited to 'fs/jbd2/journal.c')
-rw-r--r-- | fs/jbd2/journal.c | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index e0ec3db1c395..9a7826990304 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -479,9 +479,12 @@ int __jbd2_log_space_left(journal_t *journal) | |||
479 | int __jbd2_log_start_commit(journal_t *journal, tid_t target) | 479 | int __jbd2_log_start_commit(journal_t *journal, tid_t target) |
480 | { | 480 | { |
481 | /* | 481 | /* |
482 | * Are we already doing a recent enough commit? | 482 | * The only transaction we can possibly wait upon is the |
483 | * currently running transaction (if it exists). Otherwise, | ||
484 | * the target tid must be an old one. | ||
483 | */ | 485 | */ |
484 | if (!tid_geq(journal->j_commit_request, target)) { | 486 | if (journal->j_running_transaction && |
487 | journal->j_running_transaction->t_tid == target) { | ||
485 | /* | 488 | /* |
486 | * We want a new commit: OK, mark the request and wakeup the | 489 | * We want a new commit: OK, mark the request and wakeup the |
487 | * commit thread. We do _not_ do the commit ourselves. | 490 | * commit thread. We do _not_ do the commit ourselves. |
@@ -493,7 +496,15 @@ int __jbd2_log_start_commit(journal_t *journal, tid_t target) | |||
493 | journal->j_commit_sequence); | 496 | journal->j_commit_sequence); |
494 | wake_up(&journal->j_wait_commit); | 497 | wake_up(&journal->j_wait_commit); |
495 | return 1; | 498 | return 1; |
496 | } | 499 | } else if (!tid_geq(journal->j_commit_request, target)) |
500 | /* This should never happen, but if it does, preserve | ||
501 | the evidence before kjournald goes into a loop and | ||
502 | increments j_commit_sequence beyond all recognition. */ | ||
503 | WARN_ONCE(1, "jbd: bad log_start_commit: %u %u %u %u\n", | ||
504 | journal->j_commit_request, | ||
505 | journal->j_commit_sequence, | ||
506 | target, journal->j_running_transaction ? | ||
507 | journal->j_running_transaction->t_tid : 0); | ||
497 | return 0; | 508 | return 0; |
498 | } | 509 | } |
499 | 510 | ||
@@ -577,6 +588,47 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid) | |||
577 | } | 588 | } |
578 | 589 | ||
579 | /* | 590 | /* |
591 | * Return 1 if a given transaction has not yet sent barrier request | ||
592 | * connected with a transaction commit. If 0 is returned, transaction | ||
593 | * may or may not have sent the barrier. Used to avoid sending barrier | ||
594 | * twice in common cases. | ||
595 | */ | ||
596 | int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid) | ||
597 | { | ||
598 | int ret = 0; | ||
599 | transaction_t *commit_trans; | ||
600 | |||
601 | if (!(journal->j_flags & JBD2_BARRIER)) | ||
602 | return 0; | ||
603 | read_lock(&journal->j_state_lock); | ||
604 | /* Transaction already committed? */ | ||
605 | if (tid_geq(journal->j_commit_sequence, tid)) | ||
606 | goto out; | ||
607 | commit_trans = journal->j_committing_transaction; | ||
608 | if (!commit_trans || commit_trans->t_tid != tid) { | ||
609 | ret = 1; | ||
610 | goto out; | ||
611 | } | ||
612 | /* | ||
613 | * Transaction is being committed and we already proceeded to | ||
614 | * submitting a flush to fs partition? | ||
615 | */ | ||
616 | if (journal->j_fs_dev != journal->j_dev) { | ||
617 | if (!commit_trans->t_need_data_flush || | ||
618 | commit_trans->t_state >= T_COMMIT_DFLUSH) | ||
619 | goto out; | ||
620 | } else { | ||
621 | if (commit_trans->t_state >= T_COMMIT_JFLUSH) | ||
622 | goto out; | ||
623 | } | ||
624 | ret = 1; | ||
625 | out: | ||
626 | read_unlock(&journal->j_state_lock); | ||
627 | return ret; | ||
628 | } | ||
629 | EXPORT_SYMBOL(jbd2_trans_will_send_data_barrier); | ||
630 | |||
631 | /* | ||
580 | * Wait for a specified commit to complete. | 632 | * Wait for a specified commit to complete. |
581 | * The caller may not hold the journal lock. | 633 | * The caller may not hold the journal lock. |
582 | */ | 634 | */ |