mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh: Use extensible migration APIs
This commit is contained in:
parent
6f4c6af6ed
commit
bdb6578a42
@ -8345,15 +8345,15 @@ doMigrate(void *opaque)
|
|||||||
char ret = '1';
|
char ret = '1';
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
const char *desturi = NULL;
|
const char *desturi = NULL;
|
||||||
const char *migrateuri = NULL;
|
const char *opt = NULL;
|
||||||
const char *dname = NULL;
|
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
vshCtrlData *data = opaque;
|
vshCtrlData *data = opaque;
|
||||||
vshControl *ctl = data->ctl;
|
vshControl *ctl = data->ctl;
|
||||||
const vshCmd *cmd = data->cmd;
|
const vshCmd *cmd = data->cmd;
|
||||||
const char *xmlfile = NULL;
|
|
||||||
char *xml = NULL;
|
|
||||||
sigset_t sigmask, oldsigmask;
|
sigset_t sigmask, oldsigmask;
|
||||||
|
virTypedParameterPtr params = NULL;
|
||||||
|
int nparams = 0;
|
||||||
|
int maxparams = 0;
|
||||||
|
|
||||||
sigemptyset(&sigmask);
|
sigemptyset(&sigmask);
|
||||||
sigaddset(&sigmask, SIGINT);
|
sigaddset(&sigmask, SIGINT);
|
||||||
@ -8363,12 +8363,41 @@ doMigrate(void *opaque)
|
|||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "desturi", &desturi) < 0 ||
|
if (vshCommandOptStringReq(ctl, cmd, "desturi", &desturi) < 0)
|
||||||
vshCommandOptStringReq(ctl, cmd, "migrateuri", &migrateuri) < 0 ||
|
|
||||||
vshCommandOptStringReq(ctl, cmd, "dname", &dname) < 0 ||
|
|
||||||
vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (vshCommandOptStringReq(ctl, cmd, "migrateuri", &opt) < 0)
|
||||||
|
goto out;
|
||||||
|
if (opt &&
|
||||||
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_MIGRATE_PARAM_URI, opt) < 0)
|
||||||
|
goto save_error;
|
||||||
|
|
||||||
|
if (vshCommandOptStringReq(ctl, cmd, "dname", &opt) < 0)
|
||||||
|
goto out;
|
||||||
|
if (opt &&
|
||||||
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_MIGRATE_PARAM_DEST_NAME, opt) < 0)
|
||||||
|
goto save_error;
|
||||||
|
|
||||||
|
if (vshCommandOptStringReq(ctl, cmd, "xml", &opt) < 0)
|
||||||
|
goto out;
|
||||||
|
if (opt) {
|
||||||
|
char *xml;
|
||||||
|
|
||||||
|
if (virFileReadAll(opt, 1024 * 1024, &xml) < 0) {
|
||||||
|
vshError(ctl, _("cannot read file '%s'"), opt);
|
||||||
|
goto save_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_MIGRATE_PARAM_DEST_XML, xml) < 0) {
|
||||||
|
VIR_FREE(xml);
|
||||||
|
goto save_error;
|
||||||
|
}
|
||||||
|
VIR_FREE(xml);
|
||||||
|
}
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "live"))
|
if (vshCommandOptBool(cmd, "live"))
|
||||||
flags |= VIR_MIGRATE_LIVE;
|
flags |= VIR_MIGRATE_LIVE;
|
||||||
if (vshCommandOptBool(cmd, "p2p"))
|
if (vshCommandOptBool(cmd, "p2p"))
|
||||||
@ -8406,23 +8435,19 @@ doMigrate(void *opaque)
|
|||||||
if (vshCommandOptBool(cmd, "abort-on-error"))
|
if (vshCommandOptBool(cmd, "abort-on-error"))
|
||||||
flags |= VIR_MIGRATE_ABORT_ON_ERROR;
|
flags |= VIR_MIGRATE_ABORT_ON_ERROR;
|
||||||
|
|
||||||
if (xmlfile &&
|
|
||||||
virFileReadAll(xmlfile, 8192, &xml) < 0) {
|
|
||||||
vshError(ctl, _("file '%s' doesn't exist"), xmlfile);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & VIR_MIGRATE_PEER2PEER) ||
|
if ((flags & VIR_MIGRATE_PEER2PEER) ||
|
||||||
vshCommandOptBool(cmd, "direct")) {
|
vshCommandOptBool(cmd, "direct")) {
|
||||||
|
|
||||||
/* migrateuri doesn't make sense for tunnelled migration */
|
/* migrateuri doesn't make sense for tunnelled migration */
|
||||||
if (flags & VIR_MIGRATE_TUNNELLED && migrateuri != NULL) {
|
if (flags & VIR_MIGRATE_TUNNELLED &&
|
||||||
vshError(ctl, "%s", _("migrate: Unexpected migrateuri for peer2peer/direct migration"));
|
virTypedParamsGetString(params, nparams,
|
||||||
|
VIR_MIGRATE_PARAM_URI, NULL) == 1) {
|
||||||
|
vshError(ctl, "%s", _("migrate: Unexpected migrateuri for "
|
||||||
|
"peer2peer/direct migration"));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainMigrateToURI2(dom, desturi, migrateuri,
|
if (virDomainMigrateToURI3(dom, desturi, params, nparams, flags) == 0)
|
||||||
xml, flags, dname, 0) == 0)
|
|
||||||
ret = '0';
|
ret = '0';
|
||||||
} else {
|
} else {
|
||||||
/* For traditional live migration, connect to the destination host directly. */
|
/* For traditional live migration, connect to the destination host directly. */
|
||||||
@ -8430,10 +8455,10 @@ doMigrate(void *opaque)
|
|||||||
virDomainPtr ddom = NULL;
|
virDomainPtr ddom = NULL;
|
||||||
|
|
||||||
dconn = virConnectOpenAuth(desturi, virConnectAuthPtrDefault, 0);
|
dconn = virConnectOpenAuth(desturi, virConnectAuthPtrDefault, 0);
|
||||||
if (!dconn) goto out;
|
if (!dconn)
|
||||||
|
goto out;
|
||||||
|
|
||||||
ddom = virDomainMigrate2(dom, dconn, xml, flags, dname, migrateuri, 0);
|
if ((ddom = virDomainMigrate3(dom, dconn, params, nparams, flags))) {
|
||||||
if (ddom) {
|
|
||||||
virDomainFree(ddom);
|
virDomainFree(ddom);
|
||||||
ret = '0';
|
ret = '0';
|
||||||
}
|
}
|
||||||
@ -8443,9 +8468,15 @@ doMigrate(void *opaque)
|
|||||||
out:
|
out:
|
||||||
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
||||||
out_sig:
|
out_sig:
|
||||||
if (dom) virDomainFree(dom);
|
virTypedParamsFree(params, nparams);
|
||||||
VIR_FREE(xml);
|
if (dom)
|
||||||
|
virDomainFree(dom);
|
||||||
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
||||||
|
return;
|
||||||
|
|
||||||
|
save_error:
|
||||||
|
vshSaveLibvirtError();
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user