mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
libxl: support migration stream V2 in migration
Similar to "support Xen migration stream V2 in save/restore", add support for indicating the migration stream version in the migration code. To accomplish this, add a minimal migration cookie in the libxl driver that is passed between source and destination hosts. Initially, the cookie is only used in the Begin and Prepare phases of migration to communicate the version of the migration stream produced by the source. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
5325123d23
commit
f9edcfa473
@ -5151,8 +5151,8 @@ static char *
|
|||||||
libxlDomainMigrateBegin3Params(virDomainPtr domain,
|
libxlDomainMigrateBegin3Params(virDomainPtr domain,
|
||||||
virTypedParameterPtr params,
|
virTypedParameterPtr params,
|
||||||
int nparams,
|
int nparams,
|
||||||
char **cookieout ATTRIBUTE_UNUSED,
|
char **cookieout,
|
||||||
int *cookieoutlen ATTRIBUTE_UNUSED,
|
int *cookieoutlen,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const char *xmlin = NULL;
|
const char *xmlin = NULL;
|
||||||
@ -5193,15 +5193,16 @@ libxlDomainMigrateBegin3Params(virDomainPtr domain,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return libxlDomainMigrationBegin(domain->conn, vm, xmlin);
|
return libxlDomainMigrationBegin(domain->conn, vm, xmlin,
|
||||||
|
cookieout, cookieoutlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
libxlDomainMigratePrepare3Params(virConnectPtr dconn,
|
libxlDomainMigratePrepare3Params(virConnectPtr dconn,
|
||||||
virTypedParameterPtr params,
|
virTypedParameterPtr params,
|
||||||
int nparams,
|
int nparams,
|
||||||
const char *cookiein ATTRIBUTE_UNUSED,
|
const char *cookiein,
|
||||||
int cookieinlen ATTRIBUTE_UNUSED,
|
int cookieinlen,
|
||||||
char **cookieout ATTRIBUTE_UNUSED,
|
char **cookieout ATTRIBUTE_UNUSED,
|
||||||
int *cookieoutlen ATTRIBUTE_UNUSED,
|
int *cookieoutlen ATTRIBUTE_UNUSED,
|
||||||
char **uri_out,
|
char **uri_out,
|
||||||
@ -5240,7 +5241,8 @@ libxlDomainMigratePrepare3Params(virConnectPtr dconn,
|
|||||||
if (virDomainMigratePrepare3ParamsEnsureACL(dconn, def) < 0)
|
if (virDomainMigratePrepare3ParamsEnsureACL(dconn, def) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (libxlDomainMigrationPrepare(dconn, &def, uri_in, uri_out, flags) < 0)
|
if (libxlDomainMigrationPrepare(dconn, &def, uri_in, uri_out,
|
||||||
|
cookiein, cookieinlen, flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -48,6 +48,18 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("libxl.libxl_migration");
|
VIR_LOG_INIT("libxl.libxl_migration");
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct _libxlMigrationDstArgs {
|
typedef struct _libxlMigrationDstArgs {
|
||||||
virObject parent;
|
virObject parent;
|
||||||
|
|
||||||
@ -55,6 +67,7 @@ typedef struct _libxlMigrationDstArgs {
|
|||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
libxlMigrationCookiePtr migcookie;
|
||||||
|
|
||||||
/* for freeing listen sockets */
|
/* for freeing listen sockets */
|
||||||
virNetSocketPtr *socks;
|
virNetSocketPtr *socks;
|
||||||
@ -63,11 +76,166 @@ typedef struct _libxlMigrationDstArgs {
|
|||||||
|
|
||||||
static virClassPtr libxlMigrationDstArgsClass;
|
static virClassPtr libxlMigrationDstArgsClass;
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
libxlMigrationDstArgsDispose(void *obj)
|
libxlMigrationDstArgsDispose(void *obj)
|
||||||
{
|
{
|
||||||
libxlMigrationDstArgs *args = obj;
|
libxlMigrationDstArgs *args = obj;
|
||||||
|
|
||||||
|
libxlMigrationCookieFree(args->migcookie);
|
||||||
VIR_FREE(args->socks);
|
VIR_FREE(args->socks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +274,8 @@ libxlDoMigrateReceive(void *opaque)
|
|||||||
* Always start the domain paused. If needed, unpause in the
|
* Always start the domain paused. If needed, unpause in the
|
||||||
* finish phase, after transfer of the domain is complete.
|
* finish phase, after transfer of the domain is complete.
|
||||||
*/
|
*/
|
||||||
ret = libxlDomainStartRestore(driver, vm, true, recvfd, LIBXL_SAVE_VERSION);
|
ret = libxlDomainStartRestore(driver, vm, true, recvfd,
|
||||||
|
args->migcookie->xenMigStreamVer);
|
||||||
|
|
||||||
if (ret < 0 && !vm->persistent)
|
if (ret < 0 && !vm->persistent)
|
||||||
remove_dom = true;
|
remove_dom = true;
|
||||||
@ -227,10 +396,13 @@ libxlDomainMigrationIsAllowed(virDomainDefPtr def)
|
|||||||
char *
|
char *
|
||||||
libxlDomainMigrationBegin(virConnectPtr conn,
|
libxlDomainMigrationBegin(virConnectPtr conn,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *xmlin)
|
const char *xmlin,
|
||||||
|
char **cookieout,
|
||||||
|
int *cookieoutlen)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
||||||
|
libxlMigrationCookiePtr mig;
|
||||||
virDomainDefPtr tmpdef = NULL;
|
virDomainDefPtr tmpdef = NULL;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
@ -238,6 +410,12 @@ libxlDomainMigrationBegin(virConnectPtr conn,
|
|||||||
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(mig = libxlMigrationCookieNew(vm)))
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
|
if (libxlMigrationBakeCookie(mig, cookieout, cookieoutlen) < 0)
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
if (xmlin) {
|
if (xmlin) {
|
||||||
if (!(tmpdef = virDomainDefParseString(xmlin, cfg->caps,
|
if (!(tmpdef = virDomainDefParseString(xmlin, cfg->caps,
|
||||||
driver->xmlopt,
|
driver->xmlopt,
|
||||||
@ -308,9 +486,12 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
|
|||||||
virDomainDefPtr *def,
|
virDomainDefPtr *def,
|
||||||
const char *uri_in,
|
const char *uri_in,
|
||||||
char **uri_out,
|
char **uri_out,
|
||||||
|
const char *cookiein,
|
||||||
|
int cookieinlen,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = dconn->privateData;
|
libxlDriverPrivatePtr driver = dconn->privateData;
|
||||||
|
libxlMigrationCookiePtr mig = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
@ -323,6 +504,16 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
|
|||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
if (libxlMigrationEatCookie(cookiein, cookieinlen, &mig) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (mig->xenMigStreamVer > LIBXL_SAVE_VERSION) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
||||||
|
_("Xen migration stream version '%d' is not supported on this host"),
|
||||||
|
mig->xenMigStreamVer);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(vm = virDomainObjListAdd(driver->domains, *def,
|
if (!(vm = virDomainObjListAdd(driver->domains, *def,
|
||||||
driver->xmlopt,
|
driver->xmlopt,
|
||||||
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
||||||
@ -409,6 +600,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
|
|||||||
args->flags = flags;
|
args->flags = flags;
|
||||||
args->socks = socks;
|
args->socks = socks;
|
||||||
args->nsocks = nsocks;
|
args->nsocks = nsocks;
|
||||||
|
args->migcookie = mig;
|
||||||
|
|
||||||
for (i = 0; i < nsocks; i++) {
|
for (i = 0; i < nsocks; i++) {
|
||||||
if (virNetSocketSetBlocking(socks[i], true) < 0)
|
if (virNetSocketSetBlocking(socks[i], true) < 0)
|
||||||
@ -479,11 +671,14 @@ libxlDoMigrateP2P(libxlDriverPrivatePtr driver,
|
|||||||
char *uri_out = NULL;
|
char *uri_out = NULL;
|
||||||
char *dom_xml = NULL;
|
char *dom_xml = NULL;
|
||||||
unsigned long destflags;
|
unsigned long destflags;
|
||||||
|
char *cookieout = NULL;
|
||||||
|
int cookieoutlen;
|
||||||
bool cancelled = true;
|
bool cancelled = true;
|
||||||
virErrorPtr orig_err = NULL;
|
virErrorPtr orig_err = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
dom_xml = libxlDomainMigrationBegin(sconn, vm, xmlin);
|
dom_xml = libxlDomainMigrationBegin(sconn, vm, xmlin,
|
||||||
|
&cookieout, &cookieoutlen);
|
||||||
if (!dom_xml)
|
if (!dom_xml)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -509,7 +704,7 @@ libxlDoMigrateP2P(libxlDriverPrivatePtr driver,
|
|||||||
VIR_DEBUG("Prepare3");
|
VIR_DEBUG("Prepare3");
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
ret = dconn->driver->domainMigratePrepare3Params
|
ret = dconn->driver->domainMigratePrepare3Params
|
||||||
(dconn, params, nparams, NULL, 0, NULL, NULL, &uri_out, destflags);
|
(dconn, params, nparams, cookieout, cookieoutlen, NULL, NULL, &uri_out, destflags);
|
||||||
virObjectLock(vm);
|
virObjectLock(vm);
|
||||||
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
@ -580,6 +775,7 @@ libxlDoMigrateP2P(libxlDriverPrivatePtr driver,
|
|||||||
virFreeError(orig_err);
|
virFreeError(orig_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VIR_FREE(cookieout);
|
||||||
VIR_FREE(dom_xml);
|
VIR_FREE(dom_xml);
|
||||||
VIR_FREE(uri_out);
|
VIR_FREE(uri_out);
|
||||||
virTypedParamsFree(params, nparams);
|
virTypedParamsFree(params, nparams);
|
||||||
|
@ -42,7 +42,9 @@
|
|||||||
char *
|
char *
|
||||||
libxlDomainMigrationBegin(virConnectPtr conn,
|
libxlDomainMigrationBegin(virConnectPtr conn,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *xmlin);
|
const char *xmlin,
|
||||||
|
char **cookieout,
|
||||||
|
int *cookieoutlen);
|
||||||
|
|
||||||
virDomainDefPtr
|
virDomainDefPtr
|
||||||
libxlDomainMigrationPrepareDef(libxlDriverPrivatePtr driver,
|
libxlDomainMigrationPrepareDef(libxlDriverPrivatePtr driver,
|
||||||
@ -54,6 +56,8 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
|
|||||||
virDomainDefPtr *def,
|
virDomainDefPtr *def,
|
||||||
const char *uri_in,
|
const char *uri_in,
|
||||||
char **uri_out,
|
char **uri_out,
|
||||||
|
const char *cookiein,
|
||||||
|
int cookieinlen,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user