[pve-devel] [PATCH container] Fix mounting ZFS snapshots whose dataset is not mounted below '/'

Fabian Ebner f.ebner at proxmox.com
Tue Feb 18 12:31:22 CET 2020


Trying to back up a container with a ZFS dataset with non-standard mount
would fail, see [0].

This also removes the near-dead code
$name .= "\@$snapname";
when snapname is false-y, but defined and turns
the check for $snapname into one for definedness.

[0]: https://forum.proxmox.com/threads/lxc-backup-fails-unable-to-open-the-dataset-vzdump.64944/

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Hopefully there is nothing that relies on the old behavior
with $snapname. Or was it intended to be able to reach
the 'zfs set acl' call with $snapname set?

 src/PVE/LXC.pm | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 34ca2a3..21bc9c6 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1647,19 +1647,17 @@ sub __mountpoint_mount {
 
 	if ($format eq 'subvol') {
 	    if ($mount_path) {
-		if ($snapname) {
+		my (undef, $name) = PVE::Storage::parse_volname($storage_cfg, $volid);
+		if (defined($snapname)) {
+		    $name .= "\@$snapname";
 		    if ($scfg->{type} eq 'zfspool') {
-			my $path_arg = $path;
-			$path_arg =~ s!^/+!!;
-			PVE::Tools::run_command(['mount', '-o', 'ro', @extra_opts, '-t', 'zfs', $path_arg, $mount_path]);
+			PVE::Tools::run_command(['mount', '-o', 'ro', @extra_opts, '-t', 'zfs', "$scfg->{pool}/$name", $mount_path]);
 		    } else {
 			die "cannot mount subvol snapshots for storage type '$scfg->{type}'\n";
 		    }
 		} else {
 		    if (defined($acl) && $scfg->{type} eq 'zfspool') {
 			my $acltype = ($acl ? 'acltype=posixacl' : 'acltype=noacl');
-			my (undef, $name) = PVE::Storage::parse_volname($storage_cfg, $volid);
-			$name .= "\@$snapname" if defined($snapname);
 			PVE::Tools::run_command(['zfs', 'set', $acltype, "$scfg->{pool}/$name"]);
 		    }
 		    bindmount($path, $parentfd, $last_dir//$rootdir, $mount_path, $readonly, @extra_opts);
-- 
2.20.1





More information about the pve-devel mailing list