vmconfig_hotplug_pending: correctly skip values

Do not use $skip variable (simply raise an exception)

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2014-11-24 10:33:51 +01:00
parent 281fedb364
commit e56beedaba

View File

@ -3630,26 +3630,24 @@ sub vmconfig_hotplug_pending {
my @delete = PVE::Tools::split_list($conf->{pending}->{delete}); my @delete = PVE::Tools::split_list($conf->{pending}->{delete});
foreach my $opt (@delete) { foreach my $opt (@delete) {
next if $selection && !$selection->{$opt}; next if $selection && !$selection->{$opt};
my $skip;
eval { eval {
if ($opt eq 'tablet') { if ($opt eq 'tablet') {
return undef if !$hotplug; die "skip\n" if !$hotplug;
if ($defaults->{tablet}) { if ($defaults->{tablet}) {
vm_deviceplug($storecfg, $conf, $vmid, $opt); vm_deviceplug($storecfg, $conf, $vmid, $opt);
} else { } else {
vm_deviceunplug($vmid, $conf, $opt); vm_deviceunplug($vmid, $conf, $opt);
} }
} elsif ($opt eq 'cores') { } elsif ($opt eq 'cores') {
return undef if !$hotplug; die "skip\n" if !$hotplug;
qemu_cpu_hotplug($vmid, $conf, 1); qemu_cpu_hotplug($vmid, $conf, 1);
} else { } else {
$skip = 1; # skip non-hot-pluggable options die "skip\n";
return undef;
} }
}; };
if (my $err = $@) { if (my $err = $@) {
&$add_error($opt, $err); &$add_error($opt, $err) if $err ne "skip\n";
} elsif (!$skip) { } else {
# save new config if hotplug was successful # save new config if hotplug was successful
delete $conf->{$opt}; delete $conf->{$opt};
vmconfig_undelete_pending_option($conf, $opt); vmconfig_undelete_pending_option($conf, $opt);
@ -3661,31 +3659,29 @@ sub vmconfig_hotplug_pending {
foreach my $opt (keys %{$conf->{pending}}) { foreach my $opt (keys %{$conf->{pending}}) {
next if $selection && !$selection->{$opt}; next if $selection && !$selection->{$opt};
my $value = $conf->{pending}->{$opt}; my $value = $conf->{pending}->{$opt};
my $skip;
eval { eval {
if ($opt eq 'tablet') { if ($opt eq 'tablet') {
return undef if !$hotplug; die "skip\n" if !$hotplug;
if ($value == 1) { if ($value == 1) {
vm_deviceplug($storecfg, $conf, $vmid, $opt); vm_deviceplug($storecfg, $conf, $vmid, $opt);
} elsif ($value == 0) { } elsif ($value == 0) {
vm_deviceunplug($vmid, $conf, $opt); vm_deviceunplug($vmid, $conf, $opt);
} }
} elsif ($opt eq 'cores') { } elsif ($opt eq 'cores') {
return undef if !$hotplug; die "skip\n" if !$hotplug;
qemu_cpu_hotplug($vmid, $conf, $value); qemu_cpu_hotplug($vmid, $conf, $value);
} elsif ($opt eq 'balloon') { } elsif ($opt eq 'balloon') {
return undef if !(defined($conf->{shares}) && ($conf->{shares} == 0)); die "skip\n" if !(defined($conf->{shares}) && ($conf->{shares} == 0));
# allow manual ballooning if shares is set to zero # allow manual ballooning if shares is set to zero
my $balloon = $conf->{pending}->{balloon} || $conf->{memory} || $defaults->{memory}; my $balloon = $conf->{pending}->{balloon} || $conf->{memory} || $defaults->{memory};
vm_mon_cmd($vmid, "balloon", value => $balloon*1024*1024); vm_mon_cmd($vmid, "balloon", value => $balloon*1024*1024);
} else { } else {
$skip = 1; # skip non-hot-pluggable options die "skip\n"; # skip non-hot-pluggable options
return undef;
} }
}; };
if (my $err = $@) { if (my $err = $@) {
&$add_error($opt, $err); &$add_error($opt, $err) if $err ne "skip\n";
} elsif (!$skip) { } else {
# save new config if hotplug was successful # save new config if hotplug was successful
$conf->{$opt} = $value; $conf->{$opt} = $value;
delete $conf->{pending}->{$opt}; delete $conf->{pending}->{$opt};