aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.h3
-rw-r--r--fs/btrfs/extent-tree.c12
-rw-r--r--fs/btrfs/inode.c2
3 files changed, 13 insertions, 4 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e803c4daad21..09d614fcafb1 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1286,7 +1286,8 @@ int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1286 u64 owner, u64 owner_offset); 1286 u64 owner, u64 owner_offset);
1287int btrfs_alloc_extent(struct btrfs_trans_handle *trans, 1287int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1288 struct btrfs_root *root, 1288 struct btrfs_root *root,
1289 u64 num_bytes, u64 root_objectid, u64 ref_generation, 1289 u64 num_bytes, u64 min_bytes,
1290 u64 root_objectid, u64 ref_generation,
1290 u64 owner, u64 owner_offset, 1291 u64 owner, u64 owner_offset,
1291 u64 empty_size, u64 hint_byte, 1292 u64 empty_size, u64 hint_byte,
1292 u64 search_end, struct btrfs_key *ins, int data); 1293 u64 search_end, struct btrfs_key *ins, int data);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index a056a2df689a..e49147e767df 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1694,7 +1694,8 @@ error:
1694 */ 1694 */
1695int btrfs_alloc_extent(struct btrfs_trans_handle *trans, 1695int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1696 struct btrfs_root *root, 1696 struct btrfs_root *root,
1697 u64 num_bytes, u64 root_objectid, u64 ref_generation, 1697 u64 num_bytes, u64 min_alloc_size,
1698 u64 root_objectid, u64 ref_generation,
1698 u64 owner, u64 owner_offset, 1699 u64 owner, u64 owner_offset,
1699 u64 empty_size, u64 hint_byte, 1700 u64 empty_size, u64 hint_byte,
1700 u64 search_end, struct btrfs_key *ins, int data) 1701 u64 search_end, struct btrfs_key *ins, int data)
@@ -1727,7 +1728,7 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1727 info->metadata_alloc_profile; 1728 info->metadata_alloc_profile;
1728 data = BTRFS_BLOCK_GROUP_METADATA | alloc_profile; 1729 data = BTRFS_BLOCK_GROUP_METADATA | alloc_profile;
1729 } 1730 }
1730 1731again:
1731 if (root->ref_cows) { 1732 if (root->ref_cows) {
1732 if (!(data & BTRFS_BLOCK_GROUP_METADATA)) { 1733 if (!(data & BTRFS_BLOCK_GROUP_METADATA)) {
1733 ret = do_chunk_alloc(trans, root->fs_info->extent_root, 1734 ret = do_chunk_alloc(trans, root->fs_info->extent_root,
@@ -1751,6 +1752,11 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1751 search_start, search_end, hint_byte, ins, 1752 search_start, search_end, hint_byte, ins,
1752 trans->alloc_exclude_start, 1753 trans->alloc_exclude_start,
1753 trans->alloc_exclude_nr, data); 1754 trans->alloc_exclude_nr, data);
1755 if (ret == -ENOSPC && num_bytes > min_alloc_size) {
1756 num_bytes = num_bytes >> 1;
1757 num_bytes = max(num_bytes, min_alloc_size);
1758 goto again;
1759 }
1754 BUG_ON(ret); 1760 BUG_ON(ret);
1755 if (ret) 1761 if (ret)
1756 return ret; 1762 return ret;
@@ -1869,7 +1875,7 @@ struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1869 int ret; 1875 int ret;
1870 struct extent_buffer *buf; 1876 struct extent_buffer *buf;
1871 1877
1872 ret = btrfs_alloc_extent(trans, root, blocksize, 1878 ret = btrfs_alloc_extent(trans, root, blocksize, blocksize,
1873 root_objectid, ref_generation, 1879 root_objectid, ref_generation,
1874 level, first_objectid, empty_size, hint, 1880 level, first_objectid, empty_size, hint,
1875 (u64)-1, &ins, 0); 1881 (u64)-1, &ins, 0);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 46f54dfa2b0a..7869c0157a1f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -125,6 +125,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end)
125 while(num_bytes > 0) { 125 while(num_bytes > 0) {
126 cur_alloc_size = min(num_bytes, root->fs_info->max_extent); 126 cur_alloc_size = min(num_bytes, root->fs_info->max_extent);
127 ret = btrfs_alloc_extent(trans, root, cur_alloc_size, 127 ret = btrfs_alloc_extent(trans, root, cur_alloc_size,
128 root->sectorsize,
128 root->root_key.objectid, 129 root->root_key.objectid,
129 trans->transid, 130 trans->transid,
130 inode->i_ino, start, 0, 131 inode->i_ino, start, 0,
@@ -133,6 +134,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end)
133 WARN_ON(1); 134 WARN_ON(1);
134 goto out; 135 goto out;
135 } 136 }
137 cur_alloc_size = ins.offset;
136 ret = btrfs_insert_file_extent(trans, root, inode->i_ino, 138 ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
137 start, ins.objectid, ins.offset, 139 start, ins.objectid, ins.offset,
138 ins.offset); 140 ins.offset);