qemu: Implement support for VIR_MIGRATE_PARAM_LISTEN_ADDRESS

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2013-10-08 14:41:44 +02:00
parent 1f9546e365
commit c4ac7ef663
3 changed files with 103 additions and 50 deletions

View File

@ -10036,7 +10036,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
ret = qemuMigrationPrepareDirect(driver, dconn, ret = qemuMigrationPrepareDirect(driver, dconn,
NULL, 0, NULL, NULL, /* No cookies */ NULL, 0, NULL, NULL, /* No cookies */
uri_in, uri_out, uri_in, uri_out,
&def, origname, flags); &def, origname, NULL, flags);
cleanup: cleanup:
VIR_FREE(origname); VIR_FREE(origname);
@ -10087,7 +10087,8 @@ qemuDomainMigratePerform(virDomainPtr dom,
* Consume any cookie we were able to decode though * Consume any cookie we were able to decode though
*/ */
ret = qemuMigrationPerform(driver, dom->conn, vm, ret = qemuMigrationPerform(driver, dom->conn, vm,
NULL, dconnuri, uri, NULL, cookie, cookielen, NULL, dconnuri, uri, NULL, NULL,
cookie, cookielen,
NULL, NULL, /* No output cookies in v2 */ NULL, NULL, /* No output cookies in v2 */
flags, dname, resource, false); flags, dname, resource, false);
@ -10241,7 +10242,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
cookiein, cookieinlen, cookiein, cookieinlen,
cookieout, cookieoutlen, cookieout, cookieoutlen,
uri_in, uri_out, uri_in, uri_out,
&def, origname, flags); &def, origname, NULL, flags);
cleanup: cleanup:
VIR_FREE(origname); VIR_FREE(origname);
@ -10265,6 +10266,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
const char *dom_xml = NULL; const char *dom_xml = NULL;
const char *dname = NULL; const char *dname = NULL;
const char *uri_in = NULL; const char *uri_in = NULL;
const char *listenAddress = NULL;
char *origname = NULL; char *origname = NULL;
int ret = -1; int ret = -1;
@ -10280,7 +10282,10 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
&dname) < 0 || &dname) < 0 ||
virTypedParamsGetString(params, nparams, virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_URI, VIR_MIGRATE_PARAM_URI,
&uri_in) < 0) &uri_in) < 0 ||
virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_LISTEN_ADDRESS,
&listenAddress) < 0)
return -1; return -1;
if (flags & VIR_MIGRATE_TUNNELLED) { if (flags & VIR_MIGRATE_TUNNELLED) {
@ -10303,7 +10308,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
cookiein, cookieinlen, cookiein, cookieinlen,
cookieout, cookieoutlen, cookieout, cookieoutlen,
uri_in, uri_out, uri_in, uri_out,
&def, origname, flags); &def, origname, listenAddress, flags);
cleanup: cleanup:
VIR_FREE(origname); VIR_FREE(origname);
@ -10435,7 +10440,8 @@ qemuDomainMigratePerform3(virDomainPtr dom,
} }
return qemuMigrationPerform(driver, dom->conn, vm, xmlin, return qemuMigrationPerform(driver, dom->conn, vm, xmlin,
dconnuri, uri, NULL, cookiein, cookieinlen, dconnuri, uri, NULL, NULL,
cookiein, cookieinlen,
cookieout, cookieoutlen, cookieout, cookieoutlen,
flags, dname, resource, true); flags, dname, resource, true);
} }
@ -10457,6 +10463,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
const char *dname = NULL; const char *dname = NULL;
const char *uri = NULL; const char *uri = NULL;
const char *graphicsuri = NULL; const char *graphicsuri = NULL;
const char *listenAddress = NULL;
unsigned long long bandwidth = 0; unsigned long long bandwidth = 0;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1); virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@ -10477,7 +10484,10 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
&bandwidth) < 0 || &bandwidth) < 0 ||
virTypedParamsGetString(params, nparams, virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_MIGRATE_PARAM_GRAPHICS_URI,
&graphicsuri) < 0) &graphicsuri) < 0 ||
virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_LISTEN_ADDRESS,
&listenAddress) < 0)
return -1; return -1;
if (!(vm = qemuDomObjFromDomain(dom))) if (!(vm = qemuDomObjFromDomain(dom)))
@ -10489,7 +10499,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
} }
return qemuMigrationPerform(driver, dom->conn, vm, dom_xml, return qemuMigrationPerform(driver, dom->conn, vm, dom_xml,
dconnuri, uri, graphicsuri, dconnuri, uri, graphicsuri, listenAddress,
cookiein, cookieinlen, cookieout, cookieoutlen, cookiein, cookieinlen, cookieout, cookieoutlen,
flags, dname, bandwidth, true); flags, dname, bandwidth, true);
} }

View File

@ -1097,12 +1097,6 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
unsigned short port = 0; unsigned short port = 0;
char *diskAlias = NULL; char *diskAlias = NULL;
size_t i; size_t i;
const char *host;
if (STREQ(listenAddr, "[::]"))
host = "::";
else
host = listenAddr;
for (i = 0; i < vm->def->ndisks; i++) { for (i = 0; i < vm->def->ndisks; i++) {
virDomainDiskDefPtr disk = vm->def->disks[i]; virDomainDiskDefPtr disk = vm->def->disks[i];
@ -1122,7 +1116,7 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
if (!port && if (!port &&
((virPortAllocatorAcquire(driver->remotePorts, &port) < 0) || ((virPortAllocatorAcquire(driver->remotePorts, &port) < 0) ||
(qemuMonitorNBDServerStart(priv->mon, host, port) < 0))) { (qemuMonitorNBDServerStart(priv->mon, listenAddr, port) < 0))) {
qemuDomainObjExitMonitor(driver, vm); qemuDomainObjExitMonitor(driver, vm);
goto cleanup; goto cleanup;
} }
@ -2163,6 +2157,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
const char *origname, const char *origname,
virStreamPtr st, virStreamPtr st,
unsigned int port, unsigned int port,
const char *listenAddress,
unsigned long flags) unsigned long flags)
{ {
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
@ -2176,7 +2171,6 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
char *xmlout = NULL; char *xmlout = NULL;
unsigned int cookieFlags; unsigned int cookieFlags;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
const char *listenAddr = NULL;
char *migrateFrom = NULL; char *migrateFrom = NULL;
bool abort_on_error = !!(flags & VIR_MIGRATE_ABORT_ON_ERROR); bool abort_on_error = !!(flags & VIR_MIGRATE_ABORT_ON_ERROR);
@ -2260,31 +2254,65 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
if (VIR_STRDUP(migrateFrom, "stdio") < 0) if (VIR_STRDUP(migrateFrom, "stdio") < 0)
goto cleanup; goto cleanup;
} else { } else {
virSocketAddr listenAddressSocket;
bool encloseAddress = false;
bool hostIPv6Capable = false;
bool qemuIPv6Capable = false;
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
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 };
if (getaddrinfo("::", NULL, &hints, &info) == 0) {
freeaddrinfo(info);
hostIPv6Capable = true;
}
if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache, if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
(*def)->emulator))) (*def)->emulator)))
goto cleanup; goto cleanup;
/* Listen on :: instead of 0.0.0.0 if QEMU understands it qemuIPv6Capable = virQEMUCapsGet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION);
* and there is at least one IPv6 address configured
*/
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION) &&
getaddrinfo("::", NULL, &hints, &info) == 0) {
freeaddrinfo(info);
listenAddr = "[::]";
} else {
listenAddr = "0.0.0.0";
}
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
/* QEMU will be started with -incoming [::]:port if (listenAddress) {
* or -incoming 0.0.0.0:port if (virSocketAddrIsNumeric(listenAddress)) {
/* listenAddress is numeric IPv4 or IPv6 */
if (virSocketAddrParse(&listenAddressSocket, listenAddress, AF_UNSPEC) < 0)
goto cleanup;
/* address parsed successfully */
if (VIR_SOCKET_ADDR_IS_FAMILY(&listenAddressSocket, AF_INET6)) {
if (!qemuIPv6Capable) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("qemu isn't capable of IPv6"));
goto cleanup;
}
if (!hostIPv6Capable) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("host isn't capable of IPv6"));
goto cleanup;
}
/* IPv6 address must be escaped in brackets on the cmd line */
encloseAddress = true;
}
} else {
/* listenAddress is a hostname */
}
} else {
/* 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";
}
/* QEMU will be started with -incoming [<IPv6 addr>]:port,
* -incoming <IPv4 addr>:port or -incoming <hostname>:port
*/ */
if (virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddr, port) < 0) if ((encloseAddress &&
virAsprintf(&migrateFrom, "tcp:[%s]:%d", listenAddress, port) < 0) ||
(!encloseAddress &&
virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddress, port) < 0))
goto cleanup; goto cleanup;
} }
@ -2371,7 +2399,7 @@ done:
if (mig->nbd && if (mig->nbd &&
flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC) && flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC) &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_SERVER)) { virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_SERVER)) {
if (qemuMigrationStartNBDServer(driver, vm, listenAddr) < 0) { if (qemuMigrationStartNBDServer(driver, vm, listenAddress) < 0) {
/* error already reported */ /* error already reported */
goto endjob; goto endjob;
} }
@ -2475,7 +2503,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, flags); st, 0, NULL, flags);
return ret; return ret;
} }
@ -2491,6 +2519,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
char **uri_out, char **uri_out,
virDomainDefPtr *def, virDomainDefPtr *def,
const char *origname, const char *origname,
const char *listenAddress,
unsigned long flags) unsigned long flags)
{ {
static int port = 0; static int port = 0;
@ -2596,7 +2625,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen, ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, origname, cookieout, cookieoutlen, def, origname,
NULL, this_port, flags); NULL, this_port, listenAddress, flags);
cleanup: cleanup:
virURIFree(uri); virURIFree(uri);
VIR_FREE(hostname); VIR_FREE(hostname);
@ -3600,6 +3629,7 @@ doPeer2PeerMigrate3(virQEMUDriverPtr driver,
const char *dname, const char *dname,
const char *uri, const char *uri,
const char *graphicsuri, const char *graphicsuri,
const char *listenAddress,
unsigned long long bandwidth, unsigned long long bandwidth,
bool useParams, bool useParams,
unsigned long flags) unsigned long flags)
@ -3621,11 +3651,11 @@ doPeer2PeerMigrate3(virQEMUDriverPtr driver,
int maxparams = 0; int maxparams = 0;
VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, dconnuri=%s, vm=%p, xmlin=%s, " VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, dconnuri=%s, vm=%p, xmlin=%s, "
"dname=%s, uri=%s, graphicsuri=%s, bandwidth=%llu, " "dname=%s, uri=%s, graphicsuri=%s, listenAddress=%s, "
"useParams=%d, flags=%lx", "bandwidth=%llu, useParams=%d, flags=%lx",
driver, sconn, dconn, NULLSTR(dconnuri), vm, NULLSTR(xmlin), driver, sconn, dconn, NULLSTR(dconnuri), vm, NULLSTR(xmlin),
NULLSTR(dname), NULLSTR(uri), NULLSTR(graphicsuri), bandwidth, NULLSTR(dname), NULLSTR(uri), NULLSTR(graphicsuri),
useParams, flags); NULLSTR(listenAddress), bandwidth, useParams, flags);
/* Unlike the virDomainMigrateVersion3 counterpart, we don't need /* Unlike the virDomainMigrateVersion3 counterpart, we don't need
* to worry about auto-setting the VIR_MIGRATE_CHANGE_PROTECTION * to worry about auto-setting the VIR_MIGRATE_CHANGE_PROTECTION
@ -3663,6 +3693,11 @@ doPeer2PeerMigrate3(virQEMUDriverPtr driver,
VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_MIGRATE_PARAM_GRAPHICS_URI,
graphicsuri) < 0) graphicsuri) < 0)
goto cleanup; goto cleanup;
if (listenAddress &&
virTypedParamsAddString(&params, &nparams, &maxparams,
VIR_MIGRATE_PARAM_LISTEN_ADDRESS,
listenAddress) < 0)
goto cleanup;
} }
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED)
@ -3867,6 +3902,7 @@ static int doPeer2PeerMigrate(virQEMUDriverPtr driver,
const char *dconnuri, const char *dconnuri,
const char *uri, const char *uri,
const char *graphicsuri, const char *graphicsuri,
const char *listenAddress,
unsigned long flags, unsigned long flags,
const char *dname, const char *dname,
unsigned long resource, unsigned long resource,
@ -3881,10 +3917,11 @@ static int doPeer2PeerMigrate(virQEMUDriverPtr driver,
bool useParams; bool useParams;
VIR_DEBUG("driver=%p, sconn=%p, vm=%p, xmlin=%s, dconnuri=%s, " VIR_DEBUG("driver=%p, sconn=%p, vm=%p, xmlin=%s, dconnuri=%s, "
"uri=%s, graphicsuri=%s, flags=%lx, dname=%s, resource=%lu", "uri=%s, graphicsuri=%s, listenAddress=%s, flags=%lx, "
"dname=%s, resource=%lu",
driver, sconn, vm, NULLSTR(xmlin), NULLSTR(dconnuri), driver, sconn, vm, NULLSTR(xmlin), NULLSTR(dconnuri),
NULLSTR(uri), NULLSTR(graphicsuri), flags, NULLSTR(dname), NULLSTR(uri), NULLSTR(graphicsuri), NULLSTR(listenAddress),
resource); flags, NULLSTR(dname), resource);
/* the order of operations is important here; we make sure the /* the order of operations is important here; we make sure the
* destination side is completely setup before we touch the source * destination side is completely setup before we touch the source
@ -3959,8 +3996,8 @@ static int doPeer2PeerMigrate(virQEMUDriverPtr driver,
if (*v3proto) { if (*v3proto) {
ret = doPeer2PeerMigrate3(driver, sconn, dconn, dconnuri, vm, xmlin, ret = doPeer2PeerMigrate3(driver, sconn, dconn, dconnuri, vm, xmlin,
dname, uri, graphicsuri, resource, dname, uri, graphicsuri, listenAddress,
useParams, flags); resource, useParams, flags);
} else { } else {
ret = doPeer2PeerMigrate2(driver, sconn, dconn, vm, ret = doPeer2PeerMigrate2(driver, sconn, dconn, vm,
dconnuri, flags, dname, resource); dconnuri, flags, dname, resource);
@ -3994,6 +4031,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
const char *uri, const char *uri,
const char *graphicsuri, const char *graphicsuri,
const char *cookiein, const char *cookiein,
const char *listenAddress,
int cookieinlen, int cookieinlen,
char **cookieout, char **cookieout,
int *cookieoutlen, int *cookieoutlen,
@ -4028,8 +4066,8 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) { if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) {
ret = doPeer2PeerMigrate(driver, conn, vm, xmlin, ret = doPeer2PeerMigrate(driver, conn, vm, xmlin,
dconnuri, uri, graphicsuri, flags, dname, dconnuri, uri, graphicsuri, listenAddress,
resource, &v3proto); flags, dname, resource, &v3proto);
} else { } else {
qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_PERFORM2); qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_PERFORM2);
ret = doNativeMigrate(driver, vm, uri, cookiein, cookieinlen, ret = doNativeMigrate(driver, vm, uri, cookiein, cookieinlen,
@ -4194,6 +4232,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
const char *dconnuri, const char *dconnuri,
const char *uri, const char *uri,
const char *graphicsuri, const char *graphicsuri,
const char *listenAddress,
const char *cookiein, const char *cookiein,
int cookieinlen, int cookieinlen,
char **cookieout, char **cookieout,
@ -4220,7 +4259,8 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
} }
return qemuMigrationPerformJob(driver, conn, vm, xmlin, dconnuri, uri, return qemuMigrationPerformJob(driver, conn, vm, xmlin, dconnuri, uri,
graphicsuri, cookiein, cookieinlen, graphicsuri, listenAddress,
cookiein, cookieinlen,
cookieout, cookieoutlen, cookieout, cookieoutlen,
flags, dname, resource, v3proto); flags, dname, resource, v3proto);
} else { } else {
@ -4238,7 +4278,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
flags, resource); flags, resource);
} else { } else {
return qemuMigrationPerformJob(driver, conn, vm, xmlin, dconnuri, return qemuMigrationPerformJob(driver, conn, vm, xmlin, dconnuri,
uri, graphicsuri, uri, graphicsuri, listenAddress,
cookiein, cookieinlen, cookiein, cookieinlen,
cookieout, cookieoutlen, flags, cookieout, cookieoutlen, flags,
dname, resource, v3proto); dname, resource, v3proto);

View File

@ -43,11 +43,12 @@
/* All supported migration parameters and their types. */ /* All supported migration parameters and their types. */
# define QEMU_MIGRATION_PARAMETERS \ # define QEMU_MIGRATION_PARAMETERS \
VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING, \ VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING, \
VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING, \ VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING, \
VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING, \ VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING, \
VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG, \ VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG, \
VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING, \ VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING, \
VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING, \
NULL NULL
@ -124,6 +125,7 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
char **uri_out, char **uri_out,
virDomainDefPtr *def, virDomainDefPtr *def,
const char *origname, const char *origname,
const char *listenAddress,
unsigned long flags); unsigned long flags);
int qemuMigrationPerform(virQEMUDriverPtr driver, int qemuMigrationPerform(virQEMUDriverPtr driver,
@ -133,6 +135,7 @@ int qemuMigrationPerform(virQEMUDriverPtr driver,
const char *dconnuri, const char *dconnuri,
const char *uri, const char *uri,
const char *graphicsuri, const char *graphicsuri,
const char *listenAddress,
const char *cookiein, const char *cookiein,
int cookieinlen, int cookieinlen,
char **cookieout, char **cookieout,