aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 970977aab22..3351b1b2457 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2220,6 +2220,12 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2220 !IS_ALIGNED(destoff, bs)) 2220 !IS_ALIGNED(destoff, bs))
2221 goto out_unlock; 2221 goto out_unlock;
2222 2222
2223 if (destoff > inode->i_size) {
2224 ret = btrfs_cont_expand(inode, inode->i_size, destoff);
2225 if (ret)
2226 goto out_unlock;
2227 }
2228
2223 /* do any pending delalloc/csum calc on src, one way or 2229 /* do any pending delalloc/csum calc on src, one way or
2224 another, and lock file content */ 2230 another, and lock file content */
2225 while (1) { 2231 while (1) {
@@ -2325,14 +2331,21 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2325 2331
2326 if (type == BTRFS_FILE_EXTENT_REG || 2332 if (type == BTRFS_FILE_EXTENT_REG ||
2327 type == BTRFS_FILE_EXTENT_PREALLOC) { 2333 type == BTRFS_FILE_EXTENT_PREALLOC) {
2334 /*
2335 * a | --- range to clone ---| b
2336 * | ------------- extent ------------- |
2337 */
2338
2339 /* substract range b */
2340 if (key.offset + datal > off + len)
2341 datal = off + len - key.offset;
2342
2343 /* substract range a */
2328 if (off > key.offset) { 2344 if (off > key.offset) {
2329 datao += off - key.offset; 2345 datao += off - key.offset;
2330 datal -= off - key.offset; 2346 datal -= off - key.offset;
2331 } 2347 }
2332 2348
2333 if (key.offset + datal > off + len)
2334 datal = off + len - key.offset;
2335
2336 ret = btrfs_drop_extents(trans, inode, 2349 ret = btrfs_drop_extents(trans, inode,
2337 new_key.offset, 2350 new_key.offset,
2338 new_key.offset + datal, 2351 new_key.offset + datal,