[pve-devel] [PATCH qemu-server v2 1/8] bwlimit: honor bwlimit for migrate qmp call

Stoiko Ivanov s.ivanov at proxmox.com
Mon Apr 1 11:30:58 CEST 2019


The 'migrate_speed' can be set in the VM config. Additionally the 'migrate'
bwlimit from datacenter.cfg (storage-specific limits play no role for
memory+state migration) or the parameter provided to the API call can restrict
the speed. Take the lower of the two.

This patch also refactors the setting of migrate_speed and comments for clarity.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 PVE/QemuMigrate.pm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 6bb19db..bb65d63 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -675,11 +675,21 @@ sub phase2 {
     # load_defaults
     my $defaults = PVE::QemuServer::load_defaults();
 
-    # always set migrate speed (overwrite kvm default of 32m)
-    # we set a very hight default of 8192m which is basically unlimited
-    my $migrate_speed = $defaults->{migrate_speed} || 8192;
-    $migrate_speed = $conf->{migrate_speed} || $migrate_speed;
-    $migrate_speed = $migrate_speed * 1048576;
+    # 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('migrate', undef, $opt_bwlimit) // 0;
+    my $migrate_speed = $conf->{migrate_speed} // $bwlimit;
+    # migrate_speed is in MB/s, bwlimit in KB/s
+    $migrate_speed *= 1024;
+
+    $migrate_speed = ($bwlimit < $migrate_speed) ? $bwlimit : $migrate_speed;
+
+    # always set migrate speed (overwrite kvm default of 32m) we set a very high
+    # default of 8192m which is basically unlimited
+    $migrate_speed ||= ($defaults->{migrate_speed} || 8192) * 1024;
+
+    # qmp takes migrate_speed in B/s.
+    $migrate_speed *= 1024;
     $self->log('info', "migrate_set_speed: $migrate_speed");
     eval {
         PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate_set_speed", value => int($migrate_speed));
-- 
2.11.0





More information about the pve-devel mailing list