[pve-devel] [PATCH 5/7] vmconfig_hotplug_pending : add cpu hotplug

Alexandre Derumier aderumier at odiso.com
Tue Nov 18 13:39:50 CET 2014


if cpu hotplug is not possible,
we simply return to keep the changes in pending

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 387bbac..f779d80 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3232,24 +3232,25 @@ sub qemu_netdevdel {
 sub qemu_cpu_hotplug {
     my ($vmid, $conf, $cores) = @_;
 
-    die "new cores config is not defined" if !$cores;
-    die "you can't add more cores than maxcpus"
-	if $conf->{maxcpus} && ($cores > $conf->{maxcpus});
+    return if !$cores;
+    return if !$conf->{maxcpus};
     return if !check_running($vmid);
 
+    return if $cores > $conf->{maxcpus};
+
     my $currentcores = $conf->{cores} if $conf->{cores};
-    die "current cores is not defined" if !$currentcores;
-    die "maxcpus is not defined" if !$conf->{maxcpus};
-    raise_param_exc({ 'cores' => "online cpu unplug is not yet possible" })
-	if($cores < $currentcores);
+    return if !$currentcores;
+
+    return if($cores < $currentcores); # unplug is not yet possible
 
     my $currentrunningcores = vm_mon_cmd($vmid, "query-cpus");
-    raise_param_exc({ 'cores' => "cores number if running vm is different than configuration" })
-	if scalar (@{$currentrunningcores}) != $currentcores;
+    return if scalar (@{$currentrunningcores}) != $currentcores;
 
     for(my $i = $currentcores; $i < $cores; $i++) {
 	vm_mon_cmd($vmid, "cpu-add", id => int($i));
     }
+
+    $conf->{cores} = $cores;
 }
 
 sub qemu_block_set_io_throttle {
@@ -3519,7 +3520,13 @@ sub vmconfig_hotplug_pending {
 		    delete $conf->{pending}->{$opt};
 		}
 	    }
-	}
+	} elsif($opt eq 'cores'){
+	    if(PVE::QemuServer::qemu_cpu_hotplug($vmid, $conf, $conf->{pending}->{$opt})){
+		$conf->{$opt} = $conf->{pending}->{$opt};
+		delete $conf->{pending}->{$opt};
+	    }
+        }
+
     }
 
 }
-- 
1.7.10.4




More information about the pve-devel mailing list