aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/jbd2/journal.c62
-rw-r--r--fs/jbd2/transaction.c23
-rw-r--r--include/linux/jbd2.h2
3 files changed, 49 insertions, 38 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
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index fb91c8debe6a..c3645b9475f1 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1160,6 +1160,7 @@ extern void jbd2_journal_ack_err (journal_t *);
1160extern int jbd2_journal_clear_err (journal_t *); 1160extern int jbd2_journal_clear_err (journal_t *);
1161extern int jbd2_journal_bmap(journal_t *, unsigned long, unsigned long long *); 1161extern int jbd2_journal_bmap(journal_t *, unsigned long, unsigned long long *);
1162extern int jbd2_journal_force_commit(journal_t *); 1162extern int jbd2_journal_force_commit(journal_t *);
1163extern int jbd2_journal_force_commit_nested(journal_t *);
1163extern int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *inode); 1164extern int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *inode);
1164extern int jbd2_journal_begin_ordered_truncate(journal_t *journal, 1165extern int jbd2_journal_begin_ordered_truncate(journal_t *journal,
1165 struct jbd2_inode *inode, loff_t new_size); 1166 struct jbd2_inode *inode, loff_t new_size);
@@ -1235,7 +1236,6 @@ extern void jbd2_clear_buffer_revoked_flags(journal_t *journal);
1235int jbd2_log_start_commit(journal_t *journal, tid_t tid); 1236int jbd2_log_start_commit(journal_t *journal, tid_t tid);
1236int __jbd2_log_start_commit(journal_t *journal, tid_t tid); 1237int __jbd2_log_start_commit(journal_t *journal, tid_t tid);
1237int jbd2_journal_start_commit(journal_t *journal, tid_t *tid); 1238int jbd2_journal_start_commit(journal_t *journal, tid_t *tid);
1238int jbd2_journal_force_commit_nested(journal_t *journal);
1239int jbd2_log_wait_commit(journal_t *journal, tid_t tid); 1239int jbd2_log_wait_commit(journal_t *journal, tid_t tid);
1240int jbd2_complete_transaction(journal_t *journal, tid_t tid); 1240int jbd2_complete_transaction(journal_t *journal, tid_t tid);
1241int jbd2_log_do_checkpoint(journal_t *journal); 1241int jbd2_log_do_checkpoint(journal_t *journal);