提交 e16a39fc 编写于 作者: J Jiri Denemark

qemu: Prepare support for arbitrary migration protocol

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: NJiri Denemark <jdenemar@redhat.com>
上级 1cffb25c
...@@ -2457,6 +2457,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, ...@@ -2457,6 +2457,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
virDomainDefPtr *def, virDomainDefPtr *def,
const char *origname, const char *origname,
virStreamPtr st, virStreamPtr st,
const char *protocol,
unsigned short port, unsigned short port,
bool autoPort, bool autoPort,
const char *listenAddress, const char *listenAddress,
...@@ -2569,6 +2570,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, ...@@ -2569,6 +2570,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
struct addrinfo *info = NULL; struct addrinfo *info = NULL;
struct addrinfo hints = { .ai_flags = AI_ADDRCONFIG, struct addrinfo hints = { .ai_flags = AI_ADDRCONFIG,
.ai_socktype = SOCK_STREAM }; .ai_socktype = SOCK_STREAM };
const char *incFormat;
if (getaddrinfo("::", NULL, &hints, &info) == 0) { if (getaddrinfo("::", NULL, &hints, &info) == 0) {
freeaddrinfo(info); freeaddrinfo(info);
...@@ -2605,21 +2607,27 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, ...@@ -2605,21 +2607,27 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
} else { } else {
/* listenAddress is a hostname */ /* listenAddress is a hostname */
} }
} else { } else if (qemuIPv6Capable && hostIPv6Capable) {
/* Listen on :: instead of 0.0.0.0 if QEMU understands it /* Listen on :: instead of 0.0.0.0 if QEMU understands it
* and there is at least one IPv6 address configured * and there is at least one IPv6 address configured
*/ */
listenAddress = qemuIPv6Capable && hostIPv6Capable ? listenAddress = "::";
encloseAddress = true, "::" : "0.0.0.0"; encloseAddress = true;
} else {
listenAddress = "0.0.0.0";
} }
/* QEMU will be started with -incoming [<IPv6 addr>]:port, /* QEMU will be started with
* -incoming <IPv4 addr>:port or -incoming <hostname>:port * -incoming protocol:[<IPv6 addr>]:port,
* -incoming protocol:<IPv4 addr>:port, or
* -incoming protocol:<hostname>:port
*/ */
if ((encloseAddress && if (encloseAddress)
virAsprintf(&migrateFrom, "tcp:[%s]:%d", listenAddress, port) < 0) || incFormat = "%s:[%s]:%d";
(!encloseAddress && else
virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddress, port) < 0)) incFormat = "%s:%s:%d";
if (virAsprintf(&migrateFrom, incFormat,
protocol, listenAddress, port) < 0)
goto cleanup; goto cleanup;
} }
...@@ -2812,7 +2820,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, ...@@ -2812,7 +2820,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen, ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, origname, cookieout, cookieoutlen, def, origname,
st, 0, false, NULL, flags); st, NULL, 0, false, NULL, flags);
return ret; return ret;
} }
...@@ -2955,7 +2963,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, ...@@ -2955,7 +2963,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen, ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, origname, cookieout, cookieoutlen, def, origname,
NULL, port, autoPort, listenAddress, flags); NULL, uri ? uri->scheme : "tcp",
port, autoPort, listenAddress, flags);
cleanup: cleanup:
virURIFree(uri); virURIFree(uri);
VIR_FREE(hostname); VIR_FREE(hostname);
...@@ -3171,6 +3180,7 @@ struct _qemuMigrationSpec { ...@@ -3171,6 +3180,7 @@ struct _qemuMigrationSpec {
enum qemuMigrationDestinationType destType; enum qemuMigrationDestinationType destType;
union { union {
struct { struct {
const char *protocol;
const char *name; const char *name;
int port; int port;
} host; } host;
...@@ -3538,6 +3548,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, ...@@ -3538,6 +3548,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
switch (spec->destType) { switch (spec->destType) {
case MIGRATION_DEST_HOST: case MIGRATION_DEST_HOST:
ret = qemuMonitorMigrateToHost(priv->mon, migrate_flags, ret = qemuMonitorMigrateToHost(priv->mon, migrate_flags,
spec->dest.host.protocol,
spec->dest.host.name, spec->dest.host.name,
spec->dest.host.port); spec->dest.host.port);
break; break;
...@@ -3678,7 +3689,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, ...@@ -3678,7 +3689,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
/* Perform migration using QEMU's native TCP migrate support, /* Perform migration using QEMU's native migrate support,
* not encrypted obviously * not encrypted obviously
*/ */
static int doNativeMigrate(virQEMUDriverPtr driver, static int doNativeMigrate(virQEMUDriverPtr driver,
...@@ -3712,6 +3723,7 @@ static int doNativeMigrate(virQEMUDriverPtr driver, ...@@ -3712,6 +3723,7 @@ static int doNativeMigrate(virQEMUDriverPtr driver,
spec.destType = MIGRATION_DEST_CONNECT_HOST; spec.destType = MIGRATION_DEST_CONNECT_HOST;
else else
spec.destType = MIGRATION_DEST_HOST; spec.destType = MIGRATION_DEST_HOST;
spec.dest.host.protocol = uribits->scheme;
spec.dest.host.name = uribits->server; spec.dest.host.name = uribits->server;
spec.dest.host.port = uribits->port; spec.dest.host.port = uribits->port;
spec.fwdType = MIGRATION_FWD_DIRECT; spec.fwdType = MIGRATION_FWD_DIRECT;
......
...@@ -2231,6 +2231,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon, ...@@ -2231,6 +2231,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
int qemuMonitorMigrateToHost(qemuMonitorPtr mon, int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *protocol,
const char *hostname, const char *hostname,
int port) int port)
{ {
...@@ -2246,7 +2247,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon, ...@@ -2246,7 +2247,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; return -1;
if (mon->json) if (mon->json)
......
...@@ -505,6 +505,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon, ...@@ -505,6 +505,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
int qemuMonitorMigrateToHost(qemuMonitorPtr mon, int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *protocol,
const char *hostname, const char *hostname,
int port); int port);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册