[PATCH 1/3] rpc: socket: Add possibility to suppress errors on read hangup

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

 



In some cases a read error due to connection hangup is expected. This
patch adds a flag that removes the logging of a virError in such case.
---
 src/rpc/virnetsocket.c | 33 +++++++++++++++++++++++++++------
 src/rpc/virnetsocket.h |  2 ++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 325a7c7cf..4d1dc6446 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -82,6 +82,7 @@ struct _virNetSocket {
     int errfd;
     bool client;
     bool ownsFd;
+    bool quietEOF;

     /* Event callback fields */
     virNetSocketIOFunc func;
@@ -1792,12 +1793,18 @@ static ssize_t virNetSocketReadWire(virNetSocketPtr sock, char *buf, size_t len)
                                  _("Cannot recv data"));
         ret = -1;
     } else if (ret == 0) {
-        if (errout)
-            virReportSystemError(EIO,
-                                 _("End of file while reading data: %s"), errout);
-        else
-            virReportSystemError(EIO, "%s",
-                                 _("End of file while reading data"));
+        if (sock->quietEOF) {
+            VIR_DEBUG("socket='%p' EOF while reading: errout='%s'",
+                      socket, NULLSTR(errout));
+        } else {
+            if (errout)
+                virReportSystemError(EIO,
+                                     _("End of file while reading data: %s"),
+                                     errout);
+            else
+                virReportSystemError(EIO, "%s",
+                                     _("End of file while reading data"));
+        }
         ret = -1;
     }

@@ -2233,3 +2240,17 @@ void virNetSocketClose(virNetSocketPtr sock)

     virObjectUnlock(sock);
 }
+
+
+/**
+ * virNetSocketSetQuietEOF:
+ * @sock: socket object pointer
+ *
+ * Disables reporting I/O errors as a virError when @socket is closed while
+ * reading data.
+ */
+void
+virNetSocketSetQuietEOF(virNetSocketPtr sock)
+{
+    sock->quietEOF = true;
+}
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index 56c75c030..1e75ee62b 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -143,6 +143,8 @@ int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
 int virNetSocketSetBlocking(virNetSocketPtr sock,
                             bool blocking);

+void virNetSocketSetQuietEOF(virNetSocketPtr sock);
+
 ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
 ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);

-- 
2.12.0

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