task_struct: make journal_info conditional
[safe/jmp/linux-2.6] / fs / jbd / checkpoint.c
index e292935..b0435dd 100644 (file)
@@ -94,7 +94,7 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
        struct buffer_head *bh = jh2bh(jh);
 
        if (jh->b_jlist == BJ_None && !buffer_locked(bh) &&
-           !buffer_dirty(bh) && buffer_uptodate(bh)) {
+           !buffer_dirty(bh) && !buffer_write_io_error(bh)) {
                JBUFFER_TRACE(jh, "remove from checkpoint list");
                ret = __journal_remove_checkpoint(jh) + 1;
                jbd_unlock_bh_state(bh);
@@ -115,7 +115,7 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
  */
 void __log_wait_for_space(journal_t *journal)
 {
-       int nblocks;
+       int nblocks, space_left;
        assert_spin_locked(&journal->j_state_lock);
 
        nblocks = jbd_space_needed(journal);
@@ -127,14 +127,46 @@ void __log_wait_for_space(journal_t *journal)
 
                /*
                 * Test again, another process may have checkpointed while we
-                * were waiting for the checkpoint lock
+                * were waiting for the checkpoint lock. If there are no
+                * transactions ready to be checkpointed, try to recover
+                * journal space by calling cleanup_journal_tail(), and if
+                * that doesn't work, by waiting for the currently committing
+                * transaction to complete.  If there is absolutely no way
+                * to make progress, this is either a BUG or corrupted
+                * filesystem, so abort the journal and leave a stack
+                * trace for forensic evidence.
                 */
                spin_lock(&journal->j_state_lock);
+               spin_lock(&journal->j_list_lock);
                nblocks = jbd_space_needed(journal);
-               if (__log_space_left(journal) < nblocks) {
+               space_left = __log_space_left(journal);
+               if (space_left < nblocks) {
+                       int chkpt = journal->j_checkpoint_transactions != NULL;
+                       tid_t tid = 0;
+
+                       if (journal->j_committing_transaction)
+                               tid = journal->j_committing_transaction->t_tid;
+                       spin_unlock(&journal->j_list_lock);
                        spin_unlock(&journal->j_state_lock);
-                       log_do_checkpoint(journal);
+                       if (chkpt) {
+                               log_do_checkpoint(journal);
+                       } else if (cleanup_journal_tail(journal) == 0) {
+                               /* We were able to recover space; yay! */
+                               ;
+                       } else if (tid) {
+                               log_wait_commit(journal, tid);
+                       } else {
+                               printk(KERN_ERR "%s: needed %d blocks and "
+                                      "only had %d space available\n",
+                                      __func__, nblocks, space_left);
+                               printk(KERN_ERR "%s: no way to get more "
+                                      "journal space\n", __func__);
+                               WARN_ON(1);
+                               journal_abort(journal, 0);
+                       }
                        spin_lock(&journal->j_state_lock);
+               } else {
+                       spin_unlock(&journal->j_list_lock);
                }
                mutex_unlock(&journal->j_checkpoint_mutex);
        }
@@ -199,7 +231,7 @@ restart:
                        spin_lock(&journal->j_list_lock);
                        goto restart;
                }
-               if (unlikely(!buffer_uptodate(bh)))
+               if (unlikely(buffer_write_io_error(bh)))
                        ret = -EIO;
 
                /*
@@ -268,7 +300,7 @@ static int __process_buffer(journal_t *journal, struct journal_head *jh,
                ret = 1;
        } else if (!buffer_dirty(bh)) {
                ret = 1;
-               if (unlikely(!buffer_uptodate(bh)))
+               if (unlikely(buffer_write_io_error(bh)))
                        ret = -EIO;
                J_ASSERT_JH(jh, !buffer_jbddirty(bh));
                BUFFER_TRACE(bh, "remove from checkpoint");
@@ -424,7 +456,7 @@ int cleanup_journal_tail(journal_t *journal)
 {
        transaction_t * transaction;
        tid_t           first_tid;
-       unsigned long   blocknr, freed;
+       unsigned int    blocknr, freed;
 
        if (is_journal_aborted(journal))
                return 1;
@@ -470,8 +502,8 @@ int cleanup_journal_tail(journal_t *journal)
                freed = freed + journal->j_last - journal->j_first;
 
        jbd_debug(1,
-                 "Cleaning journal tail from %d to %d (offset %lu), "
-                 "freeing %lu\n",
+                 "Cleaning journal tail from %d to %d (offset %u), "
+                 "freeing %u\n",
                  journal->j_tail_sequence, first_tid, blocknr, freed);
 
        journal->j_free += freed;