[PATCH 2/3] qemu: monitor: check monitor not closed on send

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

 



It is convinient to have closed state for qemu monitor. I'm going
to use it on daemon shutdown. We can use fd to check for this state.

Now we don't need to set lastError on qemuMonitorClose as the error will
be reported explicitly by qemuMonitorSend.

Let's report VIR_ERR_OPERATION_INVALID instead of VIR_ERR_OPERATION_FAILED
as closing monitor is a part of stopping domain (and will be a part
of shutting driver down). Particularly we won't see error messages
in daemon log.
---
 src/qemu/qemu_monitor.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 363ad76..ba2371f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1000,22 +1000,9 @@ qemuMonitorClose(qemuMonitorPtr mon)
     }
 
     /* In case another thread is waiting for its monitor command to be
-     * processed, we need to wake it up with appropriate error set.
+     * processed, we need to wake it up.
      */
     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);
     }
@@ -1047,6 +1034,12 @@ qemuMonitorSend(qemuMonitorPtr mon,
 {
     int ret = -1;
 
+    if (mon->fd < 0) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("QEMU monitor was closed"));
+        return -1;
+    }
+
     /* Check whether qemu quit unexpectedly */
     if (mon->lastError.code != VIR_ERR_OK) {
         VIR_DEBUG("Attempt to send command while error is set %s",
@@ -1070,6 +1063,12 @@ qemuMonitorSend(qemuMonitorPtr mon,
         }
     }
 
+    if (mon->fd < 0) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("QEMU monitor was closed"));
+        goto cleanup;
+    }
+
     if (mon->lastError.code != VIR_ERR_OK) {
         VIR_DEBUG("Send command resulted in error %s",
                   NULLSTR(mon->lastError.message));
-- 
1.8.3.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]
  Powered by Linux