[pve-devel] [PATCH 1/2] add vcpus option
Alexandre Derumier
aderumier at odiso.com
Fri Jan 9 16:30:35 CET 2015
vcpus = current allocate vpus to virtual machine
maxcpus is now compute from $sockets*cores
vcpus = maxcpus if not defined
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 2 +-
PVE/QemuServer.pm | 28 +++++++++++-----------------
2 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index c3dad32..50d6e52 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -226,7 +226,7 @@ my $check_vm_modify_config_perm = sub {
next if PVE::QemuServer::valid_drivename($opt);
if ($opt eq 'sockets' || $opt eq 'cores' ||
- $opt eq 'cpu' || $opt eq 'smp' ||
+ $opt eq 'cpu' || $opt eq 'smp' || $opt eq 'vcpus' ||
$opt eq 'cpulimit' || $opt eq 'cpuunits') {
$rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.CPU']);
} elsif ($opt eq 'boot' || $opt eq 'bootdisk') {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 19932aa..8c74a67 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -312,12 +312,12 @@ EODESC
description => "Enable/disable Numa.",
default => 0,
},
- maxcpus => {
+ vcpus => {
optional => 1,
type => 'integer',
- description => "Maximum cpus for hotplug.",
+ description => "Number of hotplugged vcpus.",
minimum => 1,
- default => 1,
+ default => 0,
},
acpi => {
optional => 1,
@@ -2028,10 +2028,6 @@ sub write_vm_config {
delete $conf->{smp};
}
- if ($conf->{maxcpus} && $conf->{sockets}) {
- delete $conf->{sockets};
- }
-
my $used_volids = {};
my $cleanup_config = sub {
@@ -2758,19 +2754,17 @@ sub config_to_command {
$sockets = $conf->{sockets} if $conf->{sockets};
my $cores = $conf->{cores} || 1;
- my $maxcpus = $conf->{maxcpus} if $conf->{maxcpus};
- my $total_cores = $sockets * $cores;
- my $allowed_cores = $cpuinfo->{cpus};
+ my $maxcpus = $sockets * $cores;
- die "MAX $allowed_cores cores allowed per VM on this node\n"
- if ($allowed_cores < $total_cores);
+ my $vcpus = $conf->{vcpus} ? $conf->{vcpus} : $maxcpus;
- if ($maxcpus) {
- push @$cmd, '-smp', "cpus=$cores,maxcpus=$maxcpus";
- } else {
- push @$cmd, '-smp', "sockets=$sockets,cores=$cores";
- }
+ my $allowed_vcpus = $cpuinfo->{cpus};
+
+ die "MAX $maxcpus vcpus allowed per VM on this node\n"
+ if ($allowed_vcpus < $maxcpus);
+
+ push @$cmd, '-smp', "$vcpus,sockets=$sockets,cores=$cores,maxcpus=$maxcpus";
push @$cmd, '-nodefaults';
--
1.7.10.4
More information about the pve-devel
mailing list