api: create/update vm: clamp cpuunit value

While the clamping already happens before setting the actual systemd
CPU{Shares, Weight}, it can be done here too, to avoid writing new
out-of-range values into the config.

Can't use a validator enforcing this because existing out-of-range
values should not become errors upon parsing the config.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2022-10-07 14:41:50 +02:00 committed by Thomas Lamprecht
parent 0d31845364
commit dbc45fdf9f

View File

@ -814,6 +814,9 @@ __PACKAGE__->register_method({
PVE::Tools::validate_ssh_public_keys($ssh_keys);
}
$param->{cpuunits} = PVE::GuestHelpers::get_cpuunits($param->{cpuunits})
if defined($param->{cpuunits}); # clamp value depending on cgroup version
PVE::Cluster::check_cfs_quorum();
my $filename = PVE::QemuConfig->config_file($vmid);
@ -1362,6 +1365,9 @@ my $update_vm_api = sub {
PVE::Tools::validate_ssh_public_keys($ssh_keys);
}
$param->{cpuunits} = PVE::GuestHelpers::get_cpuunits($param->{cpuunits})
if defined($param->{cpuunits}); # clamp value depending on cgroup version
die "no options specified\n" if !$delete_str && !$revert_str && !scalar(keys %$param);
my $storecfg = PVE::Storage::config();