File 2703b0b5-qemu-dont-report-eof.patch of Package libvirt.22881

commit 2703b0b5bf2751d523a4d8d61901e473c92ba198
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Tue Oct 5 22:23:51 2021 -0600

    qemu: Do not report eof when processing monitor IO
    
    There have been countless reports from users concerned about the following
    error reported by libvirtd when qemu domains are shutdown
    
    internal error: End of file from qemu monitor
    
    While the error is harmless, users often mistaken it for real problem with
    their deployments. EOF from the monitor can't be entirely ignored since
    other threads may be using the monitor and must be able to detect the EOF
    condition.
    
    One potential fix is to delay reporting EOF until the monitor is used
    after EOF is detected. This patch adds a 'goteof' member to the
    qemuMonitor structure, which is set when EOF is detected on the monitor
    socket. If another thread later tries to send data on the monitor, the
    EOF error is reported.
    
    Signed-off-by: Jim Fehlig <jfehlig@suse.com>
    Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Index: libvirt-7.1.0/src/qemu/qemu_monitor.c
===================================================================
--- libvirt-7.1.0.orig/src/qemu/qemu_monitor.c
+++ libvirt-7.1.0/src/qemu/qemu_monitor.c
@@ -97,6 +97,9 @@ struct _qemuMonitor {
      * the next monitor msg */
     virError lastError;
 
+    /* Set to true when EOF is detected on the monitor */
+    bool goteof;
+
     int nextSerial;
 
     bool waitGreeting;
@@ -529,7 +532,6 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNU
 {
     qemuMonitorPtr mon = opaque;
     bool error = false;
-    bool eof = false;
     bool hangup = false;
 
     virObjectRef(mon);
@@ -547,7 +549,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNU
 
     if (mon->lastError.code != VIR_ERR_OK) {
         if (cond & (G_IO_HUP | G_IO_ERR))
-            eof = true;
+            mon->goteof = true;
         error = true;
     } else {
         if (cond & G_IO_OUT) {
@@ -565,7 +567,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNU
                 if (errno == ECONNRESET)
                     hangup = true;
             } else if (got == 0) {
-                eof = true;
+                mon->goteof = true;
             } else {
                 /* Ignore hangup/error cond if we read some data, to
                  * give time for that data to be consumed */
@@ -578,22 +580,19 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNU
 
         if (cond & G_IO_HUP) {
             hangup = true;
-            if (!error) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("End of file from qemu monitor"));
-                eof = true;
-            }
+            if (!error)
+                mon->goteof = true;
         }
 
-        if (!error && !eof &&
+        if (!error && !mon->goteof &&
             cond & G_IO_ERR) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Invalid file descriptor while waiting for monitor"));
-            eof = true;
+            mon->goteof = true;
         }
     }
 
-    if (error || eof) {
+    if (error || mon->goteof) {
         if (hangup && mon->logFunc != NULL) {
             /* Check if an error message from qemu is available and if so, use
              * it to overwrite the actual message. It's done only in early
@@ -612,7 +611,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNU
             /* Already have an error, so clear any new error */
             virResetLastError();
         } else {
-            if (virGetLastErrorCode() == VIR_ERR_OK)
+            if (virGetLastErrorCode() == VIR_ERR_OK && !mon->goteof)
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("Error while processing monitor IO"));
             virCopyLastError(&mon->lastError);
@@ -633,7 +632,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNU
     /* We have to unlock to avoid deadlock against command thread,
      * but is this safe ?  I think it is, because the callback
      * will try to acquire the virDomainObjPtr mutex next */
-    if (eof) {
+    if (mon->goteof) {
         qemuMonitorEofNotifyCallback eofNotify = mon->cb->eofNotify;
         virDomainObjPtr vm = mon->vm;
 
@@ -948,6 +947,11 @@ qemuMonitorSend(qemuMonitorPtr mon,
         virSetError(&mon->lastError);
         return -1;
     }
+    if (mon->goteof) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("End of file from qemu monitor"));
+        return -1;
+    }
 
     mon->msg = msg;
     qemuMonitorUpdateWatch(mon);
openSUSE Build Service is sponsored by