File 42874fa4-libxl-mig-failure-cleanup.patch of Package libvirt.11695

commit 42874fa45f9fab99212d0ba3f66cf4671ddb0a30
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Wed Nov 12 17:52:02 2014 -0700

    libxl: destroy domain in migration finish phase on failure
    
    This patch contains three domain cleanup improvements in the migration
    finish phase, ensuring a domain is properly disposed when a failure is
    detected or the migration is cancelled.
    
    The check for virDomainObjIsActive is moved to libxlDomainMigrationFinish,
    where cleanup can occur if migration failed and the domain is inactive.
    
    The 'cleanup' label was missplaced in libxlDomainMigrationFinish, causing
    a migrated domain to remain in the event of an error or cancelled migration.
    
    In cleanup, the domain was not removed from the driver's list of domains.
    
    Signed-off-by: Jim Fehlig <jfehlig@suse.com>

Index: libvirt-1.2.5/src/libxl/libxl_driver.c
===================================================================
--- libvirt-1.2.5.orig/src/libxl/libxl_driver.c
+++ libvirt-1.2.5/src/libxl/libxl_driver.c
@@ -4695,17 +4695,8 @@ libxlDomainMigrateFinish3Params(virConne
         return NULL;
     }
 
-    if (!virDomainObjIsActive(vm)) {
-        /* Migration failed if domain is inactive */
-        virReportError(VIR_ERR_OPERATION_FAILED,
-                       "%s", _("Migration failed. Domain is not running "
-                               "on destination host"));
-        goto endjob;
-    }
-
     ret = libxlDomainMigrationFinish(dconn, vm, flags, cancelled);
 
- endjob:
     if (!libxlDomainObjEndJob(driver, vm))
         vm = NULL;
 
Index: libvirt-1.2.5/src/libxl/libxl_migration.c
===================================================================
--- libvirt-1.2.5.orig/src/libxl/libxl_migration.c
+++ libvirt-1.2.5/src/libxl/libxl_migration.c
@@ -534,6 +534,16 @@ libxlDomainMigrationFinish(virConnectPtr
     if (cancelled)
         goto cleanup;
 
+    /* Check if domain is alive */
+    if (!virDomainObjIsActive(vm)) {
+        /* Migration failed if domain is inactive */
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       "%s", _("Migration failed. Domain is not running "
+                               "on destination host"));
+        goto cleanup;
+    }
+
+    /* Unpause if requested */
     if (!(flags & VIR_MIGRATE_PAUSED)) {
         if (libxl_domain_unpause(priv->ctx, vm->def->id) != 0) {
             virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -558,15 +568,17 @@ libxlDomainMigrationFinish(virConnectPtr
 
     dom = virGetDomain(dconn, vm->def->name, vm->def->uuid);
 
+ cleanup:
     if (dom == NULL) {
         libxl_domain_destroy(priv->ctx, vm->def->id, NULL);
         libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
         event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
                                          VIR_DOMAIN_EVENT_STOPPED_FAILED);
         libxlDomainEventQueue(driver, event);
+        if (!vm->persistent)
+            virDomainObjListRemove(driver->domains, vm);
     }
 
- cleanup:
     if (event)
         libxlDomainEventQueue(driver, event);
     virObjectUnref(cfg);