]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: MigratePrepare: use standard begin and end API pattern
authorJim Fehlig <jfehlig@suse.com>
Tue, 13 Mar 2018 16:48:28 +0000 (10:48 -0600)
committerJim Fehlig <jfehlig@suse.com>
Fri, 16 Mar 2018 20:37:01 +0000 (14:37 -0600)
libxlDomainMigrationPrepare adds the incoming domain def to the list
of domains via virDomainObjListAdd, but never adds its own ref to the
returned virDomainObj as other callers of virDomainObjListAdd do.
libxlDomainMigrationPrepareTunnel3 suffers the same discrepancy.

Change both to add a ref to the virDomainObj after a successful
virDomainObjListAdd, similar to other callers. This ensures a consistent
pattern throughout the drivers and allows using the virDomainObjEndAPI
function for cleanup.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/libxl/libxl_migration.c

index 42a84bd3582952c849153416de589de89c2a9dae..7dc39ae0250adb304788b62eb9af673c165051f1 100644 (file)
@@ -583,6 +583,7 @@ libxlDomainMigrationPrepareTunnel3(virConnectPtr dconn,
                                    NULL)))
         goto error;
 
+    virObjectRef(vm);
     *def = NULL;
     priv = vm->privateData;
 
@@ -635,13 +636,11 @@ libxlDomainMigrationPrepareTunnel3(virConnectPtr dconn,
     /* Remove virDomainObj from domain list */
     if (vm) {
         virDomainObjListRemove(driver->domains, vm);
-        vm = NULL;
+        virObjectLock(vm);
     }
 
  done:
-    if (vm)
-        virObjectUnlock(vm);
-
+    virDomainObjEndAPI(&vm);
     return ret;
 }
 
@@ -683,6 +682,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
                                    NULL)))
         goto error;
 
+    virObjectRef(vm);
     *def = NULL;
     priv = vm->privateData;
 
@@ -810,7 +810,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
     /* Remove virDomainObj from domain list */
     if (vm) {
         virDomainObjListRemove(driver->domains, vm);
-        vm = NULL;
+        virObjectLock(vm);
     }
 
  done:
@@ -820,8 +820,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
         VIR_FREE(hostname);
     else
         virURIFree(uri);
-    if (vm)
-        virObjectUnlock(vm);
+    virDomainObjEndAPI(&vm);
     virObjectUnref(cfg);
     return ret;
 }