From 5d4f3ea9b41e7dd0812da1cdd7eb9049fe289066 Mon Sep 17 00:00:00 2001 From: Emil Karlson Date: Thu, 21 May 2015 18:42:29 +0300 Subject: [PATCH] btrfs-progs: use openat for process_clone in receive 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 [added reproducer] Signed-off-by: David Sterba --- cmds-receive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index b7cf3f95..b0a312ca 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -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", -- 2.34.1