From de9d1e5574deb272538d50a1f2dee9ab8d7a2f92 Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Fri, 9 Jan 2015 16:30:35 +0100 Subject: [PATCH] add vcpus option vcpus = current allocate vpus to virtual machine maxcpus is now compute from $sockets*cores vcpus = maxcpus if not defined Signed-off-by: Alexandre Derumier --- 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 d0c05e6f..def4e5cf 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 7cfbc6f4..927914ba 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, @@ -2029,10 +2029,6 @@ sub write_vm_config { delete $conf->{smp}; } - if ($conf->{maxcpus} && $conf->{sockets}) { - delete $conf->{sockets}; - } - my $used_volids = {}; my $cleanup_config = sub { @@ -2759,19 +2755,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'; -- 2.39.5