[libvirt] [PATCH v2 2/3] test: Use virDomainObjListFindByIDRef

John Ferlan posted 3 patches 7 years, 1 month ago
[libvirt] [PATCH v2 2/3] test: Use virDomainObjListFindByIDRef
Posted by John Ferlan 7 years, 1 month ago
Rather than using virDomainObjListFindByID, let's be more consistent
and return a reffed and locked object. Since we're using the Ref API,
use virDomainObjEndAPI on @dom and not just virObjectUnlock.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/test/test_driver.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0cacab2fde..3c01aa50e1 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1720,16 +1720,14 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn,
     virDomainPtr ret = NULL;
     virDomainObjPtr dom;
 
-    if (!(dom = virDomainObjListFindByID(privconn->domains, id))) {
+    if (!(dom = virDomainObjListFindByIDRef(privconn->domains, id))) {
         virReportError(VIR_ERR_NO_DOMAIN, NULL);
-        goto cleanup;
+        return NULL;
     }
 
     ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
 
- cleanup:
-    if (dom)
-        virObjectUnlock(dom);
+    virDomainObjEndAPI(&dom);
     return ret;
 }
 
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/3] test: Use virDomainObjListFindByIDRef
Posted by Marc Hartmayer 7 years, 1 month ago
On Mon, Apr 02, 2018 at 02:27 PM +0200, John Ferlan <jferlan@redhat.com> wrote:
> Rather than using virDomainObjListFindByID, let's be more consistent
> and return a reffed and locked object. Since we're using the Ref API,
> use virDomainObjEndAPI on @dom and not just virObjectUnlock.
>
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/test/test_driver.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 0cacab2fde..3c01aa50e1 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -1720,16 +1720,14 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn,
>      virDomainPtr ret = NULL;
>      virDomainObjPtr dom;
>
> -    if (!(dom = virDomainObjListFindByID(privconn->domains, id))) {
> +    if (!(dom = virDomainObjListFindByIDRef(privconn->domains, id))) {
>          virReportError(VIR_ERR_NO_DOMAIN, NULL);
> -        goto cleanup;
> +        return NULL;
>      }
>
>      ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
>
> - cleanup:
> -    if (dom)
> -        virObjectUnlock(dom);
> +    virDomainObjEndAPI(&dom);
>      return ret;
>  }
>
> --
> 2.13.6
>
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>

Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>

--
Beste Grüße / Kind regards
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


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