die "implement me - save vmstate\n";
}
+sub __snapshot_rollback_get_unused {
+ my ($class, $conf, $snap) = @_;
+
+ my $unused = [];
+
+ $class->__snapshot_foreach_volume($conf, sub {
+ my ($vs, $volume) = @_;
+
+ return if $volume->{type} ne 'volume';
+
+ my $found = 0;
+ my $volid = $volume->{volume};
+
+ $class->__snapshot_foreach_volume($snap, sub {
+ my ($ms, $mountpoint) = @_;
+
+ return if $found;
+ return if ($mountpoint->{type} ne 'volume');
+
+ $found = 1
+ if ($mountpoint->{volume} && $mountpoint->{volume} eq $volid);
+ });
+
+ push @$unused, $volid if !$found;
+ });
+
+ return $unused;
+}
+
sub __snapshot_foreach_volume {
my ($class, $conf, $func) = @_;
},
ro => {
type => 'boolean',
- description => 'Read-only mountpoint',
+ description => 'Read-only mount point',
optional => 1,
},
quota => {
description => 'Enable user quotas inside the container (not supported with zfs subvolumes)',
optional => 1,
},
+ replicate => {
+ type => 'boolean',
+ description => 'Will include this volume to a storage replica job.',
+ optional => 1,
+ default => 1,
+ },
+ shared => {
+ type => 'boolean',
+ description => 'Mark this non-volume mount point as available on multiple nodes (see \'nodes\')',
+ 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!",
+ optional => 1,
+ default => 0,
+ },
};
PVE::JSONSchema::register_standard_option('pve-ct-rootfs', {
maximum => 6,
default => 2,
},
+ cores => {
+ optional => 1,
+ type => 'integer',
+ description => "The number of cores assigned to the container. A container can use all available cores by default.",
+ minimum => 1,
+ maximum => 128,
+ },
cpulimit => {
optional => 1,
type => 'number',
'lxc.rootfs' => 'lxc.rootfs is auto generated from rootfs',
'lxc.rootfs.mount' => 1,
'lxc.rootfs.options' => 'lxc.rootfs.options is not supported' .
- ', please use mountpoint options in the "rootfs" key',
+ ', please use mount point options in the "rootfs" key',
# lxc.cgroup.*
+ # lxc.limit.*
'lxc.cap.drop' => 1,
'lxc.cap.keep' => 1,
'lxc.aa_profile' => 1,
},
tag => {
type => 'integer',
- minimum => '1',
- maximum => '4094',
+ minimum => 1,
+ maximum => 4094,
description => "VLAN tag for this interface.",
optional => 1,
},
%$rootfs_desc,
backup => {
type => 'boolean',
- description => 'Whether to include the mountpoint in backups.',
- verbose_description => 'Whether to include the mountpoint in backups '.
- '(only used for volume mountpoints).',
+ description => 'Whether to include the mount point in backups.',
+ verbose_description => 'Whether to include the mount point in backups '.
+ '(only used for volume mount points).',
optional => 1,
},
mp => {
type => 'string',
format => 'pve-lxc-mp-string',
format_description => 'Path',
- description => 'Path to the mountpoint as seen from inside the container '.
+ description => 'Path to the mount point as seen from inside the container '.
'(must not contain symlinks).',
- verbose_description => "Path to the mountpoint as seen from inside the container.\n\n".
+ verbose_description => "Path to the mount point as seen from inside the container.\n\n".
"NOTE: Must not contain any symlinks for security reasons."
},
};
my $key = $1;
my $value = $3;
my $validity = $valid_lxc_conf_keys->{$key} || 0;
- if ($validity eq 1 || $key =~ m/^lxc\.cgroup\./) {
+ if ($validity eq 1 || $key =~ m/^lxc\.(?:cgroup|limit)\./) {
push @{$conf->{lxc}}, [$key, $value];
} elsif (my $errmsg = $validity) {
warn "vm $vmid - $key: $errmsg\n";
if (defined($delete)) {
foreach my $opt (@$delete) {
if (!exists($conf->{$opt})) {
- warn "no such option: $opt\n";
+ # silently ignore
next;
}
- if ($opt eq 'hostname' || $opt eq 'memory' || $opt eq 'rootfs') {
+ if ($opt eq 'memory' || $opt eq 'rootfs') {
die "unable to delete required option '$opt'\n";
+ } elsif ($opt eq 'hostname') {
+ delete $conf->{$opt};
} elsif ($opt eq 'swap') {
delete $conf->{$opt};
PVE::LXC::write_cgroup_value("memory", $vmid,
$opt eq 'tty' || $opt eq 'console' || $opt eq 'cmode') {
next if $hotplug_error->($opt);
delete $conf->{$opt};
+ } elsif ($opt eq 'cores') {
+ delete $conf->{$opt}; # rest is handled by pvestatd
} elsif ($opt eq 'cpulimit') {
PVE::LXC::write_cgroup_value("cpu", $vmid, "cpu.cfs_quota_us", -1);
delete $conf->{$opt};
PVE::LXC::Config->write_config($vmid, $conf) if $running;
}
+ my $storecfg = PVE::Storage::config();
+
my $used_volids = {};
my $check_content_type = sub {
my ($mp) = @_;
my $sid = PVE::Storage::parse_volume_id($mp->{volume});
- my $scfg = PVE::Storage::config();
- my $storage_config = PVE::Storage::storage_config($scfg, $sid);
+ my $storage_config = PVE::Storage::storage_config($storecfg, $sid);
die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
if !$storage_config->{content}->{rootdir};
};
foreach my $opt (keys %$param) {
my $value = $param->{$opt};
my $check_protection_msg = "can't update CT $vmid drive '$opt'";
- if ($opt eq 'hostname') {
+ if ($opt eq 'hostname' || $opt eq 'arch') {
$conf->{$opt} = $value;
} elsif ($opt eq 'onboot') {
$conf->{$opt} = $value ? 1 : 0;
next if $hotplug_error->($opt);
my $list = PVE::LXC::verify_searchdomain_list($value);
$conf->{$opt} = $list;
+ } elsif ($opt eq 'cores') {
+ $conf->{$opt} = $value;# rest is handled by pvestatd
} elsif ($opt eq 'cpulimit') {
- PVE::LXC::write_cgroup_value("cpu", $vmid, "cpu.cfs_quota_us", int(100000*$value));
+ if ($value == 0) {
+ PVE::LXC::write_cgroup_value("cpu", $vmid, "cpu.cfs_quota_us", -1);
+ } else {
+ PVE::LXC::write_cgroup_value("cpu", $vmid, "cpu.cfs_quota_us", int(100000*$value));
+ }
$conf->{$opt} = $value;
} elsif ($opt eq 'cpuunits') {
$conf->{$opt} = $value;
} else {
die "implement me: $opt";
}
+
PVE::LXC::Config->write_config($vmid, $conf) if $running;
}
$res = PVE::JSONSchema::parse_property_string($netconf_desc, $data);
$res->{type} = 'veth';
- $res->{hwaddr} = PVE::Tools::random_ether_addr() if !$res->{hwaddr};
+ if (!$res->{hwaddr}) {
+ my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ $res->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+ }
return $res;
}
return !(defined($conf->{console}) && !$conf->{console});
}
+sub has_lxc_entry {
+ my ($class, $conf, $keyname) = @_;
+
+ if (my $lxcconf = $conf->{lxc}) {
+ foreach my $entry (@$lxcconf) {
+ my ($key, undef) = @$entry;
+ return 1 if $key eq $keyname;
+ }
+ }
+
+ return 0;
+}
+
sub get_tty_count {
my ($class, $conf) = @_;
return $vollist;
}
-return 1;
+sub get_replicatable_volumes {
+ my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
+
+ my $volhash = {};
+
+ my $test_volid = sub {
+ my ($volid, $mountpoint) = @_;
+
+ return if !$volid;
+
+ my $mptype = $mountpoint->{type};
+ die "unable to replicate mountpoint type '$mptype'\n"
+ if $mptype ne 'volume';
+
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, $noerr);
+ return if !$storeid;
+
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ return if $scfg->{shared};
+
+ my ($path, $owner, $vtype) = PVE::Storage::path($storecfg, $volid);
+ return if !$owner || ($owner != $vmid);
+
+ die "unable to replicate volume '$volid', type '$vtype'\n" if $vtype ne 'images';
+
+ return if !$cleanup && defined($mountpoint->{replicate}) && !$mountpoint->{replicate};
+
+ if (!PVE::Storage::volume_has_feature($storecfg, 'replicate', $volid)) {
+ return if $cleanup || $noerr;
+ die "missing replicate feature on volume '$volid'\n";
+ }
+
+ $volhash->{$volid} = 1;
+ };
+
+ $class->foreach_mountpoint($conf, sub {
+ my ($ms, $mountpoint) = @_;
+ $test_volid->($mountpoint->{volume}, $mountpoint);
+ });
+
+ foreach my $snapname (keys %{$conf->{snapshots}}) {
+ my $snap = $conf->{snapshots}->{$snapname};
+ $class->foreach_mountpoint($snap, sub {
+ my ($ms, $mountpoint) = @_;
+ $test_volid->($mountpoint->{volume}, $mountpoint);
+ });
+ }
+
+ # add 'unusedX' volumes to volhash
+ foreach my $key (keys %$conf) {
+ if ($key =~ m/^unused/) {
+ $test_volid->($conf->{$key}, { type => 'volume', replicate => 1 });
+ }
+ }
+
+ return $volhash;
+}
+
+1;