From e2007ac2524efe443ced8d4bf46ebef82248f228 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 15 Jan 2016 10:19:50 +0100 Subject: [PATCH] fix mount_all, improve bind mount handling --- src/PVE/API2/LXC.pm | 10 +++++++--- src/PVE/LXC.pm | 24 +++++++----------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 1c97a21..1d773db 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -263,9 +263,13 @@ __PACKAGE__->register_method({ my $volid = $mountpoint->{volume}; my $mp = $mountpoint->{mp}; - my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1); - - &$check_and_activate_storage($sid) if $sid; + if ($mountpoint->{type} ne 'volume') { # bind or device + die "Only root can pass arbitrary filesystem paths.\n" + if $authuser ne 'root@pam'; + } else { + my ($sid, $volname) = PVE::Storage::parse_volume_id($volid); + &$check_and_activate_storage($sid); + } }); # check/activate default storage diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index dd27dc5..f964aca 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -2101,23 +2101,13 @@ sub mount_all { foreach_mountpoint($conf, sub { my ($ms, $mountpoint) = @_; - my $volid = $mountpoint->{volume}; - my $mount = $mountpoint->{mp}; - - return if !$volid || !$mount; - - my $image_path = PVE::Storage::path($storage_cfg, $volid); - my ($vtype, undef, undef, undef, undef, $isBase, $format) = - PVE::Storage::parse_volname($storage_cfg, $volid); - - die "unable to mount base volume - internal error" if $isBase; - mountpoint_mount($mountpoint, $rootdir, $storage_cfg); }); }; if (my $err = $@) { - warn "mounting container failed - $err"; + warn "mounting container failed\n"; umount_all($vmid, $storage_cfg, $conf, 1); + die $err; } return $rootdir; @@ -2230,7 +2220,8 @@ sub mountpoint_mount { } elsif ($type eq 'device') { PVE::Tools::run_command(['mount', $volid, $mount_path]) if $mount_path; return wantarray ? ($volid, 0) : $volid; - } elsif ($type eq 'bind' && -d $volid) { + } elsif ($type eq 'bind') { + die "directory '$volid' does not exist\n" if ! -d $volid; &$check_mount_path($volid); PVE::Tools::run_command(['mount', '-o', 'bind', $volid, $mount_path]) if $mount_path; return wantarray ? ($volid, 0) : $volid; @@ -2321,9 +2312,7 @@ sub create_disks { my ($storage, $volname) = PVE::Storage::parse_volume_id($volid, 1); - return if !$storage; - - if ($volid =~ m/^([^:\s]+):(\d+(\.\d+)?)$/) { + if ($storage && ($volid =~ m/^([^:\s]+):(\d+(\.\d+)?)$/)) { my ($storeid, $size_gb) = ($1, $2); my $size_kb = int(${size_gb}*1024) * 1024; @@ -2364,7 +2353,8 @@ sub create_disks { $mountpoint->{size} = $size_kb * 1024; $conf->{$ms} = print_ct_mountpoint($mountpoint, $ms eq 'rootfs'); } else { - # use specified/existing volid + # use specified/existing volid/dir/device + $conf->{$ms} = print_ct_mountpoint($mountpoint, $ms eq 'rootfs'); } }); -- 2.39.2