#include <config.h>
+#include <netdb.h>
+#include <sys/socket.h>
#include <sys/time.h>
#ifdef WITH_GNUTLS
# include <gnutls/gnutls.h>
*/
static int
qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
- virDomainObjPtr vm)
+ virDomainObjPtr vm,
+ const char *listenAddr)
{
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
unsigned short port = 0;
- const char *listenAddr = "0.0.0.0";
char *diskAlias = NULL;
size_t i;
int *cookieoutlen,
const char *dname,
const char *dom_xml,
- const char *migrateFrom,
virStreamPtr st,
+ unsigned int port,
unsigned long flags)
{
virDomainDefPtr def = NULL;
char *xmlout = NULL;
unsigned int cookieFlags;
virCapsPtr caps = NULL;
+ const char *listenAddr = NULL;
+ char *migrateFrom = NULL;
if (virTimeMillisNow(&now) < 0)
return -1;
}
}
+ if (tunnel) {
+ /* QEMU will be started with -incoming stdio
+ * (which qemu_command might convert to exec:cat or fd:n)
+ */
+ if (!(migrateFrom = strdup("stdio"))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ } else {
+ virQEMUCapsPtr qemuCaps = NULL;
+ struct addrinfo *info = NULL;
+ struct addrinfo hints = { .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM };
+
+ if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
+ def->emulator)))
+ goto cleanup;
+
+ /* Listen on :: instead of 0.0.0.0 if QEMU understands it
+ * 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);
+
+ /* QEMU will be started with -incoming [::]:port
+ * or -incoming 0.0.0.0:port
+ */
+ if (virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddr, port) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
+
if (!(vm = virDomainObjListAdd(driver->domains,
driver->xmlconf,
def,
if (flags & VIR_MIGRATE_TUNNELLED)
VIR_DEBUG("NBD in tunnelled migration is currently not supported");
else {
- if (qemuMigrationStartNBDServer(driver, vm) < 0) {
+ if (qemuMigrationStartNBDServer(driver, vm, listenAddr) < 0) {
/* error already reported */
goto endjob;
}
ret = 0;
cleanup:
+ VIR_FREE(migrateFrom);
VIR_FREE(origname);
VIR_FREE(xmlout);
virDomainDefFree(def);
driver, dconn, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, st, NULLSTR(dname), dom_xml, flags);
- /* QEMU will be started with -incoming stdio (which qemu_command might
- * convert to exec:cat or fd:n)
- */
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, dname, dom_xml,
- "stdio", st, flags);
+ st, 0, flags);
return ret;
}
static int port = 0;
int this_port;
char *hostname = NULL;
- char migrateFrom [64];
const char *p;
+ char *uri_str = NULL;
int ret = -1;
+ virURIPtr uri;
VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
"cookieout=%p, cookieoutlen=%p, uri_in=%s, uri_out=%p, "
* URI when passing it to the qemu monitor, so bad
* characters in hostname part don't matter.
*/
- if (!STRPREFIX(uri_in, "tcp:")) {
+ if (!(p = STRSKIP(uri_in, "tcp:"))) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("only tcp URIs are supported for KVM/QEMU"
" migrations"));
goto cleanup;
}
- /* Get the port number. */
- p = strrchr(uri_in, ':');
- if (p == strchr(uri_in, ':')) {
+ /* Convert uri_in to well-formed URI with // after tcp: */
+ if (!(STRPREFIX(uri_in, "tcp://"))) {
+ if (virAsprintf(&uri_str, "tcp://%s", p) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
+
+ uri = virURIParse(uri_str ? uri_str : uri_in);
+ VIR_FREE(uri_str);
+
+ if (uri == NULL) {
+ virReportError(VIR_ERR_INVALID_ARG, _("unable to parse URI: %s"),
+ uri_in);
+ goto cleanup;
+ }
+
+ if (uri->server == NULL) {
+ virReportError(VIR_ERR_INVALID_ARG, _("missing host in migration"
+ " URI: %s"), uri_in);
+ goto cleanup;
+ } else {
+ hostname = uri->server;
+ }
+
+ if (uri->port == 0) {
/* Generate a port */
this_port = QEMUD_MIGRATION_FIRST_PORT + port++;
if (port == QEMUD_MIGRATION_NUM_PORTS)
}
} else {
- p++; /* definitely has a ':' in it, see above */
- this_port = virParseNumber(&p);
- if (this_port == -1 || p-uri_in != strlen(uri_in)) {
- virReportError(VIR_ERR_INVALID_ARG,
- "%s", _("URI ended with incorrect ':port'"));
- goto cleanup;
- }
+ this_port = uri->port;
}
}
if (*uri_out)
VIR_DEBUG("Generated uri_out=%s", *uri_out);
- /* QEMU will be started with -incoming tcp:0.0.0.0:port */
- snprintf(migrateFrom, sizeof(migrateFrom), "tcp:0.0.0.0:%d", this_port);
-
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, dname, dom_xml,
- migrateFrom, NULL, flags);
+ NULL, this_port, flags);
cleanup:
VIR_FREE(hostname);
if (ret != 0)
QEMU_CAPS_DEVICE_VMWARE_SVGA,
QEMU_CAPS_DEVICE_USB_SERIAL,
QEMU_CAPS_DEVICE_USB_NET,
- QEMU_CAPS_DTB);
+ QEMU_CAPS_DTB,
+ QEMU_CAPS_IPV6_MIGRATION);
DO_TEST("qemu-1.2.0", 1002000, 0, 0,
QEMU_CAPS_VNC_COLON,
QEMU_CAPS_NO_REBOOT,
QEMU_CAPS_DEVICE_USB_SERIAL,
QEMU_CAPS_DEVICE_USB_NET,
QEMU_CAPS_DTB,
- QEMU_CAPS_SCSI_MEGASAS);
+ QEMU_CAPS_SCSI_MEGASAS,
+ QEMU_CAPS_IPV6_MIGRATION);
DO_TEST("qemu-kvm-1.2.0", 1002000, 1, 0,
QEMU_CAPS_VNC_COLON,
QEMU_CAPS_NO_REBOOT,
QEMU_CAPS_DEVICE_USB_SERIAL,
QEMU_CAPS_DEVICE_USB_NET,
QEMU_CAPS_DTB,
- QEMU_CAPS_SCSI_MEGASAS);
+ QEMU_CAPS_SCSI_MEGASAS,
+ QEMU_CAPS_IPV6_MIGRATION);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}