[pve-devel] [PATCH 2/3] add cpu_hotplug
Alexandre Derumier
aderumier at odiso.com
Tue Jan 7 13:32:51 CET 2014
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 4 ++++
PVE/QemuServer.pm | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index d038b06..b2c8908 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -988,6 +988,10 @@ my $update_vm_api = sub {
} elsif($opt eq 'tablet' && $param->{$opt} == 0){
PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
}
+
+ if($opt eq 'cores' && $conf->{maxcpus}){
+ PVE::QemuServer::qemu_cpu_hotplug($vmid, $conf, $param->{$opt});
+ }
$conf->{$opt} = $param->{$opt};
PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index db2535c..7ddaae7 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2943,6 +2943,26 @@ sub qemu_netdevdel {
return 1;
}
+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 !check_running($vmid);
+
+ 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);
+
+ 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;
+
+ for(my $i = $currentcores; $i < $cores; $i++){
+ vm_mon_cmd($vmid, "cpu-add", id => int($i));
+ }
+}
+
sub qemu_block_set_io_throttle {
my ($vmid, $deviceid, $bps, $bps_rd, $bps_wr, $iops, $iops_rd, $iops_wr) = @_;
--
1.7.10.4
More information about the pve-devel
mailing list