[libvirt] [PATCH RFC 3/5] qemu: monitor: add closed monitor flag

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Mon Nov 28 08:15:44 UTC 2016


More precisely this patch reuse existing mon->lastError to mark monitor as
closed.

Why we need this state? For sure monitor have closed state and attempts to send
commands in this state must fail otherwise we hang on waiting command response,
AFAIK monitor is never used in this state because of locks structure: first
check if domain is active (that is monitor is not closed), then lock monitor,
then unlock domain - any code that closes monitor first lock domain so at this
moment we have a lock on monitor and it is not closed. So this patch just makes
monitor more incapsulated. Just to be sure.

---
 src/qemu/qemu_monitor.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index f402300..950b371 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -957,23 +957,24 @@ qemuMonitorClose(qemuMonitorPtr mon)
         VIR_FORCE_CLOSE(mon->fd);
     }
 
+    if (mon->lastError.code == VIR_ERR_OK) {
+        virErrorPtr err = virSaveLastError();
+
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                       _("Qemu monitor was closed"));
+        virCopyLastError(&mon->lastError);
+        if (err) {
+            virSetError(err);
+            virFreeError(err);
+        } else {
+            virResetLastError();
+        }
+    }
+
     /* In case another thread is waiting for its monitor command to be
      * processed, we need to wake it up with appropriate error set.
      */
     if (mon->msg) {
-        if (mon->lastError.code == VIR_ERR_OK) {
-            virErrorPtr err = virSaveLastError();
-
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("Qemu monitor was closed"));
-            virCopyLastError(&mon->lastError);
-            if (err) {
-                virSetError(err);
-                virFreeError(err);
-            } else {
-                virResetLastError();
-            }
-        }
         mon->msg->finished = 1;
         virCondSignal(&mon->notify);
     }
-- 
1.8.3.1




More information about the libvir-list mailing list