[PATCH 03/19] qemu: Consolidate {Enter, Exit}Monitor{, WithDriver}

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

 



EnterMonitor and ExitMonitor methods are very similar to their
*WithDriver variants; consolidate them into EnterMonitorInternal and
ExitMonitorInternal to avoid (mainly future) code duplication.
---
 src/qemu/qemu_domain.c |   74 ++++++++++++++++++++++-------------------------
 1 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8f3eaa7..a2e77b6 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -622,16 +622,10 @@ int qemuDomainObjEndJob(virDomainObjPtr obj)
     return virDomainObjUnref(obj);
 }
 
-/*
- * obj must be locked before calling, qemud_driver must be unlocked
- *
- * To be called immediately before any QEMU monitor API call
- * Must have already called qemuDomainObjBeginJob(), and checked
- * that the VM is still active.
- *
- * To be followed with qemuDomainObjExitMonitor() once complete
- */
-void qemuDomainObjEnterMonitor(virDomainObjPtr obj)
+
+static void
+qemuDomainObjEnterMonitorInternal(struct qemud_driver *driver,
+                                  virDomainObjPtr obj)
 {
     qemuDomainObjPrivatePtr priv = obj->privateData;
 
@@ -639,14 +633,13 @@ void qemuDomainObjEnterMonitor(virDomainObjPtr obj)
     qemuMonitorRef(priv->mon);
     ignore_value(virTimeMs(&priv->monStart));
     virDomainObjUnlock(obj);
+    if (driver)
+        qemuDriverUnlock(driver);
 }
 
-
-/* obj must NOT be locked before calling, qemud_driver must be unlocked
- *
- * Should be paired with an earlier qemuDomainObjEnterMonitor() call
- */
-void qemuDomainObjExitMonitor(virDomainObjPtr obj)
+static void
+qemuDomainObjExitMonitorInternal(struct qemud_driver *driver,
+                                 virDomainObjPtr obj)
 {
     qemuDomainObjPrivatePtr priv = obj->privateData;
     int refs;
@@ -656,6 +649,8 @@ void qemuDomainObjExitMonitor(virDomainObjPtr obj)
     if (refs > 0)
         qemuMonitorUnlock(priv->mon);
 
+    if (driver)
+        qemuDriverLock(driver);
     virDomainObjLock(obj);
 
     priv->monStart = 0;
@@ -664,6 +659,28 @@ void qemuDomainObjExitMonitor(virDomainObjPtr obj)
     }
 }
 
+/*
+ * obj must be locked before calling, qemud_driver must be unlocked
+ *
+ * To be called immediately before any QEMU monitor API call
+ * Must have already called qemuDomainObjBeginJob(), and checked
+ * that the VM is still active.
+ *
+ * To be followed with qemuDomainObjExitMonitor() once complete
+ */
+void qemuDomainObjEnterMonitor(virDomainObjPtr obj)
+{
+    qemuDomainObjEnterMonitorInternal(NULL, obj);
+}
+
+/* obj must NOT be locked before calling, qemud_driver must be unlocked
+ *
+ * Should be paired with an earlier qemuDomainObjEnterMonitor() call
+ */
+void qemuDomainObjExitMonitor(virDomainObjPtr obj)
+{
+    qemuDomainObjExitMonitorInternal(NULL, obj);
+}
 
 /*
  * obj must be locked before calling, qemud_driver must be locked
@@ -676,16 +693,9 @@ void qemuDomainObjExitMonitor(virDomainObjPtr obj)
 void qemuDomainObjEnterMonitorWithDriver(struct qemud_driver *driver,
                                          virDomainObjPtr obj)
 {
-    qemuDomainObjPrivatePtr priv = obj->privateData;
-
-    qemuMonitorLock(priv->mon);
-    qemuMonitorRef(priv->mon);
-    ignore_value(virTimeMs(&priv->monStart));
-    virDomainObjUnlock(obj);
-    qemuDriverUnlock(driver);
+    qemuDomainObjEnterMonitorInternal(driver, obj);
 }
 
-
 /* obj must NOT be locked before calling, qemud_driver must be unlocked,
  * and will be locked after returning
  *
@@ -694,21 +704,7 @@ void qemuDomainObjEnterMonitorWithDriver(struct qemud_driver *driver,
 void qemuDomainObjExitMonitorWithDriver(struct qemud_driver *driver,
                                         virDomainObjPtr obj)
 {
-    qemuDomainObjPrivatePtr priv = obj->privateData;
-    int refs;
-
-    refs = qemuMonitorUnref(priv->mon);
-
-    if (refs > 0)
-        qemuMonitorUnlock(priv->mon);
-
-    qemuDriverLock(driver);
-    virDomainObjLock(obj);
-
-    priv->monStart = 0;
-    if (refs == 0) {
-        priv->mon = NULL;
-    }
+    qemuDomainObjExitMonitorInternal(driver, obj);
 }
 
 void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,
-- 
1.7.6

--
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]