|
@@ -2889,12 +2889,19 @@ static int btrfs_cmp_data(struct inode *src, u64 loff, struct inode *dst,
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-static int extent_same_check_offsets(struct inode *inode, u64 off, u64 len)
|
|
|
|
|
|
+static int extent_same_check_offsets(struct inode *inode, u64 off, u64 *plen,
|
|
|
|
+ u64 olen)
|
|
{
|
|
{
|
|
|
|
+ u64 len = *plen;
|
|
u64 bs = BTRFS_I(inode)->root->fs_info->sb->s_blocksize;
|
|
u64 bs = BTRFS_I(inode)->root->fs_info->sb->s_blocksize;
|
|
|
|
|
|
- if (off + len > inode->i_size || off + len < off)
|
|
|
|
|
|
+ if (off + olen > inode->i_size || off + olen < off)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
+
|
|
|
|
+ /* if we extend to eof, continue to block boundary */
|
|
|
|
+ if (off + len == inode->i_size)
|
|
|
|
+ *plen = len = ALIGN(inode->i_size, bs) - off;
|
|
|
|
+
|
|
/* Check that we are block aligned - btrfs_clone() requires this */
|
|
/* Check that we are block aligned - btrfs_clone() requires this */
|
|
if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs))
|
|
if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs))
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
@@ -2902,10 +2909,11 @@ static int extent_same_check_offsets(struct inode *inode, u64 off, u64 len)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-static int btrfs_extent_same(struct inode *src, u64 loff, u64 len,
|
|
|
|
|
|
+static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
|
|
struct inode *dst, u64 dst_loff)
|
|
struct inode *dst, u64 dst_loff)
|
|
{
|
|
{
|
|
int ret;
|
|
int ret;
|
|
|
|
+ u64 len = olen;
|
|
|
|
|
|
/*
|
|
/*
|
|
* btrfs_clone() can't handle extents in the same file
|
|
* btrfs_clone() can't handle extents in the same file
|
|
@@ -2920,11 +2928,11 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 len,
|
|
|
|
|
|
btrfs_double_lock(src, loff, dst, dst_loff, len);
|
|
btrfs_double_lock(src, loff, dst, dst_loff, len);
|
|
|
|
|
|
- ret = extent_same_check_offsets(src, loff, len);
|
|
|
|
|
|
+ ret = extent_same_check_offsets(src, loff, &len, olen);
|
|
if (ret)
|
|
if (ret)
|
|
goto out_unlock;
|
|
goto out_unlock;
|
|
|
|
|
|
- ret = extent_same_check_offsets(dst, dst_loff, len);
|
|
|
|
|
|
+ ret = extent_same_check_offsets(dst, dst_loff, &len, olen);
|
|
if (ret)
|
|
if (ret)
|
|
goto out_unlock;
|
|
goto out_unlock;
|
|
|
|
|
|
@@ -2937,7 +2945,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 len,
|
|
|
|
|
|
ret = btrfs_cmp_data(src, loff, dst, dst_loff, len);
|
|
ret = btrfs_cmp_data(src, loff, dst, dst_loff, len);
|
|
if (ret == 0)
|
|
if (ret == 0)
|
|
- ret = btrfs_clone(src, dst, loff, len, len, dst_loff);
|
|
|
|
|
|
+ ret = btrfs_clone(src, dst, loff, olen, len, dst_loff);
|
|
|
|
|
|
out_unlock:
|
|
out_unlock:
|
|
btrfs_double_unlock(src, loff, dst, dst_loff, len);
|
|
btrfs_double_unlock(src, loff, dst, dst_loff, len);
|