[libvirt] [PATCH v2 7/9] test: Clean up testStoragePoolCreateXML error processing

John Ferlan jferlan at redhat.com
Wed Mar 28 21:19:31 UTC 2018


Rather than 2 separate, but same 4 lines of code - let's create an
error label to make a common error path. This will help shortly when
the error path changes slightly.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/test/test_driver.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 568d537e9..0a284e3d1 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4562,20 +4562,12 @@ testStoragePoolCreateXML(virConnectPtr conn,
          * rename a few fields to mock that. */
         if (testCreateVport(privconn,
                             def->source.adapter.data.fchost.wwnn,
-                            def->source.adapter.data.fchost.wwpn) < 0) {
-            virStoragePoolObjRemove(privconn->pools, obj);
-            virObjectUnref(obj);
-            obj = NULL;
-            goto cleanup;
-        }
+                            def->source.adapter.data.fchost.wwpn) < 0)
+            goto error;
     }
 
-    if (testStoragePoolObjSetDefaults(obj) == -1) {
-        virStoragePoolObjRemove(privconn->pools, obj);
-        virObjectUnref(obj);
-        obj = NULL;
-        goto cleanup;
-    }
+    if (testStoragePoolObjSetDefaults(obj) == -1)
+        goto error;
 
     /* *SetDefaults fills this in for the persistent pools, but this
      * would be a transient pool so remove it; otherwise, the Destroy
@@ -4596,6 +4588,12 @@ testStoragePoolCreateXML(virConnectPtr conn,
     virStoragePoolObjEndAPI(&obj);
     testDriverUnlock(privconn);
     return pool;
+
+ error:
+    virStoragePoolObjRemove(privconn->pools, obj);
+    virObjectUnref(obj);
+    obj = NULL;
+    goto cleanup;
 }
 
 
-- 
2.13.6




More information about the libvir-list mailing list