]> xenbits.xensource.com Git - libvirt.git/commitdiff
Implement finer grained migration control for Xen
authorMaximilian Wilhelm <max@rfc2324.org>
Thu, 12 Nov 2009 15:04:43 +0000 (16:04 +0100)
committerDaniel Veillard <veillard@redhat.com>
Thu, 12 Nov 2009 15:04:43 +0000 (16:04 +0100)
* src/xen/xen_driver.c: Add support for VIR_MIGRATE_PERSIST_DEST flag
* src/xen/xend_internal.c: Add support for VIR_MIGRATE_UNDEFINE_SOURCE flag
* include/libvirt/virterror.h, src/util/virterror.c: Add new errorcode
  VIR_ERR_MIGRATE_PERSIST_FAILED

include/libvirt/virterror.h
src/util/virterror.c
src/xen/xen_driver.c
src/xen/xend_internal.c

index dfa23f2444e0546f71cfe11d5b7c1f5abd2deb72..8548a8dd4b400ea9acf0c6abb41521bc0ac7eb9b 100644 (file)
@@ -172,6 +172,8 @@ typedef enum {
     VIR_ERR_NO_SECRET, /* secret not found */
     VIR_ERR_CONFIG_UNSUPPORTED, /* unsupported configuration construct */
     VIR_ERR_OPERATION_TIMEOUT, /* timeout occurred during operation */
+    VIR_ERR_MIGRATE_PERSIST_FAILED, /* a migration worked, but making the
+                                       VM persist on the dest host failed */
 } virErrorNumber;
 
 /**
index 00d5b2c3b5f2059ddfb758ce7c3366a17d7dbbfa..8b374ca66ba1f4a57cce6dc94bdf26e368e0514e 100644 (file)
@@ -1101,6 +1101,12 @@ virErrorMsg(virErrorNumber error, const char *info)
             else
                 errmsg = _("Timed out during operation: %s");
             break;
+        case VIR_ERR_MIGRATE_PERSIST_FAILED:
+            if (info == NULL)
+                errmsg = _("Failed to make domain persistent after migration");
+            else
+                errmsg = _("Failed to make domain persistent after migration: %s");
+            break;
     }
     return (errmsg);
 }
index d8c70879ac9ef6e791674c22086be2abd82d8e5c..80e81326ff5bc6a5e111c24906648dc44cbc520d 100644 (file)
@@ -1301,9 +1301,47 @@ xenUnifiedDomainMigrateFinish (virConnectPtr dconn,
                                const char *cookie ATTRIBUTE_UNUSED,
                                int cookielen ATTRIBUTE_UNUSED,
                                const char *uri ATTRIBUTE_UNUSED,
-                               unsigned long flags ATTRIBUTE_UNUSED)
+                               unsigned long flags)
 {
-    return xenUnifiedDomainLookupByName (dconn, dname);
+    virDomainPtr dom = NULL;
+    char *domain_xml = NULL;
+    virDomainPtr dom_new = NULL;
+
+    dom = xenUnifiedDomainLookupByName (dconn, dname);
+    if (! dom) {
+        return NULL;
+    }
+
+    if (flags & VIR_MIGRATE_PERSIST_DEST) {
+        domain_xml = xenDaemonDomainDumpXML (dom, 0, NULL);
+        if (! domain_xml) {
+            xenUnifiedError(dconn, VIR_ERR_MIGRATE_PERSIST_FAILED,
+                            _("failed to get XML representation of migrated domain"));
+            goto failure;
+        }
+
+        dom_new = xenDaemonDomainDefineXML (dconn, domain_xml);
+        if (! dom_new) {
+            xenUnifiedError (dconn, VIR_ERR_MIGRATE_PERSIST_FAILED,
+                             _("failed to define domain on destination host"));
+            goto failure;
+        }
+
+        /* Free additional reference added by Define */
+        virDomainFree (dom_new);
+    }
+
+    VIR_FREE (domain_xml);
+
+    return dom;
+
+
+failure:
+    virDomainFree (dom);
+
+    VIR_FREE (domain_xml);
+
+    return NULL;
 }
 
 static int
index 6b9a1258ccda181f8e10f68e4fd866f0f721255b..d61e9e699b07c99319750a0ae6891cec16788f0c 100644 (file)
@@ -4396,6 +4396,8 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
     int ret;
     char *p, *hostname = NULL;
 
+    int undefined_source = 0;
+
     /* Xen doesn't support renaming domains during migration. */
     if (dname) {
         virXendError (conn, VIR_ERR_NO_SUPPORT,
@@ -4414,11 +4416,24 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
         return -1;
     }
 
-    /* Check the flags. */
+    /*
+     * Check the flags.
+     */
     if ((flags & VIR_MIGRATE_LIVE)) {
         strcpy (live, "1");
         flags &= ~VIR_MIGRATE_LIVE;
     }
+
+    /* Undefine the VM on the source host after migration? */
+    if (flags & VIR_MIGRATE_UNDEFINE_SOURCE) {
+       undefined_source = 1;
+       flags &= ~VIR_MIGRATE_UNDEFINE_SOURCE;
+    }
+
+    /* Ignore the persist_dest flag here */
+    if (flags & VIR_MIGRATE_PERSIST_DEST)
+        flags &= ~VIR_MIGRATE_PERSIST_DEST;
+
     /* XXX we could easily do tunnelled & peer2peer migration too
        if we want to. support these... */
     if (flags != 0) {
@@ -4504,6 +4519,9 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
                    NULL);
     VIR_FREE (hostname);
 
+    if (ret == 0 && undefined_source)
+        xenDaemonDomainUndefine (domain);
+
     DEBUG0("migration done");
 
     return ret;