]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Consolidate {Enter,Exit}Monitor{,WithDriver}
authorJiri Denemark <jdenemar@redhat.com>
Sun, 3 Jul 2011 21:55:47 +0000 (23:55 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 12 Jul 2011 19:17:28 +0000 (21:17 +0200)
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

index 8f3eaa76dcf900978abf468046808d9f72009a85..a2e77b6512da0d878116481910a30e0fb6dc6c04 100644 (file)
@@ -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,