aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2
diff options
context:
space:
mode:
authorDmitry Monakhov <dmonakhov@openvz.org>2013-06-12 22:24:07 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-06-12 22:24:07 -0400
commit9ff864462477206bc23b405a6ae506e92fb6dc9c (patch)
tree9d040520569d8943c33b29e310d5f6e6ccb7a7c1 /fs/jbd2
parent981250ca89261f98bdfd2d6be1fcccb96cbbc00d (diff)
jbd2: optimize jbd2_journal_force_commit
Current implementation of jbd2_journal_force_commit() is suboptimal because result in empty and useless commits. But callers just want to force and wait any unfinished commits. We already have jbd2_journal_force_commit_nested() which does exactly what we want, except we are guaranteed that we do not hold journal transaction open. Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/jbd2')
-rw-r--r--fs/jbd2/journal.c62
-rw-r--r--fs/jbd2/transaction.c23
2 files changed, 48 insertions, 37 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 70990d682a0c..0e6c13bdcc14 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -529,20 +529,17 @@ int jbd2_log_start_commit(journal_t *journal, tid_t tid)
529} 529}
530 530
531/* 531/*
532 * Force and wait upon a commit if the calling process is not within 532 * Force and wait any uncommitted transactions. We can only force the running
533 * transaction. This is used for forcing out undo-protected data which contains 533 * transaction if we don't have an active handle, otherwise, we will deadlock.
534 * bitmaps, when the fs is running out of space. 534 * Returns: <0 in case of error,
535 * 535 * 0 if nothing to commit,
536 * We can only force the running transaction if we don't have an active handle; 536 * 1 if transaction was successfully committed.
537 * otherwise, we will deadlock.
538 *
539 * Returns true if a transaction was started.
540 */ 537 */
541int jbd2_journal_force_commit_nested(journal_t *journal) 538static int __jbd2_journal_force_commit(journal_t *journal)
542{ 539{
543 transaction_t *transaction = NULL; 540 transaction_t *transaction = NULL;
544 tid_t tid; 541 tid_t tid;
545 int need_to_start = 0; 542 int need_to_start = 0, ret = 0;
546 543
547 read_lock(&journal->j_state_lock); 544 read_lock(&journal->j_state_lock);
548 if (journal->j_running_transaction && !current->journal_info) { 545 if (journal->j_running_transaction && !current->journal_info) {
@@ -553,16 +550,53 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
553 transaction = journal->j_committing_transaction; 550 transaction = journal->j_committing_transaction;
554 551
555 if (!transaction) { 552 if (!transaction) {
553 /* Nothing to commit */
556 read_unlock(&journal->j_state_lock); 554 read_unlock(&journal->j_state_lock);
557 return 0; /* Nothing to retry */ 555 return 0;
558 } 556 }
559
560 tid = transaction->t_tid; 557 tid = transaction->t_tid;
561 read_unlock(&journal->j_state_lock); 558 read_unlock(&journal->j_state_lock);
562 if (need_to_start) 559 if (need_to_start)
563 jbd2_log_start_commit(journal, tid); 560 jbd2_log_start_commit(journal, tid);
564 jbd2_log_wait_commit(journal, tid); 561 ret = jbd2_log_wait_commit(journal, tid);
565 return 1; 562 if (!ret)
563 ret = 1;
564
565 return ret;
566}
567
568/**
569 * Force and wait upon a commit if the calling process is not within
570 * transaction. This is used for forcing out undo-protected data which contains
571 * bitmaps, when the fs is running out of space.
572 *
573 * @journal: journal to force
574 * Returns true if progress was made.
575 */
576int jbd2_journal_force_commit_nested(journal_t *journal)
577{
578 int ret;
579
580 ret = __jbd2_journal_force_commit(journal);
581 return ret > 0;
582}
583
584/**
585 * int journal_force_commit() - force any uncommitted transactions
586 * @journal: journal to force
587 *
588 * Caller want unconditional commit. We can only force the running transaction
589 * if we don't have an active handle, otherwise, we will deadlock.
590 */
591int jbd2_journal_force_commit(journal_t *journal)
592{
593 int ret;
594
595 J_ASSERT(!current->journal_info);
596 ret = __jbd2_journal_force_commit(journal);
597 if (ret > 0)
598 ret = 0;
599 return ret;
566} 600}
567 601
568/* 602/*
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index f33342a2a95e..dd422e680418 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -1661,29 +1661,6 @@ int jbd2_journal_stop(handle_t *handle)
1661 return err; 1661 return err;
1662} 1662}
1663 1663
1664/**
1665 * int jbd2_journal_force_commit() - force any uncommitted transactions
1666 * @journal: journal to force
1667 *
1668 * For synchronous operations: force any uncommitted transactions
1669 * to disk. May seem kludgy, but it reuses all the handle batching
1670 * code in a very simple manner.
1671 */
1672int jbd2_journal_force_commit(journal_t *journal)
1673{
1674 handle_t *handle;
1675 int ret;
1676
1677 handle = jbd2_journal_start(journal, 1);
1678 if (IS_ERR(handle)) {
1679 ret = PTR_ERR(handle);
1680 } else {
1681 handle->h_sync = 1;
1682 ret = jbd2_journal_stop(handle);
1683 }
1684 return ret;
1685}
1686
1687/* 1664/*
1688 * 1665 *
1689 * List management code snippets: various functions for manipulating the 1666 * List management code snippets: various functions for manipulating the