[libvirt] [PATCH V2] libxl: MigratePrepare: use standard begin and end API pattern

Jim Fehlig posted 1 patch 6 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20180316194603.9268-1-jfehlig@suse.com
Test syntax-check passed
src/libxl/libxl_migration.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
[libvirt] [PATCH V2] libxl: MigratePrepare: use standard begin and end API pattern
Posted by Jim Fehlig 6 years, 1 month ago
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>
---

V2 of

https://www.redhat.com/archives/libvir-list/2018-March/msg00674.html

Changes in V2:
Add ref after call to virDomainObjListAdd so that EndAPI can be used
in the usual pattern.

 src/libxl/libxl_migration.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 42a84bd35..7dc39ae02 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -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;
 }
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH V2] libxl: MigratePrepare: use standard begin and end API pattern
Posted by John Ferlan 6 years, 1 month ago

On 03/16/2018 03:46 PM, Jim Fehlig wrote:
> 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>
> ---
> 
> V2 of
> 
> https://www.redhat.com/archives/libvir-list/2018-March/msg00674.html
> 
> Changes in V2:
> Add ref after call to virDomainObjListAdd so that EndAPI can be used
> in the usual pattern.
> 
>  src/libxl/libxl_migration.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list