]> xenbits.xensource.com Git - libvirt.git/commitdiff
migration: add support for migrateURI configuration
authorChen Fan <chen.fan.fnst@cn.fujitsu.com>
Tue, 20 May 2014 06:08:05 +0000 (14:08 +0800)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 20 May 2014 11:13:29 +0000 (13:13 +0200)
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 resolved 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
have to specify it in command line everytime.

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/libvirtd_qemu.aug
src/qemu/qemu.conf
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/qemu_migration.c
src/qemu/test_libvirtd_qemu.aug.in

index e985d22ec481da7e6526f86f55082d6ed8e05004..e7db7fe2be0236ad74b07df9f86bf45bcb1df23d 100644 (file)
@@ -84,6 +84,7 @@ module Libvirtd_qemu =
    let network_entry = str_entry "migration_address"
                  | int_entry "migration_port_min"
                  | int_entry "migration_port_max"
+                 | str_entry "migration_host"
 
    let log_entry = bool_entry "log_timestamp"
 
index 42f812dc2563b0b35145e5994f62e500c30d5718..18ce2a84904d635516c0adaa8e3822a309906aa5 100644 (file)
 #seccomp_sandbox = 1
 
 
-
 # Override the listen address for all incoming migrations. Defaults to
 # 0.0.0.0, or :: if both host and qemu are capable of IPv6.
 #migration_address = "127.0.0.1"
 
 
+# The default hostname or IP address which will be used by a migration
+# source for transferring migration data to this host.  The migration
+# source has to be able to resolve this hostname and connect to it so
+# setting "localhost" will not work.  By default, the host's configured
+# hostname is used.
+#migration_host = "host.example.com"
+
+
 # Override the port range used for incoming migrations.
 #
 # Minimum must be greater than 0, however when QEMU is not running as root,
index 400c99ca51ec0a158bad8d8180ea92ce35c3f090..f273056d31e8f0fef428f8da6a4c8226da27018c 100644 (file)
@@ -576,6 +576,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 
     GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox);
 
+    GET_VALUE_STR("migration_host", cfg->migrateHost);
     GET_VALUE_STR("migration_address", cfg->migrationAddress);
 
     GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp);
index 5d2983af3ab02bc1bac8497c1f521ac413a1a38f..78b08e55c88ba0bda3788eec670ad752c59bb575 100644 (file)
@@ -163,6 +163,7 @@ struct _virQEMUDriverConfig {
 
     int seccompSandbox;
 
+    char *migrateHost;
     /* The default for -incoming */
     char *migrationAddress;
     int migrationPortMin;
index f0df1a60445a9fb837bd8f4a1e424ebe230d1734..d6271fb57a1c2608fc50b415ce1f834f1450d10f 100644 (file)
@@ -2640,6 +2640,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, "
@@ -2653,8 +2655,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
@@ -2664,8 +2667,17 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
         if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
             goto cleanup;
 
-        if ((hostname = virGetHostname()) == NULL)
-            goto cleanup;
+        if (migrateHost != NULL) {
+            if (virSocketAddrIsNumeric(migrateHost) &&
+                virSocketAddrParse(NULL, migrateHost, AF_UNSPEC) < 0)
+                goto cleanup;
+
+           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",
@@ -2747,6 +2759,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
  cleanup:
     virURIFree(uri);
     VIR_FREE(hostname);
+    virObjectUnref(cfg);
     if (ret != 0) {
         VIR_FREE(*uri_out);
         if (autoPort)
index 30a425793e895e69e0472c36b756b8b5d4f9a16f..7796acc1d827aa5c903984dc48f22d00c606e5e8 100644 (file)
@@ -70,6 +70,7 @@ module Test_libvirtd_qemu =
 { "keepalive_count" = "5" }
 { "seccomp_sandbox" = "1" }
 { "migration_address" = "127.0.0.1" }
+{ "migration_host" = "host.example.com" }
 { "migration_port_min" = "49152" }
 { "migration_port_max" = "49215" }
 { "log_timestamp" = "0" }