From: Benedikt Morbach Date: Wed, 22 Feb 2017 22:56:37 +0000 (+0100) Subject: btrfs-progs: receive: handle root subvol path in clone X-Git-Tag: upstream/4.16.1~723 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5de4d7f45976dc41e2dd619b69a048027386138;p=platform%2Fupstream%2Fbtrfs-progs.git 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 /parent receive 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 Signed-off-by: David Sterba --- diff --git a/cmds-receive.c b/cmds-receive.c index 06e6177..6cf2263 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);