jbd2: cleanup write flags handling from jbd2_write_superblock()
[sfrench/cifs-2.6.git] / fs / jbd2 / journal.c
index a1a359bfcc9cd4ff84254e464788ab3031dfe90f..1ce13479b10dd1f7f1a9193e2df55408eb9abb09 100644 (file)
@@ -691,8 +691,21 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
 {
        int err = 0;
 
-       jbd2_might_wait_for_commit(journal);
        read_lock(&journal->j_state_lock);
+#ifdef CONFIG_PROVE_LOCKING
+       /*
+        * Some callers make sure transaction is already committing and in that
+        * case we cannot block on open handles anymore. So don't warn in that
+        * case.
+        */
+       if (tid_gt(tid, journal->j_commit_sequence) &&
+           (!journal->j_committing_transaction ||
+            journal->j_committing_transaction->t_tid != tid)) {
+               read_unlock(&journal->j_state_lock);
+               jbd2_might_wait_for_commit(journal);
+               read_lock(&journal->j_state_lock);
+       }
+#endif
 #ifdef CONFIG_JBD2_DEBUG
        if (!tid_geq(journal->j_commit_request, tid)) {
                printk(KERN_ERR
@@ -913,7 +926,8 @@ int __jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block)
         * space and if we lose sb update during power failure we'd replay
         * old transaction with possibly newly overwritten data.
         */
-       ret = jbd2_journal_update_sb_log_tail(journal, tid, block, REQ_FUA);
+       ret = jbd2_journal_update_sb_log_tail(journal, tid, block,
+                                             REQ_SYNC | REQ_FUA);
        if (ret)
                goto out;
 
@@ -1125,10 +1139,8 @@ static journal_t *journal_init_common(struct block_device *bdev,
 
        /* Set up a default-sized revoke table for the new mount. */
        err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
-       if (err) {
-               kfree(journal);
-               return NULL;
-       }
+       if (err)
+               goto err_cleanup;
 
        spin_lock_init(&journal->j_history_lock);
 
@@ -1145,23 +1157,25 @@ static journal_t *journal_init_common(struct block_device *bdev,
        journal->j_wbufsize = n;
        journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *),
                                        GFP_KERNEL);
-       if (!journal->j_wbuf) {
-               kfree(journal);
-               return NULL;
-       }
+       if (!journal->j_wbuf)
+               goto err_cleanup;
 
        bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize);
        if (!bh) {
                pr_err("%s: Cannot get buffer for journal superblock\n",
                        __func__);
-               kfree(journal->j_wbuf);
-               kfree(journal);
-               return NULL;
+               goto err_cleanup;
        }
        journal->j_sb_buffer = bh;
        journal->j_superblock = (journal_superblock_t *)bh->b_data;
 
        return journal;
+
+err_cleanup:
+       kfree(journal->j_wbuf);
+       jbd2_journal_destroy_revoke(journal);
+       kfree(journal);
+       return NULL;
 }
 
 /* jbd2_journal_init_dev and jbd2_journal_init_inode:
@@ -1314,7 +1328,7 @@ static int journal_reset(journal_t *journal)
                jbd2_journal_update_sb_log_tail(journal,
                                                journal->j_tail_sequence,
                                                journal->j_tail,
-                                               REQ_FUA);
+                                               REQ_SYNC | REQ_FUA);
                mutex_unlock(&journal->j_checkpoint_mutex);
        }
        return jbd2_journal_start_thread(journal);
@@ -1454,7 +1468,7 @@ void jbd2_journal_update_sb_errno(journal_t *journal)
        sb->s_errno    = cpu_to_be32(journal->j_errno);
        read_unlock(&journal->j_state_lock);
 
-       jbd2_write_superblock(journal, REQ_FUA);
+       jbd2_write_superblock(journal, REQ_SYNC | REQ_FUA);
 }
 EXPORT_SYMBOL(jbd2_journal_update_sb_errno);
 
@@ -1721,7 +1735,7 @@ int jbd2_journal_destroy(journal_t *journal)
                        write_unlock(&journal->j_state_lock);
 
                        jbd2_mark_journal_empty(journal,
-                                       REQ_PREFLUSH | REQ_FUA);
+                                       REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
                        mutex_unlock(&journal->j_checkpoint_mutex);
                } else
                        err = -EIO;
@@ -1980,7 +1994,7 @@ int jbd2_journal_flush(journal_t *journal)
         * the magic code for a fully-recovered superblock.  Any future
         * commits of data to the journal will restore the current
         * s_start value. */
-       jbd2_mark_journal_empty(journal, REQ_FUA);
+       jbd2_mark_journal_empty(journal, REQ_SYNC | REQ_FUA);
        mutex_unlock(&journal->j_checkpoint_mutex);
        write_lock(&journal->j_state_lock);
        J_ASSERT(!journal->j_running_transaction);
@@ -2026,7 +2040,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)
        if (write) {
                /* Lock to make assertions happy... */
                mutex_lock(&journal->j_checkpoint_mutex);
-               jbd2_mark_journal_empty(journal, REQ_FUA);
+               jbd2_mark_journal_empty(journal, REQ_SYNC | REQ_FUA);
                mutex_unlock(&journal->j_checkpoint_mutex);
        }