From 2c4ba4c3ee5f815fd358af2aff8a7a07cbacae90 Mon Sep 17 00:00:00 2001 From: Fabian Ebner Date: Fri, 29 Jan 2021 16:11:35 +0100 Subject: [PATCH] migration: fix calculation of bandwith limit for non-disk migration The case with: 1. no generic 'migration' limit from the storage plugin 2. a migrate_speed limit in the VM config was broken. It would assign 0 to migrate_speed when picking the minimum value and then default to the default value. Fix it by checking if bwlimit is 0 before picking the minimum. Also, make it a bit more readable by avoiding the trick of //-assigning bwlimit before the units match up and relying on getting back the original bwlimit value as the minimum. Instead, only ||-assign after the units match up and don't rely on other things. Signed-off-by: Fabian Ebner --- PVE/QemuMigrate.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm index 455581cf..0522208b 100644 --- a/PVE/QemuMigrate.pm +++ b/PVE/QemuMigrate.pm @@ -961,11 +961,15 @@ sub phase2 { # migrate speed can be set via bwlimit (datacenter.cfg and API) and via the # migrate_speed parameter in qm.conf - take the lower of the two. my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', undef, $opt_bwlimit) // 0; - my $migrate_speed = $conf->{migrate_speed} // $bwlimit; + my $migrate_speed = $conf->{migrate_speed} // 0; # migrate_speed is in MB/s, bwlimit in KB/s $migrate_speed *= 1024; - $migrate_speed = ($bwlimit < $migrate_speed) ? $bwlimit : $migrate_speed; + if ($bwlimit && $migrate_speed) { + $migrate_speed = ($bwlimit < $migrate_speed) ? $bwlimit : $migrate_speed; + } else { + $migrate_speed ||= $bwlimit; + } # always set migrate speed (overwrite kvm default of 32m) we set a very high # default of 8192m which is basically unlimited