@@ -3168,6 +3168,8 @@ struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location,
struct btrfs_path *path);
struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
struct btrfs_root *root, int *was_new);
+int btrfs_get_extent_map_write(struct extent_map **map, struct buffer_head *bh,
+ struct inode *inode, u64 start, u64 len);
struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
struct page *page, size_t pg_offset,
u64 start, u64 end, int create);
@@ -7592,11 +7592,10 @@ static int btrfs_get_blocks_direct_read(struct extent_map *em,
return 0;
}
-static int btrfs_get_blocks_direct_write(struct extent_map **map,
- struct buffer_head *bh_result,
- struct inode *inode,
- struct btrfs_dio_data *dio_data,
- u64 start, u64 len)
+int btrfs_get_extent_map_write(struct extent_map **map,
+ struct buffer_head *bh,
+ struct inode *inode,
+ u64 start, u64 len)
{
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct extent_map *em = *map;
@@ -7650,22 +7649,38 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
*/
btrfs_free_reserved_data_space_noquota(inode, start,
len);
- goto skip_cow;
+ /* skip COW */
+ goto out;
}
}
/* this will cow the extent */
- len = bh_result->b_size;
+ if (bh)
+ len = bh->b_size;
free_extent_map(em);
*map = em = btrfs_new_extent_direct(inode, start, len);
- if (IS_ERR(em)) {
- ret = PTR_ERR(em);
- goto out;
- }
+ if (IS_ERR(em))
+ return PTR_ERR(em);
+out:
+ return ret;
+}
+static int btrfs_get_blocks_direct_write(struct extent_map **map,
+ struct buffer_head *bh_result,
+ struct inode *inode,
+ struct btrfs_dio_data *dio_data,
+ u64 start, u64 len)
+{
+ int ret;
+ struct extent_map *em;
+
+ ret = btrfs_get_extent_map_write(map, bh_result, inode,
+ start, len);
+ if (ret < 0)
+ return ret;
+ em = *map;
len = min(len, em->len - (start - em->start));
-skip_cow:
bh_result->b_blocknr = (em->block_start + (start - em->start)) >>
inode->i_blkbits;
bh_result->b_size = len;
@@ -7686,7 +7701,6 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
dio_data->reserve -= len;
dio_data->unsubmitted_oe_range_end = start + len;
current->journal_info = dio_data;
-out:
return ret;
}