13 use Fcntl
qw(O_RDONLY O_NOFOLLOW O_DIRECTORY);
14 use Errno
qw(ELOOP ENOTDIR EROFS ECONNREFUSED ENOSYS EEXIST);
17 use PVE
::Exception
qw(raise_perm_exc);
21 use PVE
::JSONSchema
qw(get_standard_option);
22 use PVE
::Tools
qw($IPV6RE $IPV4RE dir_glob_foreach lock_file lock_file_full O_PATH AT_FDCWD);
25 use PVE
::AccessControl
;
27 use PVE
::Syscall
qw(:fsmount);
29 use PVE
::GuestHelpers
;
32 use Time
::HiRes qw
(gettimeofday
);
34 my $LXC_CONFIG_PATH = '/usr/share/lxc/config';
36 my $nodename = PVE
::INotify
::nodename
();
38 my $cpuinfo= PVE
::ProcFSTools
::read_cpuinfo
();
41 my $vmlist = PVE
::Cluster
::get_vmlist
();
43 return $res if !$vmlist || !$vmlist->{ids
};
44 my $ids = $vmlist->{ids
};
46 foreach my $vmid (keys %$ids) {
47 next if !$vmid; # skip CT0
48 my $d = $ids->{$vmid};
49 next if !$d->{node
} || $d->{node
} ne $nodename;
50 next if !$d->{type
} || $d->{type
} ne 'lxc';
51 $res->{$vmid} = { type
=> 'lxc', vmid
=> $vmid };
56 # container status helpers
58 sub list_active_containers
{
60 my $filename = "/proc/net/unix";
62 # similar test is used by lcxcontainers.c: list_active_containers
65 my $fh = IO
::File-
>new ($filename, "r");
68 while (defined(my $line = <$fh>)) {
69 if ($line =~ m/^[a-f0-9]+:\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\d+\s+(\S+)$/) {
71 if ($path =~ m!^@/var/lib/lxc/(\d+)/command$!) {
82 # warning: this is slow
86 my $active_hash = list_active_containers
();
88 return 1 if defined($active_hash->{$vmid});
93 sub get_container_disk_usage
{
94 my ($vmid, $pid) = @_;
96 return PVE
::Tools
::df
("/proc/$pid/root/", 1);
99 my $last_proc_vmid_stat;
101 my $parse_cpuacct_stat = sub {
102 my ($vmid, $unprivileged) = @_;
104 my $raw = read_cgroup_value
('cpuacct', $vmid, $unprivileged, 'cpuacct.stat', 1);
108 if ($raw =~ m/^user (\d+)\nsystem (\d+)\n/) {
118 our $vmstatus_return_properties = {
119 vmid
=> get_standard_option
('pve-vmid'),
121 description
=> "LXC Container status.",
123 enum
=> ['stopped', 'running'],
126 description
=> "Maximum memory in bytes.",
132 description
=> "Maximum SWAP memory in bytes.",
138 description
=> "Root disk size in bytes.",
144 description
=> "Container name.",
149 description
=> "Uptime.",
152 renderer
=> 'duration',
155 description
=> "Maximum usable CPUs.",
160 description
=> "The current config lock, if any.",
169 my $list = $opt_vmid ?
{ $opt_vmid => { type
=> 'lxc', vmid
=> $opt_vmid }} : config_list
();
171 my $active_hash = list_active_containers
();
173 my $cpucount = $cpuinfo->{cpus
} || 1;
175 my $cdtime = gettimeofday
;
177 my $uptime = (PVE
::ProcFSTools
::read_proc_uptime
(1))[0];
178 my $clock_ticks = POSIX
::sysconf
(&POSIX
::_SC_CLK_TCK
);
180 my $unprivileged = {};
182 foreach my $vmid (keys %$list) {
183 my $d = $list->{$vmid};
185 eval { $d->{pid
} = find_lxc_pid
($vmid) if defined($active_hash->{$vmid}); };
186 warn $@ if $@; # ignore errors (consider them stopped)
188 $d->{status
} = $active_hash->{$vmid} ?
'running' : 'stopped';
190 my $cfspath = PVE
::LXC
::Config-
>cfs_config_path($vmid);
191 my $conf = PVE
::Cluster
::cfs_read_file
($cfspath) || {};
193 $unprivileged->{$vmid} = $conf->{unprivileged
};
195 $d->{name
} = $conf->{'hostname'} || "CT$vmid";
196 $d->{name
} =~ s/[\s]//g;
198 $d->{cpus
} = $conf->{cores
} || $conf->{cpulimit
};
199 $d->{cpus
} = $cpucount if !$d->{cpus
};
201 $d->{lock} = $conf->{lock} || '';
204 my $res = get_container_disk_usage
($vmid, $d->{pid
});
205 $d->{disk
} = $res->{used
};
206 $d->{maxdisk
} = $res->{total
};
209 # use 4GB by default ??
210 if (my $rootfs = $conf->{rootfs
}) {
211 my $rootinfo = PVE
::LXC
::Config-
>parse_ct_rootfs($rootfs);
212 $d->{maxdisk
} = $rootinfo->{size
} || (4*1024*1024*1024);
214 $d->{maxdisk
} = 4*1024*1024*1024;
220 $d->{maxmem
} = ($conf->{memory
}||512)*1024*1024;
221 $d->{maxswap
} = ($conf->{swap
}//0)*1024*1024;
232 $d->{template
} = PVE
::LXC
::Config-
>is_template($conf);
233 $d->{lock} = $conf->{lock} if $conf->{lock};
236 foreach my $vmid (keys %$list) {
237 my $d = $list->{$vmid};
240 next if !$pid; # skip stopped CTs
242 my $proc_pid_stat = PVE
::ProcFSTools
::read_proc_pid_stat
($pid);
243 $d->{uptime
} = int(($uptime - $proc_pid_stat->{starttime
}) / $clock_ticks); # the method lxcfs uses
245 my $unpriv = $unprivileged->{$vmid};
247 if (-d
'/sys/fs/cgroup/memory') {
248 my $memory_stat = read_cgroup_list
('memory', $vmid, $unpriv, 'memory.stat');
249 my $mem_usage_in_bytes = read_cgroup_value
('memory', $vmid, $unpriv, 'memory.usage_in_bytes');
251 $d->{mem
} = $mem_usage_in_bytes - $memory_stat->{total_cache
};
252 $d->{swap
} = read_cgroup_value
('memory', $vmid, $unpriv, 'memory.memsw.usage_in_bytes') - $mem_usage_in_bytes;
258 if (-d
'/sys/fs/cgroup/blkio') {
259 my $blkio_bytes = read_cgroup_value
('blkio', $vmid, 0, 'blkio.throttle.io_service_bytes', 1); # don't check if unpriv
260 my @bytes = split(/\n/, $blkio_bytes);
261 foreach my $byte (@bytes) {
262 if (my ($key, $value) = $byte =~ /(Read|Write)\s+(\d+)/) {
263 $d->{diskread
} += $2 if $key eq 'Read';
264 $d->{diskwrite
} += $2 if $key eq 'Write';
272 if (-d
'/sys/fs/cgroup/cpuacct') {
273 my $pstat = $parse_cpuacct_stat->($vmid, $unpriv);
275 my $used = $pstat->{utime} + $pstat->{stime
};
277 my $old = $last_proc_vmid_stat->{$vmid};
279 $last_proc_vmid_stat->{$vmid} = {
287 my $dtime = ($cdtime - $old->{time}) * $cpucount * $cpuinfo->{user_hz
};
290 my $dutime = $used - $old->{used
};
292 $d->{cpu
} = (($dutime/$dtime)* $cpucount) / $d->{cpus
};
293 $last_proc_vmid_stat->{$vmid} = {
299 $d->{cpu
} = $old->{cpu
};
306 my $netdev = PVE
::ProcFSTools
::read_proc_net_dev
();
308 foreach my $dev (keys %$netdev) {
309 next if $dev !~ m/^veth([1-9]\d*)i/;
311 my $d = $list->{$vmid};
315 $d->{netout
} += $netdev->{$dev}->{receive
};
316 $d->{netin
} += $netdev->{$dev}->{transmit
};
323 sub read_cgroup_list
($$$$) {
324 my ($group, $vmid, $unprivileged, $name) = @_;
326 my $content = read_cgroup_value
($group, $vmid, $unprivileged, $name, 1);
328 return { split(/\s+/, $content) };
331 sub read_cgroup_value
($$$$$) {
332 my ($group, $vmid, $unprivileged, $name, $full) = @_;
334 my $nsdir = $unprivileged ?
'' : 'ns/';
335 my $path = "/sys/fs/cgroup/$group/lxc/$vmid/${nsdir}$name";
337 return PVE
::Tools
::file_get_contents
($path) if $full;
339 return PVE
::Tools
::file_read_firstline
($path);
342 sub write_cgroup_value
{
343 my ($group, $vmid, $name, $value) = @_;
345 my $path = "/sys/fs/cgroup/$group/lxc/$vmid/$name";
346 PVE
::ProcFSTools
::write_proc_entry
($path, $value) if -e
$path;
350 sub find_lxc_console_pids
{
354 PVE
::Tools
::dir_glob_foreach
('/proc', '\d+', sub {
357 my $cmdline = PVE
::Tools
::file_read_firstline
("/proc/$pid/cmdline");
360 my @args = split(/\0/, $cmdline);
362 # search for lxc-console -n <vmid>
363 return if scalar(@args) != 3;
364 return if $args[1] ne '-n';
365 return if $args[2] !~ m/^\d+$/;
366 return if $args[0] !~ m
|^(/usr/bin
/)?lxc-console
$|;
370 push @{$res->{$vmid}}, $pid;
382 $pid = $1 if $line =~ m/^PID:\s+(\d+)$/;
384 PVE
::Tools
::run_command
(['lxc-info', '-n', $vmid, '-p'], outfunc
=> $parser);
386 die "unable to get PID for CT $vmid (not running?)\n" if !$pid;
393 sysopen(my $fd, "/proc/$pid", O_RDONLY
| O_DIRECTORY
)
394 or die "failed to open /proc/$pid pid fd\n";
401 # Find the pid and open:
402 my $pid = find_lxc_pid
($vmid);
403 my $fd = open_pid_fd
($pid);
406 my $pid2 = find_lxc_pid
($vmid);
408 return () if $pid != $pid2;
415 # Find the parent pid via proc and open it:
416 my $stat = PVE
::ProcFSTools
::read_proc_pid_stat
($pid);
417 my $ppid = $stat->{ppid
} // die "failed to get parent pid\n";
419 my $fd = open_pid_fd
($ppid);
422 $stat = PVE
::ProcFSTools
::read_proc_pid_stat
($pid);
423 my $ppid2 = $stat->{ppid
} // die "failed to get parent pid for verification\n";
425 return () if $ppid != $ppid2;
429 # Note: we cannot use Net:IP, because that only allows strict
431 sub parse_ipv4_cidr
{
432 my ($cidr, $noerr) = @_;
434 if ($cidr =~ m!^($IPV4RE)(?:/(\d+))$! && ($2 > 7) && ($2 <= 32)) {
435 return { address
=> $1, netmask
=> $PVE::Network
::ipv4_reverse_mask-
>[$2] };
438 return undef if $noerr;
440 die "unable to parse ipv4 address/mask\n";
443 sub get_cgroup_subsystems
{
446 my $data = PVE
::Tools
::file_get_contents
('/proc/self/cgroup');
447 while ($data =~ /^\d+:([^:\n]*):.*$/gm) {
450 $v1->{$_} = 1 foreach split(/,/, $type);
455 return wantarray ?
($v1, $v2) : $v1;
458 # Currently we do not need to create seccomp profile 'files' as the only
459 # choice our configuration actually allows is "with or without keyctl()",
460 # so we distinguish between using lxc's "default" seccomp profile and our
461 # added pve-userns.seccomp file.
463 # This returns a configuration line added to the raw lxc config.
464 sub make_seccomp_config
{
465 my ($conf, $unprivileged, $features) = @_;
466 # User-configured profile has precedence, note that the user's entry would
467 # be written 'after' this line anyway...
468 if (PVE
::LXC
::Config-
>has_lxc_entry($conf, 'lxc.seccomp.profile')) {
469 # Warn the user if this conflicts with a feature:
470 if ($features->{keyctl
}) {
471 warn "explicitly configured lxc.seccomp.profile overrides the following settings: features:keyctl\n";
476 # Privileged containers keep using the default (which is already part of
477 # the files included via lxc.include, so we don't need to write it out,
478 # that way it stays admin-configurable via /usr/share/lxc/config/... as
480 return '' if !$unprivileged;
482 # Unprivileged containers will get keyctl() disabled by default as a
483 # workaround for systemd-networkd behavior. But we have an option to
484 # explicitly enable it:
485 return '' if $features->{keyctl
};
487 # Finally we're in an unprivileged container without `keyctl` set
488 # explicitly. We have a file prepared for this:
489 return "lxc.seccomp.profile = $LXC_CONFIG_PATH/pve-userns.seccomp\n";
492 # Since lxc-3.0.2 we can have lxc generate a profile for the container
493 # automatically. The default should be equivalent to the old
494 # `lxc-container-default-cgns` profile.
496 # Additionally this also added `lxc.apparmor.raw` which can be used to inject
497 # additional lines into the profile. We can use that to allow mounting specific
499 sub make_apparmor_config
{
500 my ($conf, $unprivileged, $features) = @_;
502 # user-configured profile has precedence, but first we go through our own
503 # code to figure out whether we should warn the user:
505 my $raw = "lxc.apparmor.profile = generated\n";
508 if ($features->{fuse
}) {
509 # For the informational warning:
510 push @profile_uses, 'features:fuse';
513 # There's lxc.apparmor.allow_nesting now, which will add the necessary
514 # apparmor lines, create an apparmor namespace for the container, but also
515 # adds proc and sysfs mounts to /dev/.lxc/{proc,sys}. These do not have
516 # lxcfs mounted over them, because that would prevent the container from
517 # mounting new instances of them for nested containers.
518 if ($features->{nesting
}) {
519 push @profile_uses, 'features:nesting';
520 $raw .= "lxc.apparmor.allow_nesting = 1\n"
522 # In the default profile in /etc/apparmor.d we patch this in because
523 # otherwise a container can for example run `chown` on /sys, breaking
524 # access to it for non-CAP_DAC_OVERRIDE tools on the host:
525 $raw .= "lxc.apparmor.raw = deny mount -> /proc/,\n";
526 $raw .= "lxc.apparmor.raw = deny mount -> /sys/,\n";
527 # Preferably we could use the 'remount' flag but this does not sit well
528 # with apparmor_parser currently:
529 # mount options=(rw, nosuid, nodev, noexec, remount) -> /sys/,
532 if (my $mount = $features->{mount
}) {
533 push @profile_uses, 'features:mount';
534 foreach my $fs (PVE
::Tools
::split_list
($mount)) {
535 $raw .= "lxc.apparmor.raw = mount fstype=$fs,\n";
541 if (PVE
::LXC
::Config-
>has_lxc_entry($conf, 'lxc.apparmor.profile')) {
542 if (length(my $used = join(', ', @profile_uses))) {
543 warn "explicitly configured lxc.apparmor.profile overrides the following settings: $used\n";
551 sub update_lxc_config
{
552 my ($vmid, $conf) = @_;
554 my $dir = "/var/lib/lxc/$vmid";
556 if ($conf->{template
}) {
558 unlink "$dir/config";
565 die "missing 'arch' - internal error" if !$conf->{arch
};
566 $raw .= "lxc.arch = $conf->{arch}\n";
568 my $custom_idmap = PVE
::LXC
::Config-
>has_lxc_entry($conf, 'lxc.idmap');
569 my $unprivileged = $conf->{unprivileged
} || $custom_idmap;
571 my $ostype = $conf->{ostype
} || die "missing 'ostype' - internal error";
573 my $cfgpath = '/usr/share/lxc/config';
574 my $inc = "$cfgpath/$ostype.common.conf";
575 $inc ="$cfgpath/common.conf" if !-f
$inc;
576 $raw .= "lxc.include = $inc\n";
578 $inc = "$cfgpath/$ostype.userns.conf";
579 $inc = "$cfgpath/userns.conf" if !-f
$inc;
580 $raw .= "lxc.include = $inc\n";
583 my $features = PVE
::LXC
::Config-
>parse_features($conf->{features
});
585 $raw .= make_seccomp_config
($conf, $unprivileged, $features);
586 $raw .= make_apparmor_config
($conf, $unprivileged, $features);
587 if ($features->{fuse
}) {
588 $raw .= "lxc.apparmor.raw = mount fstype=fuse,\n";
589 $raw .= "lxc.mount.entry = /dev/fuse dev/fuse none bind,create=file 0 0\n";
592 # WARNING: DO NOT REMOVE this without making sure that loop device nodes
593 # cannot be exposed to the container with r/w access (cgroup perms).
594 # When this is enabled mounts will still remain in the monitor's namespace
595 # after the container unmounted them and thus will not detach from their
596 # files while the container is running!
597 $raw .= "lxc.monitor.unshare = 1\n";
599 my $cgv1 = get_cgroup_subsystems
();
601 # Should we read them from /etc/subuid?
602 if ($unprivileged && !$custom_idmap) {
603 $raw .= "lxc.idmap = u 0 100000 65536\n";
604 $raw .= "lxc.idmap = g 0 100000 65536\n";
607 if (!PVE
::LXC
::Config-
>has_dev_console($conf)) {
608 $raw .= "lxc.console.path = none\n";
609 $raw .= "lxc.cgroup.devices.deny = c 5:1 rwm\n" if $cgv1->{devices
};
612 my $ttycount = PVE
::LXC
::Config-
>get_tty_count($conf);
613 $raw .= "lxc.tty.max = $ttycount\n";
615 # some init scripts expect a linux terminal (turnkey).
616 $raw .= "lxc.environment = TERM=linux\n";
618 my $utsname = $conf->{hostname
} || "CT$vmid";
619 $raw .= "lxc.uts.name = $utsname\n";
621 if ($cgv1->{memory
}) {
622 my $memory = $conf->{memory
} || 512;
623 my $swap = $conf->{swap
} // 0;
625 my $lxcmem = int($memory*1024*1024);
626 $raw .= "lxc.cgroup.memory.limit_in_bytes = $lxcmem\n";
628 my $lxcswap = int(($memory + $swap)*1024*1024);
629 $raw .= "lxc.cgroup.memory.memsw.limit_in_bytes = $lxcswap\n";
633 if (my $cpulimit = $conf->{cpulimit
}) {
634 $raw .= "lxc.cgroup.cpu.cfs_period_us = 100000\n";
635 my $value = int(100000*$cpulimit);
636 $raw .= "lxc.cgroup.cpu.cfs_quota_us = $value\n";
639 my $shares = $conf->{cpuunits
} || 1024;
640 $raw .= "lxc.cgroup.cpu.shares = $shares\n";
643 die "missing 'rootfs' configuration\n"
644 if !defined($conf->{rootfs
});
646 my $mountpoint = PVE
::LXC
::Config-
>parse_ct_rootfs($conf->{rootfs
});
648 $raw .= "lxc.rootfs.path = $dir/rootfs\n";
650 foreach my $k (sort keys %$conf) {
651 next if $k !~ m/^net(\d+)$/;
653 my $d = PVE
::LXC
::Config-
>parse_lxc_network($conf->{$k});
654 $raw .= "lxc.net.$ind.type = veth\n";
655 $raw .= "lxc.net.$ind.veth.pair = veth${vmid}i${ind}\n";
656 $raw .= "lxc.net.$ind.hwaddr = $d->{hwaddr}\n" if defined($d->{hwaddr
});
657 $raw .= "lxc.net.$ind.name = $d->{name}\n" if defined($d->{name
});
658 $raw .= "lxc.net.$ind.mtu = $d->{mtu}\n" if defined($d->{mtu
});
661 if ($cgv1->{cpuset
}) {
663 if (my $lxcconf = $conf->{lxc
}) {
664 foreach my $entry (@$lxcconf) {
665 my ($k, $v) = @$entry;
666 $had_cpuset = 1 if $k eq 'lxc.cgroup.cpuset.cpus';
671 my $cores = $conf->{cores
};
672 if (!$had_cpuset && $cores) {
673 my $cpuset = eval { PVE
::CpuSet-
>new_from_cgroup('lxc', 'effective_cpus') };
674 $cpuset = PVE
::CpuSet-
>new_from_cgroup('', 'effective_cpus') if !$cpuset;
675 my @members = $cpuset->members();
676 while (scalar(@members) > $cores) {
677 my $randidx = int(rand(scalar(@members)));
678 $cpuset->delete($members[$randidx]);
679 splice(@members, $randidx, 1); # keep track of the changes
681 $raw .= "lxc.cgroup.cpuset.cpus = ".$cpuset->short_string()."\n";
685 File
::Path
::mkpath
("$dir/rootfs");
687 PVE
::Tools
::file_set_contents
("$dir/config", $raw);
690 # verify and cleanup nameserver list (replace \0 with ' ')
691 sub verify_nameserver_list
{
692 my ($nameserver_list) = @_;
695 foreach my $server (PVE
::Tools
::split_list
($nameserver_list)) {
696 PVE
::JSONSchema
::pve_verify_ip
($server);
700 return join(' ', @list);
703 sub verify_searchdomain_list
{
704 my ($searchdomain_list) = @_;
707 foreach my $server (PVE
::Tools
::split_list
($searchdomain_list)) {
708 # todo: should we add checks for valid dns domains?
712 return join(' ', @list);
715 sub get_console_command
{
716 my ($vmid, $conf, $escapechar) = @_;
718 # '-1' as $escapechar disables keyboard escape sequence
719 # any other passed char (a-z) will result in <Ctrl+$escapechar q>
721 my $cmode = PVE
::LXC
::Config-
>get_cmode($conf);
724 if ($cmode eq 'console') {
725 push @$cmd, 'lxc-console', '-n', $vmid, '-t', 0;
726 push @$cmd, '-e', $escapechar if $escapechar;
727 } elsif ($cmode eq 'tty') {
728 push @$cmd, 'lxc-console', '-n', $vmid;
729 push @$cmd, '-e', $escapechar if $escapechar;
730 } elsif ($cmode eq 'shell') {
731 push @$cmd, 'lxc-attach', '--clear-env', '-n', $vmid;
733 die "internal error";
739 sub get_primary_ips
{
742 # return data from net0
744 return undef if !defined($conf->{net0
});
745 my $net = PVE
::LXC
::Config-
>parse_lxc_network($conf->{net0
});
747 my $ipv4 = $net->{ip
};
749 if ($ipv4 =~ /^(dhcp|manual)$/) {
755 my $ipv6 = $net->{ip6
};
757 if ($ipv6 =~ /^(auto|dhcp|manual)$/) {
764 return ($ipv4, $ipv6);
767 sub delete_mountpoint_volume
{
768 my ($storage_cfg, $vmid, $volume) = @_;
770 return if PVE
::LXC
::Config-
>classify_mountpoint($volume) ne 'volume';
772 my ($vtype, $name, $owner) = PVE
::Storage
::parse_volname
($storage_cfg, $volume);
774 if ($vmid == $owner) {
775 PVE
::Storage
::vdisk_free
($storage_cfg, $volume);
777 warn "ignore deletion of '$volume', CT $vmid isn't the owner!\n";
781 sub destroy_lxc_container
{
782 my ($storage_cfg, $vmid, $conf, $replacement_conf) = @_;
784 PVE
::LXC
::Config-
>foreach_mountpoint($conf, sub {
785 my ($ms, $mountpoint) = @_;
786 delete_mountpoint_volume
($storage_cfg, $vmid, $mountpoint->{volume
});
789 rmdir "/var/lib/lxc/$vmid/rootfs";
790 unlink "/var/lib/lxc/$vmid/config";
791 rmdir "/var/lib/lxc/$vmid";
792 if (defined $replacement_conf) {
793 PVE
::LXC
::Config-
>write_config($vmid, $replacement_conf);
795 PVE
::LXC
::Config-
>destroy_config($vmid);
799 sub vm_stop_cleanup
{
800 my ($storage_cfg, $vmid, $conf, $keepActive) = @_;
802 return if $keepActive;
805 my $vollist = PVE
::LXC
::Config-
>get_vm_volumes($conf);
806 PVE
::Storage
::deactivate_volumes
($storage_cfg, $vollist);
808 warn $@ if $@; # avoid errors - just warn
811 my $safe_num_ne = sub {
814 return 0 if !defined($a) && !defined($b);
815 return 1 if !defined($a);
816 return 1 if !defined($b);
821 my $safe_string_ne = sub {
824 return 0 if !defined($a) && !defined($b);
825 return 1 if !defined($a);
826 return 1 if !defined($b);
832 my ($vmid, $conf, $opt, $newnet, $netid, $rootdir) = @_;
834 if ($newnet->{type
} ne 'veth') {
835 # for when there are physical interfaces
836 die "cannot update interface of type $newnet->{type}";
839 my $veth = "veth${vmid}i${netid}";
840 my $eth = $newnet->{name
};
842 if (my $oldnetcfg = $conf->{$opt}) {
843 my $oldnet = PVE
::LXC
::Config-
>parse_lxc_network($oldnetcfg);
845 if (&$safe_string_ne($oldnet->{hwaddr
}, $newnet->{hwaddr
}) ||
846 &$safe_string_ne($oldnet->{name
}, $newnet->{name
})) {
848 PVE
::Network
::veth_delete
($veth);
849 delete $conf->{$opt};
850 PVE
::LXC
::Config-
>write_config($vmid, $conf);
852 hotplug_net
($vmid, $conf, $opt, $newnet, $netid);
855 if (&$safe_string_ne($oldnet->{bridge
}, $newnet->{bridge
}) ||
856 &$safe_num_ne($oldnet->{tag
}, $newnet->{tag
}) ||
857 &$safe_num_ne($oldnet->{firewall
}, $newnet->{firewall
})) {
859 if ($oldnet->{bridge
}) {
860 PVE
::Network
::tap_unplug
($veth);
861 foreach (qw(bridge tag firewall)) {
862 delete $oldnet->{$_};
864 $conf->{$opt} = PVE
::LXC
::Config-
>print_lxc_network($oldnet);
865 PVE
::LXC
::Config-
>write_config($vmid, $conf);
868 PVE
::Network
::tap_plug
($veth, $newnet->{bridge
}, $newnet->{tag
}, $newnet->{firewall
}, $newnet->{trunks
}, $newnet->{rate
});
869 # This includes the rate:
870 foreach (qw(bridge tag firewall rate)) {
871 $oldnet->{$_} = $newnet->{$_} if $newnet->{$_};
873 } elsif (&$safe_string_ne($oldnet->{rate
}, $newnet->{rate
})) {
874 # Rate can be applied on its own but any change above needs to
875 # include the rate in tap_plug since OVS resets everything.
876 PVE
::Network
::tap_rate_limit
($veth, $newnet->{rate
});
877 $oldnet->{rate
} = $newnet->{rate
}
879 $conf->{$opt} = PVE
::LXC
::Config-
>print_lxc_network($oldnet);
880 PVE
::LXC
::Config-
>write_config($vmid, $conf);
883 hotplug_net
($vmid, $conf, $opt, $newnet, $netid);
886 update_ipconfig
($vmid, $conf, $opt, $eth, $newnet, $rootdir);
890 my ($vmid, $conf, $opt, $newnet, $netid) = @_;
892 my $veth = "veth${vmid}i${netid}";
893 my $vethpeer = $veth . "p";
894 my $eth = $newnet->{name
};
896 PVE
::Network
::veth_create
($veth, $vethpeer, $newnet->{bridge
}, $newnet->{hwaddr
});
897 PVE
::Network
::tap_plug
($veth, $newnet->{bridge
}, $newnet->{tag
}, $newnet->{firewall
}, $newnet->{trunks
}, $newnet->{rate
});
899 # attach peer in container
900 my $cmd = ['lxc-device', '-n', $vmid, 'add', $vethpeer, "$eth" ];
901 PVE
::Tools
::run_command
($cmd);
903 # link up peer in container
904 $cmd = ['lxc-attach', '-n', $vmid, '-s', 'NETWORK', '--', '/sbin/ip', 'link', 'set', $eth ,'up' ];
905 PVE
::Tools
::run_command
($cmd);
907 my $done = { type
=> 'veth' };
908 foreach (qw(bridge tag firewall hwaddr name)) {
909 $done->{$_} = $newnet->{$_} if $newnet->{$_};
911 $conf->{$opt} = PVE
::LXC
::Config-
>print_lxc_network($done);
913 PVE
::LXC
::Config-
>write_config($vmid, $conf);
916 sub update_ipconfig
{
917 my ($vmid, $conf, $opt, $eth, $newnet, $rootdir) = @_;
919 my $lxc_setup = PVE
::LXC
::Setup-
>new($conf, $rootdir);
921 my $optdata = PVE
::LXC
::Config-
>parse_lxc_network($conf->{$opt});
926 PVE
::Tools
::run_command
(['lxc-attach', '-n', $vmid, '-s', 'NETWORK', '--', @_], %$cmdargs);
928 my $ipcmd = sub { &$nscmd({}, '/sbin/ip', @_) };
930 my $change_ip_config = sub {
931 my ($ipversion) = @_;
933 my $family_opt = "-$ipversion";
934 my $suffix = $ipversion == 4 ?
'' : $ipversion;
938 my $newip = $newnet->{$ip};
939 my $newgw = $newnet->{$gw};
940 my $oldip = $optdata->{$ip};
941 my $oldgw = $optdata->{$gw};
943 my $change_ip = &$safe_string_ne($oldip, $newip);
944 my $change_gw = &$safe_string_ne($oldgw, $newgw);
946 return if !$change_ip && !$change_gw;
948 # step 1: add new IP, if this fails we cancel
949 my $is_real_ip = ($newip && $newip !~ /^(?:auto|dhcp|manual)$/);
950 if ($change_ip && $is_real_ip) {
951 eval { &$ipcmd($family_opt, 'addr', 'add', $newip, 'dev', $eth); };
958 # step 2: replace gateway
959 # If this fails we delete the added IP and cancel.
960 # If it succeeds we save the config and delete the old IP, ignoring
961 # errors. The config is then saved.
962 # Note: 'ip route replace' can add
966 if ($is_real_ip && !PVE
::Network
::is_ip_in_cidr
($newgw, $newip, $ipversion)) {
967 &$ipcmd($family_opt, 'route', 'add', $newgw, 'dev', $eth);
969 &$ipcmd($family_opt, 'route', 'replace', 'default', 'via', $newgw);
973 # the route was not replaced, the old IP is still available
974 # rollback (delete new IP) and cancel
976 eval { &$ipcmd($family_opt, 'addr', 'del', $newip, 'dev', $eth); };
977 warn $@ if $@; # no need to die here
982 eval { &$ipcmd($family_opt, 'route', 'del', 'default'); };
983 # if the route was not deleted, the guest might have deleted it manually
987 if ($oldgw && $oldip && !PVE
::Network
::is_ip_in_cidr
($oldgw, $oldip)) {
988 eval { &$ipcmd($family_opt, 'route', 'del', $oldgw, 'dev', $eth); };
989 # warn if the route was deleted manually
994 # from this point on we save the configuration
995 # step 3: delete old IP ignoring errors
996 if ($change_ip && $oldip && $oldip !~ /^(?:auto|dhcp)$/) {
997 # We need to enable promote_secondaries, otherwise our newly added
998 # address will be removed along with the old one.
1001 if ($ipversion == 4) {
1002 &$nscmd({ outfunc
=> sub { $promote = int(shift) } },
1003 'cat', "/proc/sys/net/ipv4/conf/$eth/promote_secondaries");
1004 &$nscmd({}, 'sysctl', "net.ipv4.conf.$eth.promote_secondaries=1");
1006 &$ipcmd($family_opt, 'addr', 'del', $oldip, 'dev', $eth);
1008 warn $@ if $@; # no need to die here
1010 if ($ipversion == 4) {
1011 &$nscmd({}, 'sysctl', "net.ipv4.conf.$eth.promote_secondaries=$promote");
1015 foreach my $property ($ip, $gw) {
1016 if ($newnet->{$property}) {
1017 $optdata->{$property} = $newnet->{$property};
1019 delete $optdata->{$property};
1022 $conf->{$opt} = PVE
::LXC
::Config-
>print_lxc_network($optdata);
1023 PVE
::LXC
::Config-
>write_config($vmid, $conf);
1024 $lxc_setup->setup_network($conf);
1027 &$change_ip_config(4);
1028 &$change_ip_config(6);
1032 my $open_namespace = sub {
1033 my ($vmid, $pid, $kind) = @_;
1034 sysopen my $fd, "/proc/$pid/ns/$kind", O_RDONLY
1035 or die "failed to open $kind namespace of container $vmid: $!\n";
1039 my $enter_namespace = sub {
1040 my ($vmid, $pid, $kind, $type) = @_;
1041 my $fd = $open_namespace->($vmid, $pid, $kind);
1042 PVE
::Tools
::setns
(fileno($fd), $type)
1043 or die "failed to enter $kind namespace of container $vmid: $!\n";
1047 my $get_container_namespace = sub {
1048 my ($vmid, $pid, $kind) = @_;
1051 if (!defined($pid)) {
1052 # Pin the pid while we're grabbing its stuff from /proc
1053 ($pid, $pidfd) = open_lxc_pid
($vmid)
1054 or die "failed to open pidfd of container $vmid\'s init process\n";
1057 return $open_namespace->($vmid, $pid, $kind);
1060 my $do_syncfs = sub {
1061 my ($vmid, $pid, $socket) = @_;
1063 &$enter_namespace($vmid, $pid, 'mnt', PVE
::Tools
::CLONE_NEWNS
);
1065 # Tell the parent process to start reading our /proc/mounts
1066 print {$socket} "go\n";
1069 # Receive /proc/self/mounts
1070 my $mountdata = do { local $/ = undef; <$socket> };
1073 # Now sync all mountpoints...
1074 my $mounts = PVE
::ProcFSTools
::parse_mounts
($mountdata);
1075 foreach my $mp (@$mounts) {
1076 my ($what, $dir, $fs) = @$mp;
1077 next if $fs eq 'fuse.lxcfs';
1078 eval { PVE
::Tools
::sync_mountpoint
($dir); };
1083 sub sync_container_namespace
{
1085 my $pid = find_lxc_pid
($vmid);
1087 # SOCK_DGRAM is nicer for barriers but cannot be slurped
1088 socketpair my $pfd, my $cfd, AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
1089 or die "failed to create socketpair: $!\n";
1092 die "fork failed: $!\n" if !defined($child);
1097 &$do_syncfs($vmid, $pid, $cfd);
1107 die "failed to enter container namespace\n" if $go ne "go\n";
1109 open my $mounts, '<', "/proc/$child/mounts"
1110 or die "failed to open container's /proc/mounts: $!\n";
1111 my $mountdata = do { local $/ = undef; <$mounts> };
1113 print {$pfd} $mountdata;
1116 while (waitpid($child, 0) != $child) {}
1117 die "failed to sync container namespace\n" if $? != 0;
1120 sub template_create
{
1121 my ($vmid, $conf) = @_;
1123 my $storecfg = PVE
::Storage
::config
();
1125 PVE
::LXC
::Config-
>foreach_mountpoint($conf, sub {
1126 my ($ms, $mountpoint) = @_;
1128 my $volid = $mountpoint->{volume
};
1130 die "Template feature is not available for '$volid'\n"
1131 if !PVE
::Storage
::volume_has_feature
($storecfg, 'template', $volid);
1134 PVE
::LXC
::Config-
>foreach_mountpoint($conf, sub {
1135 my ($ms, $mountpoint) = @_;
1137 my $volid = $mountpoint->{volume
};
1139 PVE
::Storage
::activate_volumes
($storecfg, [$volid]);
1141 my $template_volid = PVE
::Storage
::vdisk_create_base
($storecfg, $volid);
1142 $mountpoint->{volume
} = $template_volid;
1143 $conf->{$ms} = PVE
::LXC
::Config-
>print_ct_mountpoint($mountpoint, $ms eq "rootfs");
1146 PVE
::LXC
::Config-
>write_config($vmid, $conf);
1149 sub check_ct_modify_config_perm
{
1150 my ($rpcenv, $authuser, $vmid, $pool, $newconf, $delete) = @_;
1152 return 1 if $authuser eq 'root@pam';
1155 my ($opt, $delete) = @_;
1156 if ($opt eq 'cores' || $opt eq 'cpuunits' || $opt eq 'cpulimit') {
1157 $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.CPU']);
1158 } elsif ($opt eq 'rootfs' || $opt =~ /^mp\d+$/) {
1159 $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Disk']);
1161 my $data = $opt eq 'rootfs' ? PVE
::LXC
::Config-
>parse_ct_rootfs($newconf->{$opt})
1162 : PVE
::LXC
::Config-
>parse_ct_mountpoint($newconf->{$opt});
1163 raise_perm_exc
("mount point type $data->{type} is only allowed for root\@pam")
1164 if $data->{type
} ne 'volume';
1165 } elsif ($opt eq 'memory' || $opt eq 'swap') {
1166 $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Memory']);
1167 } elsif ($opt =~ m/^net\d+$/ || $opt eq 'nameserver' ||
1168 $opt eq 'searchdomain' || $opt eq 'hostname') {
1169 $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Network']);
1170 } elsif ($opt eq 'features') {
1171 # For now this is restricted to root@pam
1172 raise_perm_exc
("changing feature flags is only allowed for root\@pam");
1173 } elsif ($opt eq 'hookscript') {
1174 # For now this is restricted to root@pam
1175 raise_perm_exc
("changing the hookscript is only allowed for root\@pam");
1177 $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Options']);
1181 foreach my $opt (keys %$newconf) {
1184 foreach my $opt (@$delete) {
1192 my ($vmid, $storage_cfg, $conf, $noerr) = @_;
1194 my $rootdir = "/var/lib/lxc/$vmid/rootfs";
1195 my $volid_list = PVE
::LXC
::Config-
>get_vm_volumes($conf);
1199 PVE
::LXC
::Config-
>foreach_mountpoint_reverse($conf, sub {
1200 my ($ms, $mountpoint) = @_;
1202 my $volid = $mountpoint->{volume
};
1203 my $mount = $mountpoint->{mp
};
1205 return if !$volid || !$mount;
1207 my $mount_path = "$rootdir/$mount";
1208 $mount_path =~ s!/+!/!g;
1210 return if !PVE
::ProcFSTools
::is_mounted
($mount_path);
1213 PVE
::Tools
::run_command
(['umount', '-d', $mount_path]);
1225 return $res; # tell caller if (some) umounts failed for the noerr case
1229 my ($vmid, $storage_cfg, $conf, $ignore_ro) = @_;
1231 my $rootdir = "/var/lib/lxc/$vmid/rootfs";
1232 File
::Path
::make_path
($rootdir);
1234 my $volid_list = PVE
::LXC
::Config-
>get_vm_volumes($conf);
1235 PVE
::Storage
::activate_volumes
($storage_cfg, $volid_list);
1237 my (undef, $rootuid, $rootgid) = parse_id_maps
($conf);
1240 PVE
::LXC
::Config-
>foreach_mountpoint($conf, sub {
1241 my ($ms, $mountpoint) = @_;
1243 $mountpoint->{ro
} = 0 if $ignore_ro;
1245 mountpoint_mount
($mountpoint, $rootdir, $storage_cfg, undef, $rootuid, $rootgid);
1249 warn "mounting container failed\n";
1250 umount_all
($vmid, $storage_cfg, $conf, 1);
1258 sub mountpoint_mount_path
{
1259 my ($mountpoint, $storage_cfg, $snapname) = @_;
1261 return mountpoint_mount
($mountpoint, undef, $storage_cfg, $snapname);
1269 if ($line =~ m
@^(/dev/loop\d
+):@) {
1273 my $cmd = ['losetup', '--associated', $path];
1274 PVE
::Tools
::run_command
($cmd, outfunc
=> $parser);
1278 # Run a function with a file attached to a loop device.
1279 # The loop device is always detached afterwards (or set to autoclear).
1280 # Returns the loop device.
1281 sub run_with_loopdev
{
1282 my ($func, $file, $readonly) = @_;
1283 my $device = query_loopdev
($file);
1284 # Try to reuse an existing device
1286 # We assume that whoever setup the loop device is responsible for
1294 if ($line =~ m
@^(/dev/loop\d
+)$@) {
1304 push @$losetup_cmd, '-r' if $readonly;
1305 PVE
::Tools
::run_command
($losetup_cmd, outfunc
=> $parser);
1306 die "failed to setup loop device for $file\n" if !$device;
1307 eval { &$func($device); };
1309 PVE
::Tools
::run_command
(['losetup', '-d', $device]);
1314 # In scalar mode: returns a file handle to the deepest directory node.
1315 # In list context: returns a list of:
1316 # * the deepest directory node
1317 # * the 2nd deepest directory (parent of the above)
1318 # * directory name of the last directory
1319 # So that the path $2/$3 should lead to $1 afterwards.
1320 sub walk_tree_nofollow
($$$;$$) {
1321 my ($start, $subdir, $mkdir, $rootuid, $rootgid) = @_;
1323 sysopen(my $fd, $start, O_PATH
| O_DIRECTORY
)
1324 or die "failed to open start directory $start: $!\n";
1326 return walk_tree_nofollow_fd
($start, $fd, $subdir, $mkdir, $rootuid, $rootgid);
1330 sub walk_tree_nofollow_fd
($$$$;$$) {
1331 my ($start_dirname, $start_fd, $subdir, $mkdir, $rootuid, $rootgid) = @_;
1333 # splitdir() returns '' for empty components including the leading /
1334 my @comps = grep { length($_)>0 } File
::Spec-
>splitdir($subdir);
1337 my $dir = $start_dirname;
1338 my $last_component = undef;
1340 foreach my $component (@comps) {
1341 $dir .= "/$component";
1342 my $next = PVE
::Tools
::openat
(fileno($fd), $component, O_NOFOLLOW
| O_DIRECTORY
);
1345 # failed, check for symlinks and try to create the path
1346 die "symlink encountered at: $dir\n" if $! == ELOOP
|| $! == ENOTDIR
;
1347 die "cannot open directory $dir: $!\n" if !$mkdir;
1349 # We don't check for errors on mkdirat() here and just try to
1350 # openat() again, since at least one error (EEXIST) is an
1351 # expected possibility if multiple containers start
1352 # simultaneously. If someone else injects a symlink now then
1353 # the subsequent openat() will fail due to O_NOFOLLOW anyway.
1354 PVE
::Tools
::mkdirat
(fileno($fd), $component, 0755);
1356 $next = PVE
::Tools
::openat
(fileno($fd), $component, O_NOFOLLOW
| O_DIRECTORY
);
1357 die "failed to create path: $dir: $!\n" if !$next;
1359 PVE
::Tools
::fchownat
(fileno($next), '', $rootuid, $rootgid, PVE
::Tools
::AT_EMPTY_PATH
)
1360 if defined($rootuid) && defined($rootgid);
1363 close $second if defined($last_component) && $second != $start_fd;
1364 $last_component = $component;
1369 return ($fd, defined($last_component) && $second, $last_component) if wantarray;
1370 close $second if defined($last_component) && $second != $start_fd;
1374 # To guard against symlink attack races against other currently running
1375 # containers with shared recursive bind mount hierarchies we prepare a
1376 # directory handle for the directory we're mounting over to verify the
1377 # mountpoint afterwards.
1378 sub __bindmount_prepare
{
1379 my ($hostroot, $dir) = @_;
1380 my $srcdh = walk_tree_nofollow
($hostroot, $dir, 0);
1384 # Assuming we mount to rootfs/a/b/c, verify with the directory handle to 'b'
1385 # ($parentfd) that 'b/c' (openat($parentfd, 'c')) really leads to the directory
1386 # we intended to bind mount.
1387 sub __bindmount_verify
{
1388 my ($srcdh, $parentfd, $last_dir, $ro) = @_;
1391 # Open the mount point path coming from the parent directory since the
1392 # filehandle we would have gotten as first result of walk_tree_nofollow
1393 # earlier is still a handle to the underlying directory instead of the
1395 $destdh = PVE
::Tools
::openat
(fileno($parentfd), $last_dir, PVE
::Tools
::O_PATH
| O_NOFOLLOW
| O_DIRECTORY
);
1396 die "failed to open mount point: $!\n" if !$destdh;
1399 # no separate function because 99% of the time it's the wrong thing to use.
1400 if (syscall(PVE
::Syscall
::faccessat
, fileno($destdh), $dot, &POSIX
::W_OK
, 0) != -1) {
1401 die "failed to mark bind mount read only\n";
1403 die "read-only check failed: $!\n" if $! != EROFS
;
1406 # For the rootfs we don't have a parentfd so we open the path directly.
1407 # Note that this means bindmounting any prefix of the host's
1408 # /var/lib/lxc/$vmid path into another container is considered a grave
1410 sysopen $destdh, $last_dir, O_PATH
| O_DIRECTORY
;
1411 die "failed to open mount point: $!\n" if !$destdh;
1414 my ($srcdev, $srcinode) = stat($srcdh);
1415 my ($dstdev, $dstinode) = stat($destdh);
1419 return ($srcdev == $dstdev && $srcinode == $dstinode);
1422 # Perform the actual bind mounting:
1423 sub __bindmount_do
{
1424 my ($dir, $dest, $ro, @extra_opts) = @_;
1425 PVE
::Tools
::run_command
(['mount', '-o', 'bind', @extra_opts, $dir, $dest]);
1427 eval { PVE
::Tools
::run_command
(['mount', '-o', 'bind,remount,ro', $dest]); };
1429 warn "bindmount error\n";
1430 # don't leave writable bind-mounts behind...
1431 PVE
::Tools
::run_command
(['umount', $dest]);
1438 my ($dir, $parentfd, $last_dir, $dest, $ro, @extra_opts) = @_;
1440 my $srcdh = __bindmount_prepare
('/', $dir);
1442 __bindmount_do
($dir, $dest, $ro, @extra_opts);
1444 if (!__bindmount_verify
($srcdh, $parentfd, $last_dir, $ro)) {
1445 PVE
::Tools
::run_command
(['umount', $dest]);
1446 die "detected mount path change at: $dir\n";
1450 # Cleanup $rootdir a bit (double and trailing slashes), build the mount path
1451 # from $rootdir and $mount and walk the path from $rootdir to the final
1452 # directory to check for symlinks.
1453 sub __mount_prepare_rootdir
{
1454 my ($rootdir, $mount, $rootuid, $rootgid) = @_;
1455 $rootdir =~ s!/+!/!g;
1456 $rootdir =~ s!/+$!!;
1457 my $mount_path = "$rootdir/$mount";
1458 my ($mpfd, $parentfd, $last_dir) = walk_tree_nofollow
($rootdir, $mount, 1, $rootuid, $rootgid);
1459 return ($rootdir, $mount_path, $mpfd, $parentfd, $last_dir);
1462 # use $rootdir = undef to just return the corresponding mount path
1463 sub mountpoint_mount
{
1464 my ($mountpoint, $rootdir, $storage_cfg, $snapname, $rootuid, $rootgid) = @_;
1465 return __mountpoint_mount
($mountpoint, $rootdir, $storage_cfg, $snapname, $rootuid, $rootgid, undef);
1468 sub mountpoint_stage
{
1469 my ($mountpoint, $stage_dir, $storage_cfg, $snapname, $rootuid, $rootgid) = @_;
1470 my ($path, $loop, $dev) =
1471 __mountpoint_mount
($mountpoint, $stage_dir, $storage_cfg, $snapname, $rootuid, $rootgid, 1);
1473 if (!defined($path)) {
1474 return undef if $! == ENOSYS
;
1475 die "failed to mount subvolume: $!\n";
1479 my $fd = PVE
::Tools
::open_tree
(&AT_FDCWD
, $stage_dir, &OPEN_TREE_CLOEXEC
| &OPEN_TREE_CLONE
)
1480 or die "open_tree() on mount point failed: $!\n";
1482 return wantarray ?
($path, $loop, $dev, $fd) : $fd;
1485 sub mountpoint_insert_staged
{
1486 my ($mount_fd, $rootdir_fd, $mp_dir, $opt, $rootuid, $rootgid) = @_;
1488 if (!defined($rootdir_fd)) {
1489 sysopen($rootdir_fd, '.', O_PATH
| O_DIRECTORY
)
1490 or die "failed to open '.': $!\n";
1493 my $dest_fd = walk_tree_nofollow_fd
('/', $rootdir_fd, $mp_dir, 1, $rootuid, $rootgid);
1495 PVE
::Tools
::move_mount
(
1500 &MOVE_MOUNT_F_EMPTY_PATH
| &MOVE_MOUNT_T_EMPTY_PATH
,
1501 ) or die "failed to move '$opt' into container hierarchy: $!\n";
1504 # Use $stage_mount, $rootdir is treated as a temporary path to "stage" the file system. The user
1505 # can then open a file descriptor to it which can be used with the `move_mount` syscall.
1506 # Note that if the kernel does not support the new mount API, this will not perform any action
1507 # and return `undef` with $! = ENOSYS.
1508 sub __mountpoint_mount
{
1509 my ($mountpoint, $rootdir, $storage_cfg, $snapname, $rootuid, $rootgid, $stage_mount) = @_;
1511 if (defined($stage_mount) && !PVE
::LXC
::Tools
::can_use_new_mount_api
()) {
1516 my $volid = $mountpoint->{volume
};
1517 my $mount = $mountpoint->{mp
};
1518 my $type = $mountpoint->{type
};
1519 my $quota = !$snapname && !$mountpoint->{ro
} && $mountpoint->{quota
};
1522 return if !$volid || !$mount;
1527 my ($mpfd, $parentfd, $last_dir);
1529 if (defined($rootdir)) {
1530 ($rootdir, $mount_path, $mpfd, $parentfd, $last_dir) =
1531 __mount_prepare_rootdir
($rootdir, $mount, $rootuid, $rootgid);
1534 if (defined($stage_mount)) {
1535 $mount_path = $rootdir;
1538 my ($storage, $volname) = PVE
::Storage
::parse_volume_id
($volid, 1);
1540 die "unknown snapshot path for '$volid'" if !$storage && defined($snapname);
1544 if (my $mountopts = $mountpoint->{mountoptions
}) {
1545 my @opts = split(/;/, $mountpoint->{mountoptions
});
1546 push @$optlist, grep { PVE
::LXC
::Config
::is_valid_mount_option
($_) } @opts;
1549 my $acl = $mountpoint->{acl
};
1550 if (defined($acl)) {
1551 push @$optlist, ($acl ?
'acl' : 'noacl');
1554 my $optstring = join(',', @$optlist);
1555 my $readonly = $mountpoint->{ro
};
1558 @extra_opts = ('-o', $optstring) if $optstring;
1562 my $scfg = PVE
::Storage
::storage_config
($storage_cfg, $storage);
1564 my $path = PVE
::Storage
::map_volume
($storage_cfg, $volid, $snapname);
1566 $path = PVE
::Storage
::path
($storage_cfg, $volid, $snapname) if !defined($path);
1568 my ($vtype, undef, undef, undef, undef, $isBase, $format) =
1569 PVE
::Storage
::parse_volname
($storage_cfg, $volid);
1571 $format = 'iso' if $vtype eq 'iso'; # allow to handle iso files
1573 if ($format eq 'subvol') {
1576 if ($scfg->{type
} eq 'zfspool') {
1577 my $path_arg = $path;
1578 $path_arg =~ s!^/+!!;
1579 PVE
::Tools
::run_command
(['mount', '-o', 'ro', @extra_opts, '-t', 'zfs', $path_arg, $mount_path]);
1581 die "cannot mount subvol snapshots for storage type '$scfg->{type}'\n";
1584 if (defined($acl) && $scfg->{type
} eq 'zfspool') {
1585 my $acltype = ($acl ?
'acltype=posixacl' : 'acltype=noacl');
1586 my (undef, $name) = PVE
::Storage
::parse_volname
($storage_cfg, $volid);
1587 $name .= "\@$snapname" if defined($snapname);
1588 PVE
::Tools
::run_command
(['zfs', 'set', $acltype, "$scfg->{pool}/$name"]);
1590 bindmount
($path, $parentfd, $last_dir//$rootdir, $mount_path, $readonly, @extra_opts);
1591 warn "cannot enable quota control for bind mounted subvolumes\n" if $quota;
1594 return wantarray ?
($path, 0, undef) : $path;
1595 } elsif ($format eq 'raw' || $format eq 'iso') {
1596 # NOTE: 'mount' performs canonicalization without the '-c' switch, which for
1597 # device-mapper devices is special-cased to use the /dev/mapper symlinks.
1598 # Our autodev hook expects the /dev/dm-* device currently
1599 # and will create the /dev/mapper symlink accordingly
1600 $path = Cwd
::realpath
($path);
1601 die "failed to get device path\n" if !$path;
1602 ($path) = ($path =~ /^(.*)$/s); #untaint
1606 if ($format eq 'iso') {
1607 PVE
::Tools
::run_command
(['mount', '-o', 'ro', @extra_opts, $path, $mount_path]);
1608 } elsif ($isBase || defined($snapname)) {
1609 PVE
::Tools
::run_command
(['mount', '-o', 'ro,noload', @extra_opts, $path, $mount_path]);
1612 push @extra_opts, '-o', 'usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0';
1614 push @extra_opts, '-o', 'ro' if $readonly;
1615 PVE
::Tools
::run_command
(['mount', @extra_opts, $path, $mount_path]);
1619 my $use_loopdev = 0;
1620 if ($scfg->{path
}) {
1621 $mounted_dev = run_with_loopdev
($domount, $path, $readonly);
1623 } elsif ($scfg->{type
} eq 'drbd' || $scfg->{type
} eq 'lvm' ||
1624 $scfg->{type
} eq 'rbd' || $scfg->{type
} eq 'lvmthin') {
1625 $mounted_dev = $path;
1628 die "unsupported storage type '$scfg->{type}'\n";
1630 return wantarray ?
($path, $use_loopdev, $mounted_dev) : $path;
1632 die "unsupported image format '$format'\n";
1634 } elsif ($type eq 'device') {
1635 push @extra_opts, '-o', 'ro' if $readonly;
1636 push @extra_opts, '-o', 'usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0' if $quota;
1637 # See the NOTE above about devicemapper canonicalization
1638 my ($devpath) = (Cwd
::realpath
($volid) =~ /^(.*)$/s); # realpath() taints
1639 PVE
::Tools
::run_command
(['mount', @extra_opts, $volid, $mount_path]) if $mount_path;
1640 return wantarray ?
($volid, 0, $devpath) : $volid;
1641 } elsif ($type eq 'bind') {
1642 die "directory '$volid' does not exist\n" if ! -d
$volid;
1643 bindmount
($volid, $parentfd, $last_dir//$rootdir, $mount_path, $readonly, @extra_opts) if $mount_path;
1644 warn "cannot enable quota control for bind mounts\n" if $quota;
1645 return wantarray ?
($volid, 0, undef) : $volid;
1648 die "unsupported storage";
1651 # Create a directory in the mountpoint staging tempfs.
1652 sub get_staging_mount_path
($) {
1655 my $target = get_staging_tempfs
() . "/$opt";
1656 if (!mkdir($target) && $! != EEXIST
) {
1657 die "failed to create directory $target: $!\n";
1663 # Mount /run/pve/mountpoints as tmpfs
1664 sub get_staging_tempfs
() {
1665 # We choose a path in /var/lib/lxc/ here because the lxc-start apparmor profile restricts most
1667 my $target = '/var/lib/lxc/.pve-staged-mounts';
1668 if (!mkdir($target)) {
1669 return $target if $! == EEXIST
;
1670 die "failed to create directory $target: $!\n";
1673 PVE
::Tools
::mount
("none", $target, 'tmpfs', 0, "size=8k,mode=755")
1674 or die "failed to mount $target as tmpfs: $!\n";
1680 my ($dev, $rootuid, $rootgid) = @_;
1682 PVE
::Tools
::run_command
(['mkfs.ext4', '-O', 'mmp',
1683 '-E', "root_owner=$rootuid:$rootgid",
1688 my ($storage_cfg, $volid, $rootuid, $rootgid) = @_;
1690 if ($volid =~ m!^/dev/.+!) {
1695 my ($storage, $volname) = PVE
::Storage
::parse_volume_id
($volid, 1);
1697 die "cannot format volume '$volid' with no storage\n" if !$storage;
1699 PVE
::Storage
::activate_volumes
($storage_cfg, [$volid]);
1701 my $path = PVE
::Storage
::map_volume
($storage_cfg, $volid);
1703 $path = PVE
::Storage
::path
($storage_cfg, $volid) if !defined($path);
1705 my ($vtype, undef, undef, undef, undef, $isBase, $format) =
1706 PVE
::Storage
::parse_volname
($storage_cfg, $volid);
1708 die "cannot format volume '$volid' (format == $format)\n"
1709 if $format ne 'raw';
1711 mkfs
($path, $rootuid, $rootgid);
1715 my ($storecfg, $vollist) = @_;
1717 foreach my $volid (@$vollist) {
1718 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
1724 my ($storecfg, $vmid, $storage, $size_kb, $rootuid, $rootgid) = @_;
1726 my $needs_chown = 0;
1729 my $scfg = PVE
::Storage
::storage_config
($storecfg, $storage);
1730 # fixme: use better naming ct-$vmid-disk-X.raw?
1734 if ($scfg->{type
} eq 'dir' || $scfg->{type
} eq 'nfs' || $scfg->{type
} eq 'cifs' ) {
1736 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'raw',
1740 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'subvol',
1744 } elsif ($scfg->{type
} eq 'zfspool') {
1746 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'subvol',
1749 } elsif ($scfg->{type
} eq 'drbd' || $scfg->{type
} eq 'lvm' || $scfg->{type
} eq 'lvmthin') {
1751 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
1754 } elsif ($scfg->{type
} eq 'rbd') {
1756 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
1759 die "unable to create containers on storage type '$scfg->{type}'\n";
1761 format_disk
($storecfg, $volid, $rootuid, $rootgid) if $do_format;
1764 # in case formatting got interrupted:
1765 if (defined($volid)) {
1766 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
1772 return ($volid, $needs_chown);
1775 our $NEW_DISK_RE = qr/^([^:\s]+):(\d+(\.\d+)?)$/;
1777 my ($storecfg, $vmid, $settings, $conf, $pending) = @_;
1782 my (undef, $rootuid, $rootgid) = PVE
::LXC
::parse_id_maps
($conf);
1783 my $chown_vollist = [];
1785 PVE
::LXC
::Config-
>foreach_mountpoint($settings, sub {
1786 my ($ms, $mountpoint) = @_;
1788 my $volid = $mountpoint->{volume
};
1789 my $mp = $mountpoint->{mp
};
1791 my ($storage, $volname) = PVE
::Storage
::parse_volume_id
($volid, 1);
1793 if ($storage && ($volid =~ $NEW_DISK_RE)) {
1794 my ($storeid, $size_gb) = ($1, $2);
1796 my $size_kb = int(${size_gb
}*1024) * 1024;
1798 my $needs_chown = 0;
1799 ($volid, $needs_chown) = alloc_disk
($storecfg, $vmid, $storage, $size_kb, $rootuid, $rootgid);
1800 push @$chown_vollist, $volid if $needs_chown;
1801 push @$vollist, $volid;
1802 $mountpoint->{volume
} = $volid;
1803 $mountpoint->{size
} = $size_kb * 1024;
1805 $conf->{pending
}->{$ms} = PVE
::LXC
::Config-
>print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
1807 $conf->{$ms} = PVE
::LXC
::Config-
>print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
1810 # use specified/existing volid/dir/device
1811 $conf->{$ms} = PVE
::LXC
::Config-
>print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
1815 PVE
::Storage
::activate_volumes
($storecfg, $chown_vollist, undef);
1816 foreach my $volid (@$chown_vollist) {
1817 my $path = PVE
::Storage
::path
($storecfg, $volid, undef);
1818 chown($rootuid, $rootgid, $path);
1820 PVE
::Storage
::deactivate_volumes
($storecfg, $chown_vollist, undef);
1822 # free allocated images on error
1824 destroy_disks
($storecfg, $vollist);
1830 sub update_disksize
{
1831 my ($vmid, $conf, $all_volumes) = @_;
1834 my $prefix = "CT $vmid:";
1836 my $update_mp = sub {
1837 my ($key, $mp, @param) = @_;
1838 my $size = $all_volumes->{$mp->{volume
}}->{size
} // 0;
1840 if (!defined($mp->{size
}) || $size != $mp->{size
}) {
1842 print "$prefix updated volume size of '$mp->{volume}' in config.\n";
1843 $mp->{size
} = $size;
1844 my $nomp = 1 if ($key eq 'rootfs');
1845 $conf->{$key} = PVE
::LXC
::Config-
>print_ct_mountpoint($mp, $nomp);
1849 PVE
::LXC
::Config-
>foreach_mountpoint($conf, $update_mp);
1855 my ($vmid, $conf, $all_volumes) = @_;
1858 my $prefix = "CT $vmid:";
1860 # Note: it is allowed to define multiple storage entries with the same path
1861 # (alias), so we need to check both 'volid' and real 'path' (two different
1862 # volid can point to the same path).
1864 # used and unused disks
1868 foreach my $opt (keys %$conf) {
1869 next if ($opt !~ m/^unused\d+$/);
1870 my $vol = $all_volumes->{$conf->{$opt}};
1871 $refpath->{$vol->{path
}} = $vol->{volid
};
1874 foreach my $key (keys %$all_volumes) {
1875 my $vol = $all_volumes->{$key};
1876 my $in_use = PVE
::LXC
::Config-
>is_volume_in_use($conf, $vol->{volid
});
1877 my $path = $vol->{path
};
1880 $refpath->{$path} = $key;
1881 delete $orphans->{$path};
1883 if ((!$orphans->{$path}) && (!$refpath->{$path})) {
1884 $orphans->{$path} = $key;
1889 for my $key (keys %$orphans) {
1890 my $disk = $orphans->{$key};
1891 my $unused = PVE
::LXC
::Config-
>add_unused_volume($conf, $disk);
1895 print "$prefix add unreferenced volume '$disk' as '$unused' to config.\n";
1903 my ($cfg, $vmid) = @_;
1905 my $info = PVE
::Storage
::vdisk_list
($cfg, undef, $vmid);
1907 my $all_volumes = {};
1908 foreach my $storeid (keys %$info) {
1909 foreach my $item (@{$info->{$storeid}}) {
1910 my $volid = $item->{volid
};
1911 next if !($volid && $item->{size
});
1912 $item->{path
} = PVE
::Storage
::path
($cfg, $volid);
1913 $all_volumes->{$volid} = $item;
1917 return $all_volumes;
1921 my ($vmid, $nolock, $dryrun) = @_;
1923 my $cfg = PVE
::Storage
::config
();
1925 # FIXME: Remove once our RBD plugin can handle CT and VM on a single storage
1926 # see: https://pve.proxmox.com/pipermail/pve-devel/2018-July/032900.html
1927 foreach my $stor (keys %{$cfg->{ids
}}) {
1928 delete($cfg->{ids
}->{$stor}) if !$cfg->{ids
}->{$stor}->{content
}->{rootdir
};
1931 print "rescan volumes...\n";
1932 my $all_volumes = scan_volids
($cfg, $vmid);
1934 my $updatefn = sub {
1938 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
1940 PVE
::LXC
::Config-
>check_lock($conf);
1943 foreach my $volid (keys %$all_volumes) {
1944 my $info = $all_volumes->{$volid};
1945 $vm_volids->{$volid} = $info if $info->{vmid
} == $vmid;
1948 my $upu = update_unused
($vmid, $conf, $vm_volids);
1949 my $upd = update_disksize
($vmid, $conf, $vm_volids);
1950 $changes = $upu || $upd;
1952 PVE
::LXC
::Config-
>write_config($vmid, $conf) if $changes && !$dryrun;
1955 if (defined($vmid)) {
1959 PVE
::LXC
::Config-
>lock_config($vmid, $updatefn, $vmid);
1962 my $vmlist = config_list
();
1963 foreach my $vmid (keys %$vmlist) {
1967 PVE
::LXC
::Config-
>lock_config($vmid, $updatefn, $vmid);
1974 # bash completion helper
1976 sub complete_os_templates
{
1977 my ($cmdname, $pname, $cvalue) = @_;
1979 my $cfg = PVE
::Storage
::config
();
1983 if ($cvalue =~ m/^([^:]+):/) {
1987 my $vtype = $cmdname eq 'restore' ?
'backup' : 'vztmpl';
1988 my $data = PVE
::Storage
::template_list
($cfg, $storeid, $vtype);
1991 foreach my $id (keys %$data) {
1992 foreach my $item (@{$data->{$id}}) {
1993 push @$res, $item->{volid
} if defined($item->{volid
});
2000 my $complete_ctid_full = sub {
2003 my $idlist = vmstatus
();
2005 my $active_hash = list_active_containers
();
2009 foreach my $id (keys %$idlist) {
2010 my $d = $idlist->{$id};
2011 if (defined($running)) {
2012 next if $d->{template
};
2013 next if $running && !$active_hash->{$id};
2014 next if !$running && $active_hash->{$id};
2023 return &$complete_ctid_full();
2026 sub complete_ctid_stopped
{
2027 return &$complete_ctid_full(0);
2030 sub complete_ctid_running
{
2031 return &$complete_ctid_full(1);
2041 my $lxc = $conf->{lxc
};
2042 foreach my $entry (@$lxc) {
2043 my ($key, $value) = @$entry;
2044 # FIXME: remove the 'id_map' variant when lxc-3.0 arrives
2045 next if $key ne 'lxc.idmap' && $key ne 'lxc.id_map';
2046 if ($value =~ /^([ug])\s+(\d+)\s+(\d+)\s+(\d+)\s*$/) {
2047 my ($type, $ct, $host, $length) = ($1, $2, $3, $4);
2048 push @$id_map, [$type, $ct, $host, $length];
2050 $rootuid = $host if $type eq 'u';
2051 $rootgid = $host if $type eq 'g';
2054 die "failed to parse idmap: $value\n";
2058 if (!@$id_map && $conf->{unprivileged
}) {
2059 # Should we read them from /etc/subuid?
2060 $id_map = [ ['u', '0', '100000', '65536'],
2061 ['g', '0', '100000', '65536'] ];
2062 $rootuid = $rootgid = 100000;
2065 return ($id_map, $rootuid, $rootgid);
2068 sub userns_command
{
2071 return ['lxc-usernsexec', (map { ('-m', join(':', @$_)) } @$id_map), '--'];
2077 my ($vmid, $conf, $skiplock) = @_;
2079 # apply pending changes while starting
2080 if (scalar(keys %{$conf->{pending
}})) {
2081 my $storecfg = PVE
::Storage
::config
();
2082 PVE
::LXC
::Config-
>vmconfig_apply_pending($vmid, $conf, $storecfg);
2083 $conf = PVE
::LXC
::Config-
>load_config($vmid); # update/reload
2086 update_lxc_config
($vmid, $conf);
2088 my $skiplock_flag_fn = "/run/lxc/skiplock-$vmid";
2091 open(my $fh, '>', $skiplock_flag_fn) || die "failed to open $skiplock_flag_fn for writing: $!\n";
2095 my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];
2097 PVE
::GuestHelpers
::exec_hookscript
($conf, $vmid, 'pre-start', 1);
2098 eval { PVE
::Tools
::run_command
($cmd); };
2100 unlink $skiplock_flag_fn;
2103 PVE
::GuestHelpers
::exec_hookscript
($conf, $vmid, 'post-start');
2108 # Helper to stop a container completely and make sure it has stopped completely.
2109 # This is necessary because we want the post-stop hook to have completed its
2110 # unmount-all step, but post-stop happens after lxc puts the container into the
2112 # $kill - if true it will always do an immediate hard-stop
2113 # $shutdown_timeout - the timeout to wait for a gracefull shutdown
2114 # $kill_after_timeout - if true, send a hardstop if shutdown timed out
2116 my ($vmid, $kill, $shutdown_timeout, $kill_after_timeout) = @_;
2118 # Open the container's command socket.
2119 my $path = "\0/var/lib/lxc/$vmid/command";
2120 my $sock = IO
::Socket
::UNIX-
>new(
2121 Type
=> SOCK_STREAM
(),
2125 return if $! == ECONNREFUSED
; # The container is not running
2126 die "failed to open container ${vmid}'s command socket: $!\n";
2129 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
2130 PVE
::GuestHelpers
::exec_hookscript
($conf, $vmid, 'pre-stop');
2132 # Stop the container:
2134 my $cmd = ['lxc-stop', '-n', $vmid];
2137 push @$cmd, '--kill'; # doesn't allow timeouts
2139 # lxc-stop uses a default timeout
2140 push @$cmd, '--nokill' if !$kill_after_timeout;
2142 if (defined($shutdown_timeout)) {
2143 push @$cmd, '--timeout', $shutdown_timeout;
2144 # Give run_command 5 extra seconds
2145 $shutdown_timeout += 5;
2149 eval { PVE
::Tools
::run_command
($cmd, timeout
=> $shutdown_timeout) };
2154 my $result = <$sock>;
2156 return if !defined $result; # monitor is gone and the ct has stopped.
2157 die "container did not stop\n";
2163 return PVE
::Tools
::run_fork
(sub {
2164 # Unshare the mount namespace
2165 die "failed to unshare mount namespace: $!\n"
2166 if !PVE
::Tools
::unshare
(PVE
::Tools
::CLONE_NEWNS
);
2167 PVE
::Tools
::run_command
(['mount', '--make-rslave', '/']);
2172 my $copy_volume = sub {
2173 my ($src_volid, $src, $dst_volid, $dest, $storage_cfg, $snapname, $bwlimit, $rootuid, $rootgid) = @_;
2175 my $src_mp = { volume
=> $src_volid, mp
=> '/', ro
=> 1 };
2176 $src_mp->{type
} = PVE
::LXC
::Config-
>classify_mountpoint($src_volid);
2178 my $dst_mp = { volume
=> $dst_volid, mp
=> '/', ro
=> 0 };
2179 $dst_mp->{type
} = PVE
::LXC
::Config-
>classify_mountpoint($dst_volid);
2185 mountpoint_mount
($src_mp, $src, $storage_cfg, $snapname, $rootuid, $rootgid);
2186 push @mounted, $src;
2188 mountpoint_mount
($dst_mp, $dest, $storage_cfg, undef, $rootuid, $rootgid);
2189 push @mounted, $dest;
2193 PVE
::Tools
::run_command
(['/usr/bin/rsync', '--stats', '-X', '-A', '--numeric-ids',
2194 '-aH', '--whole-file', '--sparse', '--one-file-system',
2195 "--bwlimit=$bwlimit", "$src/", $dest]);
2199 # Wait for rsync's children to release dest so that
2200 # consequent file operations (umount, remove) are possible
2201 while ((system {"fuser"} "fuser", "-s", $dest) == 0) {sleep 1};
2203 foreach my $mount (reverse @mounted) {
2204 eval { PVE
::Tools
::run_command
(['/bin/umount', $mount], errfunc
=> sub{})};
2205 warn "Can't umount $mount\n" if $@;
2208 # If this fails they're used as mount points in a concurrent operation
2209 # (which should not happen but there's also no real need to get rid of them).
2216 # Should not be called after unsharing the mount namespace!
2218 my ($mp, $vmid, $storage, $storage_cfg, $conf, $snapname, $bwlimit) = @_;
2220 die "cannot copy volumes of type $mp->{type}\n" if $mp->{type
} ne 'volume';
2221 File
::Path
::make_path
("/var/lib/lxc/$vmid");
2222 my $dest = "/var/lib/lxc/$vmid/.copy-volume-1";
2223 my $src = "/var/lib/lxc/$vmid/.copy-volume-2";
2225 # get id's for unprivileged container
2226 my (undef, $rootuid, $rootgid) = parse_id_maps
($conf);
2228 # Allocate the disk before unsharing in order to make sure zfs subvolumes
2229 # are visible in this namespace, otherwise the host only sees the empty
2230 # (not-mounted) directory.
2233 # Make sure $mp contains a correct size.
2234 $mp->{size
} = PVE
::Storage
::volume_size_info
($storage_cfg, $mp->{volume
});
2236 ($new_volid, $needs_chown) = alloc_disk
($storage_cfg, $vmid, $storage, $mp->{size
}/1024, $rootuid, $rootgid);
2238 PVE
::Storage
::activate_volumes
($storage_cfg, [$new_volid], undef);
2239 my $path = PVE
::Storage
::path
($storage_cfg, $new_volid, undef);
2240 chown($rootuid, $rootgid, $path);
2244 $copy_volume->($mp->{volume
}, $src, $new_volid, $dest, $storage_cfg, $snapname, $bwlimit, $rootuid, $rootgid);
2248 PVE
::Storage
::vdisk_free
($storage_cfg, $new_volid)
2249 if defined($new_volid);