]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ocfs2/dir.c
ocfs2: Support creation of unwritten extents
[linux-2.6-omap-h63xx.git] / fs / ocfs2 / dir.c
index 66821e178167d385866ce28c9d079425cf41b850..0d5fdde959c8018a2d244ae678d16fde1e5b3f33 100644 (file)
@@ -358,15 +358,17 @@ int ocfs2_do_extend_dir(struct super_block *sb,
 {
        int status;
        int extend;
-       u64 p_blkno;
+       u64 p_blkno, v_blkno;
 
        spin_lock(&OCFS2_I(dir)->ip_lock);
        extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters));
        spin_unlock(&OCFS2_I(dir)->ip_lock);
 
        if (extend) {
-               status = ocfs2_do_extend_allocation(OCFS2_SB(sb), dir, 1,
-                                                   parent_fe_bh, handle,
+               u32 offset = OCFS2_I(dir)->ip_clusters;
+
+               status = ocfs2_do_extend_allocation(OCFS2_SB(sb), dir, &offset,
+                                                   1, 0, parent_fe_bh, handle,
                                                    data_ac, meta_ac, NULL);
                BUG_ON(status == -EAGAIN);
                if (status < 0) {
@@ -375,9 +377,8 @@ int ocfs2_do_extend_dir(struct super_block *sb,
                }
        }
 
-       status = ocfs2_extent_map_get_blocks(dir, (dir->i_blocks >>
-                                                  (sb->s_blocksize_bits - 9)),
-                                            1, &p_blkno, NULL);
+       v_blkno = ocfs2_blocks_for_bytes(sb, i_size_read(dir));
+       status = ocfs2_extent_map_get_blocks(dir, v_blkno, &p_blkno, NULL, NULL);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
@@ -402,7 +403,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
                            struct buffer_head **new_de_bh)
 {
        int status = 0;
-       int credits, num_free_extents;
+       int credits, num_free_extents, drop_alloc_sem = 0;
        loff_t dir_i_size;
        struct ocfs2_dinode *fe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
        struct ocfs2_alloc_context *data_ac = NULL;
@@ -451,6 +452,9 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
                credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS;
        }
 
+       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);
@@ -486,7 +490,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
 
        dir_i_size += dir->i_sb->s_blocksize;
        i_size_write(dir, dir_i_size);
-       dir->i_blocks = ocfs2_align_bytes_to_sectors(dir_i_size);
+       dir->i_blocks = ocfs2_inode_sector_count(dir);
        status = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh);
        if (status < 0) {
                mlog_errno(status);
@@ -496,6 +500,8 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
        *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);