jbd: Provide function to check whether transaction will issue data barrier
authorJan Kara <jack@suse.cz>
Thu, 15 Apr 2010 20:16:24 +0000 (22:16 +0200)
committerJan Kara <jack@suse.cz>
Fri, 21 May 2010 17:30:40 +0000 (19:30 +0200)
Provide a function which returns whether a transaction with given tid
will send a barrier to the filesystem device. The function will be used
by ext3 to detect whether fsync needs to send a separate barrier or not.

Signed-off-by: Jan Kara <jack@suse.cz>
fs/jbd/commit.c
fs/jbd/journal.c
include/linux/jbd.h

index ecb44c94ba8de4251de699bd6e35a317ecee8a85..28a9ddaa0c496f85625ccab2d543fc5e0886872b 100644 (file)
@@ -786,6 +786,12 @@ wait_for_iobuf:
 
        jbd_debug(3, "JBD: commit phase 6\n");
 
+       /* All metadata is written, now write commit record and do cleanup */
+       spin_lock(&journal->j_state_lock);
+       J_ASSERT(commit_transaction->t_state == T_COMMIT);
+       commit_transaction->t_state = T_COMMIT_RECORD;
+       spin_unlock(&journal->j_state_lock);
+
        if (journal_write_commit_record(journal, commit_transaction))
                err = -EIO;
 
@@ -923,7 +929,7 @@ restart_loop:
 
        jbd_debug(3, "JBD: commit phase 8\n");
 
-       J_ASSERT(commit_transaction->t_state == T_COMMIT);
+       J_ASSERT(commit_transaction->t_state == T_COMMIT_RECORD);
 
        commit_transaction->t_state = T_FINISHED;
        J_ASSERT(commit_transaction == journal->j_committing_transaction);
index bd224eec9b072d5ebe0a075c57e203b9fde61c1d..99c71940155af8beec811e77c677b37d77e1959e 100644 (file)
@@ -564,6 +564,38 @@ int log_wait_commit(journal_t *journal, tid_t tid)
        return err;
 }
 
+/*
+ * Return 1 if a given transaction has not yet sent barrier request
+ * connected with a transaction commit. If 0 is returned, transaction
+ * may or may not have sent the barrier. Used to avoid sending barrier
+ * twice in common cases.
+ */
+int journal_trans_will_send_data_barrier(journal_t *journal, tid_t tid)
+{
+       int ret = 0;
+       transaction_t *commit_trans;
+
+       if (!(journal->j_flags & JFS_BARRIER))
+               return 0;
+       spin_lock(&journal->j_state_lock);
+       /* Transaction already committed? */
+       if (tid_geq(journal->j_commit_sequence, tid))
+               goto out;
+       /*
+        * Transaction is being committed and we already proceeded to
+        * writing commit record?
+        */
+       commit_trans = journal->j_committing_transaction;
+       if (commit_trans && commit_trans->t_tid == tid &&
+           commit_trans->t_state >= T_COMMIT_RECORD)
+               goto out;
+       ret = 1;
+out:
+       spin_unlock(&journal->j_state_lock);
+       return ret;
+}
+EXPORT_SYMBOL(journal_commit_will_send_barrier);
+
 /*
  * Log buffer allocation routines:
  */
@@ -1157,6 +1189,7 @@ int journal_destroy(journal_t *journal)
 {
        int err = 0;
 
+       
        /* Wait for the commit thread to wake up and die. */
        journal_kill_thread(journal);
 
index 516a2a27e87a3ce4c7ed3eeeedb12219aa28faec..e06965081ba5548f74db935543af84334f58259e 100644 (file)
@@ -427,9 +427,9 @@ struct transaction_s
        enum {
                T_RUNNING,
                T_LOCKED,
-               T_RUNDOWN,
                T_FLUSH,
                T_COMMIT,
+               T_COMMIT_RECORD,
                T_FINISHED
        }                       t_state;
 
@@ -991,6 +991,7 @@ int journal_start_commit(journal_t *journal, tid_t *tid);
 int journal_force_commit_nested(journal_t *journal);
 int log_wait_commit(journal_t *journal, tid_t tid);
 int log_do_checkpoint(journal_t *journal);
+int journal_trans_will_send_data_barrier(journal_t *journal, tid_t tid);
 
 void __log_wait_for_space(journal_t *journal);
 extern void    __journal_drop_transaction(journal_t *, transaction_t *);