Re: [libvirt] [PATCH 2/8] test: Switch to reference counting with testDomObjFromDomain

2015-06-19 Thread Michal Privoznik
On 16.06.2015 19:43, Peter Krempa wrote:
 Retrieve domain objects with reference and release them with
 virDomainObjEndAPI.
 ---
  src/test/test_driver.c | 89 
 --
  1 file changed, 35 insertions(+), 54 deletions(-)
 
 diff --git a/src/test/test_driver.c b/src/test/test_driver.c
 index c0ef459..6613ed7 100644
 --- a/src/test/test_driver.c
 +++ b/src/test/test_driver.c
 @@ -484,7 +484,7 @@ testDomObjFromDomain(virDomainPtr domain)
  char uuidstr[VIR_UUID_STRING_BUFLEN];
 
  testDriverLock(driver);
 -vm = virDomainObjListFindByUUID(driver-domains, domain-uuid);
 +vm = virDomainObjListFindByUUIDRef(driver-domains, domain-uuid);
  if (!vm) {
  virUUIDFormat(domain-uuid, uuidstr);
  virReportError(VIR_ERR_NO_DOMAIN,

Oh, this reminds me that I wanted to drop testDriverLock. It's
unnecessary here - domainObjList has self-locking APIs.

ACK

Michal

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


[libvirt] [PATCH 2/8] test: Switch to reference counting with testDomObjFromDomain

2015-06-16 Thread Peter Krempa
Retrieve domain objects with reference and release them with
virDomainObjEndAPI.
---
 src/test/test_driver.c | 89 --
 1 file changed, 35 insertions(+), 54 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index c0ef459..6613ed7 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -484,7 +484,7 @@ testDomObjFromDomain(virDomainPtr domain)
 char uuidstr[VIR_UUID_STRING_BUFLEN];

 testDriverLock(driver);
-vm = virDomainObjListFindByUUID(driver-domains, domain-uuid);
+vm = virDomainObjListFindByUUIDRef(driver-domains, domain-uuid);
 if (!vm) {
 virUUIDFormat(domain-uuid, uuidstr);
 virReportError(VIR_ERR_NO_DOMAIN,
@@ -6262,19 +6262,17 @@ static int
 testDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
 {
 virDomainObjPtr vm = NULL;
-int n = -1;
+int n;

 virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
   VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);

 if (!(vm = testDomObjFromDomain(domain)))
-goto cleanup;
+return -1;

 n = virDomainSnapshotObjListNum(vm-snapshots, NULL, flags);

- cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return n;
 }

@@ -6285,20 +6283,18 @@ testDomainSnapshotListNames(virDomainPtr domain,
 unsigned int flags)
 {
 virDomainObjPtr vm = NULL;
-int n = -1;
+int n;

 virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
   VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);

 if (!(vm = testDomObjFromDomain(domain)))
-goto cleanup;
+return -1;

 n = virDomainSnapshotObjListGetNames(vm-snapshots, NULL, names, nameslen,
  flags);

- cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return n;
 }

@@ -6308,19 +6304,17 @@ testDomainListAllSnapshots(virDomainPtr domain,
unsigned int flags)
 {
 virDomainObjPtr vm = NULL;
-int n = -1;
+int n;

 virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
   VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);

 if (!(vm = testDomObjFromDomain(domain)))
-goto cleanup;
+return -1;

 n = virDomainListSnapshots(vm-snapshots, NULL, domain, snaps, flags);

- cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return n;
 }

@@ -6338,7 +6332,7 @@ testDomainSnapshotListChildrenNames(virDomainSnapshotPtr 
snapshot,
   VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);

 if (!(vm = testDomObjFromSnapshot(snapshot)))
-goto cleanup;
+return -1;

 if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
 goto cleanup;
@@ -6347,8 +6341,7 @@ testDomainSnapshotListChildrenNames(virDomainSnapshotPtr 
snapshot,
  flags);

  cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return n;
 }

@@ -6364,7 +6357,7 @@ testDomainSnapshotNumChildren(virDomainSnapshotPtr 
snapshot,
   VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);

 if (!(vm = testDomObjFromSnapshot(snapshot)))
-goto cleanup;
+return -1;

 if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
 goto cleanup;
@@ -6372,8 +6365,7 @@ testDomainSnapshotNumChildren(virDomainSnapshotPtr 
snapshot,
 n = virDomainSnapshotObjListNum(vm-snapshots, snap, flags);

  cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return n;
 }

@@ -6390,7 +6382,7 @@ testDomainSnapshotListAllChildren(virDomainSnapshotPtr 
snapshot,
   VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);

 if (!(vm = testDomObjFromSnapshot(snapshot)))
-goto cleanup;
+return -1;

 if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
 goto cleanup;
@@ -6399,8 +6391,7 @@ testDomainSnapshotListAllChildren(virDomainSnapshotPtr 
snapshot,
flags);

  cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return n;
 }

@@ -6416,7 +6407,7 @@ testDomainSnapshotLookupByName(virDomainPtr domain,
 virCheckFlags(0, NULL);

 if (!(vm = testDomObjFromDomain(domain)))
-goto cleanup;
+return NULL;

 if (!(snap = testSnapObjFromName(vm, name)))
 goto cleanup;
@@ -6424,8 +6415,7 @@ testDomainSnapshotLookupByName(virDomainPtr domain,
 snapshot = virGetDomainSnapshot(domain, snap-def-name);

  cleanup:
-if (vm)
-virObjectUnlock(vm);
+virDomainObjEndAPI(vm);
 return snapshot;
 }

@@ -6434,18 +6424,16 @@ testDomainHasCurrentSnapshot(virDomainPtr domain,
  unsigned int flags)
 {
 virDomainObjPtr vm;
-int ret = -1;
+int ret;

 virCheckFlags(0, -1);

 if (!(vm = testDomObjFromDomain(domain)))
-goto cleanup;
+return -1;

 ret =