]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: acquire job in migration finish phase
authorJim Fehlig <jfehlig@suse.com>
Thu, 13 Nov 2014 21:41:56 +0000 (14:41 -0700)
committerJim Fehlig <jfehlig@suse.com>
Fri, 21 Nov 2014 20:11:47 +0000 (13:11 -0700)
Moving data reception of the perform phase of migration to a
thread introduces a race with the finish phase, where checking
if the domain is active races with the thread finishing the
perform phase.  The race is easily solved by acquiring a job in
the finish phase, which must wait for the perform phase job to
complete.

While wrapping the finish phase in a job, noticed the virDomainObj
was being unlocked in a callee - libxlDomainMigrationFinish.  Move
the unlocking to libxlDomainMigrateFinish3Params, where the lock
is acquired.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
src/libxl/libxl_driver.c
src/libxl/libxl_migration.c

index 8cbf3c0bdd8b0302398f679a66b7c7e12e91d50a..8c2b19211ffc95ed35f240a3012f0a1bc3df5f5c 100644 (file)
@@ -4650,6 +4650,7 @@ libxlDomainMigrateFinish3Params(virConnectPtr dconn,
     libxlDriverPrivatePtr driver = dconn->privateData;
     virDomainObjPtr vm = NULL;
     const char *dname = NULL;
+    virDomainPtr ret = NULL;
 
 #ifdef LIBXL_HAVE_NO_SUSPEND_RESUME
     virReportUnsupportedError();
@@ -4680,16 +4681,29 @@ libxlDomainMigrateFinish3Params(virConnectPtr dconn,
         return NULL;
     }
 
+    if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
+        virObjectUnlock(vm);
+        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"));
-        virObjectUnlock(vm);
-        return NULL;
+        goto endjob;
     }
 
-    return libxlDomainMigrationFinish(dconn, vm, flags, cancelled);
+    ret = libxlDomainMigrationFinish(dconn, vm, flags, cancelled);
+
+ endjob:
+    if (!libxlDomainObjEndJob(driver, vm))
+        vm = NULL;
+
+    if (vm)
+        virObjectUnlock(vm);
+
+    return ret;
 }
 
 static int
index c728fa27ed73a4041e9b75a6331b1a2f07af0b51..fa80a0cca73bb64278bd63fe62438ac1aab372e5 100644 (file)
@@ -573,7 +573,6 @@ libxlDomainMigrationFinish(virConnectPtr dconn,
  cleanup:
     if (event)
         libxlDomainEventQueue(driver, event);
-    virObjectUnlock(vm);
     virObjectUnref(cfg);
     return dom;
 }