]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/jbd2/transaction.c
Merge branch 'bkl/core' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[karo-tx-linux.git] / fs / jbd2 / transaction.c
index 663065142b4245910583c1a33d282af53fe03f37..d95cc9d0401dda527b6c202ca2b3da11f73eb992 100644 (file)
@@ -57,6 +57,7 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
        spin_lock_init(&transaction->t_handle_lock);
        atomic_set(&transaction->t_updates, 0);
        atomic_set(&transaction->t_outstanding_credits, 0);
+       atomic_set(&transaction->t_handle_count, 0);
        INIT_LIST_HEAD(&transaction->t_inode_list);
        INIT_LIST_HEAD(&transaction->t_private_list);
 
@@ -180,8 +181,8 @@ repeat:
         * buffers requested by this operation, we need to stall pending a log
         * checkpoint to free some more log space.
         */
-       spin_lock(&transaction->t_handle_lock);
-       needed = atomic_read(&transaction->t_outstanding_credits) + nblocks;
+       needed = atomic_add_return(nblocks,
+                                  &transaction->t_outstanding_credits);
 
        if (needed > journal->j_max_transaction_buffers) {
                /*
@@ -192,7 +193,7 @@ repeat:
                DEFINE_WAIT(wait);
 
                jbd_debug(2, "Handle %p starting new commit...\n", handle);
-               spin_unlock(&transaction->t_handle_lock);
+               atomic_sub(nblocks, &transaction->t_outstanding_credits);
                prepare_to_wait(&journal->j_wait_transaction_locked, &wait,
                                TASK_UNINTERRUPTIBLE);
                __jbd2_log_start_commit(journal, transaction->t_tid);
@@ -229,7 +230,7 @@ repeat:
         */
        if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) {
                jbd_debug(2, "Handle %p waiting for checkpoint...\n", handle);
-               spin_unlock(&transaction->t_handle_lock);
+               atomic_sub(nblocks, &transaction->t_outstanding_credits);
                read_unlock(&journal->j_state_lock);
                write_lock(&journal->j_state_lock);
                if (__jbd2_log_space_left(journal) < jbd_space_needed(journal))
@@ -239,23 +240,33 @@ repeat:
        }
 
        /* OK, account for the buffers that this operation expects to
-        * use and add the handle to the running transaction. */
-
-       if (time_after(transaction->t_start, ts)) {
+        * use and add the handle to the running transaction. 
+        *
+        * In order for t_max_wait to be reliable, it must be
+        * protected by a lock.  But doing so will mean that
+        * start_this_handle() can not be run in parallel on SMP
+        * systems, which limits our scalability.  So we only enable
+        * it when debugging is enabled.  We may want to use a
+        * separate flag, eventually, so we can enable this
+        * independently of debugging.
+        */
+#ifdef CONFIG_JBD2_DEBUG
+       if (jbd2_journal_enable_debug &&
+           time_after(transaction->t_start, ts)) {
                ts = jbd2_time_diff(ts, transaction->t_start);
+               spin_lock(&transaction->t_handle_lock);
                if (ts > transaction->t_max_wait)
                        transaction->t_max_wait = ts;
+               spin_unlock(&transaction->t_handle_lock);
        }
-
+#endif
        handle->h_transaction = transaction;
-       atomic_add(nblocks, &transaction->t_outstanding_credits);
        atomic_inc(&transaction->t_updates);
-       transaction->t_handle_count++;
+       atomic_inc(&transaction->t_handle_count);
        jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n",
                  handle, nblocks,
                  atomic_read(&transaction->t_outstanding_credits),
                  __jbd2_log_space_left(journal));
-       spin_unlock(&transaction->t_handle_lock);
        read_unlock(&journal->j_state_lock);
 
        lock_map_acquire(&handle->h_lockdep_map);
@@ -756,6 +767,9 @@ done:
                page = jh2bh(jh)->b_page;
                offset = ((unsigned long) jh2bh(jh)->b_data) & ~PAGE_MASK;
                source = kmap_atomic(page, KM_USER0);
+               /* Fire data frozen trigger just before we copy the data */
+               jbd2_buffer_frozen_trigger(jh, source + offset,
+                                          jh->b_triggers);
                memcpy(jh->b_frozen_data, source+offset, jh2bh(jh)->b_size);
                kunmap_atomic(source, KM_USER0);
 
@@ -994,15 +1008,15 @@ void jbd2_journal_set_triggers(struct buffer_head *bh,
        jh->b_triggers = type;
 }
 
-void jbd2_buffer_commit_trigger(struct journal_head *jh, void *mapped_data,
+void jbd2_buffer_frozen_trigger(struct journal_head *jh, void *mapped_data,
                                struct jbd2_buffer_trigger_type *triggers)
 {
        struct buffer_head *bh = jh2bh(jh);
 
-       if (!triggers || !triggers->t_commit)
+       if (!triggers || !triggers->t_frozen)
                return;
 
-       triggers->t_commit(triggers, bh, mapped_data, bh->b_size);
+       triggers->t_frozen(triggers, bh, mapped_data, bh->b_size);
 }
 
 void jbd2_buffer_abort_trigger(struct journal_head *jh,