]> git.proxmox.com Git - qemu-server.git/commitdiff
api: create/update vm: clamp cpuunit value
authorFiona Ebner <f.ebner@proxmox.com>
Fri, 7 Oct 2022 12:41:50 +0000 (14:41 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 8 Nov 2022 15:21:27 +0000 (16:21 +0100)
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>
PVE/API2/Qemu.pm

index 3ec31c26898644114c7727d9030a6545626dd849..625d6ea7ff491843c0672fe5ed42b73bb197a7b9 100644 (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();