ocfs2: Take the inode out of the metadata read/write paths.
[deliverable/linux.git] / fs / ocfs2 / dir.c
index c5752305627c669359f6e6cd688b9f3eecbb6958..273fb7648fcee7b79110365ce6920d6f7bcac13e 100644 (file)
@@ -564,7 +564,8 @@ static int ocfs2_read_dir_block_direct(struct inode *dir, u64 phys,
        int ret;
        struct buffer_head *tmp = *bh;
 
-       ret = ocfs2_read_block(dir, phys, &tmp, ocfs2_validate_dir_block);
+       ret = ocfs2_read_block(INODE_CACHE(dir), phys, &tmp,
+                              ocfs2_validate_dir_block);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -622,7 +623,8 @@ static int ocfs2_read_dx_root(struct inode *dir, struct ocfs2_dinode *di,
        u64 blkno = le64_to_cpu(di->i_dx_root);
        struct buffer_head *tmp = *dx_root_bh;
 
-       ret = ocfs2_read_block(dir, blkno, &tmp, ocfs2_validate_dx_root);
+       ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp,
+                              ocfs2_validate_dx_root);
 
        /* If ocfs2_read_block() got us a new bh, pass it up. */
        if (!ret && !*dx_root_bh)
@@ -662,7 +664,8 @@ static int ocfs2_read_dx_leaf(struct inode *dir, u64 blkno,
        int ret;
        struct buffer_head *tmp = *dx_leaf_bh;
 
-       ret = ocfs2_read_block(dir, blkno, &tmp, ocfs2_validate_dx_leaf);
+       ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp,
+                              ocfs2_validate_dx_leaf);
 
        /* If ocfs2_read_block() got us a new bh, pass it up. */
        if (!ret && !*dx_leaf_bh)
@@ -680,7 +683,7 @@ static int ocfs2_read_dx_leaves(struct inode *dir, u64 start, int num,
 {
        int ret;
 
-       ret = ocfs2_read_blocks(dir, start, num, dx_leaf_bhs, 0,
+       ret = ocfs2_read_blocks(INODE_CACHE(dir), start, num, dx_leaf_bhs, 0,
                                ocfs2_validate_dx_leaf);
        if (ret)
                mlog_errno(ret);
@@ -2332,7 +2335,7 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb,
                goto bail;
        }
 
-       ocfs2_set_new_buffer_uptodate(inode, new_bh);
+       ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh);
 
        status = ocfs2_journal_access_db(handle, inode, new_bh,
                                         OCFS2_JOURNAL_ACCESS_CREATE);
@@ -2418,7 +2421,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
                ret = -EIO;
                goto out;
        }
-       ocfs2_set_new_buffer_uptodate(dir, dx_root_bh);
+       ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dx_root_bh);
 
        ret = ocfs2_journal_access_dr(handle, dir, dx_root_bh,
                                      OCFS2_JOURNAL_ACCESS_CREATE);
@@ -2495,7 +2498,7 @@ static int ocfs2_dx_dir_format_cluster(struct ocfs2_super *osb,
                }
                dx_leaves[i] = bh;
 
-               ocfs2_set_new_buffer_uptodate(dir, bh);
+               ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), bh);
 
                ret = ocfs2_journal_access_dl(handle, dir, bh,
                                              OCFS2_JOURNAL_ACCESS_CREATE);
@@ -2900,6 +2903,8 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
        alloc = ocfs2_clusters_for_bytes(sb, bytes);
        dx_alloc = 0;
 
+       down_write(&oi->ip_alloc_sem);
+
        if (ocfs2_supports_indexed_dirs(osb)) {
                credits += ocfs2_add_dir_index_credits(sb);
 
@@ -2940,8 +2945,6 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
                goto out;
        }
 
-       down_write(&oi->ip_alloc_sem);
-
        /*
         * Prepare for worst case allocation scenario of two separate
         * extents in the unindexed tree.
@@ -2953,7 +2956,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
        if (IS_ERR(handle)) {
                ret = PTR_ERR(handle);
                mlog_errno(ret);
-               goto out_sem;
+               goto out;
        }
 
        if (vfs_dq_alloc_space_nodirty(dir,
@@ -3005,7 +3008,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
                goto out_commit;
        }
 
-       ocfs2_set_new_buffer_uptodate(dir, dirdata_bh);
+       ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dirdata_bh);
 
        ret = ocfs2_journal_access_db(handle, dir, dirdata_bh,
                                      OCFS2_JOURNAL_ACCESS_CREATE);
@@ -3172,10 +3175,8 @@ out_commit:
 
        ocfs2_commit_trans(osb, handle);
 
-out_sem:
-       up_write(&oi->ip_alloc_sem);
-
 out:
+       up_write(&oi->ip_alloc_sem);
        if (data_ac)
                ocfs2_free_alloc_context(data_ac);
        if (meta_ac)
@@ -3322,11 +3323,15 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
                brelse(new_bh);
                new_bh = NULL;
 
+               down_write(&OCFS2_I(dir)->ip_alloc_sem);
+               drop_alloc_sem = 1;
                dir_i_size = i_size_read(dir);
                credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS;
                goto do_extend;
        }
 
+       down_write(&OCFS2_I(dir)->ip_alloc_sem);
+       drop_alloc_sem = 1;
        dir_i_size = i_size_read(dir);
        mlog(0, "extending dir %llu (i_size = %lld)\n",
             (unsigned long long)OCFS2_I(dir)->ip_blkno, dir_i_size);
@@ -3370,9 +3375,6 @@ do_extend:
                credits++; /* For attaching the new dirent block to the
                            * dx_root */
 
-       down_write(&OCFS2_I(dir)->ip_alloc_sem);
-       drop_alloc_sem = 1;
-
        handle = ocfs2_start_trans(osb, credits);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
@@ -3388,7 +3390,7 @@ do_extend:
                goto bail;
        }
 
-       ocfs2_set_new_buffer_uptodate(dir, new_bh);
+       ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), new_bh);
 
        status = ocfs2_journal_access_db(handle, dir, new_bh,
                                         OCFS2_JOURNAL_ACCESS_CREATE);
@@ -3435,10 +3437,10 @@ bail_bh:
        *new_de_bh = new_bh;
        get_bh(*new_de_bh);
 bail:
-       if (drop_alloc_sem)
-               up_write(&OCFS2_I(dir)->ip_alloc_sem);
        if (handle)
                ocfs2_commit_trans(osb, handle);
+       if (drop_alloc_sem)
+               up_write(&OCFS2_I(dir)->ip_alloc_sem);
 
        if (data_ac)
                ocfs2_free_alloc_context(data_ac);
@@ -4566,7 +4568,7 @@ remove_index:
                goto out;
        }
 
-       ocfs2_remove_from_cache(dir, dx_root_bh);
+       ocfs2_remove_from_cache(INODE_CACHE(dir), dx_root_bh);
 out:
        ocfs2_schedule_truncate_log_flush(osb, 1);
        ocfs2_run_deallocs(osb, &dealloc);
This page took 0.026326 seconds and 5 git commands to generate.