btrfs-progs: use openat for process_clone in receive
authorEmil Karlson <jekarlson@gmail.com>
Thu, 21 May 2015 15:42:29 +0000 (18:42 +0300)
committerDavid Sterba <dsterba@suse.cz>
Tue, 26 May 2015 14:31:32 +0000 (16:31 +0200)
This will fix breakage, when doing chrooted receive with cloned paths
outside main subvolume.

Steps to reproduce:
 $ create subvolume
 $ create file
 $ snapshot to snap1
 $ delete file
 $ snapshot to snap2
 $ reflink file from snap1
 $ snapsthot to snap3

 $ send full snap1 | receive --chroot
 $ send incremental snap2 | receive --chroot
 $ send incremental snap3 | receive --chroot

The last step would fail with:

 Chroot to /mnt/recvdir
 At snapshot snap3
 ERROR: failed to open /recvdir/snap1/file. No such file or directory

Signed-off-by: Emil Karlson <jekarlson@gmail.com>
[added reproducer]
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-receive.c

index b7cf3f955528cf2f923ba185791c035cc8c4f27e..b0a312ca560a0ae92886ad96aa0f4ab1704e2224 100644 (file)
@@ -609,9 +609,9 @@ static int process_clone(const char *path, u64 offset, u64 len,
                subvol_path = strdup(si->path);
        }
 
-       full_clone_path = path_cat3(r->root_path, subvol_path, clone_path);
+       full_clone_path = path_cat(subvol_path, clone_path);
 
-       clone_fd = open(full_clone_path, O_RDONLY | O_NOATIME);
+       clone_fd = openat(r->mnt_fd, full_clone_path, O_RDONLY | O_NOATIME);
        if (clone_fd < 0) {
                ret = -errno;
                fprintf(stderr, "ERROR: failed to open %s. %s\n",