Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[pandora-kernel.git] / fs / ext4 / ext4_jbd2.h
index b455c68..139fb8c 100644 (file)
@@ -32,8 +32,8 @@
  * 5 levels of tree + root which are stored in the inode. */
 
 #define EXT4_SINGLEDATA_TRANS_BLOCKS(sb)                               \
-       (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)   \
-               || test_opt(sb, EXTENTS) ? 27U : 8U)
+       (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)   \
+        ? 27U : 8U)
 
 /* Extended attribute operations touch at most two data buffers,
  * two bitmap buffers, and two group summaries, in addition to the inode
@@ -122,12 +122,6 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
  * been done yet.
  */
 
-static inline void ext4_journal_release_buffer(handle_t *handle,
-                                               struct buffer_head *bh)
-{
-       jbd2_journal_release_buffer(handle, bh);
-}
-
 void ext4_journal_abort_handle(const char *caller, const char *err_fn,
                struct buffer_head *bh, handle_t *handle, int err);
 
@@ -137,17 +131,19 @@ int __ext4_journal_get_undo_access(const char *where, handle_t *handle,
 int __ext4_journal_get_write_access(const char *where, handle_t *handle,
                                struct buffer_head *bh);
 
+/* When called with an invalid handle, this will still do a put on the BH */
 int __ext4_journal_forget(const char *where, handle_t *handle,
                                struct buffer_head *bh);
 
+/* When called with an invalid handle, this will still do a put on the BH */
 int __ext4_journal_revoke(const char *where, handle_t *handle,
                                ext4_fsblk_t blocknr, struct buffer_head *bh);
 
 int __ext4_journal_get_create_access(const char *where,
                                handle_t *handle, struct buffer_head *bh);
 
-int __ext4_journal_dirty_metadata(const char *where,
-                               handle_t *handle, struct buffer_head *bh);
+int __ext4_handle_dirty_metadata(const char *where, handle_t *handle,
+                                struct inode *inode, struct buffer_head *bh);
 
 #define ext4_journal_get_undo_access(handle, bh) \
        __ext4_journal_get_undo_access(__func__, (handle), (bh))
@@ -157,14 +153,57 @@ int __ext4_journal_dirty_metadata(const char *where,
        __ext4_journal_revoke(__func__, (handle), (blocknr), (bh))
 #define ext4_journal_get_create_access(handle, bh) \
        __ext4_journal_get_create_access(__func__, (handle), (bh))
-#define ext4_journal_dirty_metadata(handle, bh) \
-       __ext4_journal_dirty_metadata(__func__, (handle), (bh))
 #define ext4_journal_forget(handle, bh) \
        __ext4_journal_forget(__func__, (handle), (bh))
+#define ext4_handle_dirty_metadata(handle, inode, bh) \
+       __ext4_handle_dirty_metadata(__func__, (handle), (inode), (bh))
 
 handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
 int __ext4_journal_stop(const char *where, handle_t *handle);
 
+#define EXT4_NOJOURNAL_HANDLE  ((handle_t *) 0x1)
+
+static inline int ext4_handle_valid(handle_t *handle)
+{
+       if (handle == EXT4_NOJOURNAL_HANDLE)
+               return 0;
+       return 1;
+}
+
+static inline void ext4_handle_sync(handle_t *handle)
+{
+       if (ext4_handle_valid(handle))
+               handle->h_sync = 1;
+}
+
+static inline void ext4_handle_release_buffer(handle_t *handle,
+                                               struct buffer_head *bh)
+{
+       if (ext4_handle_valid(handle))
+               jbd2_journal_release_buffer(handle, bh);
+}
+
+static inline int ext4_handle_is_aborted(handle_t *handle)
+{
+       if (ext4_handle_valid(handle))
+               return is_handle_aborted(handle);
+       return 0;
+}
+
+static inline int ext4_handle_has_enough_credits(handle_t *handle, int needed)
+{
+       if (ext4_handle_valid(handle) && handle->h_buffer_credits < needed)
+               return 0;
+       return 1;
+}
+
+static inline void ext4_journal_release_buffer(handle_t *handle,
+                                               struct buffer_head *bh)
+{
+       if (ext4_handle_valid(handle))
+               jbd2_journal_release_buffer(handle, bh);
+}
+
 static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks)
 {
        return ext4_journal_start_sb(inode->i_sb, nblocks);
@@ -180,27 +219,37 @@ static inline handle_t *ext4_journal_current_handle(void)
 
 static inline int ext4_journal_extend(handle_t *handle, int nblocks)
 {
-       return jbd2_journal_extend(handle, nblocks);
+       if (ext4_handle_valid(handle))
+               return jbd2_journal_extend(handle, nblocks);
+       return 0;
 }
 
 static inline int ext4_journal_restart(handle_t *handle, int nblocks)
 {
-       return jbd2_journal_restart(handle, nblocks);
+       if (ext4_handle_valid(handle))
+               return jbd2_journal_restart(handle, nblocks);
+       return 0;
 }
 
 static inline int ext4_journal_blocks_per_page(struct inode *inode)
 {
-       return jbd2_journal_blocks_per_page(inode);
+       if (EXT4_JOURNAL(inode) != NULL)
+               return jbd2_journal_blocks_per_page(inode);
+       return 0;
 }
 
 static inline int ext4_journal_force_commit(journal_t *journal)
 {
-       return jbd2_journal_force_commit(journal);
+       if (journal)
+               return jbd2_journal_force_commit(journal);
+       return 0;
 }
 
 static inline int ext4_jbd2_file_inode(handle_t *handle, struct inode *inode)
 {
-       return jbd2_journal_file_inode(handle, &EXT4_I(inode)->jinode);
+       if (ext4_handle_valid(handle))
+               return jbd2_journal_file_inode(handle, &EXT4_I(inode)->jinode);
+       return 0;
 }
 
 /* super.c */
@@ -208,6 +257,8 @@ int ext4_force_commit(struct super_block *sb);
 
 static inline int ext4_should_journal_data(struct inode *inode)
 {
+       if (EXT4_JOURNAL(inode) == NULL)
+               return 0;
        if (!S_ISREG(inode->i_mode))
                return 1;
        if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
@@ -219,6 +270,8 @@ static inline int ext4_should_journal_data(struct inode *inode)
 
 static inline int ext4_should_order_data(struct inode *inode)
 {
+       if (EXT4_JOURNAL(inode) == NULL)
+               return 0;
        if (!S_ISREG(inode->i_mode))
                return 0;
        if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
@@ -232,6 +285,8 @@ static inline int ext4_should_writeback_data(struct inode *inode)
 {
        if (!S_ISREG(inode->i_mode))
                return 0;
+       if (EXT4_JOURNAL(inode) == NULL)
+               return 1;
        if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
                return 0;
        if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)