ocfs2: ocfs2_complete_edge_insert() doesn't need struct inode at all.
[pandora-kernel.git] / fs / ocfs2 / alloc.c
index 678a067..4a8e971 100644 (file)
@@ -352,6 +352,7 @@ static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et,
 {
        et->et_ops = ops;
        et->et_root_bh = bh;
+       et->et_ci = INODE_CACHE(inode);
        et->et_root_journal_access = access;
        if (!obj)
                obj = (void *)bh->b_data;
@@ -415,11 +416,10 @@ static inline void ocfs2_et_update_clusters(struct inode *inode,
 }
 
 static inline int ocfs2_et_root_journal_access(handle_t *handle,
-                                              struct inode *inode,
                                               struct ocfs2_extent_tree *et,
                                               int type)
 {
-       return et->et_root_journal_access(handle, inode, et->et_root_bh,
+       return et->et_root_journal_access(handle, et->et_ci, et->et_root_bh,
                                          type);
 }
 
@@ -475,6 +475,12 @@ struct ocfs2_path {
 #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el)
 #define path_num_items(_path) ((_path)->p_tree_depth + 1)
 
+static int ocfs2_find_path(struct ocfs2_caching_info *ci,
+                          struct ocfs2_path *path, u32 cpos);
+static void ocfs2_adjust_rightmost_records(struct inode *inode,
+                                          handle_t *handle,
+                                          struct ocfs2_path *path,
+                                          struct ocfs2_extent_rec *insert_rec);
 /*
  * Reset the actual path elements so that we can re-use the structure
  * to build another path. Generally, this involves freeing the buffer
@@ -627,7 +633,7 @@ static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et)
  * ocfs2_journal_access_path(), but I don't have a better one.
  */
 static int ocfs2_path_bh_journal_access(handle_t *handle,
-                                       struct inode *inode,
+                                       struct ocfs2_caching_info *ci,
                                        struct ocfs2_path *path,
                                        int idx)
 {
@@ -639,14 +645,15 @@ static int ocfs2_path_bh_journal_access(handle_t *handle,
        if (idx)
                access = ocfs2_journal_access_eb;
 
-       return access(handle, inode, path->p_node[idx].bh,
+       return access(handle, ci, path->p_node[idx].bh,
                      OCFS2_JOURNAL_ACCESS_WRITE);
 }
 
 /*
  * Convenience function to journal all components in a path.
  */
-static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle,
+static int ocfs2_journal_access_path(struct ocfs2_caching_info *ci,
+                                    handle_t *handle,
                                     struct ocfs2_path *path)
 {
        int i, ret = 0;
@@ -655,7 +662,7 @@ static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle,
                goto out;
 
        for(i = 0; i < path_num_items(path); i++) {
-               ret = ocfs2_path_bh_journal_access(handle, inode, path, i);
+               ret = ocfs2_path_bh_journal_access(handle, ci, path, i);
                if (ret < 0) {
                        mlog_errno(ret);
                        goto out;
@@ -847,13 +854,13 @@ static int ocfs2_validate_extent_block(struct super_block *sb,
        return 0;
 }
 
-int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno,
+int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
                            struct buffer_head **bh)
 {
        int rc;
        struct buffer_head *tmp = *bh;
 
-       rc = ocfs2_read_block(inode, eb_blkno, &tmp,
+       rc = ocfs2_read_block(ci, eb_blkno, &tmp,
                              ocfs2_validate_extent_block);
 
        /* If ocfs2_read_block() got us a new bh, pass it up. */
@@ -868,7 +875,6 @@ int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno,
  * How many free extents have we got before we need more meta data?
  */
 int ocfs2_num_free_extents(struct ocfs2_super *osb,
-                          struct inode *inode,
                           struct ocfs2_extent_tree *et)
 {
        int retval;
@@ -883,7 +889,8 @@ int ocfs2_num_free_extents(struct ocfs2_super *osb,
        last_eb_blk = ocfs2_et_get_last_eb_blk(et);
 
        if (last_eb_blk) {
-               retval = ocfs2_read_extent_block(inode, last_eb_blk, &eb_bh);
+               retval = ocfs2_read_extent_block(et->et_ci, last_eb_blk,
+                                                &eb_bh);
                if (retval < 0) {
                        mlog_errno(retval);
                        goto bail;
@@ -907,9 +914,8 @@ bail:
  * sets h_signature, h_blkno, h_suballoc_bit, h_suballoc_slot, and
  * l_count for you
  */
-static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
-                                    handle_t *handle,
-                                    struct inode *inode,
+static int ocfs2_create_new_meta_bhs(handle_t *handle,
+                                    struct ocfs2_extent_tree *et,
                                     int wanted,
                                     struct ocfs2_alloc_context *meta_ac,
                                     struct buffer_head *bhs[])
@@ -918,6 +924,8 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
        u16 suballoc_bit_start;
        u32 num_got;
        u64 first_blkno;
+       struct ocfs2_super *osb =
+               OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci));
        struct ocfs2_extent_block *eb;
 
        mlog_entry_void();
@@ -943,9 +951,10 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
                                mlog_errno(status);
                                goto bail;
                        }
-                       ocfs2_set_new_buffer_uptodate(inode, bhs[i]);
+                       ocfs2_set_new_buffer_uptodate(et->et_ci, bhs[i]);
 
-                       status = ocfs2_journal_access_eb(handle, inode, bhs[i],
+                       status = ocfs2_journal_access_eb(handle, et->et_ci,
+                                                        bhs[i],
                                                         OCFS2_JOURNAL_ACCESS_CREATE);
                        if (status < 0) {
                                mlog_errno(status);
@@ -1012,6 +1021,54 @@ static inline u32 ocfs2_sum_rightmost_rec(struct ocfs2_extent_list  *el)
                ocfs2_rec_clusters(el, &el->l_recs[i]);
 }
 
+/*
+ * Change range of the branches in the right most path according to the leaf
+ * extent block's rightmost record.
+ */
+static int ocfs2_adjust_rightmost_branch(handle_t *handle,
+                                        struct inode *inode,
+                                        struct ocfs2_extent_tree *et)
+{
+       int status;
+       struct ocfs2_path *path = NULL;
+       struct ocfs2_extent_list *el;
+       struct ocfs2_extent_rec *rec;
+
+       path = ocfs2_new_path_from_et(et);
+       if (!path) {
+               status = -ENOMEM;
+               return status;
+       }
+
+       status = ocfs2_find_path(et->et_ci, path, UINT_MAX);
+       if (status < 0) {
+               mlog_errno(status);
+               goto out;
+       }
+
+       status = ocfs2_extend_trans(handle, path_num_items(path) +
+                                   handle->h_buffer_credits);
+       if (status < 0) {
+               mlog_errno(status);
+               goto out;
+       }
+
+       status = ocfs2_journal_access_path(INODE_CACHE(inode), handle, path);
+       if (status < 0) {
+               mlog_errno(status);
+               goto out;
+       }
+
+       el = path_leaf_el(path);
+       rec = &el->l_recs[le32_to_cpu(el->l_next_free_rec) - 1];
+
+       ocfs2_adjust_rightmost_records(inode, handle, path, rec);
+
+out:
+       ocfs2_free_path(path);
+       return status;
+}
+
 /*
  * Add an entire tree branch to our inode. eb_bh is the extent block
  * to start at, if we don't want to start the branch at the dinode
@@ -1038,7 +1095,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb,
        struct ocfs2_extent_block *eb;
        struct ocfs2_extent_list  *eb_el;
        struct ocfs2_extent_list  *el;
-       u32 new_cpos;
+       u32 new_cpos, root_end;
 
        mlog_entry_void();
 
@@ -1055,6 +1112,27 @@ static int ocfs2_add_branch(struct ocfs2_super *osb,
 
        new_blocks = le16_to_cpu(el->l_tree_depth);
 
+       eb = (struct ocfs2_extent_block *)(*last_eb_bh)->b_data;
+       new_cpos = ocfs2_sum_rightmost_rec(&eb->h_list);
+       root_end = ocfs2_sum_rightmost_rec(et->et_root_el);
+
+       /*
+        * If there is a gap before the root end and the real end
+        * of the righmost leaf block, we need to remove the gap
+        * between new_cpos and root_end first so that the tree
+        * is consistent after we add a new branch(it will start
+        * from new_cpos).
+        */
+       if (root_end > new_cpos) {
+               mlog(0, "adjust the cluster end from %u to %u\n",
+                    root_end, new_cpos);
+               status = ocfs2_adjust_rightmost_branch(handle, inode, et);
+               if (status) {
+                       mlog_errno(status);
+                       goto bail;
+               }
+       }
+
        /* allocate the number of new eb blocks we need */
        new_eb_bhs = kcalloc(new_blocks, sizeof(struct buffer_head *),
                             GFP_KERNEL);
@@ -1064,16 +1142,13 @@ static int ocfs2_add_branch(struct ocfs2_super *osb,
                goto bail;
        }
 
-       status = ocfs2_create_new_meta_bhs(osb, handle, inode, new_blocks,
+       status = ocfs2_create_new_meta_bhs(handle, et, new_blocks,
                                           meta_ac, new_eb_bhs);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
        }
 
-       eb = (struct ocfs2_extent_block *)(*last_eb_bh)->b_data;
-       new_cpos = ocfs2_sum_rightmost_rec(&eb->h_list);
-
        /* Note: new_eb_bhs[new_blocks - 1] is the guy which will be
         * linked with the rest of the tree.
         * conversly, new_eb_bhs[0] is the new bottommost leaf.
@@ -1089,7 +1164,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb,
                BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb));
                eb_el = &eb->h_list;
 
-               status = ocfs2_journal_access_eb(handle, inode, bh,
+               status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), bh,
                                                 OCFS2_JOURNAL_ACCESS_CREATE);
                if (status < 0) {
                        mlog_errno(status);
@@ -1129,20 +1204,20 @@ static int ocfs2_add_branch(struct ocfs2_super *osb,
         * journal_dirty erroring as it won't unless we've aborted the
         * handle (in which case we would never be here) so reserving
         * the write with journal_access is all we need to do. */
-       status = ocfs2_journal_access_eb(handle, inode, *last_eb_bh,
+       status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), *last_eb_bh,
                                         OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
        }
-       status = ocfs2_et_root_journal_access(handle, inode, et,
+       status = ocfs2_et_root_journal_access(handle, et,
                                              OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
        }
        if (eb_bh) {
-               status = ocfs2_journal_access_eb(handle, inode, eb_bh,
+               status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), eb_bh,
                                                 OCFS2_JOURNAL_ACCESS_WRITE);
                if (status < 0) {
                        mlog_errno(status);
@@ -1218,7 +1293,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb,
 
        mlog_entry_void();
 
-       status = ocfs2_create_new_meta_bhs(osb, handle, inode, 1, meta_ac,
+       status = ocfs2_create_new_meta_bhs(handle, et, 1, meta_ac,
                                           &new_eb_bh);
        if (status < 0) {
                mlog_errno(status);
@@ -1232,7 +1307,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb,
        eb_el = &eb->h_list;
        root_el = et->et_root_el;
 
-       status = ocfs2_journal_access_eb(handle, inode, new_eb_bh,
+       status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), new_eb_bh,
                                         OCFS2_JOURNAL_ACCESS_CREATE);
        if (status < 0) {
                mlog_errno(status);
@@ -1251,7 +1326,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb,
                goto bail;
        }
 
-       status = ocfs2_et_root_journal_access(handle, inode, et,
+       status = ocfs2_et_root_journal_access(handle, et,
                                              OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
@@ -1308,7 +1383,6 @@ bail:
  * return status < 0 indicates an error.
  */
 static int ocfs2_find_branch_target(struct ocfs2_super *osb,
-                                   struct inode *inode,
                                    struct ocfs2_extent_tree *et,
                                    struct buffer_head **target_bh)
 {
@@ -1327,19 +1401,21 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb,
 
        while(le16_to_cpu(el->l_tree_depth) > 1) {
                if (le16_to_cpu(el->l_next_free_rec) == 0) {
-                       ocfs2_error(inode->i_sb, "Dinode %llu has empty "
+                       ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
+                                   "Owner %llu has empty "
                                    "extent list (next_free_rec == 0)",
-                                   (unsigned long long)OCFS2_I(inode)->ip_blkno);
+                                   (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci));
                        status = -EIO;
                        goto bail;
                }
                i = le16_to_cpu(el->l_next_free_rec) - 1;
                blkno = le64_to_cpu(el->l_recs[i].e_blkno);
                if (!blkno) {
-                       ocfs2_error(inode->i_sb, "Dinode %llu has extent "
+                       ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
+                                   "Owner %llu has extent "
                                    "list where extent # %d has no physical "
                                    "block start",
-                                   (unsigned long long)OCFS2_I(inode)->ip_blkno, i);
+                                   (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), i);
                        status = -EIO;
                        goto bail;
                }
@@ -1347,7 +1423,7 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb,
                brelse(bh);
                bh = NULL;
 
-               status = ocfs2_read_extent_block(inode, blkno, &bh);
+               status = ocfs2_read_extent_block(et->et_ci, blkno, &bh);
                if (status < 0) {
                        mlog_errno(status);
                        goto bail;
@@ -1401,7 +1477,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle,
 
        BUG_ON(meta_ac == NULL);
 
-       shift = ocfs2_find_branch_target(osb, inode, et, &bh);
+       shift = ocfs2_find_branch_target(osb, et, &bh);
        if (shift < 0) {
                ret = shift;
                mlog_errno(ret);
@@ -1653,7 +1729,7 @@ typedef void (path_insert_t)(void *, struct buffer_head *);
  * This code can be called with a cpos larger than the tree, in which
  * case it will return the rightmost path.
  */
-static int __ocfs2_find_path(struct inode *inode,
+static int __ocfs2_find_path(struct ocfs2_caching_info *ci,
                             struct ocfs2_extent_list *root_el, u32 cpos,
                             path_insert_t *func, void *data)
 {
@@ -1664,15 +1740,14 @@ static int __ocfs2_find_path(struct inode *inode,
        struct ocfs2_extent_block *eb;
        struct ocfs2_extent_list *el;
        struct ocfs2_extent_rec *rec;
-       struct ocfs2_inode_info *oi = OCFS2_I(inode);
 
        el = root_el;
        while (el->l_tree_depth) {
                if (le16_to_cpu(el->l_next_free_rec) == 0) {
-                       ocfs2_error(inode->i_sb,
-                                   "Inode %llu has empty extent list at "
+                       ocfs2_error(ocfs2_metadata_cache_get_super(ci),
+                                   "Owner %llu has empty extent list at "
                                    "depth %u\n",
-                                   (unsigned long long)oi->ip_blkno,
+                                   (unsigned long long)ocfs2_metadata_cache_owner(ci),
                                    le16_to_cpu(el->l_tree_depth));
                        ret = -EROFS;
                        goto out;
@@ -1695,10 +1770,10 @@ static int __ocfs2_find_path(struct inode *inode,
 
                blkno = le64_to_cpu(el->l_recs[i].e_blkno);
                if (blkno == 0) {
-                       ocfs2_error(inode->i_sb,
-                                   "Inode %llu has bad blkno in extent list "
+                       ocfs2_error(ocfs2_metadata_cache_get_super(ci),
+                                   "Owner %llu has bad blkno in extent list "
                                    "at depth %u (index %d)\n",
-                                   (unsigned long long)oi->ip_blkno,
+                                   (unsigned long long)ocfs2_metadata_cache_owner(ci),
                                    le16_to_cpu(el->l_tree_depth), i);
                        ret = -EROFS;
                        goto out;
@@ -1706,7 +1781,7 @@ static int __ocfs2_find_path(struct inode *inode,
 
                brelse(bh);
                bh = NULL;
-               ret = ocfs2_read_extent_block(inode, blkno, &bh);
+               ret = ocfs2_read_extent_block(ci, blkno, &bh);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
@@ -1717,10 +1792,10 @@ static int __ocfs2_find_path(struct inode *inode,
 
                if (le16_to_cpu(el->l_next_free_rec) >
                    le16_to_cpu(el->l_count)) {
-                       ocfs2_error(inode->i_sb,
-                                   "Inode %llu has bad count in extent list "
+                       ocfs2_error(ocfs2_metadata_cache_get_super(ci),
+                                   "Owner %llu has bad count in extent list "
                                    "at block %llu (next free=%u, count=%u)\n",
-                                   (unsigned long long)oi->ip_blkno,
+                                   (unsigned long long)ocfs2_metadata_cache_owner(ci),
                                    (unsigned long long)bh->b_blocknr,
                                    le16_to_cpu(el->l_next_free_rec),
                                    le16_to_cpu(el->l_count));
@@ -1764,14 +1839,14 @@ static void find_path_ins(void *data, struct buffer_head *bh)
        ocfs2_path_insert_eb(fp->path, fp->index, bh);
        fp->index++;
 }
-static int ocfs2_find_path(struct inode *inode, struct ocfs2_path *path,
-                          u32 cpos)
+static int ocfs2_find_path(struct ocfs2_caching_info *ci,
+                          struct ocfs2_path *path, u32 cpos)
 {
        struct find_path_data data;
 
        data.index = 1;
        data.path = path;
-       return __ocfs2_find_path(inode, path_root_el(path), cpos,
+       return __ocfs2_find_path(ci, path_root_el(path), cpos,
                                 find_path_ins, &data);
 }
 
@@ -1796,13 +1871,14 @@ static void find_leaf_ins(void *data, struct buffer_head *bh)
  *
  * This function doesn't handle non btree extent lists.
  */
-int ocfs2_find_leaf(struct inode *inode, struct ocfs2_extent_list *root_el,
-                   u32 cpos, struct buffer_head **leaf_bh)
+int ocfs2_find_leaf(struct ocfs2_caching_info *ci,
+                   struct ocfs2_extent_list *root_el, u32 cpos,
+                   struct buffer_head **leaf_bh)
 {
        int ret;
        struct buffer_head *bh = NULL;
 
-       ret = __ocfs2_find_path(inode, root_el, cpos, find_leaf_ins, &bh);
+       ret = __ocfs2_find_path(ci, root_el, cpos, find_leaf_ins, &bh);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -1842,7 +1918,8 @@ static void ocfs2_adjust_adjacent_records(struct ocfs2_extent_rec *left_rec,
         * immediately to their right.
         */
        left_clusters = le32_to_cpu(right_child_el->l_recs[0].e_cpos);
-       if (ocfs2_is_empty_extent(&right_child_el->l_recs[0])) {
+       if (!ocfs2_rec_clusters(right_child_el, &right_child_el->l_recs[0])) {
+               BUG_ON(right_child_el->l_tree_depth);
                BUG_ON(le16_to_cpu(right_child_el->l_next_free_rec) <= 1);
                left_clusters = le32_to_cpu(right_child_el->l_recs[1].e_cpos);
        }
@@ -1907,7 +1984,7 @@ static void ocfs2_adjust_root_records(struct ocfs2_extent_list *root_el,
  *   - When we've adjusted the last extent record in the left path leaf and the
  *     1st extent record in the right path leaf during cross extent block merge.
  */
-static void ocfs2_complete_edge_insert(struct inode *inode, handle_t *handle,
+static void ocfs2_complete_edge_insert(handle_t *handle,
                                       struct ocfs2_path *left_path,
                                       struct ocfs2_path *right_path,
                                       int subtree_index)
@@ -2021,7 +2098,7 @@ static int ocfs2_rotate_subtree_right(struct inode *inode,
        root_bh = left_path->p_node[subtree_index].bh;
        BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
 
-       ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
+       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), right_path,
                                           subtree_index);
        if (ret) {
                mlog_errno(ret);
@@ -2029,14 +2106,14 @@ static int ocfs2_rotate_subtree_right(struct inode *inode,
        }
 
        for(i = subtree_index + 1; i < path_num_items(right_path); i++) {
-               ret = ocfs2_path_bh_journal_access(handle, inode,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                   right_path, i);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
                }
 
-               ret = ocfs2_path_bh_journal_access(handle, inode,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                   left_path, i);
                if (ret) {
                        mlog_errno(ret);
@@ -2084,8 +2161,8 @@ static int ocfs2_rotate_subtree_right(struct inode *inode,
                goto out;
        }
 
-       ocfs2_complete_edge_insert(inode, handle, left_path, right_path,
-                               subtree_index);
+       ocfs2_complete_edge_insert(handle, left_path, right_path,
+                                  subtree_index);
 
 out:
        return ret;
@@ -2306,7 +2383,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode,
                mlog(0, "Rotating a tree: ins. cpos: %u, left path cpos: %u\n",
                     insert_cpos, cpos);
 
-               ret = ocfs2_find_path(inode, left_path, cpos);
+               ret = ocfs2_find_path(INODE_CACHE(inode), left_path, cpos);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
@@ -2404,15 +2481,37 @@ out_ret_path:
        return ret;
 }
 
-static void ocfs2_update_edge_lengths(struct inode *inode, handle_t *handle,
-                                     struct ocfs2_path *path)
+static int ocfs2_update_edge_lengths(struct inode *inode, handle_t *handle,
+                                    int subtree_index, struct ocfs2_path *path)
 {
-       int i, idx;
+       int i, idx, ret;
        struct ocfs2_extent_rec *rec;
        struct ocfs2_extent_list *el;
        struct ocfs2_extent_block *eb;
        u32 range;
 
+       /*
+        * In normal tree rotation process, we will never touch the
+        * tree branch above subtree_index and ocfs2_extend_rotate_transaction
+        * doesn't reserve the credits for them either.
+        *
+        * But we do have a special case here which will update the rightmost
+        * records for all the bh in the path.
+        * So we have to allocate extra credits and access them.
+        */
+       ret = ocfs2_extend_trans(handle,
+                                handle->h_buffer_credits + subtree_index);
+       if (ret) {
+               mlog_errno(ret);
+               goto out;
+       }
+
+       ret = ocfs2_journal_access_path(INODE_CACHE(inode), handle, path);
+       if (ret) {
+               mlog_errno(ret);
+               goto out;
+       }
+
        /* Path should always be rightmost. */
        eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data;
        BUG_ON(eb->h_next_leaf_blk != 0ULL);
@@ -2433,9 +2532,12 @@ static void ocfs2_update_edge_lengths(struct inode *inode, handle_t *handle,
 
                ocfs2_journal_dirty(handle, path->p_node[i].bh);
        }
+out:
+       return ret;
 }
 
-static void ocfs2_unlink_path(struct inode *inode, handle_t *handle,
+static void ocfs2_unlink_path(handle_t *handle,
+                             struct ocfs2_extent_tree *et,
                              struct ocfs2_cached_dealloc_ctxt *dealloc,
                              struct ocfs2_path *path, int unlink_start)
 {
@@ -2457,12 +2559,12 @@ static void ocfs2_unlink_path(struct inode *inode, handle_t *handle,
                        mlog(ML_ERROR,
                             "Inode %llu, attempted to remove extent block "
                             "%llu with %u records\n",
-                            (unsigned long long)OCFS2_I(inode)->ip_blkno,
+                            (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
                             (unsigned long long)le64_to_cpu(eb->h_blkno),
                             le16_to_cpu(el->l_next_free_rec));
 
                        ocfs2_journal_dirty(handle, bh);
-                       ocfs2_remove_from_cache(inode, bh);
+                       ocfs2_remove_from_cache(et->et_ci, bh);
                        continue;
                }
 
@@ -2475,11 +2577,12 @@ static void ocfs2_unlink_path(struct inode *inode, handle_t *handle,
                if (ret)
                        mlog_errno(ret);
 
-               ocfs2_remove_from_cache(inode, bh);
+               ocfs2_remove_from_cache(et->et_ci, bh);
        }
 }
 
-static void ocfs2_unlink_subtree(struct inode *inode, handle_t *handle,
+static void ocfs2_unlink_subtree(handle_t *handle,
+                                struct ocfs2_extent_tree *et,
                                 struct ocfs2_path *left_path,
                                 struct ocfs2_path *right_path,
                                 int subtree_index,
@@ -2510,7 +2613,7 @@ static void ocfs2_unlink_subtree(struct inode *inode, handle_t *handle,
        ocfs2_journal_dirty(handle, root_bh);
        ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
 
-       ocfs2_unlink_path(inode, handle, dealloc, right_path,
+       ocfs2_unlink_path(handle, et, dealloc, right_path,
                          subtree_index + 1);
 }
 
@@ -2556,7 +2659,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
                        return -EAGAIN;
 
                if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) {
-                       ret = ocfs2_journal_access_eb(handle, inode,
+                       ret = ocfs2_journal_access_eb(handle, INODE_CACHE(inode),
                                                      path_leaf_bh(right_path),
                                                      OCFS2_JOURNAL_ACCESS_WRITE);
                        if (ret) {
@@ -2575,7 +2678,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
                 * We have to update i_last_eb_blk during the meta
                 * data delete.
                 */
-               ret = ocfs2_et_root_journal_access(handle, inode, et,
+               ret = ocfs2_et_root_journal_access(handle, et,
                                                   OCFS2_JOURNAL_ACCESS_WRITE);
                if (ret) {
                        mlog_errno(ret);
@@ -2591,7 +2694,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
         */
        BUG_ON(right_has_empty && !del_right_subtree);
 
-       ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
+       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), right_path,
                                           subtree_index);
        if (ret) {
                mlog_errno(ret);
@@ -2599,14 +2702,14 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
        }
 
        for(i = subtree_index + 1; i < path_num_items(right_path); i++) {
-               ret = ocfs2_path_bh_journal_access(handle, inode,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                   right_path, i);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
                }
 
-               ret = ocfs2_path_bh_journal_access(handle, inode,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                   left_path, i);
                if (ret) {
                        mlog_errno(ret);
@@ -2643,9 +2746,14 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
                mlog_errno(ret);
 
        if (del_right_subtree) {
-               ocfs2_unlink_subtree(inode, handle, left_path, right_path,
+               ocfs2_unlink_subtree(handle, et, left_path, right_path,
                                     subtree_index, dealloc);
-               ocfs2_update_edge_lengths(inode, handle, left_path);
+               ret = ocfs2_update_edge_lengths(inode, handle, subtree_index,
+                                               left_path);
+               if (ret) {
+                       mlog_errno(ret);
+                       goto out;
+               }
 
                eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
                ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));
@@ -2664,7 +2772,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
 
                *deleted = 1;
        } else
-               ocfs2_complete_edge_insert(inode, handle, left_path, right_path,
+               ocfs2_complete_edge_insert(handle, left_path, right_path,
                                           subtree_index);
 
 out:
@@ -2761,7 +2869,7 @@ static int ocfs2_rotate_rightmost_leaf_left(struct inode *inode,
        if (!ocfs2_is_empty_extent(&el->l_recs[0]))
                return 0;
 
-       ret = ocfs2_path_bh_journal_access(handle, inode, path,
+       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), path,
                                           path_num_items(path) - 1);
        if (ret) {
                mlog_errno(ret);
@@ -2818,7 +2926,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode,
        }
 
        while (right_cpos) {
-               ret = ocfs2_find_path(inode, right_path, right_cpos);
+               ret = ocfs2_find_path(et->et_ci, right_path, right_cpos);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
@@ -2844,7 +2952,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode,
                 * Caller might still want to make changes to the
                 * tree root, so re-add it to the journal here.
                 */
-               ret = ocfs2_path_bh_journal_access(handle, inode,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                   left_path, 0);
                if (ret) {
                        mlog_errno(ret);
@@ -2922,13 +3030,14 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle,
                goto out;
        }
 
-       ret = ocfs2_journal_access_path(inode, handle, path);
+       ret = ocfs2_journal_access_path(et->et_ci, handle, path);
        if (ret) {
                mlog_errno(ret);
                goto out;
        }
 
-       ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, &cpos);
+       ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci),
+                                           path, &cpos);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -2946,13 +3055,13 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle,
                        goto out;
                }
 
-               ret = ocfs2_find_path(inode, left_path, cpos);
+               ret = ocfs2_find_path(et->et_ci, left_path, cpos);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
                }
 
-               ret = ocfs2_journal_access_path(inode, handle, left_path);
+               ret = ocfs2_journal_access_path(et->et_ci, handle, left_path);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
@@ -2960,9 +3069,14 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle,
 
                subtree_index = ocfs2_find_subtree_root(inode, left_path, path);
 
-               ocfs2_unlink_subtree(inode, handle, left_path, path,
+               ocfs2_unlink_subtree(handle, et, left_path, path,
                                     subtree_index, dealloc);
-               ocfs2_update_edge_lengths(inode, handle, left_path);
+               ret = ocfs2_update_edge_lengths(inode, handle, subtree_index,
+                                               left_path);
+               if (ret) {
+                       mlog_errno(ret);
+                       goto out;
+               }
 
                eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
                ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));
@@ -2974,7 +3088,7 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle,
                 * revert the inode back to having extents
                 * in-line.
                 */
-               ocfs2_unlink_path(inode, handle, dealloc, path, 1);
+               ocfs2_unlink_path(handle, et, dealloc, path, 1);
 
                el = et->et_root_el;
                el->l_tree_depth = 0;
@@ -3186,7 +3300,7 @@ static int ocfs2_get_right_path(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_find_path(inode, right_path, right_cpos);
+       ret = ocfs2_find_path(INODE_CACHE(inode), right_path, right_cpos);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -3262,7 +3376,7 @@ static int ocfs2_merge_rec_right(struct inode *inode,
                root_bh = left_path->p_node[subtree_index].bh;
                BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
 
-               ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), right_path,
                                                   subtree_index);
                if (ret) {
                        mlog_errno(ret);
@@ -3271,14 +3385,14 @@ static int ocfs2_merge_rec_right(struct inode *inode,
 
                for (i = subtree_index + 1;
                     i < path_num_items(right_path); i++) {
-                       ret = ocfs2_path_bh_journal_access(handle, inode,
+                       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                           right_path, i);
                        if (ret) {
                                mlog_errno(ret);
                                goto out;
                        }
 
-                       ret = ocfs2_path_bh_journal_access(handle, inode,
+                       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                           left_path, i);
                        if (ret) {
                                mlog_errno(ret);
@@ -3291,7 +3405,7 @@ static int ocfs2_merge_rec_right(struct inode *inode,
                right_rec = &el->l_recs[index + 1];
        }
 
-       ret = ocfs2_path_bh_journal_access(handle, inode, left_path,
+       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), left_path,
                                           path_num_items(left_path) - 1);
        if (ret) {
                mlog_errno(ret);
@@ -3316,8 +3430,8 @@ static int ocfs2_merge_rec_right(struct inode *inode,
                if (ret)
                        mlog_errno(ret);
 
-               ocfs2_complete_edge_insert(inode, handle, left_path,
-                                          right_path, subtree_index);
+               ocfs2_complete_edge_insert(handle, left_path, right_path,
+                                          subtree_index);
        }
 out:
        if (right_path)
@@ -3355,7 +3469,7 @@ static int ocfs2_get_left_path(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_find_path(inode, left_path, left_cpos);
+       ret = ocfs2_find_path(INODE_CACHE(inode), left_path, left_cpos);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -3431,7 +3545,7 @@ static int ocfs2_merge_rec_left(struct inode *inode,
                root_bh = left_path->p_node[subtree_index].bh;
                BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
 
-               ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
+               ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), right_path,
                                                   subtree_index);
                if (ret) {
                        mlog_errno(ret);
@@ -3440,14 +3554,14 @@ static int ocfs2_merge_rec_left(struct inode *inode,
 
                for (i = subtree_index + 1;
                     i < path_num_items(right_path); i++) {
-                       ret = ocfs2_path_bh_journal_access(handle, inode,
+                       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                           right_path, i);
                        if (ret) {
                                mlog_errno(ret);
                                goto out;
                        }
 
-                       ret = ocfs2_path_bh_journal_access(handle, inode,
+                       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode),
                                                           left_path, i);
                        if (ret) {
                                mlog_errno(ret);
@@ -3460,7 +3574,7 @@ static int ocfs2_merge_rec_left(struct inode *inode,
                        has_empty_extent = 1;
        }
 
-       ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
+       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), right_path,
                                           path_num_items(right_path) - 1);
        if (ret) {
                mlog_errno(ret);
@@ -3515,7 +3629,7 @@ static int ocfs2_merge_rec_left(struct inode *inode,
                        ocfs2_mv_path(right_path, left_path);
                        left_path = NULL;
                } else
-                       ocfs2_complete_edge_insert(inode, handle, left_path,
+                       ocfs2_complete_edge_insert(handle, left_path,
                                                   right_path, subtree_index);
        }
 out:
@@ -3885,7 +3999,8 @@ static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle,
                                goto out;
                        }
 
-                       ret = ocfs2_find_path(inode, left_path, left_cpos);
+                       ret = ocfs2_find_path(INODE_CACHE(inode), left_path,
+                                             left_cpos);
                        if (ret) {
                                mlog_errno(ret);
                                goto out;
@@ -3898,7 +4013,7 @@ static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle,
                }
        }
 
-       ret = ocfs2_journal_access_path(inode, handle, right_path);
+       ret = ocfs2_journal_access_path(INODE_CACHE(inode), handle, right_path);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -4027,7 +4142,7 @@ static int ocfs2_insert_path(struct inode *inode,
                        goto out;
                }
 
-               ret = ocfs2_journal_access_path(inode, handle, left_path);
+               ret = ocfs2_journal_access_path(INODE_CACHE(inode), handle, left_path);
                if (ret < 0) {
                        mlog_errno(ret);
                        goto out;
@@ -4038,7 +4153,7 @@ static int ocfs2_insert_path(struct inode *inode,
         * Pass both paths to the journal. The majority of inserts
         * will be touching all components anyway.
         */
-       ret = ocfs2_journal_access_path(inode, handle, right_path);
+       ret = ocfs2_journal_access_path(INODE_CACHE(inode), handle, right_path);
        if (ret < 0) {
                mlog_errno(ret);
                goto out;
@@ -4080,8 +4195,8 @@ static int ocfs2_insert_path(struct inode *inode,
                 */
                subtree_index = ocfs2_find_subtree_root(inode, left_path,
                                                        right_path);
-               ocfs2_complete_edge_insert(inode, handle, left_path,
-                                          right_path, subtree_index);
+               ocfs2_complete_edge_insert(handle, left_path, right_path,
+                                          subtree_index);
        }
 
        ret = 0;
@@ -4103,7 +4218,7 @@ static int ocfs2_do_insert_extent(struct inode *inode,
 
        el = et->et_root_el;
 
-       ret = ocfs2_et_root_journal_access(handle, inode, et,
+       ret = ocfs2_et_root_journal_access(handle, et,
                                           OCFS2_JOURNAL_ACCESS_WRITE);
        if (ret) {
                mlog_errno(ret);
@@ -4134,7 +4249,7 @@ static int ocfs2_do_insert_extent(struct inode *inode,
                cpos = UINT_MAX;
        }
 
-       ret = ocfs2_find_path(inode, right_path, cpos);
+       ret = ocfs2_find_path(et->et_ci, right_path, cpos);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -4165,7 +4280,7 @@ static int ocfs2_do_insert_extent(struct inode *inode,
                 * ocfs2_rotate_tree_right() might have extended the
                 * transaction without re-journaling our tree root.
                 */
-               ret = ocfs2_et_root_journal_access(handle, inode, et,
+               ret = ocfs2_et_root_journal_access(handle, et,
                                                   OCFS2_JOURNAL_ACCESS_WRITE);
                if (ret) {
                        mlog_errno(ret);
@@ -4231,7 +4346,8 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path,
                        if (!left_path)
                                goto out;
 
-                       status = ocfs2_find_path(inode, left_path, left_cpos);
+                       status = ocfs2_find_path(INODE_CACHE(inode),
+                                                left_path, left_cpos);
                        if (status)
                                goto out;
 
@@ -4287,7 +4403,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path,
                if (!right_path)
                        goto out;
 
-               status = ocfs2_find_path(inode, right_path, right_cpos);
+               status = ocfs2_find_path(INODE_CACHE(inode), right_path, right_cpos);
                if (status)
                        goto out;
 
@@ -4448,7 +4564,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
                 * ocfs2_figure_insert_type() and ocfs2_add_branch()
                 * may want it later.
                 */
-               ret = ocfs2_read_extent_block(inode,
+               ret = ocfs2_read_extent_block(et->et_ci,
                                              ocfs2_et_get_last_eb_blk(et),
                                              &bh);
                if (ret) {
@@ -4489,7 +4605,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
         * us the rightmost tree path. This is accounted for below in
         * the appending code.
         */
-       ret = ocfs2_find_path(inode, path, le32_to_cpu(insert_rec->e_cpos));
+       ret = ocfs2_find_path(et->et_ci, path, le32_to_cpu(insert_rec->e_cpos));
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -4651,7 +4767,7 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
        if (mark_unwritten)
                flags = OCFS2_EXT_UNWRITTEN;
 
-       free_extents = ocfs2_num_free_extents(osb, inode, et);
+       free_extents = ocfs2_num_free_extents(osb, et);
        if (free_extents < 0) {
                status = free_extents;
                mlog_errno(status);
@@ -4688,7 +4804,7 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
        BUG_ON(num_bits > clusters_to_add);
 
        /* reserve our write early -- insert_extent may update the tree root */
-       status = ocfs2_et_root_journal_access(handle, inode, et,
+       status = ocfs2_et_root_journal_access(handle, et,
                                              OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
@@ -4839,7 +4955,7 @@ leftright:
                ocfs2_reinit_path(path, 1);
 
                cpos = le32_to_cpu(split_rec.e_cpos);
-               ret = ocfs2_find_path(inode, path, cpos);
+               ret = ocfs2_find_path(et->et_ci, path, cpos);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
@@ -4863,7 +4979,7 @@ static int ocfs2_replace_extent_rec(struct inode *inode,
 {
        int ret;
 
-       ret = ocfs2_path_bh_journal_access(handle, inode, path,
+       ret = ocfs2_path_bh_journal_access(handle, INODE_CACHE(inode), path,
                                           path_num_items(path) - 1);
        if (ret) {
                mlog_errno(ret);
@@ -4939,7 +5055,7 @@ static int __ocfs2_mark_extent_written(struct inode *inode,
        if (path->p_tree_depth) {
                struct ocfs2_extent_block *eb;
 
-               ret = ocfs2_read_extent_block(inode,
+               ret = ocfs2_read_extent_block(et->et_ci,
                                              ocfs2_et_get_last_eb_blk(et),
                                              &last_eb_bh);
                if (ret) {
@@ -5037,7 +5153,7 @@ int ocfs2_mark_extent_written(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_find_path(inode, left_path, cpos);
+       ret = ocfs2_find_path(et->et_ci, left_path, cpos);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -5094,7 +5210,7 @@ static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et,
 
        depth = path->p_tree_depth;
        if (depth > 0) {
-               ret = ocfs2_read_extent_block(inode,
+               ret = ocfs2_read_extent_block(et->et_ci,
                                              ocfs2_et_get_last_eb_blk(et),
                                              &last_eb_bh);
                if (ret < 0) {
@@ -5209,7 +5325,8 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle,
                                goto out;
                        }
 
-                       ret = ocfs2_find_path(inode, left_path, left_cpos);
+                       ret = ocfs2_find_path(et->et_ci, left_path,
+                                             left_cpos);
                        if (ret) {
                                mlog_errno(ret);
                                goto out;
@@ -5225,13 +5342,13 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle,
                goto out;
        }
 
-       ret = ocfs2_journal_access_path(inode, handle, path);
+       ret = ocfs2_journal_access_path(et->et_ci, handle, path);
        if (ret) {
                mlog_errno(ret);
                goto out;
        }
 
-       ret = ocfs2_journal_access_path(inode, handle, left_path);
+       ret = ocfs2_journal_access_path(et->et_ci, handle, left_path);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -5280,7 +5397,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle,
                int subtree_index;
 
                subtree_index = ocfs2_find_subtree_root(inode, left_path, path);
-               ocfs2_complete_edge_insert(inode, handle, left_path, path,
+               ocfs2_complete_edge_insert(handle, left_path, path,
                                           subtree_index);
        }
 
@@ -5318,7 +5435,7 @@ int ocfs2_remove_extent(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_find_path(inode, path, cpos);
+       ret = ocfs2_find_path(et->et_ci, path, cpos);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -5383,7 +5500,7 @@ int ocfs2_remove_extent(struct inode *inode,
                 */
                ocfs2_reinit_path(path, 1);
 
-               ret = ocfs2_find_path(inode, path, cpos);
+               ret = ocfs2_find_path(et->et_ci, path, cpos);
                if (ret) {
                        mlog_errno(ret);
                        goto out;
@@ -5466,7 +5583,7 @@ int ocfs2_remove_btree_range(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_et_root_journal_access(handle, inode, et,
+       ret = ocfs2_et_root_journal_access(handle, et,
                                           OCFS2_JOURNAL_ACCESS_WRITE);
        if (ret) {
                mlog_errno(ret);
@@ -5583,7 +5700,7 @@ int ocfs2_truncate_log_append(struct ocfs2_super *osb,
                goto bail;
        }
 
-       status = ocfs2_journal_access_di(handle, tl_inode, tl_bh,
+       status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh,
                                         OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
@@ -5645,7 +5762,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb,
        while (i >= 0) {
                /* Caller has given us at least enough credits to
                 * update the truncate log dinode */
-               status = ocfs2_journal_access_di(handle, tl_inode, tl_bh,
+               status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh,
                                                 OCFS2_JOURNAL_ACCESS_WRITE);
                if (status < 0) {
                        mlog_errno(status);
@@ -5903,7 +6020,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb,
                tl->tl_used = 0;
 
                ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check);
-               status = ocfs2_write_block(osb, tl_bh, tl_inode);
+               status = ocfs2_write_block(osb, tl_bh, INODE_CACHE(tl_inode));
                if (status < 0) {
                        mlog_errno(status);
                        goto bail;
@@ -6411,7 +6528,7 @@ static int ocfs2_find_new_last_ext_blk(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_find_leaf(inode, path_root_el(path), cpos, &bh);
+       ret = ocfs2_find_leaf(INODE_CACHE(inode), path_root_el(path), cpos, &bh);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -6612,7 +6729,7 @@ delete:
 
                        mlog(0, "deleting this extent block.\n");
 
-                       ocfs2_remove_from_cache(inode, bh);
+                       ocfs2_remove_from_cache(INODE_CACHE(inode), bh);
 
                        BUG_ON(ocfs2_rec_clusters(el, &el->l_recs[0]));
                        BUG_ON(le32_to_cpu(el->l_recs[0].e_cpos));
@@ -6662,14 +6779,14 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb,
         * Each component will be touched, so we might as well journal
         * here to avoid having to handle errors later.
         */
-       status = ocfs2_journal_access_path(inode, handle, path);
+       status = ocfs2_journal_access_path(INODE_CACHE(inode), handle, path);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
        }
 
        if (last_eb_bh) {
-               status = ocfs2_journal_access_eb(handle, inode, last_eb_bh,
+               status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), last_eb_bh,
                                                 OCFS2_JOURNAL_ACCESS_WRITE);
                if (status < 0) {
                        mlog_errno(status);
@@ -6744,7 +6861,7 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb,
        }
        status = 0;
 bail:
-
+       brelse(last_eb_bh);
        mlog_exit(status);
        return status;
 }
@@ -7031,7 +7148,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
                goto out_unlock;
        }
 
-       ret = ocfs2_journal_access_di(handle, inode, di_bh,
+       ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
                                      OCFS2_JOURNAL_ACCESS_WRITE);
        if (ret) {
                mlog_errno(ret);
@@ -7188,7 +7305,7 @@ start:
        /*
         * Truncate always works against the rightmost tree branch.
         */
-       status = ocfs2_find_path(inode, path, UINT_MAX);
+       status = ocfs2_find_path(INODE_CACHE(inode), path, UINT_MAX);
        if (status) {
                mlog_errno(status);
                goto bail;
@@ -7338,7 +7455,7 @@ int ocfs2_prepare_truncate(struct ocfs2_super *osb,
        ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc);
 
        if (fe->id2.i_list.l_tree_depth) {
-               status = ocfs2_read_extent_block(inode,
+               status = ocfs2_read_extent_block(INODE_CACHE(inode),
                                                 le64_to_cpu(fe->i_last_eb_blk),
                                                 &last_eb_bh);
                if (status < 0) {
@@ -7400,7 +7517,7 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh,
                goto out;
        }
 
-       ret = ocfs2_journal_access_di(handle, inode, di_bh,
+       ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
                                      OCFS2_JOURNAL_ACCESS_WRITE);
        if (ret) {
                mlog_errno(ret);