From e5d611c382e48144311f500681d4777e9064d126 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 16 Oct 2020 16:52:11 +0200 Subject: [PATCH] fix various conditionally declared vars Signed-off-by: Thomas Lamprecht --- PVE/QemuMigrate.pm | 2 +- PVE/QemuServer.pm | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm index 11fec4b4..2f4eec33 100644 --- a/PVE/QemuMigrate.pm +++ b/PVE/QemuMigrate.pm @@ -974,7 +974,7 @@ sub phase2 { my $downtimecounter = 0; while (1) { $i++; - my $avglstat = $lstat/$i if $lstat; + my $avglstat = $lstat ? $lstat / $i : 0; usleep($usleep); my $stat; diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 95d18668..9b646b56 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3210,17 +3210,7 @@ sub config_to_command { push @$devices, '-device', $kbd if defined($kbd); } - my $bootorder = {}; - my $boot = parse_property_string($boot_fmt, $conf->{boot}) if $conf->{boot}; - if (!defined($boot) || $boot->{legacy}) { - $bootorder = bootorder_from_legacy($conf, $boot); - } elsif ($boot->{order}) { - # start at 100 to allow user to insert devices before us with -args - my $i = 100; - for my $dev (PVE::Tools::split_list($boot->{order})) { - $bootorder->{$dev} = $i++; - } - } + my $bootorder = device_bootorder($conf); # host pci device passthrough my ($kvm_off, $gpu_passthrough, $legacy_igd) = PVE::QemuServer::PCI::print_hostpci_devices( @@ -3370,8 +3360,8 @@ sub config_to_command { } } - my $rng = parse_rng($conf->{rng0}) if $conf->{rng0}; - if ($rng && &$version_guard(4, 1, 2)) { + my $rng = $conf->{rng0} ? parse_rng($conf->{rng0}) : undef; + if ($rng && $version_guard->(4, 1, 2)) { check_rng_source($rng->{source}); my $max_bytes = $rng->{max_bytes} // $rng_fmt->{max_bytes}->{default}; @@ -7275,6 +7265,26 @@ sub get_default_bootdevices { return \@ret; } +sub device_bootorder { + my ($conf) = @_; + + return bootorder_from_legacy($conf) if !defined($conf->{boot}); + + my $boot = parse_property_string($boot_fmt, $conf->{boot}); + + my $bootorder = {}; + if (!defined($boot) || $boot->{legacy}) { + $bootorder = bootorder_from_legacy($conf, $boot); + } elsif ($boot->{order}) { + my $i = 100; # start at 100 to allow user to insert devices before us with -args + for my $dev (PVE::Tools::split_list($boot->{order})) { + $bootorder->{$dev} = $i++; + } + } + + return $bootorder; +} + # bash completion helper sub complete_backup_archives {