Blob Blame History Raw
From 3b3b9b240e186546abf11b2683bf917be5fc854f Mon Sep 17 00:00:00 2001
Message-Id: <3b3b9b240e186546abf11b2683bf917be5fc854f.1382534061.git.jdenemar@redhat.com>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Tue, 22 Oct 2013 16:24:47 +0100
Subject: [PATCH] qemu: Make migration port range configurable

https://bugzilla.redhat.com/show_bug.cgi?id=1019237

(cherry picked from commit e3ef20d7f7fee595ac4fc6094e04b7d65ee0583a)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu.conf                 | 11 +++++++++++
 src/qemu/qemu_conf.c               | 21 +++++++++++++++++++++
 src/qemu/qemu_conf.h               |  2 ++
 src/qemu/qemu_driver.c             |  4 ++--
 src/qemu/test_libvirtd_qemu.aug.in |  2 ++
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index 541db64..4b59320 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -427,3 +427,14 @@
 # Override the listen address for all incoming migrations. Defaults to
 # 0.0.0.0 or :: in case if both host and qemu are capable of IPv6.
 #migration_address = "127.0.0.1"
+
+
+# Override the port range used for incoming migrations.
+#
+# Minimum must be greater than 0, however when QEMU is not running as root,
+# setting the minimum to be lower than 1024 will not work.
+#
+# Maximum must not be greater than 65535.
+#
+#migration_port_min = 49152
+#migration_port_max = 49215
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index cea139d..e45180a 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -207,6 +207,9 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
     cfg->webSocketPortMin = QEMU_WEBSOCKET_PORT_MIN;
     cfg->webSocketPortMax = QEMU_WEBSOCKET_PORT_MAX;
 
+    cfg->migrationPortMin = QEMU_MIGRATION_PORT_MIN;
+    cfg->migrationPortMax = QEMU_MIGRATION_PORT_MAX;
+
 #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
     /* For privileged driver, try and find hugepage mount automatically.
      * Non-privileged driver requires admin to create a dir for the
@@ -440,6 +443,24 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
         goto cleanup;
     }
 
+    GET_VALUE_LONG("migration_port_min", cfg->migrationPortMin);
+    if (cfg->migrationPortMin <= 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%s: migration_port_min: port must be greater than 0"),
+                        filename);
+        goto cleanup;
+    }
+
+    GET_VALUE_LONG("migration_port_max", cfg->migrationPortMax);
+    if (cfg->migrationPortMax > 65535 ||
+        cfg->migrationPortMax < cfg->migrationPortMin) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("%s: migration_port_max: port must be between "
+                          "the minimal port %d and 65535"),
+                       filename, cfg->migrationPortMin);
+        goto cleanup;
+    }
+
     p = virConfGetValue(conf, "user");
     CHECK_TYPE("user", VIR_CONF_STRING);
     if (p && p->str &&
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 4acc67b..576a2e2 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -158,6 +158,8 @@ struct _virQEMUDriverConfig {
 
     /* The default for -incoming */
     char *migrationAddress;
+    int migrationPortMin;
+    int migrationPortMax;
 };
 
 /* Main driver state */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4a4880c..226e32d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -688,8 +688,8 @@ qemuStateInitialize(bool privileged,
         goto error;
 
     if ((qemu_driver->migrationPorts =
-         virPortAllocatorNew(QEMU_MIGRATION_PORT_MIN,
-                             QEMU_MIGRATION_PORT_MAX)) == NULL)
+         virPortAllocatorNew(cfg->migrationPortMin,
+                             cfg->migrationPortMax)) == NULL)
         goto error;
 
     if (qemuSecurityInit(qemu_driver) < 0)
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in
index be4518c..d6d55b8 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -67,3 +67,5 @@ module Test_libvirtd_qemu =
 { "keepalive_count" = "5" }
 { "seccomp_sandbox" = "1" }
 { "migration_address" = "127.0.0.1" }
+{ "migration_port_min" = "1234" }
+{ "migration_port_max" = "12345" }
-- 
1.8.4