[PATCH 4/8] test: Refactor test driver event sending

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make testObjectEventQueue tolerant to NULL @event and move it so that it
does not require a prototype. Additionally add
testObjectEventQueueUnlocked that will lock @driver before sending the
event.

Refactor the rest of the codebase to make use of the above features
---
 src/test/test_driver.c | 112 +++++++++++++++++++------------------------------
 1 file changed, 44 insertions(+), 68 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index dc6e49a..20d3c71 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -137,8 +137,6 @@ static const virNodeInfo defaultNodeInfo = {


 static int testConnectClose(virConnectPtr conn);
-static void testObjectEventQueue(testConnPtr driver,
-                                 virObjectEventPtr event);

 static void testDriverLock(testConnPtr driver)
 {
@@ -150,6 +148,28 @@ static void testDriverUnlock(testConnPtr driver)
     virMutexUnlock(&driver->lock);
 }

+static void testObjectEventQueue(testConnPtr driver,
+                                 virObjectEventPtr event)
+{
+    if (!event)
+        return;
+
+    virObjectEventStateQueue(driver->eventState, event);
+}
+
+
+static void
+testObjectEventQueueUnlocked(testConnPtr driver,
+                             virObjectEventPtr event)
+{
+    if (!event)
+        return;
+
+    testDriverLock(driver);
+    testObjectEventQueue(driver, event);
+    testDriverUnlock(driver);
+}
+
 static void *testDomainObjPrivateAlloc(void)
 {
     testDomainObjPrivatePtr priv;
@@ -1774,8 +1794,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
  cleanup:
     if (dom)
         virObjectUnlock(dom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     virDomainDefFree(def);
     testDriverUnlock(privconn);
     return ret;
@@ -1896,8 +1915,7 @@ static int testDomainDestroy(virDomainPtr domain)
     ret = 0;
  cleanup:
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -1927,11 +1945,7 @@ static int testDomainResume(virDomainPtr domain)

  cleanup:
     virDomainObjEndAPI(&privdom);
-    if (event) {
-        testDriverLock(privconn);
-        testObjectEventQueue(privconn, event);
-        testDriverUnlock(privconn);
-    }
+    testObjectEventQueueUnlocked(privconn, event);
     return ret;
 }

@@ -1961,12 +1975,7 @@ static int testDomainSuspend(virDomainPtr domain)

  cleanup:
     virDomainObjEndAPI(&privdom);
-
-    if (event) {
-        testDriverLock(privconn);
-        testObjectEventQueue(privconn, event);
-        testDriverUnlock(privconn);
-    }
+    testObjectEventQueueUnlocked(privconn, event);
     return ret;
 }

@@ -2002,8 +2011,7 @@ static int testDomainShutdownFlags(virDomainPtr domain,
     ret = 0;
  cleanup:
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -2070,8 +2078,7 @@ static int testDomainReboot(virDomainPtr domain,
     ret = 0;
  cleanup:
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -2214,8 +2221,7 @@ testDomainSaveFlags(virDomainPtr domain, const char *path,
         unlink(path);
     }
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -2319,8 +2325,7 @@ testDomainRestoreFlags(virConnectPtr conn,
     VIR_FORCE_CLOSE(fd);
     if (dom)
         virObjectUnlock(dom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -2389,8 +2394,7 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain,
  cleanup:
     VIR_FORCE_CLOSE(fd);
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -2817,8 +2821,7 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
     virDomainDefFree(oldDef);
     if (dom)
         virObjectUnlock(dom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -2938,8 +2941,7 @@ static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)

  cleanup:
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -3006,8 +3008,7 @@ static int testDomainUndefineFlags(virDomainPtr domain,

  cleanup:
     virDomainObjEndAPI(&privdom);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     testDriverUnlock(privconn);
     return ret;
 }
@@ -3385,8 +3386,7 @@ static virNetworkPtr testNetworkCreateXML(virConnectPtr conn, const char *xml)

  cleanup:
     virNetworkDefFree(def);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     virNetworkObjEndAPI(&net);
     return ret;
 }
@@ -3415,8 +3415,7 @@ virNetworkPtr testNetworkDefineXML(virConnectPtr conn, const char *xml)

  cleanup:
     virNetworkDefFree(def);
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     virNetworkObjEndAPI(&net);
     return ret;
 }
@@ -3449,8 +3448,7 @@ static int testNetworkUndefine(virNetworkPtr network)
     ret = 0;

  cleanup:
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     virNetworkObjEndAPI(&privnet);
     return ret;
 }
@@ -3527,8 +3525,7 @@ static int testNetworkCreate(virNetworkPtr network)
     ret = 0;

  cleanup:
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     virNetworkObjEndAPI(&privnet);
     return ret;
 }
@@ -3556,8 +3553,7 @@ static int testNetworkDestroy(virNetworkPtr network)
     ret = 0;

  cleanup:
-    if (event)
-        testObjectEventQueue(privconn, event);
+    testObjectEventQueue(privconn, event);
     virNetworkObjEndAPI(&privnet);
     return ret;
 }
@@ -5840,15 +5836,6 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn,
     return ret;
 }

-
-/* driver must be locked before calling */
-static void testObjectEventQueue(testConnPtr driver,
-                                 virObjectEventPtr event)
-{
-    virObjectEventStateQueue(driver->eventState, event);
-}
-
-
 static int testConnectListAllDomains(virConnectPtr conn,
                                      virDomainPtr **domains,
                                      unsigned int flags)
@@ -5959,11 +5946,7 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags)
     ret = 0;
  cleanup:
     virDomainObjEndAPI(&vm);
-    if (event) {
-        testDriverLock(privconn);
-        testObjectEventQueue(privconn, event);
-        testDriverUnlock(privconn);
-    }
+    testObjectEventQueueUnlocked(privconn, event);

     return ret;
 }
@@ -6476,11 +6459,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
         }
         virDomainObjEndAPI(&vm);
     }
-    if (event) {
-        testDriverLock(privconn);
-        testObjectEventQueue(privconn, event);
-        testDriverUnlock(privconn);
-    }
+    testObjectEventQueueUnlocked(privconn, event);
     virDomainSnapshotDefFree(def);
     return snapshot;
 }
@@ -6720,8 +6699,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
                 event = virDomainEventLifecycleNewFromObj(vm,
                             VIR_DOMAIN_EVENT_STOPPED,
                             VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
-                if (event)
-                    testObjectEventQueue(privconn, event);
+                testObjectEventQueue(privconn, event);
                 goto load;
             }

@@ -6800,8 +6778,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
             /* Flush first event, now do transition 2 or 3 */
             bool paused = (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED) != 0;

-            if (event)
-                testObjectEventQueue(privconn, event);
+            testObjectEventQueue(privconn, event);
             event = virDomainEventLifecycleNewFromObj(vm,
                             VIR_DOMAIN_EVENT_STARTED,
                             VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT);
@@ -6818,8 +6795,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
  cleanup:
     if (event) {
         testObjectEventQueue(privconn, event);
-        if (event2)
-            testObjectEventQueue(privconn, event2);
+        testObjectEventQueue(privconn, event2);
     } else {
         virObjectUnref(event2);
     }
-- 
2.4.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]