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 <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2015-01-09 16:30:35 +01:00 committed by Dietmar Maurer
parent 70b048219e
commit de9d1e5574
2 changed files with 12 additions and 18 deletions

View File

@ -226,7 +226,7 @@ my $check_vm_modify_config_perm = sub {
next if PVE::QemuServer::valid_drivename($opt); next if PVE::QemuServer::valid_drivename($opt);
if ($opt eq 'sockets' || $opt eq 'cores' || 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') { $opt eq 'cpulimit' || $opt eq 'cpuunits') {
$rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.CPU']); $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.CPU']);
} elsif ($opt eq 'boot' || $opt eq 'bootdisk') { } elsif ($opt eq 'boot' || $opt eq 'bootdisk') {

View File

@ -312,12 +312,12 @@ EODESC
description => "Enable/disable Numa.", description => "Enable/disable Numa.",
default => 0, default => 0,
}, },
maxcpus => { vcpus => {
optional => 1, optional => 1,
type => 'integer', type => 'integer',
description => "Maximum cpus for hotplug.", description => "Number of hotplugged vcpus.",
minimum => 1, minimum => 1,
default => 1, default => 0,
}, },
acpi => { acpi => {
optional => 1, optional => 1,
@ -2029,10 +2029,6 @@ sub write_vm_config {
delete $conf->{smp}; delete $conf->{smp};
} }
if ($conf->{maxcpus} && $conf->{sockets}) {
delete $conf->{sockets};
}
my $used_volids = {}; my $used_volids = {};
my $cleanup_config = sub { my $cleanup_config = sub {
@ -2759,19 +2755,17 @@ sub config_to_command {
$sockets = $conf->{sockets} if $conf->{sockets}; $sockets = $conf->{sockets} if $conf->{sockets};
my $cores = $conf->{cores} || 1; my $cores = $conf->{cores} || 1;
my $maxcpus = $conf->{maxcpus} if $conf->{maxcpus};
my $total_cores = $sockets * $cores; my $maxcpus = $sockets * $cores;
my $allowed_cores = $cpuinfo->{cpus};
die "MAX $allowed_cores cores allowed per VM on this node\n" my $vcpus = $conf->{vcpus} ? $conf->{vcpus} : $maxcpus;
if ($allowed_cores < $total_cores);
if ($maxcpus) { my $allowed_vcpus = $cpuinfo->{cpus};
push @$cmd, '-smp', "cpus=$cores,maxcpus=$maxcpus";
} else { die "MAX $maxcpus vcpus allowed per VM on this node\n"
push @$cmd, '-smp', "sockets=$sockets,cores=$cores"; if ($allowed_vcpus < $maxcpus);
}
push @$cmd, '-smp', "$vcpus,sockets=$sockets,cores=$cores,maxcpus=$maxcpus";
push @$cmd, '-nodefaults'; push @$cmd, '-nodefaults';