[libvirt] [PATCH 04/20] libxl: Use virDomainObjListFindBy{UUID|ID}Ref

John Ferlan posted 20 patches 7 years, 2 months ago
[libvirt] [PATCH 04/20] libxl: Use virDomainObjListFindBy{UUID|ID}Ref
Posted by John Ferlan 7 years, 2 months ago
For libxlDomainLookupByID and libxlDomainLookupByUUID let's
return a locked and referenced @vm object so that callers can
then use the common and more consistent virDomainObjEndAPI in
order to handle cleanup rather than needing to know that the
returned object is locked and calling virObjectUnlock.

The LookupByName already returns the ref counted and locked object,
so this will make things more consistent.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/libxl/libxl_driver.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 9aa4a293c..e78fe2d4b 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1090,7 +1090,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id)
     virDomainObjPtr vm;
     virDomainPtr dom = NULL;
 
-    vm = virDomainObjListFindByID(driver->domains, id);
+    vm = virDomainObjListFindByIDRef(driver->domains, id);
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -1102,8 +1102,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id)
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
  cleanup:
-    if (vm)
-        virObjectUnlock(vm);
+    virDomainObjEndAPI(&vm);
     return dom;
 }
 
@@ -1114,7 +1113,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
     virDomainObjPtr vm;
     virDomainPtr dom = NULL;
 
-    vm = virDomainObjListFindByUUID(driver->domains, uuid);
+    vm = virDomainObjListFindByUUIDRef(driver->domains, uuid);
     if (!vm) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
@@ -1126,8 +1125,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
  cleanup:
-    if (vm)
-        virObjectUnlock(vm);
+    virDomainObjEndAPI(&vm);
     return dom;
 }
 
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/20] libxl: Use virDomainObjListFindBy{UUID|ID}Ref
Posted by Jim Fehlig 7 years, 2 months ago
On 03/09/2018 09:48 AM, John Ferlan wrote:
> For libxlDomainLookupByID and libxlDomainLookupByUUID let's
> return a locked and referenced @vm object so that callers can
> then use the common and more consistent virDomainObjEndAPI in
> order to handle cleanup rather than needing to know that the
> returned object is locked and calling virObjectUnlock.
> 
> The LookupByName already returns the ref counted and locked object,
> so this will make things more consistent.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>   src/libxl/libxl_driver.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)

Reviewed-by: Jim Fehlig <jfehlig@suse.com>

Regards,
Jim

> 
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index 9aa4a293c..e78fe2d4b 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -1090,7 +1090,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id)
>       virDomainObjPtr vm;
>       virDomainPtr dom = NULL;
>   
> -    vm = virDomainObjListFindByID(driver->domains, id);
> +    vm = virDomainObjListFindByIDRef(driver->domains, id);
>       if (!vm) {
>           virReportError(VIR_ERR_NO_DOMAIN, NULL);
>           goto cleanup;
> @@ -1102,8 +1102,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id)
>       dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
>   
>    cleanup:
> -    if (vm)
> -        virObjectUnlock(vm);
> +    virDomainObjEndAPI(&vm);
>       return dom;
>   }
>   
> @@ -1114,7 +1113,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
>       virDomainObjPtr vm;
>       virDomainPtr dom = NULL;
>   
> -    vm = virDomainObjListFindByUUID(driver->domains, uuid);
> +    vm = virDomainObjListFindByUUIDRef(driver->domains, uuid);
>       if (!vm) {
>           virReportError(VIR_ERR_NO_DOMAIN, NULL);
>           goto cleanup;
> @@ -1126,8 +1125,7 @@ libxlDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
>       dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
>   
>    cleanup:
> -    if (vm)
> -        virObjectUnlock(vm);
> +    virDomainObjEndAPI(&vm);
>       return dom;
>   }
>   
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/20] libxl: Use virDomainObjListFindBy{UUID|ID}Ref
Posted by Jim Fehlig 7 years, 1 month ago
On 03/11/2018 08:14 PM, Jim Fehlig wrote:
> On 03/09/2018 09:48 AM, John Ferlan wrote:
>> For libxlDomainLookupByID and libxlDomainLookupByUUID let's
>> return a locked and referenced @vm object so that callers can
>> then use the common and more consistent virDomainObjEndAPI in
>> order to handle cleanup rather than needing to know that the
>> returned object is locked and calling virObjectUnlock.
>>
>> The LookupByName already returns the ref counted and locked object,
>> so this will make things more consistent.
>>
>> Signed-off-by: John Ferlan <jferlan@redhat.com>
>> ---
>>   src/libxl/libxl_driver.c | 10 ++++------
>>   1 file changed, 4 insertions(+), 6 deletions(-)
> 
> Reviewed-by: Jim Fehlig <jfehlig@suse.com>

I pushed this one as well.

Regards,
Jim

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