jbd2: add support for avoiding data writes during transaction commits
[sfrench/cifs-2.6.git] / fs / jbd2 / transaction.c
index 01e4652d88f69c81d6593dd4baabfa63766b9441..be56c8ca34c292e5156f840cac2ddcce6b562145 100644 (file)
@@ -2263,7 +2263,7 @@ int jbd2_journal_invalidatepage(journal_t *journal,
        struct buffer_head *head, *bh, *next;
        unsigned int stop = offset + length;
        unsigned int curr_off = 0;
-       int partial_page = (offset || length < PAGE_CACHE_SIZE);
+       int partial_page = (offset || length < PAGE_SIZE);
        int may_free = 1;
        int ret = 0;
 
@@ -2272,7 +2272,7 @@ int jbd2_journal_invalidatepage(journal_t *journal,
        if (!page_has_buffers(page))
                return 0;
 
-       BUG_ON(stop > PAGE_CACHE_SIZE || stop < length);
+       BUG_ON(stop > PAGE_SIZE || stop < length);
 
        /* We will potentially be playing with lists other than just the
         * data lists (especially for journaled data mode), so be
@@ -2462,7 +2462,8 @@ void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh)
 /*
  * File inode in the inode list of the handle's transaction
  */
-int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode)
+static int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode,
+                                  unsigned long flags)
 {
        transaction_t *transaction = handle->h_transaction;
        journal_t *journal;
@@ -2487,12 +2488,14 @@ int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode)
         * and if jinode->i_next_transaction == transaction, commit code
         * will only file the inode where we want it.
         */
-       if (jinode->i_transaction == transaction ||
-           jinode->i_next_transaction == transaction)
+       if ((jinode->i_transaction == transaction ||
+           jinode->i_next_transaction == transaction) &&
+           (jinode->i_flags & flags) == flags)
                return 0;
 
        spin_lock(&journal->j_list_lock);
-
+       jinode->i_flags |= flags;
+       /* Is inode already attached where we need it? */
        if (jinode->i_transaction == transaction ||
            jinode->i_next_transaction == transaction)
                goto done;
@@ -2523,6 +2526,17 @@ done:
        return 0;
 }
 
+int jbd2_journal_inode_add_write(handle_t *handle, struct jbd2_inode *jinode)
+{
+       return jbd2_journal_file_inode(handle, jinode,
+                                      JI_WRITE_DATA | JI_WAIT_DATA);
+}
+
+int jbd2_journal_inode_add_wait(handle_t *handle, struct jbd2_inode *jinode)
+{
+       return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA);
+}
+
 /*
  * File truncate and transaction commit interact with each other in a
  * non-trivial way.  If a transaction writing data block A is