diff options
author | Benedikt Morbach <benedikt.morbach@googlemail.com> | 2017-02-22 23:56:37 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2017-03-16 17:02:44 +0100 |
commit | a5de4d7f45976dc41e2dd619b69a048027386138 (patch) | |
tree | e621a3c235368caa055b8adaf214f2accf9440d3 | |
parent | 30c7b11f7f030756d97711cef86c9891efc1d3ee (diff) |
btrfs-progs: receive: handle root subvol path in clone
testcase:
# ro subvol /src/parent
# rw subvol /src/foo
clone /src/parent/file /src/foo/file
subvol snapshot -r /src/foo /src/foo.snap
# generates a "clone parent/file -> foo.snap/file" send command
send -p /src/parent /src/foo.snap
# target fs:
# dest/
# |--- parent/...
# mounted with -o subvol=dest, such that "parent" is at <target>/parent
receive <target>
result:
ERROR: cannot open dest/parent/file: No such file or directory
expected:
"dest/" get's stripped from the clone source path to get the actual
path in the target fs, if reachable from the mount point/chroot.
This is exactly what process_snapshot does, which gets called on
_every_ incremental receive and I'm quite certain is correct in
doing so
Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | cmds-receive.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/cmds-receive.c b/cmds-receive.c index 06e61773..6cf22637 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -783,7 +783,24 @@ static int process_clone(const char *path, u64 offset, u64 len, r->subvol_parent_name); } }*/ - subvol_path = strdup(si->path); + + /* strip the subvolume that we are receiving to from the start of subvol_path */ + if (rctx->full_root_path) { + size_t root_len = strlen(rctx->full_root_path); + size_t sub_len = strlen(si->path); + + if (sub_len > root_len && + strstr(si->path, rctx->full_root_path) == si->path && + si->path[root_len] == '/') { + subvol_path = strdup(si->path + root_len + 1); + } else { + error("clone: source subvol path %s unreachable from %s", + si->path, rctx->full_root_path); + goto out; + } + } else { + subvol_path = strdup(si->path); + } } ret = path_cat_out(full_clone_path, subvol_path, clone_path); |