[PATCH V1] on special migration(domain defined, not started yet)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




From: liguang <lig.fnst@xxxxxxxxxxxxxx>

a roughly way for offline-migrate (domain defined,
not started yet), now can do like this:
migrate --hard-migrate --xml dom.xml dom qemu+ssh://target/system

this patch will push dom.xml and all disk images to target

Signed-off-by: liguang <lig.fnst@xxxxxxxxxxxxxx>
---
 tools/virsh.c |   76
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 53d1825..5793233 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7344,9 +7344,75 @@ static const vshCmdOptDef opts_migrate[] = {
     {"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")},
+    {"hard-migrate", VSH_OT_BOOL, 0, N_("migration when there's no
domain")},
     {NULL, 0, 0, NULL}
 };
 
+#define VIR_MIGRATE_HARD 1 << 10
+#define push_file(file) {                       \
+        virAsprintf(&topath, "%s:%s", to, file);            \
+        cmd = virCommandNewArgList("scp", file, topath, NULL);  \
+        vshPrint(ctl, "pushing %s to %s\n", file, to);          \
+        if (virCommandRunAsync(cmd, NULL) < 0 ||                \
+            virCommandWait(cmd, NULL) < 0) {                    \
+            virshReportError(ctl);                              \
+            goto cleanup;                                       \
+        }                                                       \
+}
+
+static void
+vshMigrateHard(vshControl *ctl, char *doc, char dst[])
+{
+    xmlDocPtr xml = NULL;
+    xmlXPathObjectPtr obj= NULL;
+    xmlXPathContextPtr ctxt = NULL;
+    xmlNodePtr *disks = NULL;
+    virCommandPtr cmd;
+    int i = 0, ret = 0;
+    int outfd = STDOUT_FILENO;
+    int errfd = STDERR_FILENO;
+    char *src[] = {NULL}, *to, *topath;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return;
+
+    xml = virXMLParseFileCtxt(doc, &ctxt);
+    if (!xml) {
+        vshError(NULL, "%s", _("Fail to get domain information from"));
+        goto cleanup;
+    }
+
+    ret = virXPathNodeSet("./devices/disk", ctxt, &disks);
+    if (ret < 0) {
+        vshError(NULL, "%s", _("Fail to get disk node"));
+        goto cleanup;
+    }
+
+    to = strtok(dst, "/");
+    to = strtok(NULL, "/");
+    virCommandSetInputFD(cmd, STDIN_FILENO);
+    virCommandSetOutputFD(cmd, &outfd);
+    virCommandSetErrorFD(cmd, &errfd);
+
+    push_file(doc);
+
+    for (i = 0 ; i < ret ; i++) {
+        ctxt->node = disks[i];
+        src[i] = virXPathString("string(./source/@file"
+                                "|./source/@dir"
+                                "|./source/@name)", ctxt);
+        push_file(src[i]);
+    }
+
+cleanup:
+    xmlXPathFreeObject(obj);
+    xmlXPathFreeContext(ctxt);
+    xmlFreeDoc(xml);
+    virCommandFree(cmd);
+    if (src)
+        VIR_FREE(src);    return;
+}
+
 static void
 doMigrate (void *opaque)
 {
@@ -7413,12 +7479,22 @@ doMigrate (void *opaque)
     if (vshCommandOptBool(cmd, "unsafe"))
         flags |= VIR_MIGRATE_UNSAFE;
 
+    if (vshCommandOptBool(cmd, "hard-migrate")) {
+        flags |= VIR_MIGRATE_HARD;
+        if (xmlfile == NULL)
+            vshError(ctl, _("please specify xmlfile for
hard-migrate"));
+    }
     if (xmlfile &&
         virFileReadAll(xmlfile, 8192, &xml) < 0) {
         vshError(ctl, _("file '%s' doesn't exist"), xmlfile);
         goto out;
     }
 
+    if (flags & VIR_MIGRATE_HARD) {
+        vshMigrateHard(ctl, (char *)xmlfile, (char *)desturi);
+        goto out;
+    }
+
     if ((flags & VIR_MIGRATE_PEER2PEER) ||
         vshCommandOptBool(cmd, "direct")) {
         /* For peer2peer migration or direct migration we only expect
one URI
-- 
1.7.2.5


在 2012-08-01三的 06:13 -0600,Eric Blake写道:
> On 07/31/2012 09:30 PM, liguang wrote:
> > Hi, All
> > 
> > If a VM domain defined, but not started yet,
> > and I want to migrate it to another server,
> > so that It can be started at there, what's 
> > should i do? or is it rational?
> 
> Yes it is rational, and you're not the first to request it.
> Unfortunately, we haven't yet taught 'virsh migrate' to support offline
> migration, even though (or because?) it is dead simple to cobble
> together yourself:
> 
> source$ virsh dumpxml $dom > file.xml
> dest$ virsh define file.xml
> 
> optionally followed by
> source$ virsh undefine $dom
> 
> Patches are welcome to make 'virsh migrate' automatically handle an
> offline migration.
> 



--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]