1 package PVE
::LXC
::Config
;
6 use Fcntl
qw(O_RDONLY);
8 use PVE
::AbstractConfig
;
9 use PVE
::Cluster
qw(cfs_register_file);
10 use PVE
::DataCenterConfig
;
11 use PVE
::GuestHelpers
;
13 use PVE
::JSONSchema
qw(get_standard_option);
18 use base
qw(PVE::AbstractConfig);
21 FIFREEZE
=> 0xc0045877,
25 my $nodename = PVE
::INotify
::nodename
();
26 my $lock_handles = {};
27 my $lockdir = "/run/lock/lxc";
29 mkdir "/etc/pve/nodes/$nodename/lxc";
30 my $MAX_MOUNT_POINTS = 256;
31 my $MAX_UNUSED_DISKS = $MAX_MOUNT_POINTS;
33 # BEGIN implemented abstract methods from PVE::AbstractConfig
39 sub __config_max_unused_disks
{
42 return $MAX_UNUSED_DISKS;
45 sub config_file_lock
{
46 my ($class, $vmid) = @_;
48 return "$lockdir/pve-config-${vmid}.lock";
52 my ($class, $vmid, $node) = @_;
54 $node = $nodename if !$node;
55 return "nodes/$node/lxc/$vmid.conf";
58 sub mountpoint_backup_enabled
{
59 my ($class, $mp_key, $mountpoint) = @_;
64 if ($mp_key eq 'rootfs') {
67 } elsif ($mountpoint->{type
} ne 'volume') {
69 $reason = 'not a volume';
70 } elsif ($mountpoint->{backup
}) {
77 return wantarray ?
($enabled, $reason) : $enabled;
81 my ($class, $feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
85 if ($feature eq 'copy' || $feature eq 'clone') {
86 $opts = {'valid_target_formats' => ['raw', 'subvol']};
89 $class->foreach_volume($conf, sub {
90 my ($ms, $mountpoint) = @_;
92 return if $err; # skip further test
93 return if $backup_only && !$class->mountpoint_backup_enabled($ms, $mountpoint);
95 $err = 1 if !PVE
::Storage
::volume_has_feature
(
96 $storecfg, $feature, $mountpoint->{volume
}, $snapname, $running, $opts);
102 sub __snapshot_save_vmstate
{
103 my ($class, $vmid, $conf, $snapname, $storecfg) = @_;
104 die "implement me - snapshot_save_vmstate\n";
107 sub __snapshot_activate_storages
{
108 my ($class, $conf, $include_vmstate) = @_;
110 my $storecfg = PVE
::Storage
::config
();
111 my $opts = $include_vmstate ?
{ 'extra_keys' => ['vmstate'] } : {};
112 my $storage_hash = {};
114 $class->foreach_volume_full($conf, $opts, sub {
115 my ($vs, $mountpoint) = @_;
117 return if $mountpoint->{type
} ne 'volume';
119 my ($storeid) = PVE
::Storage
::parse_volume_id
($mountpoint->{volume
});
120 $storage_hash->{$storeid} = 1;
123 PVE
::Storage
::activate_storage_list
($storecfg, [ sort keys $storage_hash->%* ]);
126 sub __snapshot_check_running
{
127 my ($class, $vmid) = @_;
128 return PVE
::LXC
::check_running
($vmid);
131 sub __snapshot_check_freeze_needed
{
132 my ($class, $vmid, $config, $save_vmstate) = @_;
134 my $ret = $class->__snapshot_check_running($vmid);
138 # implements similar functionality to fsfreeze(8)
139 sub fsfreeze_mountpoint
{
140 my ($path, $thaw) = @_;
142 my $op = $thaw ?
'thaw' : 'freeze';
143 my $ioctl = $thaw ? FITHAW
: FIFREEZE
;
145 sysopen my $fd, $path, O_RDONLY
or die "failed to open $path: $!\n";
147 if (!ioctl($fd, $ioctl, 0)) {
151 die "fs$op '$path' failed - $ioctl_err\n" if defined $ioctl_err;
154 sub __snapshot_freeze
{
155 my ($class, $vmid, $unfreeze) = @_;
157 my $conf = $class->load_config($vmid);
158 my $storagecfg = PVE
::Storage
::config
();
161 $class->foreach_volume($conf, sub {
162 my ($ms, $mountpoint) = @_;
164 return if $mountpoint->{type
} ne 'volume';
166 if (PVE
::Storage
::volume_snapshot_needs_fsfreeze
($storagecfg, $mountpoint->{volume
})) {
167 push @$freeze_mps, $mountpoint->{mp
};
171 my $freeze_mountpoints = sub {
174 return if scalar(@$freeze_mps) == 0;
176 my $pid = PVE
::LXC
::find_lxc_pid
($vmid);
178 for my $mp (@$freeze_mps) {
179 eval{ fsfreeze_mountpoint
("/proc/${pid}/root/${mp}", $thaw); };
185 eval { PVE
::LXC
::thaw
($vmid); };
187 $freeze_mountpoints->(1);
189 PVE
::LXC
::freeze
($vmid);
190 PVE
::LXC
::sync_container_namespace
($vmid);
191 $freeze_mountpoints->(0);
195 sub __snapshot_create_vol_snapshot
{
196 my ($class, $vmid, $ms, $mountpoint, $snapname) = @_;
198 my $storecfg = PVE
::Storage
::config
();
200 return if $snapname eq 'vzdump' &&
201 !$class->mountpoint_backup_enabled($ms, $mountpoint);
203 PVE
::Storage
::volume_snapshot
($storecfg, $mountpoint->{volume
}, $snapname);
206 sub __snapshot_delete_remove_drive
{
207 my ($class, $snap, $remove_drive) = @_;
209 if ($remove_drive eq 'vmstate') {
210 die "implement me - saving vmstate\n";
212 my $value = $snap->{$remove_drive};
213 my $mountpoint = $class->parse_volume($remove_drive, $value, 1);
214 delete $snap->{$remove_drive};
216 $class->add_unused_volume($snap, $mountpoint->{volume
})
217 if $mountpoint && ($mountpoint->{type
} eq 'volume');
221 sub __snapshot_delete_vmstate_file
{
222 my ($class, $snap, $force) = @_;
224 die "implement me - saving vmstate\n";
227 sub __snapshot_delete_vol_snapshot
{
228 my ($class, $vmid, $ms, $mountpoint, $snapname, $unused) = @_;
230 return if $snapname eq 'vzdump' &&
231 !$class->mountpoint_backup_enabled($ms, $mountpoint);
233 my $storecfg = PVE
::Storage
::config
();
234 PVE
::Storage
::volume_snapshot_delete
($storecfg, $mountpoint->{volume
}, $snapname);
235 push @$unused, $mountpoint->{volume
};
238 sub __snapshot_rollback_vol_possible
{
239 my ($class, $mountpoint, $snapname, $blockers) = @_;
241 my $storecfg = PVE
::Storage
::config
();
242 PVE
::Storage
::volume_rollback_is_possible
(
244 $mountpoint->{volume
},
250 sub __snapshot_rollback_vol_rollback
{
251 my ($class, $mountpoint, $snapname) = @_;
253 my $storecfg = PVE
::Storage
::config
();
254 PVE
::Storage
::volume_snapshot_rollback
($storecfg, $mountpoint->{volume
}, $snapname);
257 sub __snapshot_rollback_vm_stop
{
258 my ($class, $vmid) = @_;
260 PVE
::LXC
::vm_stop
($vmid, 1)
261 if $class->__snapshot_check_running($vmid);
264 sub __snapshot_rollback_vm_start
{
265 my ($class, $vmid, $vmstate, $data);
267 die "implement me - save vmstate\n";
270 sub __snapshot_rollback_get_unused
{
271 my ($class, $conf, $snap) = @_;
275 $class->foreach_volume($conf, sub {
276 my ($vs, $volume) = @_;
278 return if $volume->{type
} ne 'volume';
281 my $volid = $volume->{volume
};
283 $class->foreach_volume($snap, sub {
284 my ($ms, $mountpoint) = @_;
287 return if ($mountpoint->{type
} ne 'volume');
290 if ($mountpoint->{volume
} && $mountpoint->{volume
} eq $volid);
293 push @$unused, $volid if !$found;
299 # END implemented abstract methods from PVE::AbstractConfig
301 # BEGIN JSON config code
303 cfs_register_file
('/lxc/', \
&parse_pct_config
, \
&write_pct_config
);
306 my $valid_mount_option_re = qr/(noatime|lazytime|nodev|nosuid|noexec)/;
308 sub is_valid_mount_option
{
310 return $option =~ $valid_mount_option_re;
317 format
=> 'pve-lxc-mp-string',
318 format_description
=> 'volume',
319 description
=> 'Volume, device or directory to mount into the container.',
323 format
=> 'disk-size',
324 format_description
=> 'DiskSize',
325 description
=> 'Volume size (read only value).',
330 description
=> 'Explicitly enable or disable ACL support.',
336 description
=> 'Extra mount options for rootfs/mps.',
337 format_description
=> 'opt[;opt...]',
338 pattern
=> qr/$valid_mount_option_re(;$valid_mount_option_re)*/,
342 description
=> 'Read-only mount point',
347 description
=> 'Enable user quotas inside the container (not supported with zfs subvolumes)',
352 description
=> 'Will include this volume to a storage replica job.',
358 description
=> 'Mark this non-volume mount point as available on multiple nodes (see \'nodes\')',
359 verbose_description
=> "Mark this non-volume mount point as available on all nodes.\n\nWARNING: This option does not share the mount point automatically, it assumes it is shared already!",
365 PVE
::JSONSchema
::register_standard_option
('pve-ct-rootfs', {
366 type
=> 'string', format
=> $rootfs_desc,
367 description
=> "Use volume as container root.",
371 # IP address with optional interface suffix for link local ipv6 addresses
372 PVE
::JSONSchema
::register_format
('lxc-ip-with-ll-iface', \
&verify_ip_with_ll_iface
);
373 sub verify_ip_with_ll_iface
{
374 my ($addr, $noerr) = @_;
376 if (my ($addr, $iface) = ($addr =~ /^(fe80:[^%]+)%(.*)$/)) {
377 if (PVE
::JSONSchema
::pve_verify_ip
($addr, 1)
378 && PVE
::JSONSchema
::pve_verify_iface
($iface, 1))
384 return PVE
::JSONSchema
::pve_verify_ip
($addr, $noerr);
388 my $features_desc = {
392 description
=> "Allow mounting file systems of specific types."
393 ." This should be a list of file system types as used with the mount command."
394 ." Note that this can have negative effects on the container's security."
395 ." With access to a loop device, mounting a file can circumvent the mknod"
396 ." permission of the devices cgroup, mounting an NFS file system can"
397 ." block the host's I/O completely and prevent it from rebooting, etc.",
398 format_description
=> 'fstype;fstype;...',
399 pattern
=> qr/[a-zA-Z0-9_; ]+/,
405 description
=> "Allow nesting."
406 ." Best used with unprivileged containers with additional id mapping."
407 ." Note that this will expose procfs and sysfs contents of the host"
414 description
=> "For unprivileged containers only: Allow the use of the keyctl() system call."
415 ." This is required to use docker inside a container."
416 ." By default unprivileged containers will see this system call as non-existent."
417 ." This is mostly a workaround for systemd-networkd, as it will treat it as a fatal"
418 ." error when some keyctl() operations are denied by the kernel due to lacking permissions."
419 ." Essentially, you can choose between running systemd-networkd or docker.",
425 description
=> "Allow using 'fuse' file systems in a container."
426 ." Note that interactions between fuse and the freezer cgroup can potentially cause I/O deadlocks.",
432 description
=> "Allow unprivileged containers to use mknod() to add certain device nodes."
433 ." This requires a kernel with seccomp trap to user space support (5.3 or newer)."
434 ." This is experimental.",
440 description
=> "Mount /sys in unprivileged containers as `rw` instead of `mixed`."
441 ." This can break networking under newer (>= v245) systemd-network use."
449 description
=> "Lock/unlock the container.",
450 enum
=> [qw(backup create destroyed disk fstrim migrate mounted rollback snapshot snapshot-delete)],
455 description
=> "Specifies whether a container will be started during system bootup.",
458 startup
=> get_standard_option
('pve-startup-order'),
462 description
=> "Enable/disable Template.",
468 enum
=> ['amd64', 'i386', 'arm64', 'armhf'],
469 description
=> "OS architecture type.",
475 enum
=> [qw(debian devuan ubuntu centos fedora opensuse archlinux alpine gentoo nixos unmanaged)],
476 description
=> "OS type. This is used to setup configuration inside the container, and corresponds to lxc setup scripts in /usr/share/lxc/config/<ostype>.common.conf. Value 'unmanaged' can be used to skip and OS specific setup.",
481 description
=> "Attach a console device (/dev/console) to the container.",
487 description
=> "Specify the number of tty available to the container",
495 description
=> "The number of cores assigned to the container. A container can use all available cores by default.",
502 description
=> "Limit of CPU usage.\n\nNOTE: If the computer has 2 CPUs, it has a total of '2' CPU time. Value '0' indicates no CPU limit.",
510 description
=> "CPU weight for a container, will be clamped to [1, 10000] in cgroup v2.",
511 verbose_description
=> "CPU weight for a container. Argument is used in the kernel fair "
512 ."scheduler. The larger the number is, the more CPU time this container gets. Number "
513 ."is relative to the weights of all the other running guests.",
516 default => 'cgroup v1: 1024, cgroup v2: 100',
521 description
=> "Amount of RAM for the container in MB.",
528 description
=> "Amount of SWAP for the container in MB.",
534 description
=> "Set a host name for the container.",
535 type
=> 'string', format
=> 'dns-name',
541 description
=> "Description for the Container. Shown in the web-interface CT's summary."
542 ." This is saved as comment inside the configuration file.",
543 maxLength
=> 1024 * 8,
547 type
=> 'string', format
=> 'dns-name-list',
548 description
=> "Sets DNS search domains for a container. Create will automatically use the setting from the host if you neither set searchdomain nor nameserver.",
552 type
=> 'string', format
=> 'lxc-ip-with-ll-iface-list',
553 description
=> "Sets DNS server IP address for a container. Create will automatically use the setting from the host if you neither set searchdomain nor nameserver.",
557 type
=> 'string', format
=> 'pve-ct-timezone',
558 description
=> "Time zone to use in the container. If option isn't set, then nothing will be done. Can be set to 'host' to match the host time zone, or an arbitrary time zone option from /usr/share/zoneinfo/zone.tab",
560 rootfs
=> get_standard_option
('pve-ct-rootfs'),
563 type
=> 'string', format
=> 'pve-configid',
565 description
=> "Parent snapshot name. This is used internally, and should not be modified.",
569 description
=> "Timestamp for snapshots.",
575 description
=> "Console mode. By default, the console command tries to open a connection to one of the available tty devices. By setting cmode to 'console' it tries to attach to /dev/console instead. If you set cmode to 'shell', it simply invokes a shell inside the container (no login).",
577 enum
=> ['shell', 'console', 'tty'],
583 description
=> "Sets the protection flag of the container. This will prevent the CT or CT's disk remove/update operation.",
589 description
=> "Makes the container run as unprivileged user. (Should not be modified manually.)",
595 format
=> $features_desc,
596 description
=> "Allow containers access to advanced features.",
601 format
=> 'pve-volume-id',
602 description
=> 'Script that will be exectued during various steps in the containers lifetime.',
605 type
=> 'string', format
=> 'pve-tag-list',
606 description
=> 'Tags of the Container. This is only meta information.',
612 description
=> "Try to be more verbose. For now this only enables debug log-level on start.",
617 my $valid_lxc_conf_keys = {
618 'lxc.apparmor.profile' => 1,
619 'lxc.apparmor.allow_incomplete' => 1,
620 'lxc.apparmor.allow_nesting' => 1,
621 'lxc.apparmor.raw' => 1,
622 'lxc.selinux.context' => 1,
626 'lxc.signal.halt' => 1,
627 'lxc.signal.reboot' => 1,
628 'lxc.signal.stop' => 1,
631 'lxc.console.logfile' => 1,
632 'lxc.console.path' => 1,
634 'lxc.devtty.dir' => 1,
635 'lxc.hook.autodev' => 1,
638 'lxc.mount.fstab' => 1,
639 'lxc.mount.entry' => 1,
640 'lxc.mount.auto' => 1,
641 'lxc.rootfs.path' => 'lxc.rootfs.path is auto generated from rootfs',
642 'lxc.rootfs.mount' => 1,
643 'lxc.rootfs.options' => 'lxc.rootfs.options is not supported' .
644 ', please use mount point options in the "rootfs" key',
650 'lxc.seccomp.profile' => 1,
651 'lxc.seccomp.notify.proxy' => 1,
652 'lxc.seccomp.notify.cookie' => 1,
654 'lxc.hook.pre-start' => 1,
655 'lxc.hook.pre-mount' => 1,
656 'lxc.hook.mount' => 1,
657 'lxc.hook.start' => 1,
658 'lxc.hook.stop' => 1,
659 'lxc.hook.post-stop' => 1,
660 'lxc.hook.clone' => 1,
661 'lxc.hook.destroy' => 1,
662 'lxc.hook.version' => 1,
663 'lxc.log.level' => 1,
665 'lxc.start.auto' => 1,
666 'lxc.start.delay' => 1,
667 'lxc.start.order' => 1,
669 'lxc.environment' => 1,
671 # All these are namespaced via CLONE_NEWIPC (see namespaces(7)).
672 'lxc.sysctl.fs.mqueue' => 1,
673 'lxc.sysctl.kernel.msgmax' => 1,
674 'lxc.sysctl.kernel.msgmnb' => 1,
675 'lxc.sysctl.kernel.msgmni' => 1,
676 'lxc.sysctl.kernel.sem' => 1,
677 'lxc.sysctl.kernel.shmall' => 1,
678 'lxc.sysctl.kernel.shmmax' => 1,
679 'lxc.sysctl.kernel.shmmni' => 1,
680 'lxc.sysctl.kernel.shm_rmid_forced' => 1,
683 my $deprecated_lxc_conf_keys = {
684 # Deprecated (removed with lxc 3.0):
685 'lxc.aa_profile' => 'lxc.apparmor.profile',
686 'lxc.aa_allow_incomplete' => 'lxc.apparmor.allow_incomplete',
687 'lxc.console' => 'lxc.console.path',
688 'lxc.devttydir' => 'lxc.tty.dir',
689 'lxc.haltsignal' => 'lxc.signal.halt',
690 'lxc.rebootsignal' => 'lxc.signal.reboot',
691 'lxc.stopsignal' => 'lxc.signal.stop',
692 'lxc.id_map' => 'lxc.idmap',
693 'lxc.init_cmd' => 'lxc.init.cmd',
694 'lxc.loglevel' => 'lxc.log.level',
695 'lxc.logfile' => 'lxc.log.file',
696 'lxc.mount' => 'lxc.mount.fstab',
697 'lxc.network.type' => 'lxc.net.INDEX.type',
698 'lxc.network.flags' => 'lxc.net.INDEX.flags',
699 'lxc.network.link' => 'lxc.net.INDEX.link',
700 'lxc.network.mtu' => 'lxc.net.INDEX.mtu',
701 'lxc.network.name' => 'lxc.net.INDEX.name',
702 'lxc.network.hwaddr' => 'lxc.net.INDEX.hwaddr',
703 'lxc.network.ipv4' => 'lxc.net.INDEX.ipv4.address',
704 'lxc.network.ipv4.gateway' => 'lxc.net.INDEX.ipv4.gateway',
705 'lxc.network.ipv6' => 'lxc.net.INDEX.ipv6.address',
706 'lxc.network.ipv6.gateway' => 'lxc.net.INDEX.ipv6.gateway',
707 'lxc.network.script.up' => 'lxc.net.INDEX.script.up',
708 'lxc.network.script.down' => 'lxc.net.INDEX.script.down',
709 'lxc.pts' => 'lxc.pty.max',
710 'lxc.se_context' => 'lxc.selinux.context',
711 'lxc.seccomp' => 'lxc.seccomp.profile',
712 'lxc.tty' => 'lxc.tty.max',
713 'lxc.utsname' => 'lxc.uts.name',
716 sub is_valid_lxc_conf_key
{
717 my ($vmid, $key) = @_;
718 if ($key =~ /^lxc\.limit\./) {
719 warn "vm $vmid - $key: lxc.limit.* was renamed to lxc.prlimit.*\n";
722 if (defined(my $new_name = $deprecated_lxc_conf_keys->{$key})) {
723 warn "vm $vmid - $key is deprecated and was renamed to $new_name\n";
726 my $validity = $valid_lxc_conf_keys->{$key};
727 return $validity if defined($validity);
728 return 1 if $key =~ /^lxc\.cgroup2?\./ # allow all cgroup values
729 || $key =~ /^lxc\.prlimit\./ # allow all prlimits
730 || $key =~ /^lxc\.net\./; # allow custom network definitions
734 our $netconf_desc = {
738 description
=> "Network interface type.",
743 format_description
=> 'string',
744 description
=> 'Name of the network device as seen from inside the container. (lxc.network.name)',
745 pattern
=> '[-_.\w\d]+',
749 format_description
=> 'bridge',
750 description
=> 'Bridge to attach the network device to.',
751 pattern
=> '[-_.\w\d]+',
754 hwaddr
=> get_standard_option
('mac-addr', {
755 description
=> 'The interface MAC address. This is dynamically allocated by default, but you can set that statically if needed, for example to always have the same link-local IPv6 address. (lxc.network.hwaddr)',
759 description
=> 'Maximum transfer unit of the interface. (lxc.network.mtu)',
760 minimum
=> 64, # minimum ethernet frame is 64 bytes
766 format
=> 'pve-ipv4-config',
767 format_description
=> '(IPv4/CIDR|dhcp|manual)',
768 description
=> 'IPv4 address in CIDR format.',
774 format_description
=> 'GatewayIPv4',
775 description
=> 'Default gateway for IPv4 traffic.',
780 format
=> 'pve-ipv6-config',
781 format_description
=> '(IPv6/CIDR|auto|dhcp|manual)',
782 description
=> 'IPv6 address in CIDR format.',
788 format_description
=> 'GatewayIPv6',
789 description
=> 'Default gateway for IPv6 traffic.',
794 description
=> "Controls whether this interface's firewall rules should be used.",
801 description
=> "VLAN tag for this interface.",
806 pattern
=> qr/\d+(?:;\d+)*/,
807 format_description
=> 'vlanid[;vlanid...]',
808 description
=> "VLAN ids to pass through the interface",
813 format_description
=> 'mbps',
814 description
=> "Apply rate limiting to the interface",
818 PVE
::JSONSchema
::register_format
('pve-lxc-network', $netconf_desc);
820 my $MAX_LXC_NETWORKS = 32;
821 for (my $i = 0; $i < $MAX_LXC_NETWORKS; $i++) {
822 $confdesc->{"net$i"} = {
824 type
=> 'string', format
=> $netconf_desc,
825 description
=> "Specifies network interfaces for the container.",
829 PVE
::JSONSchema
::register_format
('pve-ct-timezone', \
&verify_ct_timezone
);
830 sub verify_ct_timezone
{
831 my ($timezone, $noerr) = @_;
833 return if $timezone eq 'host'; # using host settings
835 PVE
::JSONSchema
::pve_verify_timezone
($timezone);
838 PVE
::JSONSchema
::register_format
('pve-lxc-mp-string', \
&verify_lxc_mp_string
);
839 sub verify_lxc_mp_string
{
840 my ($mp, $noerr) = @_;
844 # /. or /.. at the end
845 # ../ at the beginning
847 if($mp =~ m
@/\.\
.?
/@ ||
850 return undef if $noerr;
851 die "$mp contains illegal character sequences\n";
860 description
=> 'Whether to include the mount point in backups.',
861 verbose_description
=> 'Whether to include the mount point in backups '.
862 '(only used for volume mount points).',
867 format
=> 'pve-lxc-mp-string',
868 format_description
=> 'Path',
869 description
=> 'Path to the mount point as seen from inside the container '.
870 '(must not contain symlinks).',
871 verbose_description
=> "Path to the mount point as seen from inside the container.\n\n".
872 "NOTE: Must not contain any symlinks for security reasons."
875 PVE
::JSONSchema
::register_format
('pve-ct-mountpoint', $mp_desc);
881 format
=> 'pve-volume-id',
882 format_description
=> 'volume',
883 description
=> 'The volume that is not used currently.',
887 for (my $i = 0; $i < $MAX_MOUNT_POINTS; $i++) {
888 $confdesc->{"mp$i"} = {
890 type
=> 'string', format
=> $mp_desc,
891 description
=> "Use volume as container mount point. Use the special " .
892 "syntax STORAGE_ID:SIZE_IN_GiB to allocate a new volume.",
897 for (my $i = 0; $i < $MAX_UNUSED_DISKS; $i++) {
898 $confdesc->{"unused$i"} = {
900 type
=> 'string', format
=> $unused_desc,
901 description
=> "Reference to unused volumes. This is used internally, and should not be modified manually.",
905 sub parse_pct_config
{
906 my ($filename, $raw, $strict) = @_;
908 return undef if !defined($raw);
911 digest
=> Digest
::SHA
::sha1_hex
($raw),
916 my $handle_error = sub {
926 $filename =~ m
|/lxc/(\d
+).conf
$|
927 || die "got strange filename '$filename'";
935 my @lines = split(/\n/, $raw);
936 foreach my $line (@lines) {
937 next if $line =~ m/^\s*$/;
939 if ($line =~ m/^\[pve:pending\]\s*$/i) {
940 $section = 'pending';
941 $conf->{description
} = $descr if $descr;
943 $conf = $res->{$section} = {};
945 } elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
947 $conf->{description
} = $descr if $descr;
949 $conf = $res->{snapshots
}->{$section} = {};
953 if ($line =~ m/^\#(.*)$/) {
954 $descr .= PVE
::Tools
::decode_text
($1) . "\n";
958 if ($line =~ m/^(lxc\.[a-z0-9_\-\.]+)(:|\s*=)\s*(.*?)\s*$/) {
961 my $validity = is_valid_lxc_conf_key
($vmid, $key);
962 if ($validity eq 1) {
963 push @{$conf->{lxc
}}, [$key, $value];
964 } elsif (my $errmsg = $validity) {
965 $handle_error->("vm $vmid - $key: $errmsg\n");
967 $handle_error->("vm $vmid - unable to parse config: $line\n");
969 } elsif ($line =~ m/^(description):\s*(.*\S)\s*$/) {
970 $descr .= PVE
::Tools
::decode_text
($2);
971 } elsif ($line =~ m/snapstate:\s*(prepare|delete)\s*$/) {
972 $conf->{snapstate
} = $1;
973 } elsif ($line =~ m/^delete:\s*(.*\S)\s*$/) {
975 if ($section eq 'pending') {
976 $conf->{delete} = $value;
978 $handle_error->("vm $vmid - property 'delete' is only allowed in [pve:pending]\n");
980 } elsif ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) {
983 eval { $value = PVE
::LXC
::Config-
>check_type($key, $value); };
984 $handle_error->("vm $vmid - unable to parse value of '$key' - $@") if $@;
985 $conf->{$key} = $value;
987 $handle_error->("vm $vmid - unable to parse config: $line\n");
991 $conf->{description
} = $descr if $descr;
993 delete $res->{snapstate
}; # just to be sure
998 sub write_pct_config
{
999 my ($filename, $conf) = @_;
1001 delete $conf->{snapstate
}; # just to be sure
1003 my $volidlist = PVE
::LXC
::Config-
>get_vm_volumes($conf);
1004 my $used_volids = {};
1005 foreach my $vid (@$volidlist) {
1006 $used_volids->{$vid} = 1;
1009 # remove 'unusedX' settings if the volume is still used
1010 foreach my $key (keys %$conf) {
1011 my $value = $conf->{$key};
1012 if ($key =~ m/^unused/ && $used_volids->{$value}) {
1013 delete $conf->{$key};
1017 my $generate_raw_config = sub {
1022 # add description as comment to top of file
1023 my $descr = $conf->{description
} || '';
1024 foreach my $cl (split(/\n/, $descr)) {
1025 $raw .= '#' . PVE
::Tools
::encode_text
($cl) . "\n";
1028 foreach my $key (sort keys %$conf) {
1029 next if $key eq 'digest' || $key eq 'description' ||
1030 $key eq 'pending' || $key eq 'snapshots' ||
1031 $key eq 'snapname' || $key eq 'lxc';
1032 my $value = $conf->{$key};
1033 die "detected invalid newline inside property '$key'\n"
1035 $raw .= "$key: $value\n";
1038 if (my $lxcconf = $conf->{lxc
}) {
1039 foreach my $entry (@$lxcconf) {
1040 my ($k, $v) = @$entry;
1048 my $raw = &$generate_raw_config($conf);
1050 if (scalar(keys %{$conf->{pending
}})){
1051 $raw .= "\n[pve:pending]\n";
1052 $raw .= &$generate_raw_config($conf->{pending
});
1055 foreach my $snapname (sort keys %{$conf->{snapshots
}}) {
1056 $raw .= "\n[$snapname]\n";
1057 $raw .= &$generate_raw_config($conf->{snapshots
}->{$snapname});
1063 sub update_pct_config
{
1064 my ($class, $vmid, $conf, $running, $param, $delete, $revert) = @_;
1066 my $storage_cfg = PVE
::Storage
::config
();
1068 foreach my $opt (@$revert) {
1069 delete $conf->{pending
}->{$opt};
1070 $class->remove_from_pending_delete($conf, $opt); # also remove from deletion queue
1073 # write updates to pending section
1074 my $modified = {}; # record modified options
1076 foreach my $opt (@$delete) {
1077 if (!defined($conf->{$opt}) && !defined($conf->{pending
}->{$opt})) {
1078 warn "cannot delete '$opt' - not set in current configuration!\n";
1081 $modified->{$opt} = 1;
1082 if ($opt eq 'memory' || $opt eq 'rootfs' || $opt eq 'ostype') {
1083 die "unable to delete required option '$opt'\n";
1084 } elsif ($opt =~ m/^unused(\d+)$/) {
1085 $class->check_protection($conf, "can't remove CT $vmid drive '$opt'");
1086 } elsif ($opt =~ m/^mp(\d+)$/) {
1087 $class->check_protection($conf, "can't remove CT $vmid drive '$opt'");
1088 } elsif ($opt eq 'unprivileged') {
1089 die "unable to delete read-only option: '$opt'\n";
1091 $class->add_to_pending_delete($conf, $opt);
1094 my $check_content_type = sub {
1096 my $sid = PVE
::Storage
::parse_volume_id
($mp->{volume
});
1097 my $storage_config = PVE
::Storage
::storage_config
($storage_cfg, $sid);
1098 die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
1099 if !$storage_config->{content
}->{rootdir
};
1102 foreach my $opt (sort keys %$param) { # add/change
1103 $modified->{$opt} = 1;
1104 my $value = $param->{$opt};
1105 if ($opt =~ m/^mp(\d+)$/ || $opt eq 'rootfs') {
1106 $class->check_protection($conf, "can't update CT $vmid drive '$opt'");
1107 my $mp = $class->parse_volume($opt, $value);
1108 $check_content_type->($mp) if ($mp->{type
} eq 'volume');
1109 } elsif ($opt eq 'hookscript') {
1110 PVE
::GuestHelpers
::check_hookscript
($value);
1111 } elsif ($opt eq 'nameserver') {
1112 $value = PVE
::LXC
::verify_nameserver_list
($value);
1113 } elsif ($opt eq 'searchdomain') {
1114 $value = PVE
::LXC
::verify_searchdomain_list
($value);
1115 } elsif ($opt eq 'unprivileged') {
1116 die "unable to modify read-only option: '$opt'\n";
1117 } elsif ($opt =~ m/^net(\d+)$/) {
1118 my $res = PVE
::JSONSchema
::parse_property_string
($netconf_desc, $value);
1120 if (my $mtu = $res->{mtu
}) {
1121 my $bridge_mtu = PVE
::Network
::read_bridge_mtu
($res->{bridge
});
1122 die "$opt: MTU size '$mtu' is bigger than bridge MTU '$bridge_mtu'\n"
1123 if ($mtu > $bridge_mtu);
1126 $conf->{pending
}->{$opt} = $value;
1127 $class->remove_from_pending_delete($conf, $opt);
1130 my $changes = $class->cleanup_pending($conf);
1134 $class->vmconfig_hotplug_pending($vmid, $conf, $storage_cfg, $modified, $errors);
1136 $class->vmconfig_apply_pending($vmid, $conf, $storage_cfg, $modified, $errors);
1143 my ($class, $key, $value) = @_;
1145 die "unknown setting '$key'\n" if !$confdesc->{$key};
1147 my $type = $confdesc->{$key}->{type
};
1149 if (!defined($value)) {
1150 die "got undefined value\n";
1153 if ($value =~ m/[\n\r]/) {
1154 die "property contains a line feed\n";
1157 if ($type eq 'boolean') {
1158 return 1 if ($value eq '1') || ($value =~ m/^(on|yes|true)$/i);
1159 return 0 if ($value eq '0') || ($value =~ m/^(off|no|false)$/i);
1160 die "type check ('boolean') failed - got '$value'\n";
1161 } elsif ($type eq 'integer') {
1162 return int($1) if $value =~ m/^(\d+)$/;
1163 die "type check ('integer') failed - got '$value'\n";
1164 } elsif ($type eq 'number') {
1165 return $value if $value =~ m/^(\d+)(\.\d+)?$/;
1166 die "type check ('number') failed - got '$value'\n";
1167 } elsif ($type eq 'string') {
1168 if (my $fmt = $confdesc->{$key}->{format
}) {
1169 PVE
::JSONSchema
::check_format
($fmt, $value);
1174 die "internal error"
1179 # add JSON properties for create and set function
1180 sub json_config_properties
{
1181 my ($class, $prop) = @_;
1183 foreach my $opt (keys %$confdesc) {
1184 next if $opt eq 'parent' || $opt eq 'snaptime';
1185 next if $prop->{$opt};
1186 $prop->{$opt} = $confdesc->{$opt};
1192 my $parse_ct_mountpoint_full = sub {
1193 my ($class, $desc, $data, $noerr) = @_;
1198 eval { $res = PVE
::JSONSchema
::parse_property_string
($desc, $data) };
1200 return undef if $noerr;
1204 if (defined(my $size = $res->{size
})) {
1205 $size = PVE
::JSONSchema
::parse_size
($size);
1206 if (!defined($size)) {
1207 return undef if $noerr;
1208 die "invalid size: $size\n";
1210 $res->{size
} = $size;
1213 $res->{type
} = $class->classify_mountpoint($res->{volume
});
1218 sub print_ct_mountpoint
{
1219 my ($class, $info, $nomp) = @_;
1220 my $skip = [ 'type' ];
1221 push @$skip, 'mp' if $nomp;
1222 return PVE
::JSONSchema
::print_property_string
($info, $mp_desc, $skip);
1225 sub print_ct_unused
{
1226 my ($class, $info) = @_;
1228 my $skip = [ 'type' ];
1229 return PVE
::JSONSchema
::print_property_string
($info, $unused_desc, $skip);
1233 my ($class, $key, $volume_string, $noerr) = @_;
1235 if ($key eq 'rootfs') {
1236 my $res = $parse_ct_mountpoint_full->($class, $rootfs_desc, $volume_string, $noerr);
1237 $res->{mp
} = '/' if defined($res);
1239 } elsif ($key =~ m/^mp\d+$/) {
1240 return $parse_ct_mountpoint_full->($class, $mp_desc, $volume_string, $noerr);
1241 } elsif ($key =~ m/^unused\d+$/) {
1242 return $parse_ct_mountpoint_full->($class, $unused_desc, $volume_string, $noerr);
1245 die "parse_volume - unknown type: $key\n" if !$noerr;
1251 my ($class, $key, $volume) = @_;
1253 return $class->print_ct_unused($volume) if $key =~ m/^unused(\d+)$/;
1255 return $class->print_ct_mountpoint($volume, $key eq 'rootfs');
1264 sub print_lxc_network
{
1265 my ($class, $net) = @_;
1266 return PVE
::JSONSchema
::print_property_string
($net, $netconf_desc);
1269 sub parse_lxc_network
{
1270 my ($class, $data) = @_;
1272 return {} if !$data;
1274 my $res = PVE
::JSONSchema
::parse_property_string
($netconf_desc, $data);
1276 $res->{type
} = 'veth';
1277 if (!$res->{hwaddr
}) {
1278 my $dc = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
1279 $res->{hwaddr
} = PVE
::Tools
::random_ether_addr
($dc->{mac_prefix
});
1285 sub parse_features
{
1286 my ($class, $data) = @_;
1287 return {} if !$data;
1288 return PVE
::JSONSchema
::parse_property_string
($features_desc, $data);
1292 my ($class, $name) = @_;
1294 return defined($confdesc->{$name});
1296 # END JSON config code
1298 my $LXC_FASTPLUG_OPTIONS= {
1310 sub vmconfig_hotplug_pending
{
1311 my ($class, $vmid, $conf, $storecfg, $selection, $errors) = @_;
1313 my $pid = PVE
::LXC
::find_lxc_pid
($vmid);
1314 my $rootdir = "/proc/$pid/root";
1316 my $add_hotplug_error = sub {
1317 my ($opt, $msg) = @_;
1318 $errors->{$opt} = "unable to hotplug $opt: $msg";
1321 foreach my $opt (sort keys %{$conf->{pending
}}) { # add/change
1322 next if $selection && !$selection->{$opt};
1323 if ($LXC_FASTPLUG_OPTIONS->{$opt}) {
1324 $conf->{$opt} = delete $conf->{pending
}->{$opt};
1328 my $cgroup = PVE
::LXC
::CGroup-
>new($vmid);
1330 # There's no separate swap size to configure, there's memory and "total"
1331 # memory (iow. memory+swap). This means we have to change them together.
1332 my $hotplug_memory_done;
1333 my $hotplug_memory = sub {
1334 my ($wanted_memory, $wanted_swap) = @_;
1336 $wanted_memory = int($wanted_memory * 1024 * 1024) if defined($wanted_memory);
1337 $wanted_swap = int($wanted_swap * 1024 * 1024) if defined($wanted_swap);
1338 $cgroup->change_memory_limit($wanted_memory, $wanted_swap);
1340 $hotplug_memory_done = 1;
1343 my $pending_delete_hash = $class->parse_pending_delete($conf->{pending
}->{delete});
1344 # FIXME: $force deletion is not implemented for CTs
1345 foreach my $opt (sort keys %$pending_delete_hash) {
1346 next if $selection && !$selection->{$opt};
1348 if ($LXC_FASTPLUG_OPTIONS->{$opt}) {
1350 } elsif ($opt =~ m/^unused(\d+)$/) {
1351 PVE
::LXC
::delete_mountpoint_volume
($storecfg, $vmid, $conf->{$opt})
1352 if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
1353 } elsif ($opt eq 'swap') {
1354 $hotplug_memory->(undef, 0);
1355 } elsif ($opt eq 'cpulimit') {
1356 $cgroup->change_cpu_quota(undef, undef); # reset, cgroup module can better decide values
1357 } elsif ($opt eq 'cpuunits') {
1358 $cgroup->change_cpu_shares(undef);
1359 } elsif ($opt =~ m/^net(\d)$/) {
1361 PVE
::Network
::veth_delete
("veth${vmid}i$netid");
1363 die "skip\n"; # skip non-hotpluggable opts
1367 $add_hotplug_error->($opt, $err) if $err ne "skip\n";
1369 delete $conf->{$opt};
1370 $class->remove_from_pending_delete($conf, $opt);
1374 foreach my $opt (sort keys %{$conf->{pending
}}) {
1375 next if $opt eq 'delete'; # just to be sure
1376 next if $selection && !$selection->{$opt};
1377 my $value = $conf->{pending
}->{$opt};
1379 if ($opt eq 'cpulimit') {
1380 my $quota = 100000 * $value;
1381 $cgroup->change_cpu_quota(int(100000 * $value), 100000);
1382 } elsif ($opt eq 'cpuunits') {
1383 $cgroup->change_cpu_shares($value);
1384 } elsif ($opt =~ m/^net(\d+)$/) {
1386 my $net = $class->parse_lxc_network($value);
1387 $value = $class->print_lxc_network($net);
1388 PVE
::LXC
::update_net
($vmid, $conf, $opt, $net, $netid, $rootdir);
1389 } elsif ($opt eq 'memory' || $opt eq 'swap') {
1390 if (!$hotplug_memory_done) { # don't call twice if both opts are passed
1391 $hotplug_memory->($conf->{pending
}->{memory
}, $conf->{pending
}->{swap
});
1393 } elsif ($opt =~ m/^mp(\d+)$/) {
1394 if (!PVE
::LXC
::Tools
::can_use_new_mount_api
()) {
1398 if (exists($conf->{$opt})) {
1399 die "skip\n"; # don't try to hotplug over existing mp
1402 $class->apply_pending_mountpoint($vmid, $conf, $opt, $storecfg, 1);
1403 # apply_pending_mountpoint modifies the value if it creates a new disk
1404 $value = $conf->{pending
}->{$opt};
1406 die "skip\n"; # skip non-hotpluggable
1410 $add_hotplug_error->($opt, $err) if $err ne "skip\n";
1412 $conf->{$opt} = $value;
1413 delete $conf->{pending
}->{$opt};
1418 sub vmconfig_apply_pending
{
1419 my ($class, $vmid, $conf, $storecfg, $selection, $errors) = @_;
1421 my $add_apply_error = sub {
1422 my ($opt, $msg) = @_;
1423 my $err_msg = "unable to apply pending change $opt : $msg";
1424 $errors->{$opt} = $err_msg;
1428 my $pending_delete_hash = $class->parse_pending_delete($conf->{pending
}->{delete});
1429 # FIXME: $force deletion is not implemented for CTs
1430 foreach my $opt (sort keys %$pending_delete_hash) {
1431 next if $selection && !$selection->{$opt};
1433 if ($opt =~ m/^mp(\d+)$/) {
1434 my $mp = $class->parse_volume($opt, $conf->{$opt});
1435 if ($mp->{type
} eq 'volume') {
1436 $class->add_unused_volume($conf, $mp->{volume
})
1437 if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
1439 } elsif ($opt =~ m/^unused(\d+)$/) {
1440 PVE
::LXC
::delete_mountpoint_volume
($storecfg, $vmid, $conf->{$opt})
1441 if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
1445 $add_apply_error->($opt, $err);
1447 delete $conf->{$opt};
1448 $class->remove_from_pending_delete($conf, $opt);
1452 $class->cleanup_pending($conf);
1454 foreach my $opt (sort keys %{$conf->{pending
}}) { # add/change
1455 next if $opt eq 'delete'; # just to be sure
1456 next if $selection && !$selection->{$opt};
1458 if ($opt =~ m/^mp(\d+)$/) {
1459 $class->apply_pending_mountpoint($vmid, $conf, $opt, $storecfg, 0);
1460 } elsif ($opt =~ m/^net(\d+)$/) {
1462 my $net = $class->parse_lxc_network($conf->{pending
}->{$opt});
1463 $conf->{pending
}->{$opt} = $class->print_lxc_network($net);
1467 $add_apply_error->($opt, $err);
1469 $conf->{$opt} = delete $conf->{pending
}->{$opt};
1474 my $rescan_volume = sub {
1475 my ($storecfg, $mp) = @_;
1477 $mp->{size
} = PVE
::Storage
::volume_size_info
($storecfg, $mp->{volume
}, 5);
1479 warn "Could not rescan volume size - $@\n" if $@;
1482 sub apply_pending_mountpoint
{
1483 my ($class, $vmid, $conf, $opt, $storecfg, $running) = @_;
1485 my $mp = $class->parse_volume($opt, $conf->{pending
}->{$opt});
1486 my $old = $conf->{$opt};
1487 if ($mp->{type
} eq 'volume' && $mp->{volume
} =~ $PVE::LXC
::NEW_DISK_RE
) {
1488 my $original_value = $conf->{pending
}->{$opt};
1489 my $vollist = PVE
::LXC
::create_disks
(
1492 { $opt => $original_value },
1497 # Re-parse mount point:
1498 my $mp = $class->parse_volume($opt, $conf->{pending
}->{$opt});
1500 PVE
::LXC
::mountpoint_hotplug
($vmid, $conf, $opt, $mp, $storecfg);
1504 PVE
::LXC
::destroy_disks
($storecfg, $vollist);
1505 # The pending-changes code collects errors but keeps on looping through further
1506 # pending changes, so unroll the change in $conf as well if destroy_disks()
1508 $conf->{pending
}->{$opt} = $original_value;
1513 die "skip\n" if $running && defined($old); # TODO: "changing" mount points?
1514 $rescan_volume->($storecfg, $mp) if $mp->{type
} eq 'volume';
1516 PVE
::LXC
::mountpoint_hotplug
($vmid, $conf, $opt, $mp, $storecfg);
1518 $conf->{pending
}->{$opt} = $class->print_ct_mountpoint($mp);
1521 if (defined($old)) {
1522 my $mp = $class->parse_volume($opt, $old);
1523 if ($mp->{type
} eq 'volume') {
1524 $class->add_unused_volume($conf, $mp->{volume
})
1525 if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
1530 sub classify_mountpoint
{
1531 my ($class, $vol) = @_;
1532 if ($vol =~ m!^/!) {
1533 return 'device' if $vol =~ m!^/dev/!;
1539 my $__is_volume_in_use = sub {
1540 my ($class, $config, $volid) = @_;
1543 $class->foreach_volume($config, sub {
1544 my ($ms, $mountpoint) = @_;
1546 $used = $mountpoint->{type
} eq 'volume' && $mountpoint->{volume
} eq $volid;
1552 sub is_volume_in_use_by_snapshots
{
1553 my ($class, $config, $volid) = @_;
1555 if (my $snapshots = $config->{snapshots
}) {
1556 foreach my $snap (keys %$snapshots) {
1557 return 1 if $__is_volume_in_use->($class, $snapshots->{$snap}, $volid);
1564 sub is_volume_in_use
{
1565 my ($class, $config, $volid, $include_snapshots, $include_pending) = @_;
1566 return 1 if $__is_volume_in_use->($class, $config, $volid);
1567 return 1 if $include_snapshots && $class->is_volume_in_use_by_snapshots($config, $volid);
1568 return 1 if $include_pending && $__is_volume_in_use->($class, $config->{pending
}, $volid);
1572 sub has_dev_console
{
1573 my ($class, $conf) = @_;
1575 return !(defined($conf->{console
}) && !$conf->{console
});
1579 my ($class, $conf, $keyname) = @_;
1581 if (my $lxcconf = $conf->{lxc
}) {
1582 foreach my $entry (@$lxcconf) {
1583 my ($key, undef) = @$entry;
1584 return 1 if $key eq $keyname;
1592 my ($class, $conf) = @_;
1594 return $conf->{tty
} // $confdesc->{tty
}->{default};
1598 my ($class, $conf) = @_;
1600 return $conf->{cmode
} // $confdesc->{cmode
}->{default};
1603 sub valid_volume_keys
{
1604 my ($class, $reverse) = @_;
1606 my @names = ('rootfs');
1608 for (my $i = 0; $i < $MAX_MOUNT_POINTS; $i++) {
1609 push @names, "mp$i";
1612 return $reverse ?
reverse @names : @names;
1615 sub valid_volume_keys_with_unused
{
1616 my ($class, $reverse) = @_;
1617 my @names = $class->valid_volume_keys();
1618 for (my $i = 0; $i < $MAX_UNUSED_DISKS; $i++) {
1619 push @names, "unused$i";
1621 return $reverse ?
reverse @names : @names;
1624 sub get_vm_volumes
{
1625 my ($class, $conf, $excludes) = @_;
1629 $class->foreach_volume($conf, sub {
1630 my ($ms, $mountpoint) = @_;
1632 return if $excludes && $ms eq $excludes;
1634 my $volid = $mountpoint->{volume
};
1635 return if !$volid || $mountpoint->{type
} ne 'volume';
1637 my ($sid, $volname) = PVE
::Storage
::parse_volume_id
($volid, 1);
1640 push @$vollist, $volid;
1646 sub get_replicatable_volumes
{
1647 my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
1651 my $test_volid = sub {
1652 my ($volid, $mountpoint) = @_;
1656 my $mptype = $mountpoint->{type
};
1657 my $replicate = $mountpoint->{replicate
} // 1;
1659 if ($mptype ne 'volume') {
1660 # skip bindmounts if replicate = 0 even for cleanup,
1661 # since bind mounts could not have been replicated ever
1662 return if !$replicate;
1663 die "unable to replicate mountpoint type '$mptype'\n";
1666 my ($storeid, $volname) = PVE
::Storage
::parse_volume_id
($volid, $noerr);
1667 return if !$storeid;
1669 my $scfg = PVE
::Storage
::storage_config
($storecfg, $storeid);
1670 return if $scfg->{shared
};
1672 my ($path, $owner, $vtype) = PVE
::Storage
::path
($storecfg, $volid);
1673 return if !$owner || ($owner != $vmid);
1675 die "unable to replicate volume '$volid', type '$vtype'\n" if $vtype ne 'images';
1677 return if !$cleanup && !$replicate;
1679 if (!PVE
::Storage
::volume_has_feature
($storecfg, 'replicate', $volid)) {
1680 return if $cleanup || $noerr;
1681 die "missing replicate feature on volume '$volid'\n";
1684 $volhash->{$volid} = 1;
1687 $class->foreach_volume($conf, sub {
1688 my ($ms, $mountpoint) = @_;
1689 $test_volid->($mountpoint->{volume
}, $mountpoint);
1692 foreach my $snapname (keys %{$conf->{snapshots
}}) {
1693 my $snap = $conf->{snapshots
}->{$snapname};
1694 $class->foreach_volume($snap, sub {
1695 my ($ms, $mountpoint) = @_;
1696 $test_volid->($mountpoint->{volume
}, $mountpoint);
1700 # add 'unusedX' volumes to volhash
1701 foreach my $key (keys %$conf) {
1702 if ($key =~ m/^unused/) {
1703 $test_volid->($conf->{$key}, { type
=> 'volume', replicate
=> 1 });
1710 sub get_backup_volumes
{
1711 my ($class, $conf) = @_;
1713 my $return_volumes = [];
1715 my $test_mountpoint = sub {
1716 my ($key, $volume) = @_;
1718 my ($included, $reason) = $class->mountpoint_backup_enabled($key, $volume);
1720 push @$return_volumes, {
1722 included
=> $included,
1724 volume_config
=> $volume,
1728 PVE
::LXC
::Config-
>foreach_volume($conf, $test_mountpoint);
1730 return $return_volumes;