Skip to contentSkip to conversation

btrfs-progs: use openat for process_clone in receive

PATCH Applied [email protected] 2 participants 3 messages May 21, 2015 – May 26, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: use openat for process_clone in receive

From: Emil Karlson <[email protected]>

This will fix breakage, when doing chrooted receive with cloned paths outside main subvolume.

---
 cmds-receive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmds-receive.c +2 -2
index b7cf3f9..b0a312c 100644
@@ -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",
Signature · 1 line
2.3.6
#1 lore raw

Greetigns

I actually also tested this... btrfs on PATH is from btrfs-progs-4.0 and the other is the upstream master with the patch

schur log # lzop -dc
/home/sftponly/eira-receive/log/snapshot-2015-05-21T09.52.59N00003f.far.lzo
| /home/jkarlson/.local/repo/btrfs-progs/btrfs receive $PWD
At snapshot snapshot-2015-05-21T09.52.59N00003f
schur log # find snapshot-2015-05-21T09.52.59N00003f -type f -exec
sha1sum '{}' + | sort > filelist-received && sha1sum filelist-received
&& rm filelist-received
8ecfd188a5c80924784b80267837c24b43be619b filelist-received
schur log # btrfs sub del
/mnt/snapshots/eira/log/snapshot-2015-05-21T09.52.59N00003f/
Delete subvolume (no-commit):
'/mnt/snapshots/eira/log/snapshot-2015-05-21T09.52.59N00003f'
schur log # lzop -dc
/home/sftponly/eira-receive/log/snapshot-2015-05-21T09.52.59N00003f.far.lzo
| /home/jkarlson/.local/repo/btrfs-progs/btrfs receive -C $PWD
Chroot to /mnt/snapshots/eira/log
At snapshot snapshot-2015-05-21T09.52.59N00003f
schur log # find snapshot-2015-05-21T09.52.59N00003f -type f -exec
sha1sum '{}' + | sort > filelist-received && sha1sum filelist-received
&& rm filelist-received
8ecfd188a5c80924784b80267837c24b43be619b filelist-received
schur log # btrfs sub del
/mnt/snapshots/eira/log/snapshot-2015-05-21T09.52.59N00003f/
Delete subvolume (no-commit):
'/mnt/snapshots/eira/log/snapshot-2015-05-21T09.52.59N00003f'
schur log # lzop -dc
/home/sftponly/eira-receive/log/snapshot-2015-05-21T09.52.59N00003f.far.lzo
| btrfs receive $PWD
At snapshot snapshot-2015-05-21T09.52.59N00003f
schur log # find snapshot-2015-05-21T09.52.59N00003f -type f -exec
sha1sum '{}' + | sort > filelist-received && sha1sum filelist-received
&& rm filelist-received
8ecfd188a5c80924784b80267837c24b43be619b filelist-received
schur log # btrfs sub del
/mnt/snapshots/eira/log/snapshot-2015-05-21T09.52.59N00003f/
Delete subvolume (no-commit):
'/mnt/snapshots/eira/log/snapshot-2015-05-21T09.52.59N00003f'
schur log # lzop -dc
/home/sftponly/eira-receive/log/snapshot-2015-05-21T09.52.59N00003f.far.lzo
| btrfs receive -C $PWD
Chroot to /mnt/snapshots/eira/log
At snapshot snapshot-2015-05-21T09.52.59N00003f
ERROR: failed to open /snapshots/eira/log/snapshot-2015-05-15T17.00.28N00001f/journal/1d6156a06c4a45feaef97336a4b154b8/user-1001.journal. No such file or directory

Best Regards
-Emil

Quoted 27 lines · On Thu, May 21, 2015 at 6:42 PM, <[email protected]> wrote:

From: Emil Karlson <[email protected]>

This will fix breakage, when doing chrooted receive with cloned paths outside main subvolume.

---
 cmds-receive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmds-receive.c +2 -3
index b7cf3f9..b0a312c 100644
@@ -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.3.6