/* FIXME...EIEIO, ENOSPC and more */
        /* insert any holes we need to create */
-       if (isize < end_pos) {
+       if (isize < start_pos) {
                u64 last_pos_in_file;
                u64 hole_size;
                u64 mask = root->sectorsize - 1;
                last_pos_in_file = (isize + mask) & ~mask;
-               hole_size = (end_pos - last_pos_in_file + mask) & ~mask;
-               if (last_pos_in_file < end_pos) {
+               hole_size = (start_pos - last_pos_in_file + mask) & ~mask;
+               if (last_pos_in_file < start_pos) {
                        err = btrfs_drop_extents(trans, root, inode,
                                                 last_pos_in_file,
                                                 last_pos_in_file + hole_size,
 
        trans = btrfs_start_transaction(root, 1);
 
        btrfs_set_trans_block_group(trans, inode);
+       mutex_lock(&BTRFS_I(inode)->csum_mutex);
        btrfs_csum_file_blocks(trans, root, inode, bio, sums);
+       mutex_unlock(&BTRFS_I(inode)->csum_mutex);
 
        ret = btrfs_end_transaction(trans, root);
        BUG_ON(ret);
                             inode->i_mapping, GFP_NOFS);
        extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
                             inode->i_mapping, GFP_NOFS);
+       mutex_init(&BTRFS_I(inode)->csum_mutex);
        atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
        return 0;
 }
                             inode->i_mapping, GFP_NOFS);
        extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
                             inode->i_mapping, GFP_NOFS);
+       mutex_init(&BTRFS_I(inode)->csum_mutex);
        atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
        BTRFS_I(inode)->delalloc_bytes = 0;
        BTRFS_I(inode)->root = root;
                                     inode->i_mapping, GFP_NOFS);
                extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
                                     inode->i_mapping, GFP_NOFS);
+               mutex_init(&BTRFS_I(inode)->csum_mutex);
                BTRFS_I(inode)->delalloc_bytes = 0;
                atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
                BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
                                     inode->i_mapping, GFP_NOFS);
                extent_io_tree_init(&BTRFS_I(inode)->io_failure_tree,
                                     inode->i_mapping, GFP_NOFS);
+               mutex_init(&BTRFS_I(inode)->csum_mutex);
                BTRFS_I(inode)->delalloc_bytes = 0;
                atomic_set(&BTRFS_I(inode)->ordered_writeback, 0);
                BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;