From ec5301cb85eea2a032ea2f0637dd0adb6940486f Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 27 May 2011 11:28:35 +0100 Subject: [PATCH] Allow virsh to pass in a custom XML document for migration Switch virsh migrate over to use virDomainMigrate2 and virDomainMigrateToURI2. This is still compatible with older libvirts, because these methods dynamically choose whether to perform v1, v2 or v3 migration based on declared RPC support from the libvirtd instances Add a --xml arg which allows the user to pass in a custom XML document. This XML document must be ABI compatible with the current *live* XML document for the running guest on the source host. ABI compatibility will be enforced by any driver supporting this function * tools/virsh.c: Add '--xml' arg to migrate command --- tools/virsh.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 418ef83880..520d16ee55 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -3828,6 +3828,7 @@ static const vshCmdOptDef opts_migrate[] = { {"migrateuri", VSH_OT_DATA, 0, N_("migration URI, usually can be omitted")}, {"dname", VSH_OT_DATA, 0, N_("rename to new name during migration (if supported)")}, {"timeout", VSH_OT_INT, 0, N_("force guest to suspend if live migration exceeds timeout (in seconds)")}, + {"xml", VSH_OT_STRING, 0, N_("filename containing updated XML for the target")}, {NULL, 0, 0, NULL} }; @@ -3851,6 +3852,8 @@ doMigrate (void *opaque) const vshCmd *cmd = data->cmd; #if HAVE_PTHREAD_SIGMASK sigset_t sigmask, oldsigmask; + const char *xmlfile = NULL; + char *xml = NULL; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); @@ -3871,6 +3874,11 @@ doMigrate (void *opaque) goto out; } + if (vshCommandOptString(cmd, "xml", &xmlfile) < 0) { + vshError(ctl, "%s", _("malformed xml argument")); + goto out; + } + if (vshCommandOptBool (cmd, "live")) flags |= VIR_MIGRATE_LIVE; if (vshCommandOptBool (cmd, "p2p")) @@ -3892,6 +3900,12 @@ doMigrate (void *opaque) if (vshCommandOptBool (cmd, "copy-storage-inc")) flags |= VIR_MIGRATE_NON_SHARED_INC; + + if (xmlfile && + virFileReadAll(xmlfile, 8192, &xml) < 0) + goto out; + + if ((flags & VIR_MIGRATE_PEER2PEER) || vshCommandOptBool (cmd, "direct")) { /* For peer2peer migration or direct migration we only expect one URI @@ -3902,7 +3916,7 @@ doMigrate (void *opaque) goto out; } - if (virDomainMigrateToURI (dom, desturi, flags, dname, 0) == 0) + if (virDomainMigrateToURI2(dom, desturi, NULL, xml, flags, dname, 0) == 0) ret = '0'; } else { /* For traditional live migration, connect to the destination host directly. */ @@ -3912,7 +3926,7 @@ doMigrate (void *opaque) dconn = virConnectOpenAuth (desturi, virConnectAuthPtrDefault, 0); if (!dconn) goto out; - ddom = virDomainMigrate (dom, dconn, flags, dname, migrateuri, 0); + ddom = virDomainMigrate2(dom, dconn, xml, flags, dname, migrateuri, 0); if (ddom) { virDomainFree(ddom); ret = '0'; @@ -3926,6 +3940,7 @@ out: out_sig: #endif if (dom) virDomainFree (dom); + VIR_FREE(xml); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); }