aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 82d0342763c5..c77da440146a 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1963,11 +1963,13 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
1963 struct btrfs_key key; 1963 struct btrfs_key key;
1964 int ret; 1964 int ret;
1965 1965
1966 if (btrfs_fs_incompat(root->fs_info, NO_HOLES))
1967 goto out;
1968
1966 key.objectid = btrfs_ino(inode); 1969 key.objectid = btrfs_ino(inode);
1967 key.type = BTRFS_EXTENT_DATA_KEY; 1970 key.type = BTRFS_EXTENT_DATA_KEY;
1968 key.offset = offset; 1971 key.offset = offset;
1969 1972
1970
1971 ret = btrfs_search_slot(trans, root, &key, path, 0, 1); 1973 ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
1972 if (ret < 0) 1974 if (ret < 0)
1973 return ret; 1975 return ret;
@@ -2064,8 +2066,10 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
2064 u64 drop_end; 2066 u64 drop_end;
2065 int ret = 0; 2067 int ret = 0;
2066 int err = 0; 2068 int err = 0;
2069 int rsv_count;
2067 bool same_page = ((offset >> PAGE_CACHE_SHIFT) == 2070 bool same_page = ((offset >> PAGE_CACHE_SHIFT) ==
2068 ((offset + len - 1) >> PAGE_CACHE_SHIFT)); 2071 ((offset + len - 1) >> PAGE_CACHE_SHIFT));
2072 bool no_holes = btrfs_fs_incompat(root->fs_info, NO_HOLES);
2069 2073
2070 ret = btrfs_wait_ordered_range(inode, offset, len); 2074 ret = btrfs_wait_ordered_range(inode, offset, len);
2071 if (ret) 2075 if (ret)
@@ -2163,9 +2167,10 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
2163 /* 2167 /*
2164 * 1 - update the inode 2168 * 1 - update the inode
2165 * 1 - removing the extents in the range 2169 * 1 - removing the extents in the range
2166 * 1 - adding the hole extent 2170 * 1 - adding the hole extent if no_holes isn't set
2167 */ 2171 */
2168 trans = btrfs_start_transaction(root, 3); 2172 rsv_count = no_holes ? 2 : 3;
2173 trans = btrfs_start_transaction(root, rsv_count);
2169 if (IS_ERR(trans)) { 2174 if (IS_ERR(trans)) {
2170 err = PTR_ERR(trans); 2175 err = PTR_ERR(trans);
2171 goto out_free; 2176 goto out_free;
@@ -2202,7 +2207,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
2202 btrfs_end_transaction(trans, root); 2207 btrfs_end_transaction(trans, root);
2203 btrfs_btree_balance_dirty(root); 2208 btrfs_btree_balance_dirty(root);
2204 2209
2205 trans = btrfs_start_transaction(root, 3); 2210 trans = btrfs_start_transaction(root, rsv_count);
2206 if (IS_ERR(trans)) { 2211 if (IS_ERR(trans)) {
2207 ret = PTR_ERR(trans); 2212 ret = PTR_ERR(trans);
2208 trans = NULL; 2213 trans = NULL;