[libvirt] [PATCH v5] migration: add support for migrateURI configuration

Chen Fan chen.fan.fnst at cn.fujitsu.com
Tue May 20 06:08:05 UTC 2014


For now, we set the migration URI via command line '--migrate_uri' or
construct the URI by looking up the dest host's hostname which could be
solved by DNS automatically.

But in cases the dest host have two or more NICs to reach, we may need to
send the migration data over a specific NIC which is different from the
automatically resloved one for some reason like performance, security, etc.
thus we must explicitly specify the migrateuri in command line everytime,
but it is too troublesome if there are many such hosts(and don't forget
virt-manager).

This patch adds a configuration file option on dest host to save the
default value set which can be specified to a migration hostname or
one of this host's addresses used for transferring data, thus user doesn't
boring to specify it in command line everytime.

Signed-off-by: Chen Fan <chen.fan.fnst at cn.fujitsu.com>
---

v4-v5: using "migrate_host" instead of "migrate_uri" configuration.

 src/qemu/qemu.conf        |  7 ++++++-
 src/qemu/qemu_conf.c      |  1 +
 src/qemu/qemu_conf.h      |  1 +
 src/qemu/qemu_migration.c | 25 +++++++++++++++++++++----
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index f0e802f..421efc4 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -449,7 +449,12 @@
 #
 #seccomp_sandbox = 1
 
-
+# Override the migration hostname for transfering the migration data. By
+# default, the migrate hostname is set to the host's configured hostname.
+# This can be used to override the default value set by a migration
+# hostname or an IP address of the host machine. both IPv4 and IPv6
+# addresses are accepted.
+#migrate_host = "localhost"
 
 # Override the listen address for all incoming migrations. Defaults to
 # 0.0.0.0, or :: if both host and qemu are capable of IPv6.
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 198ee2f..391fc57 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -574,6 +574,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 
     GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox);
 
+    GET_VALUE_STR("migrate_host", cfg->migrateHost);
     GET_VALUE_STR("migration_address", cfg->migrationAddress);
 
     ret = 0;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a36ea63..8e872b9 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -163,6 +163,7 @@ struct _virQEMUDriverConfig {
 
     int seccompSandbox;
 
+    char *migrateHost;
     /* The default for -incoming */
     char *migrationAddress;
     int migrationPortMin;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a9f7fea..963d1ef 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2639,6 +2639,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
     int ret = -1;
     virURIPtr uri = NULL;
     bool well_formed_uri = true;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    const char *migrateHost = cfg->migrateHost;
 
     VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
               "cookieout=%p, cookieoutlen=%p, uri_in=%s, uri_out=%p, "
@@ -2652,8 +2654,9 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
     /* The URI passed in may be NULL or a string "tcp://somehostname:port".
      *
      * If the URI passed in is NULL then we allocate a port number
-     * from our pool of port numbers and return a URI of
-     * "tcp://ourhostname:port".
+     * from our pool of port numbers, and if the migrateHost is configured,
+     * we return a URI of "tcp://migrateHost:port", otherwise return a URI
+     * of "tcp://ourhostname:port".
      *
      * If the URI passed in is not NULL then we try to parse out the
      * port number and use that (note that the hostname is assumed
@@ -2663,8 +2666,21 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
         if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
             goto cleanup;
 
-        if ((hostname = virGetHostname()) == NULL)
-            goto cleanup;
+        if (migrateHost != NULL) {
+            if (virSocketAddrIsNumeric(migrateHost)) {
+                /* migrateHost is numeric IPv4 or IPv6 */
+                if (virSocketAddrParse(NULL, migrateHost, AF_UNSPEC) < 0)
+                    goto cleanup;
+            } else {
+                /* migrateHost is a hostname */
+            }
+
+           if (VIR_STRDUP(hostname, migrateHost) < 0)
+                goto cleanup;
+        } else {
+            if ((hostname = virGetHostname()) == NULL)
+                goto cleanup;
+        }
 
         if (STRPREFIX(hostname, "localhost")) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2746,6 +2762,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
  cleanup:
     virURIFree(uri);
     VIR_FREE(hostname);
+    virObjectUnref(cfg);
     if (ret != 0) {
         VIR_FREE(*uri_out);
         if (autoPort)
-- 
1.8.1.4




More information about the libvir-list mailing list