]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Finer grained migration control
authorChris Lalancette <clalance@redhat.com>
Fri, 31 Jul 2009 10:10:22 +0000 (12:10 +0200)
committerChris Lalancette <clalance@redhat.com>
Wed, 14 Oct 2009 09:35:51 +0000 (11:35 +0200)
Normally, when you migrate a domain from host A to host B,
the domain on host A remains defined but shutoff and the domain
on host B remains running but is a "transient".  Add a new
flag to virDomainMigrate() to allow the original domain to be
undefined on source host A, and a new flag to virDomainMigrate() to
allow the new domain to be persisted on the destination host B.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
include/libvirt/libvirt.h.in
src/libvirt.c
src/qemu/qemu_driver.c
tools/virsh.c

index f51a565132b09a1c19ad53e0a79aed25c30754e3..6186d4e02fc9fd5e4be14a5d4a8bac83b38185fa 100644 (file)
@@ -339,6 +339,8 @@ typedef enum {
     VIR_MIGRATE_LIVE              = (1 << 0), /* live migration */
     VIR_MIGRATE_PEER2PEER         = (1 << 1), /* direct source -> dest host control channel */
     VIR_MIGRATE_TUNNELLED         = (1 << 2), /* tunnel migration data over libvirtd connection */
+    VIR_MIGRATE_PERSIST_DEST      = (1 << 3), /* persist the VM on the destination */
+    VIR_MIGRATE_UNDEFINE_SOURCE   = (1 << 4), /* undefine the VM on the source */
 } virDomainMigrateFlags;
 
 /* Domain migration. */
index b14942da2360ab1c16ac34001b3cd54fcc910eba..92a1eaa010da6bcd0b38848bb724f3f3f5b3c89e 100644 (file)
@@ -3128,6 +3128,10 @@ virDomainMigrateDirect (virDomainPtr domain,
  *   VIR_MIGRATE_LIVE      Do not pause the VM during migration
  *   VIR_MIGRATE_PEER2PEER Direct connection between source & destination hosts
  *   VIR_MIGRATE_TUNNELLED Tunnel migration data over the libvirt RPC channel
+ *   VIR_MIGRATE_PERSIST_DEST If the migration is successful, persist the domain
+ *                            on the destination host.
+ *   VIR_MIGRATE_UNDEFINE_SOURCE If the migration is successful, undefine the
+ *                               domain on the source host.
  *
  * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
  * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
index c544c4b4c741eb3807ce28cc8c0626ed360a2ae8..d37b18435728281809dfb10d33ee4b6e0cd9d969 100644 (file)
@@ -6847,7 +6847,8 @@ qemudDomainMigratePerform (virDomainPtr dom,
     event = virDomainEventNewFromObj(vm,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
-    if (!vm->persistent) {
+    if (!vm->persistent || (flags & VIR_MIGRATE_UNDEFINE_SOURCE)) {
+        virDomainDeleteConfig(dom->conn, driver->configDir, driver->autostartDir, vm);
         virDomainRemoveInactive(&driver->domains, vm);
         vm = NULL;
     }
@@ -6885,13 +6886,14 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn,
                            const char *cookie ATTRIBUTE_UNUSED,
                            int cookielen ATTRIBUTE_UNUSED,
                            const char *uri ATTRIBUTE_UNUSED,
-                           unsigned long flags ATTRIBUTE_UNUSED,
+                           unsigned long flags,
                            int retcode)
 {
     struct qemud_driver *driver = dconn->privateData;
     virDomainObjPtr vm;
     virDomainPtr dom = NULL;
     virDomainEventPtr event = NULL;
+    int newVM = 1;
 
     qemuDriverLock(driver);
     vm = virDomainFindByName(&driver->domains, dname);
@@ -6905,6 +6907,34 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn,
      * object, but if no, clean up the empty qemu process.
      */
     if (retcode == 0) {
+        if (flags & VIR_MIGRATE_PERSIST_DEST) {
+            if (vm->persistent)
+                newVM = 0;
+            vm->persistent = 1;
+
+            if (virDomainSaveConfig(dconn, driver->configDir, vm->def) < 0) {
+                /* Hmpf.  Migration was successful, but making it persistent
+                 * was not.  If we report successful, then when this domain
+                 * shuts down, management tools are in for a surprise.  On the
+                 * other hand, if we report failure, then the management tools
+                 * might try to restart the domain on the source side, even
+                 * though the domain is actually running on the destination.
+                 * Return a NULL dom pointer, and hope that this is a rare
+                 * situation and management tools are smart.
+                 */
+                vm = NULL;
+                goto cleanup;
+            }
+
+            event = virDomainEventNewFromObj(vm,
+                                             VIR_DOMAIN_EVENT_DEFINED,
+                                             newVM ?
+                                             VIR_DOMAIN_EVENT_DEFINED_ADDED :
+                                             VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+            if (event)
+                qemuDomainEventQueue(driver, event);
+
+        }
         dom = virGetDomain (dconn, vm->def->name, vm->def->uuid);
 
         /* run 'cont' on the destination, which allows migration on qemu
index 46c545469c86f66f4a3e72cb5d4657e3757b6fe1..47122d508d3cac8b939a7a850d95cd857151e461 100644 (file)
@@ -2465,6 +2465,8 @@ static const vshCmdOptDef opts_migrate[] = {
     {"p2p", VSH_OT_BOOL, 0, gettext_noop("peer-2-peer migration")},
     {"direct", VSH_OT_BOOL, 0, gettext_noop("direct migration")},
     {"tunnelled", VSH_OT_BOOL, 0, gettext_noop("tunnelled migration")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist VM on destination")},
+    {"undefinesource", VSH_OT_BOOL, 0, gettext_noop("undefine VM on source")},
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
     {"desturi", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("connection URI of the destination host")},
     {"migrateuri", VSH_OT_DATA, 0, gettext_noop("migration URI, usually can be omitted")},
@@ -2504,6 +2506,12 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool (cmd, "tunnelled"))
         flags |= VIR_MIGRATE_TUNNELLED;
 
+    if (vshCommandOptBool (cmd, "persistent"))
+        flags |= VIR_MIGRATE_PERSIST_DEST;
+
+    if (vshCommandOptBool (cmd, "undefinesource"))
+        flags |= VIR_MIGRATE_UNDEFINE_SOURCE;
+
     if ((flags & VIR_MIGRATE_PEER2PEER) ||
         vshCommandOptBool (cmd, "direct")) {
         /* For peer2peer migration or direct migration we only expect one URI