Commit 362a20c5 authored by David Sterba's avatar David Sterba Committed by Alexander Block

btrfs: allow cross-subvolume file clone

Lift the EXDEV condition and allow different root trees for files being
cloned, then pass source inode's root when searching for extents.
Cloning is not allowed to cross vfsmounts, ie. when two subvolumes from
one filesystem are mounted separately.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.cz>
parent 28a33cbc
...@@ -2340,6 +2340,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -2340,6 +2340,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
goto out_drop_write; goto out_drop_write;
} }
ret = -EXDEV;
if (src_file->f_path.mnt != file->f_path.mnt)
goto out_fput;
src = src_file->f_dentry->d_inode; src = src_file->f_dentry->d_inode;
ret = -EINVAL; ret = -EINVAL;
...@@ -2360,7 +2364,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -2360,7 +2364,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
goto out_fput; goto out_fput;
ret = -EXDEV; ret = -EXDEV;
if (src->i_sb != inode->i_sb || BTRFS_I(src)->root != root) if (src->i_sb != inode->i_sb)
goto out_fput; goto out_fput;
ret = -ENOMEM; ret = -ENOMEM;
...@@ -2434,13 +2438,14 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -2434,13 +2438,14 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
* note the key will change type as we walk through the * note the key will change type as we walk through the
* tree. * tree.
*/ */
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, BTRFS_I(src)->root, &key, path,
0, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
nritems = btrfs_header_nritems(path->nodes[0]); nritems = btrfs_header_nritems(path->nodes[0]);
if (path->slots[0] >= nritems) { if (path->slots[0] >= nritems) {
ret = btrfs_next_leaf(root, path); ret = btrfs_next_leaf(BTRFS_I(src)->root, path);
if (ret < 0) if (ret < 0)
goto out; goto out;
if (ret > 0) if (ret > 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment