[pve-devel] [PATCH manager 2/2] migrateall: use get_filtered_vmlist

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Feb 24 10:47:03 CET 2017


instead of using get_start_stop_list in a rather hacky way use the
new get_filtered_vmlist method and adapt the loop, as now only one
level is required.

most changes  are just an indent shift left as we lost an unnecessary
loop level

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

 PVE/API2/Nodes.pm | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index de99322..d13bec2 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -1588,32 +1588,20 @@ __PACKAGE__->register_method ({
 	    die "either 'maxworkers' parameter or max_workers in datacenter.cfg must be set!\n";
 
 	my $code = sub {
-
 	    $rpcenv->{type} = 'priv'; # to start tasks in background
 
-	    my $migrateList = &$get_start_stop_list($nodename, undef, $param->{vms});
+	    my $vmlist = &$get_filtered_vmlist($nodename, $param->{vms}, 1, 1);
 
-	    foreach my $order (sort {$b <=> $a} keys %$migrateList) {
-		my $vmlist = $migrateList->{$order};
-		my $workers = {};
-		foreach my $vmid (sort {$b <=> $a} keys %$vmlist) {
-		    my $d = $vmlist->{$vmid};
-		    my $pid;
-		    eval { $pid = &$create_migrate_worker($nodename, $d->{type}, $vmid, $target); };
-		    warn $@ if $@;
-		    next if !$pid;
+	    my $workers = {};
+	    foreach my $vmid (sort keys %$vmlist) {
+		my $d = $vmlist->{$vmid};
+		my $pid;
+		eval { $pid = &$create_migrate_worker($nodename, $d->{type}, $vmid, $target); };
+		warn $@ if $@;
+		next if !$pid;
 
-		    $workers->{$pid} = 1;
-		    while (scalar(keys %$workers) >= $maxWorkers) {
-			foreach my $p (keys %$workers) {
-			    if (!PVE::ProcFSTools::check_process_running($p)) {
-				delete $workers->{$p};
-			    }
-			}
-			sleep(1);
-		    }
-		}
-		while (scalar(keys %$workers)) {
+		$workers->{$pid} = 1;
+		while (scalar(keys %$workers) >= $maxWorkers) {
 		    foreach my $p (keys %$workers) {
 			if (!PVE::ProcFSTools::check_process_running($p)) {
 			    delete $workers->{$p};
@@ -1622,6 +1610,14 @@ __PACKAGE__->register_method ({
 		    sleep(1);
 		}
 	    }
+	    while (scalar(keys %$workers)) {
+		foreach my $p (keys %$workers) {
+		    if (!PVE::ProcFSTools::check_process_running($p)) {
+			delete $workers->{$p};
+		    }
+		}
+		sleep(1);
+	    }
 	    return;
 	};
 
-- 
2.1.4





More information about the pve-devel mailing list