Currently we only support TCP protocol for native QEMU migration but
this is going to be changed. Let's make the code more general and remove
hardcoded TCP protocol from several places.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 3:
- separated from "qemu: RDMA migration support"
src/qemu/qemu_migration.c | 36 ++++++++++++++++++++++++------------
src/qemu/qemu_monitor.c | 3 ++-
src/qemu/qemu_monitor.h | 1 +
3 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 5741de2..d0e2653 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2457,6 +2457,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
virDomainDefPtr *def,
const char *origname,
virStreamPtr st,
+ const char *protocol,
unsigned short port,
bool autoPort,
const char *listenAddress,
@@ -2569,6 +2570,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
struct addrinfo *info = NULL;
struct addrinfo hints = { .ai_flags = AI_ADDRCONFIG,
.ai_socktype = SOCK_STREAM };
+ const char *incFormat;
if (getaddrinfo("::", NULL, &hints, &info) == 0) {
freeaddrinfo(info);
@@ -2605,21 +2607,27 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
} else {
/* listenAddress is a hostname */
}
- } else {
+ } else if (qemuIPv6Capable && hostIPv6Capable) {
/* Listen on :: instead of 0.0.0.0 if QEMU understands it
* and there is at least one IPv6 address configured
*/
- listenAddress = qemuIPv6Capable && hostIPv6Capable ?
- encloseAddress = true, "::" : "0.0.0.0";
+ listenAddress = "::";
+ encloseAddress = true;
+ } else {
+ listenAddress = "0.0.0.0";
}
- /* QEMU will be started with -incoming [<IPv6 addr>]:port,
- * -incoming <IPv4 addr>:port or -incoming <hostname>:port
+ /* QEMU will be started with
+ * -incoming protocol:[<IPv6 addr>]:port,
+ * -incoming protocol:<IPv4 addr>:port, or
+ * -incoming protocol:<hostname>:port
*/
- if ((encloseAddress &&
- virAsprintf(&migrateFrom, "tcp:[%s]:%d", listenAddress, port)
< 0) ||
- (!encloseAddress &&
- virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddress, port)
< 0))
+ if (encloseAddress)
+ incFormat = "%s:[%s]:%d";
+ else
+ incFormat = "%s:%s:%d";
+ if (virAsprintf(&migrateFrom, incFormat,
+ protocol, listenAddress, port) < 0)
goto cleanup;
}
@@ -2812,7 +2820,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, origname,
- st, 0, false, NULL, flags);
+ st, NULL, 0, false, NULL, flags);
return ret;
}
@@ -2953,7 +2961,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
VIR_DEBUG("Generated uri_out=%s", *uri_out);
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, origname,
- NULL, port, autoPort, listenAddress, flags);
+ NULL, uri ? uri->scheme : "tcp",
+ port, autoPort, listenAddress, flags);
cleanup:
virURIFree(uri);
VIR_FREE(hostname);
@@ -3169,6 +3178,7 @@ struct _qemuMigrationSpec {
enum qemuMigrationDestinationType destType;
union {
struct {
+ const char *protocol;
const char *name;
int port;
} host;
@@ -3536,6 +3546,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
switch (spec->destType) {
case MIGRATION_DEST_HOST:
ret = qemuMonitorMigrateToHost(priv->mon, migrate_flags,
+ spec->dest.host.protocol,
spec->dest.host.name,
spec->dest.host.port);
break;
@@ -3676,7 +3687,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
goto cleanup;
}
-/* Perform migration using QEMU's native TCP migrate support,
+/* Perform migration using QEMU's native migrate support,
* not encrypted obviously
*/
static int doNativeMigrate(virQEMUDriverPtr driver,
@@ -3710,6 +3721,7 @@ static int doNativeMigrate(virQEMUDriverPtr driver,
spec.destType = MIGRATION_DEST_CONNECT_HOST;
else
spec.destType = MIGRATION_DEST_HOST;
+ spec.dest.host.protocol = uribits->scheme;
spec.dest.host.name = uribits->server;
spec.dest.host.port = uribits->port;
spec.fwdType = MIGRATION_FWD_DIRECT;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 3603cd8..31ab37d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2205,6 +2205,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
unsigned int flags,
+ const char *protocol,
const char *hostname,
int port)
{
@@ -2220,7 +2221,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
}
- if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0)
+ if (virAsprintf(&uri, "%s:%s:%d", protocol, hostname, port) < 0)
return -1;
if (mon->json)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 5fb83ff..ca11631 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -485,6 +485,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
unsigned int flags,
+ const char *protocol,
const char *hostname,
int port);
--
2.1.0