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

Alexandre Derumier aderumier at odiso.com
Mon Nov 17 16:43:40 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 2542059..067bc1c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3272,24 +3272,28 @@ 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;
+    delete $conf->{pending}->{cores};
+    PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+
 }
 
 sub qemu_block_set_io_throttle {
@@ -3548,7 +3552,10 @@ sub vmconfig_hotplug_pending {
 	    } elsif($conf->{pending}->{$opt} == 0){
 		PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
 	    }
-	}
+	} elsif($opt eq 'cores'){
+	    PVE::QemuServer::qemu_cpu_hotplug($vmid, $conf, $conf->{pending}->{$opt});
+        }
+
     }
 
 }
-- 
1.7.10.4




More information about the pve-devel mailing list