From 84e1e9d99648dfea190469b14606fdde54e17c25 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 13 Nov 2023 14:06:01 +0100 Subject: [PATCH] api: bulk suspension: code clean-ups Signed-off-by: Thomas Lamprecht --- PVE/API2/Nodes.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index e1e2c16b..39b049d8 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -2061,7 +2061,7 @@ __PACKAGE__->register_method ({ if (scalar(@vms) > 0) { $rpcenv->check($authuser, "/vms/$_", [ 'VM.PowerMgmt' ]) for @vms; } else { - raise_perm_exc("/, VM.PowerMgmt && VM.Config.Disk"); + raise_perm_exc("/, VM.PowerMgmt && VM.Config.Disk"); } } @@ -2072,15 +2072,15 @@ __PACKAGE__->register_method ({ $rpcenv->{type} = 'priv'; # to start tasks in background - my $stopList = $get_start_stop_list->($nodename, undef, $param->{vms}); + my $toSuspendList = $get_start_stop_list->($nodename, undef, $param->{vms}); my $cpuinfo = PVE::ProcFSTools::read_cpuinfo(); my $datacenterconfig = cfs_read_file('datacenter.cfg'); # if not set by user spawn max cpu count number of workers my $maxWorkers = $datacenterconfig->{max_workers} || $cpuinfo->{cpus}; - for my $order (sort {$b <=> $a} keys %$stopList) { - my $vmlist = $stopList->{$order}; + for my $order (sort {$b <=> $a} keys %$toSuspendList) { + my $vmlist = $toSuspendList->{$order}; my $workers = {}; my $finish_worker = sub { @@ -2106,10 +2106,10 @@ __PACKAGE__->register_method ({ next if !$task; my $pid = $task->{pid}; - $workers->{$pid} = { type => $d->{type}, upid => $upid, vmid => $vmid }; + while (scalar(keys %$workers) >= $maxWorkers) { - foreach my $p (keys %$workers) { + for my $p (keys %$workers) { if (!PVE::ProcFSTools::check_process_running($p)) { $finish_worker->($p); }