Rework some of the test driver API's to remove the need to return failure
when testStoragePoolObjFindByName returns NULL rather than going to cleanup.
This removes the need for check for "if (obj)" and in some instances the
need to for a cleanup label and a local ret variable.

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/test/test_driver.c | 49 ++++++++++++++++---------------------------------
 1 file changed, 16 insertions(+), 33 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index c0e46af..efa54ff 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4060,14 +4060,12 @@ testStoragePoolLookupByUUID(virConnectPtr conn,
     virStoragePoolPtr ret = NULL;
 
     if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid)))
-        goto cleanup;
+        return NULL;
 
     ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
                             NULL, NULL);
 
- cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
+    virStoragePoolObjUnlock(obj);
     return ret;
 }
 
@@ -4081,14 +4079,12 @@ testStoragePoolLookupByName(virConnectPtr conn,
     virStoragePoolPtr ret = NULL;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, name)))
-        goto cleanup;
+        return NULL;
 
     ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
                             NULL, NULL);
 
- cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
+    virStoragePoolObjUnlock(obj);
     return ret;
 }
 
@@ -4210,13 +4206,11 @@ testStoragePoolIsPersistent(virStoragePoolPtr pool)
     int ret = -1;
 
     if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid)))
-        goto cleanup;
+        return -1;
 
     ret = obj->configFile ? 1 : 0;
 
- cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
+    virStoragePoolObjUnlock(obj);
     return ret;
 }
 
@@ -4668,10 +4662,9 @@ testStoragePoolGetInfo(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
-    int ret = -1;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
-        goto cleanup;
+        return -1;
 
     memset(info, 0, sizeof(virStoragePoolInfo));
     if (obj->active)
@@ -4681,12 +4674,9 @@ testStoragePoolGetInfo(virStoragePoolPtr pool,
     info->capacity = obj->def->capacity;
     info->allocation = obj->def->allocation;
     info->available = obj->def->available;
-    ret = 0;
 
- cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
-    return ret;
+    virStoragePoolObjUnlock(obj);
+    return 0;
 }
 
 
@@ -4701,13 +4691,11 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool,
     virCheckFlags(0, NULL);
 
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
-        goto cleanup;
+        return NULL;
 
     ret = virStoragePoolDefFormat(obj->def);
 
- cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
+    virStoragePoolObjUnlock(obj);
     return ret;
 }
 
@@ -4718,22 +4706,18 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
-    int ret = -1;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
-        goto cleanup;
+        return -1;
 
     if (!obj->configFile) {
         *autostart = 0;
     } else {
         *autostart = obj->autostart;
     }
-    ret = 0;
 
- cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
-    return ret;
+    virStoragePoolObjUnlock(obj);
+    return 0;
 }
 
 
@@ -4746,7 +4730,7 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool,
     int ret = -1;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
-        goto cleanup;
+        return -1;
 
     if (!obj->configFile) {
         virReportError(VIR_ERR_INVALID_ARG,
@@ -4759,8 +4743,7 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool,
     ret = 0;
 
  cleanup:
-    if (obj)
-        virStoragePoolObjUnlock(obj);
+    virStoragePoolObjUnlock(obj);
     return ret;
 }
 
-- 
2.9.3

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

Reply via email to