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.eb...@proxmox.com>
---
 PVE/API2/Qemu.pm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 3ec31c26..625d6ea7 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -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();
-- 
2.30.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to