2014-05-08 21:56:51 +00:00
|
|
|
/*
|
|
|
|
* libxl_migration.c: methods for handling migration with libxenlight
|
|
|
|
*
|
2015-02-11 23:40:07 +00:00
|
|
|
* Copyright (C) 2014-2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
2014-05-08 21:56:51 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Jim Fehlig <jfehlig@suse.com>
|
|
|
|
* Chunyan Liu <cyliu@suse.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "virlog.h"
|
|
|
|
#include "virerror.h"
|
|
|
|
#include "virconf.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "virfile.h"
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "viruuid.h"
|
|
|
|
#include "vircommand.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "virobject.h"
|
2014-11-12 22:32:02 +00:00
|
|
|
#include "virthread.h"
|
2016-07-11 11:55:53 +00:00
|
|
|
#include "virhook.h"
|
2014-05-08 21:56:51 +00:00
|
|
|
#include "rpc/virnetsocket.h"
|
|
|
|
#include "libxl_domain.h"
|
|
|
|
#include "libxl_driver.h"
|
|
|
|
#include "libxl_conf.h"
|
|
|
|
#include "libxl_migration.h"
|
2015-04-14 20:38:46 +00:00
|
|
|
#include "locking/domain_lock.h"
|
2016-02-05 20:45:02 +00:00
|
|
|
#include "virtypedparam.h"
|
2017-03-07 09:34:47 +00:00
|
|
|
#include "virfdstream.h"
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
|
|
|
|
|
|
|
VIR_LOG_INIT("libxl.libxl_migration");
|
|
|
|
|
2016-04-29 21:08:05 +00:00
|
|
|
typedef struct _libxlMigrationCookie libxlMigrationCookie;
|
|
|
|
typedef libxlMigrationCookie *libxlMigrationCookiePtr;
|
|
|
|
struct _libxlMigrationCookie {
|
|
|
|
/* Host properties */
|
|
|
|
char *srcHostname;
|
|
|
|
uint32_t xenMigStreamVer;
|
|
|
|
|
|
|
|
/* Guest properties */
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
typedef struct _libxlMigrationDstArgs {
|
|
|
|
virObject parent;
|
|
|
|
|
2014-11-12 22:32:02 +00:00
|
|
|
int recvfd;
|
2014-05-08 21:56:51 +00:00
|
|
|
virConnectPtr conn;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
unsigned int flags;
|
2016-04-29 21:08:05 +00:00
|
|
|
libxlMigrationCookiePtr migcookie;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
/* for freeing listen sockets */
|
|
|
|
virNetSocketPtr *socks;
|
|
|
|
size_t nsocks;
|
|
|
|
} libxlMigrationDstArgs;
|
|
|
|
|
|
|
|
static virClassPtr libxlMigrationDstArgsClass;
|
|
|
|
|
2016-04-29 21:08:05 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
libxlMigrationCookieFree(libxlMigrationCookiePtr mig)
|
|
|
|
{
|
|
|
|
if (!mig)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(mig->srcHostname);
|
|
|
|
VIR_FREE(mig->name);
|
|
|
|
VIR_FREE(mig);
|
|
|
|
}
|
|
|
|
|
|
|
|
static libxlMigrationCookiePtr
|
|
|
|
libxlMigrationCookieNew(virDomainObjPtr dom)
|
|
|
|
{
|
|
|
|
libxlMigrationCookiePtr mig = NULL;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(mig) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(mig->name, dom->def->name) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
if (!(mig->srcHostname = virGetHostname()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
mig->xenMigStreamVer = LIBXL_SAVE_VERSION;
|
|
|
|
|
|
|
|
return mig;
|
|
|
|
|
|
|
|
error:
|
|
|
|
libxlMigrationCookieFree(mig);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
libxlMigrationBakeCookie(libxlMigrationCookiePtr mig,
|
|
|
|
char **cookieout,
|
|
|
|
int *cookieoutlen)
|
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
if (!cookieout || !cookieoutlen)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*cookieoutlen = 0;
|
|
|
|
virUUIDFormat(mig->uuid, uuidstr);
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, "<libxl-migration>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
|
|
|
virBufferEscapeString(&buf, "<name>%s</name>\n", mig->name);
|
|
|
|
virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", uuidstr);
|
|
|
|
virBufferEscapeString(&buf, "<hostname>%s</hostname>\n", mig->srcHostname);
|
|
|
|
virBufferAsprintf(&buf, "<migration-stream-version>%u</migration-stream-version>\n", mig->xenMigStreamVer);
|
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</libxl-migration>\n");
|
|
|
|
|
|
|
|
if (virBufferCheckError(&buf) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*cookieout = virBufferContentAndReset(&buf);
|
|
|
|
*cookieoutlen = strlen(*cookieout) + 1;
|
|
|
|
|
|
|
|
VIR_DEBUG("cookielen=%d cookie=%s", *cookieoutlen, *cookieout);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
libxlMigrationEatCookie(const char *cookiein,
|
|
|
|
int cookieinlen,
|
|
|
|
libxlMigrationCookiePtr *migout)
|
|
|
|
{
|
|
|
|
libxlMigrationCookiePtr mig = NULL;
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
char *uuidstr = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assume a legacy (V1) migration stream if request came from a
|
|
|
|
* source host without cookie support, and hence no way to
|
|
|
|
* specify a stream version.
|
|
|
|
*/
|
|
|
|
if (!cookiein || !cookieinlen) {
|
|
|
|
if (VIR_ALLOC(mig) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
mig->xenMigStreamVer = 1;
|
|
|
|
*migout = mig;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cookiein[cookieinlen-1] != '\0') {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Migration cookie was not NULL terminated"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("cookielen=%d cookie='%s'", cookieinlen, NULLSTR(cookiein));
|
|
|
|
|
|
|
|
if (VIR_ALLOC(mig) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(doc = virXMLParseStringCtxt(cookiein,
|
|
|
|
_("(libxl_migration_cookie)"),
|
|
|
|
&ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Extract domain name */
|
|
|
|
if (!(mig->name = virXPathString("string(./name[1])", ctxt))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing name element in migration data"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract domain uuid */
|
|
|
|
uuidstr = virXPathString("string(./uuid[1])", ctxt);
|
|
|
|
if (!uuidstr) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing uuid element in migration data"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virUUIDParse(uuidstr, mig->uuid) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("malformed uuid element"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXPathUInt("string(./migration-stream-version[1])",
|
|
|
|
ctxt, &mig->xenMigStreamVer) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing Xen migration stream version"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*migout = mig;
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
error:
|
|
|
|
libxlMigrationCookieFree(mig);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(uuidstr);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
static void
|
|
|
|
libxlMigrationDstArgsDispose(void *obj)
|
|
|
|
{
|
|
|
|
libxlMigrationDstArgs *args = obj;
|
|
|
|
|
2016-04-29 21:08:05 +00:00
|
|
|
libxlMigrationCookieFree(args->migcookie);
|
2014-05-08 21:56:51 +00:00
|
|
|
VIR_FREE(args->socks);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
libxlMigrationDstArgsOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!(libxlMigrationDstArgsClass = virClassNew(virClassForObject(),
|
|
|
|
"libxlMigrationDstArgs",
|
|
|
|
sizeof(libxlMigrationDstArgs),
|
|
|
|
libxlMigrationDstArgsDispose)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(libxlMigrationDstArgs)
|
|
|
|
|
|
|
|
static void
|
2014-11-12 22:32:02 +00:00
|
|
|
libxlDoMigrateReceive(void *opaque)
|
2014-05-08 21:56:51 +00:00
|
|
|
{
|
|
|
|
libxlMigrationDstArgs *args = opaque;
|
|
|
|
virDomainObjPtr vm = args->vm;
|
|
|
|
virNetSocketPtr *socks = args->socks;
|
|
|
|
size_t nsocks = args->nsocks;
|
2014-11-12 22:32:02 +00:00
|
|
|
libxlDriverPrivatePtr driver = args->conn->privateData;
|
|
|
|
int recvfd = args->recvfd;
|
2014-05-08 21:56:51 +00:00
|
|
|
size_t i;
|
|
|
|
int ret;
|
2015-07-16 18:24:32 +00:00
|
|
|
bool remove_dom = 0;
|
|
|
|
|
2016-06-12 10:30:00 +00:00
|
|
|
virObjectRef(vm);
|
2015-07-16 18:24:32 +00:00
|
|
|
virObjectLock(vm);
|
|
|
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
|
|
|
goto cleanup;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2014-11-13 00:15:37 +00:00
|
|
|
/*
|
|
|
|
* Always start the domain paused. If needed, unpause in the
|
|
|
|
* finish phase, after transfer of the domain is complete.
|
|
|
|
*/
|
2016-04-29 21:08:05 +00:00
|
|
|
ret = libxlDomainStartRestore(driver, vm, true, recvfd,
|
|
|
|
args->migcookie->xenMigStreamVer);
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
if (ret < 0 && !vm->persistent)
|
2015-07-16 18:24:32 +00:00
|
|
|
remove_dom = true;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2014-11-12 22:32:02 +00:00
|
|
|
/* Remove all listen socks from event handler, and close them. */
|
|
|
|
for (i = 0; i < nsocks; i++) {
|
|
|
|
virNetSocketRemoveIOCallback(socks[i]);
|
|
|
|
virNetSocketClose(socks[i]);
|
|
|
|
virObjectUnref(socks[i]);
|
|
|
|
socks[i] = NULL;
|
|
|
|
}
|
|
|
|
args->nsocks = 0;
|
|
|
|
VIR_FORCE_CLOSE(recvfd);
|
2015-07-15 22:35:50 +00:00
|
|
|
virObjectUnref(args);
|
2015-07-16 18:24:32 +00:00
|
|
|
|
2016-06-12 10:30:00 +00:00
|
|
|
libxlDomainObjEndJob(driver, vm);
|
2015-07-16 18:24:32 +00:00
|
|
|
|
|
|
|
cleanup:
|
2016-08-03 12:48:01 +00:00
|
|
|
if (remove_dom) {
|
2015-07-16 18:24:32 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
2016-06-12 10:30:00 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-11-12 22:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
libxlMigrateReceive(virNetSocketPtr sock,
|
|
|
|
int events ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
libxlMigrationDstArgs *args = opaque;
|
|
|
|
virNetSocketPtr *socks = args->socks;
|
|
|
|
size_t nsocks = args->nsocks;
|
|
|
|
virNetSocketPtr client_sock;
|
|
|
|
int recvfd = -1;
|
|
|
|
virThread thread;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* Accept migration connection */
|
2014-12-01 16:10:18 +00:00
|
|
|
if (virNetSocketAccept(sock, &client_sock) < 0 || !client_sock) {
|
2014-11-12 22:32:02 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Failed to accept migration connection"));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Accepted migration connection."
|
2017-03-16 07:39:32 +00:00
|
|
|
" Spawning thread to process migration data");
|
2014-11-12 22:32:02 +00:00
|
|
|
recvfd = virNetSocketDupFD(client_sock, true);
|
|
|
|
virObjectUnref(client_sock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid blocking the event loop. Start a thread to receive
|
|
|
|
* the migration data
|
|
|
|
*/
|
|
|
|
args->recvfd = recvfd;
|
|
|
|
if (virThreadCreate(&thread, false,
|
|
|
|
libxlDoMigrateReceive, args) < 0) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Failed to create thread for receiving migration data"));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
2014-05-08 21:56:51 +00:00
|
|
|
/* Remove all listen socks from event handler, and close them. */
|
|
|
|
for (i = 0; i < nsocks; i++) {
|
|
|
|
virNetSocketUpdateIOCallback(socks[i], 0);
|
|
|
|
virNetSocketRemoveIOCallback(socks[i]);
|
|
|
|
virNetSocketClose(socks[i]);
|
|
|
|
socks[i] = NULL;
|
|
|
|
}
|
|
|
|
args->nsocks = 0;
|
|
|
|
VIR_FORCE_CLOSE(recvfd);
|
2015-07-15 22:35:50 +00:00
|
|
|
virObjectUnref(args);
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
libxlDoMigrateSend(libxlDriverPrivatePtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
unsigned long flags,
|
|
|
|
int sockfd)
|
|
|
|
{
|
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
|
|
|
int xl_flags = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (flags & VIR_MIGRATE_LIVE)
|
|
|
|
xl_flags = LIBXL_SUSPEND_LIVE;
|
|
|
|
|
2015-02-11 23:40:07 +00:00
|
|
|
ret = libxl_domain_suspend(cfg->ctx, vm->def->id, sockfd,
|
2014-05-08 21:56:51 +00:00
|
|
|
xl_flags, NULL);
|
|
|
|
if (ret != 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Failed to send migration data to destination host"));
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
libxlDomainMigrationIsAllowed(virDomainDefPtr def)
|
|
|
|
{
|
|
|
|
/* Migration is not allowed if definition contains any hostdevs */
|
|
|
|
if (def->nhostdevs > 0) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("domain has assigned host devices"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
libxlDomainMigrationBegin(virConnectPtr conn,
|
|
|
|
virDomainObjPtr vm,
|
2016-04-29 21:08:05 +00:00
|
|
|
const char *xmlin,
|
|
|
|
char **cookieout,
|
|
|
|
int *cookieoutlen)
|
2014-05-08 21:56:51 +00:00
|
|
|
{
|
|
|
|
libxlDriverPrivatePtr driver = conn->privateData;
|
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
2016-05-16 12:20:46 +00:00
|
|
|
libxlMigrationCookiePtr mig = NULL;
|
2014-05-08 21:56:51 +00:00
|
|
|
virDomainDefPtr tmpdef = NULL;
|
|
|
|
virDomainDefPtr def;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
|
|
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-04-29 21:08:05 +00:00
|
|
|
if (!(mig = libxlMigrationCookieNew(vm)))
|
|
|
|
goto endjob;
|
|
|
|
|
|
|
|
if (libxlMigrationBakeCookie(mig, cookieout, cookieoutlen) < 0)
|
|
|
|
goto endjob;
|
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
if (xmlin) {
|
|
|
|
if (!(tmpdef = virDomainDefParseString(xmlin, cfg->caps,
|
|
|
|
driver->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL,
|
2016-05-26 13:58:53 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE |
|
|
|
|
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
|
2014-05-08 21:56:51 +00:00
|
|
|
goto endjob;
|
|
|
|
|
|
|
|
if (!libxlDomainDefCheckABIStability(driver, vm->def, tmpdef))
|
|
|
|
goto endjob;
|
|
|
|
|
|
|
|
def = tmpdef;
|
|
|
|
} else {
|
|
|
|
def = vm->def;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!libxlDomainMigrationIsAllowed(def))
|
|
|
|
goto endjob;
|
|
|
|
|
2016-02-03 21:40:35 +00:00
|
|
|
xml = virDomainDefFormat(def, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE);
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2014-07-08 21:17:58 +00:00
|
|
|
endjob:
|
2016-06-12 10:30:00 +00:00
|
|
|
libxlDomainObjEndJob(driver, vm);
|
2014-07-08 21:17:58 +00:00
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
cleanup:
|
2016-05-16 12:20:46 +00:00
|
|
|
libxlMigrationCookieFree(mig);
|
2014-05-08 21:56:51 +00:00
|
|
|
virDomainDefFree(tmpdef);
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainDefPtr
|
|
|
|
libxlDomainMigrationPrepareDef(libxlDriverPrivatePtr driver,
|
|
|
|
const char *dom_xml,
|
|
|
|
const char *dname)
|
|
|
|
{
|
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
|
|
|
virDomainDefPtr def;
|
|
|
|
char *name = NULL;
|
|
|
|
|
|
|
|
if (!dom_xml) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("no domain XML passed"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(def = virDomainDefParseString(dom_xml, cfg->caps, driver->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL,
|
2016-05-26 13:58:53 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE |
|
|
|
|
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
|
2014-05-08 21:56:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (dname) {
|
|
|
|
name = def->name;
|
|
|
|
if (VIR_STRDUP(def->name, dname) < 0) {
|
|
|
|
virDomainDefFree(def);
|
|
|
|
def = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
VIR_FREE(name);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2017-02-15 11:17:37 +00:00
|
|
|
static int
|
|
|
|
libxlDomainMigrationPrepareAny(virConnectPtr dconn,
|
|
|
|
virDomainDefPtr *def,
|
|
|
|
const char *cookiein,
|
|
|
|
int cookieinlen,
|
|
|
|
libxlMigrationCookiePtr *mig,
|
|
|
|
char **xmlout,
|
|
|
|
bool *taint_hook)
|
2014-05-08 21:56:51 +00:00
|
|
|
{
|
|
|
|
libxlDriverPrivatePtr driver = dconn->privateData;
|
2016-07-11 11:55:53 +00:00
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2017-02-15 11:17:37 +00:00
|
|
|
if (libxlMigrationEatCookie(cookiein, cookieinlen, mig) < 0)
|
|
|
|
return -1;
|
2016-04-29 21:08:05 +00:00
|
|
|
|
2017-02-15 11:17:37 +00:00
|
|
|
if ((*mig)->xenMigStreamVer > LIBXL_SAVE_VERSION) {
|
2016-04-29 21:08:05 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
|
|
|
_("Xen migration stream version '%d' is not supported on this host"),
|
2017-02-15 11:17:37 +00:00
|
|
|
(*mig)->xenMigStreamVer);
|
|
|
|
return -1;
|
2016-04-29 21:08:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 11:55:53 +00:00
|
|
|
/* Let migration hook filter domain XML */
|
|
|
|
if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) {
|
|
|
|
char *xml;
|
|
|
|
int hookret;
|
|
|
|
|
|
|
|
if (!(xml = virDomainDefFormat(*def, cfg->caps,
|
|
|
|
VIR_DOMAIN_XML_SECURE |
|
|
|
|
VIR_DOMAIN_XML_MIGRATABLE)))
|
2017-02-15 11:17:37 +00:00
|
|
|
return -1;
|
2016-07-11 11:55:53 +00:00
|
|
|
|
|
|
|
hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, (*def)->name,
|
|
|
|
VIR_HOOK_LIBXL_OP_MIGRATE, VIR_HOOK_SUBOP_BEGIN,
|
2017-02-15 11:17:37 +00:00
|
|
|
NULL, xml, xmlout);
|
2016-07-11 11:55:53 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
if (hookret < 0) {
|
2017-02-15 11:17:37 +00:00
|
|
|
return -1;
|
2016-07-11 11:55:53 +00:00
|
|
|
} else if (hookret == 0) {
|
2017-02-15 11:17:37 +00:00
|
|
|
if (virStringIsEmpty(*xmlout)) {
|
2016-07-11 11:55:53 +00:00
|
|
|
VIR_DEBUG("Migrate hook filter returned nothing; using the"
|
|
|
|
" original XML");
|
|
|
|
} else {
|
|
|
|
virDomainDefPtr newdef;
|
|
|
|
|
2017-02-15 11:17:37 +00:00
|
|
|
VIR_DEBUG("Using hook-filtered domain XML: %s", *xmlout);
|
|
|
|
newdef = virDomainDefParseString(*xmlout, cfg->caps, driver->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL,
|
2016-07-11 11:55:53 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE |
|
|
|
|
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
|
|
|
|
if (!newdef)
|
2017-02-15 11:17:37 +00:00
|
|
|
return -1;
|
2016-07-11 11:55:53 +00:00
|
|
|
|
|
|
|
/* TODO At some stage we will want to have some check of what the user
|
|
|
|
* did in the hook. */
|
|
|
|
|
|
|
|
virDomainDefFree(*def);
|
|
|
|
*def = newdef;
|
|
|
|
/* We should taint the domain here. However, @vm and therefore
|
|
|
|
* privateData too are still NULL, so just notice the fact and
|
|
|
|
* taint it later. */
|
2017-02-15 11:17:37 +00:00
|
|
|
*taint_hook = true;
|
2016-07-11 11:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 11:17:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-15 11:17:38 +00:00
|
|
|
int
|
|
|
|
libxlDomainMigrationPrepareTunnel3(virConnectPtr dconn,
|
|
|
|
virStreamPtr st,
|
|
|
|
virDomainDefPtr *def,
|
|
|
|
const char *cookiein,
|
|
|
|
int cookieinlen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
libxlMigrationCookiePtr mig = NULL;
|
|
|
|
libxlDriverPrivatePtr driver = dconn->privateData;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
libxlMigrationDstArgs *args = NULL;
|
|
|
|
virThread thread;
|
|
|
|
bool taint_hook = false;
|
|
|
|
libxlDomainObjPrivatePtr priv = NULL;
|
|
|
|
char *xmlout = NULL;
|
|
|
|
int dataFD[2] = { -1, -1 };
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (libxlDomainMigrationPrepareAny(dconn, def, cookiein, cookieinlen,
|
|
|
|
&mig, &xmlout, &taint_hook) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, *def,
|
|
|
|
driver->xmlopt,
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
*def = NULL;
|
|
|
|
priv = vm->privateData;
|
|
|
|
|
|
|
|
if (taint_hook) {
|
|
|
|
/* Domain XML has been altered by a hook script. */
|
|
|
|
priv->hookRun = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The data flow of tunnel3 migration in the dest side:
|
|
|
|
* stream -> pipe -> recvfd of libxlDomainStartRestore
|
|
|
|
*/
|
|
|
|
if (pipe(dataFD) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Stream data will be written to pipeIn */
|
|
|
|
if (virFDStreamOpen(st, dataFD[1]) < 0)
|
|
|
|
goto error;
|
|
|
|
dataFD[1] = -1; /* 'st' owns the FD now & will close it */
|
|
|
|
|
|
|
|
if (libxlMigrationDstArgsInitialize() < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(args = virObjectNew(libxlMigrationDstArgsClass)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
args->conn = dconn;
|
|
|
|
args->vm = vm;
|
|
|
|
args->flags = flags;
|
|
|
|
args->migcookie = mig;
|
|
|
|
/* Receive from pipeOut */
|
|
|
|
args->recvfd = dataFD[0];
|
|
|
|
args->nsocks = 0;
|
2017-02-16 16:43:05 +00:00
|
|
|
mig = NULL;
|
|
|
|
|
2017-02-15 11:17:38 +00:00
|
|
|
if (virThreadCreate(&thread, false, libxlDoMigrateReceive, args) < 0) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Failed to create thread for receiving migration data"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
error:
|
2017-02-16 16:43:05 +00:00
|
|
|
libxlMigrationCookieFree(mig);
|
2017-02-15 11:17:38 +00:00
|
|
|
VIR_FORCE_CLOSE(dataFD[1]);
|
|
|
|
VIR_FORCE_CLOSE(dataFD[0]);
|
|
|
|
virObjectUnref(args);
|
|
|
|
/* Remove virDomainObj from domain list */
|
|
|
|
if (vm) {
|
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-15 11:17:37 +00:00
|
|
|
int
|
|
|
|
libxlDomainMigrationPrepare(virConnectPtr dconn,
|
|
|
|
virDomainDefPtr *def,
|
|
|
|
const char *uri_in,
|
|
|
|
char **uri_out,
|
|
|
|
const char *cookiein,
|
|
|
|
int cookieinlen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
libxlDriverPrivatePtr driver = dconn->privateData;
|
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
|
|
|
libxlMigrationCookiePtr mig = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
char *hostname = NULL;
|
|
|
|
char *xmlout = NULL;
|
|
|
|
unsigned short port;
|
|
|
|
char portstr[100];
|
|
|
|
virURIPtr uri = NULL;
|
|
|
|
virNetSocketPtr *socks = NULL;
|
|
|
|
size_t nsocks = 0;
|
|
|
|
int nsocks_listen = 0;
|
|
|
|
libxlMigrationDstArgs *args = NULL;
|
|
|
|
bool taint_hook = false;
|
|
|
|
libxlDomainObjPrivatePtr priv = NULL;
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (libxlDomainMigrationPrepareAny(dconn, def, cookiein, cookieinlen,
|
|
|
|
&mig, &xmlout, &taint_hook) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2014-07-08 17:15:34 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, *def,
|
2014-05-08 21:56:51 +00:00
|
|
|
driver->xmlopt,
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2017-02-15 11:17:37 +00:00
|
|
|
|
2014-07-08 17:15:34 +00:00
|
|
|
*def = NULL;
|
2016-07-11 11:55:53 +00:00
|
|
|
priv = vm->privateData;
|
|
|
|
|
|
|
|
if (taint_hook) {
|
|
|
|
/* Domain XML has been altered by a hook script. */
|
|
|
|
priv->hookRun = true;
|
|
|
|
}
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
/* Create socket connection to receive migration data */
|
|
|
|
if (!uri_in) {
|
|
|
|
if ((hostname = virGetHostname()) == NULL)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
if (STRPREFIX(hostname, "localhost")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("hostname on destination resolved to localhost,"
|
|
|
|
" but migration requires an FQDN"));
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2016-10-14 17:55:52 +00:00
|
|
|
priv->migrationPort = port;
|
2014-05-08 21:56:51 +00:00
|
|
|
if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
} else {
|
|
|
|
if (!(STRPREFIX(uri_in, "tcp://"))) {
|
|
|
|
/* not full URI, add prefix tcp:// */
|
|
|
|
char *tmp;
|
|
|
|
if (virAsprintf(&tmp, "tcp://%s", uri_in) < 0)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
uri = virURIParse(tmp);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
} else {
|
|
|
|
uri = virURIParse(uri_in);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unable to parse URI: %s"),
|
|
|
|
uri_in);
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uri->server == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("missing host in migration URI: %s"),
|
|
|
|
uri_in);
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
} else {
|
|
|
|
hostname = uri->server;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri->port == 0) {
|
|
|
|
if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2016-10-14 17:55:52 +00:00
|
|
|
priv->migrationPort = port;
|
2014-05-08 21:56:51 +00:00
|
|
|
} else {
|
|
|
|
port = uri->port;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(portstr, sizeof(portstr), "%d", port);
|
|
|
|
|
2015-05-21 14:51:28 +00:00
|
|
|
if (virNetSocketNewListenTCP(hostname, portstr,
|
|
|
|
AF_UNSPEC,
|
|
|
|
&socks, &nsocks) < 0) {
|
2014-05-08 21:56:51 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Fail to create socket for incoming migration"));
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (libxlMigrationDstArgsInitialize() < 0)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
if (!(args = virObjectNew(libxlMigrationDstArgsClass)))
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
args->conn = dconn;
|
|
|
|
args->vm = vm;
|
|
|
|
args->flags = flags;
|
|
|
|
args->socks = socks;
|
|
|
|
args->nsocks = nsocks;
|
2016-04-29 21:08:05 +00:00
|
|
|
args->migcookie = mig;
|
2016-05-16 12:20:46 +00:00
|
|
|
mig = NULL;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nsocks; i++) {
|
|
|
|
if (virNetSocketSetBlocking(socks[i], true) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (virNetSocketListen(socks[i], 1) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (virNetSocketAddIOCallback(socks[i],
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
2014-11-12 22:32:02 +00:00
|
|
|
libxlMigrateReceive,
|
2014-05-08 21:56:51 +00:00
|
|
|
args,
|
2015-07-15 22:35:50 +00:00
|
|
|
NULL) < 0)
|
2014-05-08 21:56:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
nsocks_listen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsocks_listen)
|
2014-07-08 16:59:39 +00:00
|
|
|
goto error;
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
|
2014-07-08 16:59:39 +00:00
|
|
|
error:
|
2014-05-08 21:56:51 +00:00
|
|
|
for (i = 0; i < nsocks; i++) {
|
|
|
|
virNetSocketClose(socks[i]);
|
|
|
|
virObjectUnref(socks[i]);
|
|
|
|
}
|
2015-05-01 11:25:39 +00:00
|
|
|
VIR_FREE(socks);
|
2015-07-15 22:35:50 +00:00
|
|
|
virObjectUnref(args);
|
2018-02-06 09:09:08 +00:00
|
|
|
virPortAllocatorRelease(priv->migrationPort);
|
2016-10-14 17:55:52 +00:00
|
|
|
priv->migrationPort = 0;
|
2015-07-15 22:35:50 +00:00
|
|
|
|
2014-07-08 17:15:34 +00:00
|
|
|
/* Remove virDomainObj from domain list */
|
|
|
|
if (vm) {
|
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
done:
|
2016-07-11 11:55:53 +00:00
|
|
|
VIR_FREE(xmlout);
|
2016-05-16 12:20:46 +00:00
|
|
|
libxlMigrationCookieFree(mig);
|
2014-08-27 19:22:33 +00:00
|
|
|
if (!uri_in)
|
|
|
|
VIR_FREE(hostname);
|
|
|
|
else
|
|
|
|
virURIFree(uri);
|
2014-05-08 21:56:51 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
2016-07-11 11:55:53 +00:00
|
|
|
virObjectUnref(cfg);
|
2014-05-08 21:56:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-15 11:17:38 +00:00
|
|
|
typedef struct _libxlTunnelMigrationThread libxlTunnelMigrationThread;
|
|
|
|
struct _libxlTunnelMigrationThread {
|
|
|
|
virStreamPtr st;
|
|
|
|
int srcFD;
|
|
|
|
};
|
|
|
|
#define TUNNEL_SEND_BUF_SIZE 65536
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The data flow of tunnel3 migration in the src side:
|
|
|
|
* libxlDoMigrateSend() -> pipe
|
|
|
|
* libxlTunnel3MigrationFunc() polls pipe out and then write to dest stream.
|
|
|
|
*/
|
|
|
|
static void libxlTunnel3MigrationFunc(void *arg)
|
|
|
|
{
|
|
|
|
libxlTunnelMigrationThread *data = (libxlTunnelMigrationThread *)arg;
|
|
|
|
char *buffer = NULL;
|
|
|
|
struct pollfd fds[1];
|
|
|
|
int timeout = -1;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(buffer, TUNNEL_SEND_BUF_SIZE) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fds[0].fd = data->srcFD;
|
|
|
|
for (;;) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
fds[0].revents = 0;
|
|
|
|
ret = poll(fds, ARRAY_CARDINALITY(fds), timeout);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (errno == EAGAIN || errno == EINTR)
|
|
|
|
continue;
|
|
|
|
virReportError(errno, "%s",
|
|
|
|
_("poll failed in libxlTunnel3MigrationFunc"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
VIR_DEBUG("poll returned 0");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fds[0].revents & (POLLIN | POLLERR | POLLHUP)) {
|
|
|
|
int nbytes;
|
|
|
|
|
|
|
|
nbytes = read(data->srcFD, buffer, TUNNEL_SEND_BUF_SIZE);
|
|
|
|
if (nbytes > 0) {
|
|
|
|
/* Write to dest stream */
|
|
|
|
if (virStreamSend(data->st, buffer, nbytes) < 0) {
|
|
|
|
virStreamAbort(data->st);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (nbytes < 0) {
|
|
|
|
virReportError(errno, "%s",
|
|
|
|
_("tunnelled migration failed to read from xen side"));
|
|
|
|
virStreamAbort(data->st);
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
/* EOF; transferred all data */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ignore_value(virStreamFinish(data->st));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct libxlTunnelControl {
|
|
|
|
libxlTunnelMigrationThread tmThread;
|
|
|
|
virThread thread;
|
|
|
|
int dataFD[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
libxlMigrationStartTunnel(libxlDriverPrivatePtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
unsigned long flags,
|
|
|
|
virStreamPtr st,
|
2017-02-16 16:43:05 +00:00
|
|
|
struct libxlTunnelControl **tnl)
|
2017-02-15 11:17:38 +00:00
|
|
|
{
|
2017-02-16 16:43:05 +00:00
|
|
|
struct libxlTunnelControl *tc = NULL;
|
2017-02-15 11:17:38 +00:00
|
|
|
libxlTunnelMigrationThread *arg = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(tc) < 0)
|
|
|
|
goto out;
|
2017-02-16 16:43:05 +00:00
|
|
|
*tnl = tc;
|
2017-02-15 11:17:38 +00:00
|
|
|
|
|
|
|
tc->dataFD[0] = -1;
|
|
|
|
tc->dataFD[1] = -1;
|
|
|
|
if (pipe(tc->dataFD) < 0) {
|
|
|
|
virReportError(errno, "%s", _("Unable to make pipes"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
arg = &tc->tmThread;
|
|
|
|
/* Read from pipe */
|
|
|
|
arg->srcFD = tc->dataFD[0];
|
|
|
|
/* Write to dest stream */
|
|
|
|
arg->st = st;
|
|
|
|
if (virThreadCreate(&tc->thread, true,
|
|
|
|
libxlTunnel3MigrationFunc, arg) < 0) {
|
|
|
|
virReportError(errno, "%s",
|
|
|
|
_("Unable to create tunnel migration thread"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
/* Send data to pipe */
|
|
|
|
ret = libxlDoMigrateSend(driver, vm, flags, tc->dataFD[1]);
|
|
|
|
virObjectLock(vm);
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* libxlMigrationStopTunnel will be called in libxlDoMigrateP2P to free
|
|
|
|
* all resources for us. */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void libxlMigrationStopTunnel(struct libxlTunnelControl *tc)
|
|
|
|
{
|
|
|
|
if (!tc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
virThreadCancel(&tc->thread);
|
|
|
|
virThreadJoin(&tc->thread);
|
|
|
|
|
|
|
|
VIR_FORCE_CLOSE(tc->dataFD[0]);
|
|
|
|
VIR_FORCE_CLOSE(tc->dataFD[1]);
|
|
|
|
VIR_FREE(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is a simplification of virDomainMigrateVersion3Full and
|
|
|
|
* restricting it to migration v3 with params since it was the first to be
|
|
|
|
* introduced in libxl.
|
2016-02-05 20:45:02 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
libxlDoMigrateP2P(libxlDriverPrivatePtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virConnectPtr sconn,
|
|
|
|
const char *xmlin,
|
|
|
|
virConnectPtr dconn,
|
|
|
|
const char *dconnuri ATTRIBUTE_UNUSED,
|
|
|
|
const char *dname,
|
|
|
|
const char *uri,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainPtr ddomain = NULL;
|
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
int nparams = 0;
|
|
|
|
int maxparams = 0;
|
|
|
|
char *uri_out = NULL;
|
|
|
|
char *dom_xml = NULL;
|
|
|
|
unsigned long destflags;
|
2016-04-29 21:08:05 +00:00
|
|
|
char *cookieout = NULL;
|
|
|
|
int cookieoutlen;
|
2016-02-05 20:45:02 +00:00
|
|
|
bool cancelled = true;
|
|
|
|
virErrorPtr orig_err = NULL;
|
|
|
|
int ret = -1;
|
2017-02-15 11:17:38 +00:00
|
|
|
/* For tunnel migration */
|
|
|
|
virStreamPtr st = NULL;
|
|
|
|
struct libxlTunnelControl *tc = NULL;
|
2016-02-05 20:45:02 +00:00
|
|
|
|
2016-04-29 21:08:05 +00:00
|
|
|
dom_xml = libxlDomainMigrationBegin(sconn, vm, xmlin,
|
|
|
|
&cookieout, &cookieoutlen);
|
2016-02-05 20:45:02 +00:00
|
|
|
if (!dom_xml)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_XML, dom_xml) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (dname &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_NAME, dname) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (uri &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_URI, uri) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* We don't require the destination to have P2P support
|
|
|
|
* as it looks to be normal migration from the receiver perpective.
|
|
|
|
*/
|
|
|
|
destflags = flags & ~(VIR_MIGRATE_PEER2PEER);
|
|
|
|
|
|
|
|
VIR_DEBUG("Prepare3");
|
|
|
|
virObjectUnlock(vm);
|
2017-02-15 11:17:38 +00:00
|
|
|
if (flags & VIR_MIGRATE_TUNNELLED) {
|
|
|
|
if (!(st = virStreamNew(dconn, 0)))
|
|
|
|
goto cleanup;
|
|
|
|
ret = dconn->driver->domainMigratePrepareTunnel3Params
|
|
|
|
(dconn, st, params, nparams, cookieout, cookieoutlen, NULL, NULL, destflags);
|
|
|
|
} else {
|
|
|
|
ret = dconn->driver->domainMigratePrepare3Params
|
|
|
|
(dconn, params, nparams, cookieout, cookieoutlen, NULL, NULL, &uri_out, destflags);
|
|
|
|
}
|
2016-02-05 20:45:02 +00:00
|
|
|
virObjectLock(vm);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-02-15 11:17:38 +00:00
|
|
|
if (!(flags & VIR_MIGRATE_TUNNELLED)) {
|
|
|
|
if (uri_out) {
|
|
|
|
if (virTypedParamsReplaceString(¶ms, &nparams,
|
|
|
|
VIR_MIGRATE_PARAM_URI, uri_out) < 0) {
|
|
|
|
orig_err = virSaveLastError();
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domainMigratePrepare3 did not set uri"));
|
2016-02-05 20:45:02 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Perform3 uri=%s", NULLSTR(uri_out));
|
2017-02-15 11:17:38 +00:00
|
|
|
if (flags & VIR_MIGRATE_TUNNELLED)
|
2017-02-16 16:43:05 +00:00
|
|
|
ret = libxlMigrationStartTunnel(driver, vm, flags, st, &tc);
|
2017-02-15 11:17:38 +00:00
|
|
|
else
|
|
|
|
ret = libxlDomainMigrationPerform(driver, vm, NULL, NULL,
|
|
|
|
uri_out, NULL, flags);
|
2016-02-05 20:45:02 +00:00
|
|
|
if (ret < 0)
|
|
|
|
orig_err = virSaveLastError();
|
|
|
|
|
|
|
|
cancelled = (ret < 0);
|
|
|
|
|
|
|
|
finish:
|
|
|
|
VIR_DEBUG("Finish3 ret=%d", ret);
|
|
|
|
if (virTypedParamsGetString(params, nparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_NAME, NULL) <= 0 &&
|
|
|
|
virTypedParamsReplaceString(¶ms, &nparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_NAME,
|
|
|
|
vm->def->name) < 0) {
|
|
|
|
ddomain = NULL;
|
|
|
|
} else {
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
ddomain = dconn->driver->domainMigrateFinish3Params
|
|
|
|
(dconn, params, nparams, NULL, 0, NULL, NULL,
|
|
|
|
destflags, cancelled);
|
|
|
|
virObjectLock(vm);
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelled = (ddomain == NULL);
|
|
|
|
|
|
|
|
/* If Finish3Params set an error, and we don't have an earlier
|
|
|
|
* one we need to preserve it in case confirm3 overwrites
|
|
|
|
*/
|
|
|
|
if (!orig_err)
|
|
|
|
orig_err = virSaveLastError();
|
|
|
|
|
|
|
|
VIR_DEBUG("Confirm3 cancelled=%d vm=%p", cancelled, vm);
|
|
|
|
ret = libxlDomainMigrationConfirm(driver, vm, flags, cancelled);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
VIR_WARN("Guest %s probably left in 'paused' state on source",
|
|
|
|
vm->def->name);
|
|
|
|
|
|
|
|
cleanup:
|
2017-02-15 11:17:38 +00:00
|
|
|
if (flags & VIR_MIGRATE_TUNNELLED) {
|
|
|
|
libxlMigrationStopTunnel(tc);
|
|
|
|
virObjectUnref(st);
|
|
|
|
}
|
|
|
|
|
2016-02-05 20:45:02 +00:00
|
|
|
if (ddomain) {
|
|
|
|
virObjectUnref(ddomain);
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (orig_err) {
|
|
|
|
virSetError(orig_err);
|
|
|
|
virFreeError(orig_err);
|
|
|
|
}
|
|
|
|
|
2016-04-29 21:08:05 +00:00
|
|
|
VIR_FREE(cookieout);
|
2016-02-05 20:45:02 +00:00
|
|
|
VIR_FREE(dom_xml);
|
|
|
|
VIR_FREE(uri_out);
|
|
|
|
virTypedParamsFree(params, nparams);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virConnectCredType[] = {
|
|
|
|
VIR_CRED_AUTHNAME,
|
|
|
|
VIR_CRED_PASSPHRASE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static virConnectAuth virConnectAuthConfig = {
|
|
|
|
.credtype = virConnectCredType,
|
|
|
|
.ncredtype = ARRAY_CARDINALITY(virConnectCredType),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* On P2P mode there is only the Perform3 phase and we need to handle
|
|
|
|
* the connection with the destination libvirtd and perform the migration.
|
|
|
|
* Here we first tackle the first part of it, and libxlDoMigrationP2P handles
|
|
|
|
* the migration process with an established virConnectPtr to the destination.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
libxlDomainMigrationPerformP2P(libxlDriverPrivatePtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virConnectPtr sconn,
|
|
|
|
const char *xmlin,
|
|
|
|
const char *dconnuri,
|
|
|
|
const char *uri_str ATTRIBUTE_UNUSED,
|
|
|
|
const char *dname,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
bool useParams;
|
|
|
|
virConnectPtr dconn = NULL;
|
|
|
|
virErrorPtr orig_err = NULL;
|
2016-02-05 20:45:03 +00:00
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
2016-02-05 20:45:02 +00:00
|
|
|
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
dconn = virConnectOpenAuth(dconnuri, &virConnectAuthConfig, 0);
|
|
|
|
virObjectLock(vm);
|
|
|
|
|
|
|
|
if (dconn == NULL) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Failed to connect to remote libvirt URI %s: %s"),
|
|
|
|
dconnuri, virGetLastErrorMessage());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-05 20:45:03 +00:00
|
|
|
if (virConnectSetKeepAlive(dconn, cfg->keepAliveInterval,
|
|
|
|
cfg->keepAliveCount) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-02-05 20:45:02 +00:00
|
|
|
virObjectUnlock(vm);
|
|
|
|
useParams = VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
|
|
|
|
VIR_DRV_FEATURE_MIGRATION_PARAMS);
|
|
|
|
virObjectLock(vm);
|
|
|
|
|
|
|
|
if (!useParams) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Destination libvirt does not support migration with extensible parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = libxlDoMigrateP2P(driver, vm, sconn, xmlin, dconn, dconnuri,
|
|
|
|
dname, uri_str, flags);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
orig_err = virSaveLastError();
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
virObjectUnref(dconn);
|
2016-02-05 20:45:03 +00:00
|
|
|
virObjectUnref(cfg);
|
2016-02-05 20:45:02 +00:00
|
|
|
virObjectLock(vm);
|
|
|
|
if (orig_err) {
|
|
|
|
virSetError(orig_err);
|
|
|
|
virFreeError(orig_err);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
int
|
|
|
|
libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
const char *dom_xml ATTRIBUTE_UNUSED,
|
|
|
|
const char *dconnuri ATTRIBUTE_UNUSED,
|
|
|
|
const char *uri_str,
|
|
|
|
const char *dname ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-04-14 20:38:46 +00:00
|
|
|
libxlDomainObjPrivatePtr priv = vm->privateData;
|
2014-05-08 21:56:51 +00:00
|
|
|
char *hostname = NULL;
|
|
|
|
unsigned short port = 0;
|
|
|
|
char portstr[100];
|
|
|
|
virURIPtr uri = NULL;
|
|
|
|
virNetSocketPtr sock;
|
|
|
|
int sockfd = -1;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* parse dst host:port from uri */
|
|
|
|
uri = virURIParse(uri_str);
|
|
|
|
if (uri == NULL || uri->server == NULL || uri->port == 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
hostname = uri->server;
|
|
|
|
port = uri->port;
|
|
|
|
snprintf(portstr, sizeof(portstr), "%d", port);
|
|
|
|
|
|
|
|
/* socket connect to dst host:port */
|
2015-05-21 14:51:28 +00:00
|
|
|
if (virNetSocketNewConnectTCP(hostname, portstr,
|
|
|
|
AF_UNSPEC,
|
2015-09-03 16:14:20 +00:00
|
|
|
&sock) < 0)
|
2014-05-08 21:56:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virNetSocketSetBlocking(sock, true) < 0) {
|
|
|
|
virObjectUnref(sock);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
sockfd = virNetSocketDupFD(sock, true);
|
|
|
|
virObjectUnref(sock);
|
|
|
|
|
2015-04-14 20:38:46 +00:00
|
|
|
if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
|
|
|
|
VIR_WARN("Unable to release lease on %s", vm->def->name);
|
|
|
|
VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState));
|
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
/* suspend vm and send saved data to dst through socket fd */
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
ret = libxlDoMigrateSend(driver, vm, flags, sockfd);
|
|
|
|
virObjectLock(vm);
|
|
|
|
|
2018-01-24 21:23:04 +00:00
|
|
|
if (ret < 0)
|
|
|
|
virDomainLockProcessResume(driver->lockManager,
|
|
|
|
"xen:///system",
|
|
|
|
vm,
|
|
|
|
priv->lockState);
|
|
|
|
|
2014-05-08 21:56:51 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FORCE_CLOSE(sockfd);
|
|
|
|
virURIFree(uri);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainPtr
|
|
|
|
libxlDomainMigrationFinish(virConnectPtr dconn,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
unsigned int flags,
|
|
|
|
int cancelled)
|
|
|
|
{
|
|
|
|
libxlDriverPrivatePtr driver = dconn->privateData;
|
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
|
|
|
libxlDomainObjPrivatePtr priv = vm->privateData;
|
|
|
|
virObjectEventPtr event = NULL;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
2018-02-06 09:09:08 +00:00
|
|
|
virPortAllocatorRelease(priv->migrationPort);
|
2014-05-08 21:56:51 +00:00
|
|
|
priv->migrationPort = 0;
|
|
|
|
|
|
|
|
if (cancelled)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-11-13 00:52:02 +00:00
|
|
|
/* Check if domain is alive */
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
/* Migration failed if domain is inactive */
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
"%s", _("Migration failed. Domain is not running "
|
|
|
|
"on destination host"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unpause if requested */
|
2014-05-08 21:56:51 +00:00
|
|
|
if (!(flags & VIR_MIGRATE_PAUSED)) {
|
2015-02-11 23:40:07 +00:00
|
|
|
if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) {
|
2014-05-08 21:56:51 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Failed to unpause domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
|
|
|
|
VIR_DOMAIN_RUNNING_MIGRATED);
|
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
|
|
|
|
} else {
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
|
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
|
|
|
|
}
|
|
|
|
|
2014-08-28 18:56:33 +00:00
|
|
|
if (event) {
|
|
|
|
libxlDomainEventQueue(driver, event);
|
|
|
|
event = NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:34:34 +00:00
|
|
|
if (flags & VIR_MIGRATE_PERSIST_DEST) {
|
|
|
|
unsigned int oldPersist = vm->persistent;
|
|
|
|
virDomainDefPtr vmdef;
|
|
|
|
|
|
|
|
vm->persistent = 1;
|
|
|
|
if (!(vmdef = virDomainObjGetPersistentDef(cfg->caps,
|
|
|
|
driver->xmlopt, vm)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainSaveConfig(cfg->configDir, cfg->caps, vmdef) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED,
|
|
|
|
oldPersist ?
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_UPDATED :
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_ADDED);
|
|
|
|
if (event) {
|
|
|
|
libxlDomainEventQueue(driver, event);
|
|
|
|
event = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-04 12:32:45 +00:00
|
|
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0)
|
2014-11-13 00:52:02 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(dconn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-05-08 21:56:51 +00:00
|
|
|
|
2014-11-13 00:52:02 +00:00
|
|
|
cleanup:
|
2014-05-08 21:56:51 +00:00
|
|
|
if (dom == NULL) {
|
2015-03-04 00:54:50 +00:00
|
|
|
libxlDomainDestroyInternal(driver, vm);
|
2015-07-07 18:29:24 +00:00
|
|
|
libxlDomainCleanup(driver, vm);
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
|
|
|
|
VIR_DOMAIN_SHUTOFF_FAILED);
|
2014-05-08 21:56:51 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_FAILED);
|
2014-11-13 00:52:02 +00:00
|
|
|
if (!vm->persistent)
|
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
libxlDomainEventQueue(driver, event);
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libxlDomainMigrationConfirm(libxlDriverPrivatePtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
unsigned int flags,
|
|
|
|
int cancelled)
|
|
|
|
{
|
|
|
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
2018-01-24 21:23:04 +00:00
|
|
|
libxlDomainObjPrivatePtr priv = vm->privateData;
|
2014-05-08 21:56:51 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (cancelled) {
|
2018-01-24 21:23:04 +00:00
|
|
|
/* Resume lock process that was paused in MigrationPerform */
|
|
|
|
virDomainLockProcessResume(driver->lockManager,
|
|
|
|
"xen:///system",
|
|
|
|
vm,
|
|
|
|
priv->lockState);
|
2015-02-11 23:40:07 +00:00
|
|
|
if (libxl_domain_resume(cfg->ctx, vm->def->id, 1, 0) == 0) {
|
2014-05-08 21:56:51 +00:00
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("Unable to resume domain '%s' after failed migration",
|
|
|
|
vm->def->name);
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
|
|
|
|
VIR_DOMAIN_PAUSED_MIGRATION);
|
|
|
|
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED);
|
2016-02-04 12:32:45 +00:00
|
|
|
ignore_value(virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps));
|
2014-05-08 21:56:51 +00:00
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-03-04 00:54:50 +00:00
|
|
|
libxlDomainDestroyInternal(driver, vm);
|
2015-07-07 18:29:24 +00:00
|
|
|
libxlDomainCleanup(driver, vm);
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
|
|
|
|
VIR_DOMAIN_SHUTOFF_MIGRATED);
|
2014-05-08 21:56:51 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
|
|
|
|
|
|
|
|
VIR_DEBUG("Domain '%s' successfully migrated", vm->def->name);
|
|
|
|
|
|
|
|
if (flags & VIR_MIGRATE_UNDEFINE_SOURCE)
|
|
|
|
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
|
|
|
|
|
libxl: fix crash in migrate confirm for transient domains
In libxlDomainMigrationConfirm(), a transient domain is removed
from the domain list after successful migration. Later in cleanup,
the domain object is unlocked, resulting in a crash
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fb4208ed700 (LWP 12044)]
0x00007fb4267251e6 in virClassIsDerivedFrom (klass=0xdeadbeef,
parent=0x7fb42830d0c0) at util/virobject.c:169
169 if (klass->magic == parent->magic)
(gdb) bt
0 0x00007fb4267251e6 in virClassIsDerivedFrom (klass=0xdeadbeef,
parent=0x7fb42830d0c0) at util/virobject.c:169
1 0x00007fb42672591b in virObjectIsClass (anyobj=0x7fb4100082b0,
klass=0x7fb42830d0c0) at util/virobject.c:365
2 0x00007fb42672583c in virObjectUnlock (anyobj=0x7fb4100082b0)
at util/virobject.c:338
3 0x00007fb41a8c7d7a in libxlDomainMigrationConfirm (driver=0x7fb4100404c0,
vm=0x7fb4100082b0, flags=1, cancelled=0) at libxl/libxl_migration.c:583
Fix by setting the virDomainObjPtr to NULL after removing it from
the domain list.
2014-07-08 21:34:48 +00:00
|
|
|
if (!vm->persistent || (flags & VIR_MIGRATE_UNDEFINE_SOURCE)) {
|
2014-05-08 21:56:51 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
libxl: fix crash in migrate confirm for transient domains
In libxlDomainMigrationConfirm(), a transient domain is removed
from the domain list after successful migration. Later in cleanup,
the domain object is unlocked, resulting in a crash
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fb4208ed700 (LWP 12044)]
0x00007fb4267251e6 in virClassIsDerivedFrom (klass=0xdeadbeef,
parent=0x7fb42830d0c0) at util/virobject.c:169
169 if (klass->magic == parent->magic)
(gdb) bt
0 0x00007fb4267251e6 in virClassIsDerivedFrom (klass=0xdeadbeef,
parent=0x7fb42830d0c0) at util/virobject.c:169
1 0x00007fb42672591b in virObjectIsClass (anyobj=0x7fb4100082b0,
klass=0x7fb42830d0c0) at util/virobject.c:365
2 0x00007fb42672583c in virObjectUnlock (anyobj=0x7fb4100082b0)
at util/virobject.c:338
3 0x00007fb41a8c7d7a in libxlDomainMigrationConfirm (driver=0x7fb4100404c0,
vm=0x7fb4100082b0, flags=1, cancelled=0) at libxl/libxl_migration.c:583
Fix by setting the virDomainObjPtr to NULL after removing it from
the domain list.
2014-07-08 21:34:48 +00:00
|
|
|
vm = NULL;
|
|
|
|
}
|
2014-05-08 21:56:51 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (event)
|
|
|
|
libxlDomainEventQueue(driver, event);
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
return ret;
|
|
|
|
}
|