Blame SOURCES/libvirt-qemu_process-Make-qemuProcessReadLog-more-versatile-and-reusable.patch

43fe83
From aaffe43897ee06be10aca64861022dfeea735ed3 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <aaffe43897ee06be10aca64861022dfeea735ed3.1382534060.git.jdenemar@redhat.com>
43fe83
From: Peter Krempa <pkrempa@redhat.com>
43fe83
Date: Thu, 10 Oct 2013 13:56:29 +0200
43fe83
Subject: [PATCH] qemu_process: Make qemuProcessReadLog() more versatile and
43fe83
 reusable
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1001738
43fe83
43fe83
Teach the function to skip character device definitions printed by qemu
43fe83
at startup in addition to libvirt log messages and make it usable from
43fe83
outside of qemu_process.c. Also add documentation about the func.
43fe83
43fe83
(cherry picked from commit 310651a5e346b23db9015061452b1887335aed67)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/qemu/qemu_process.c | 24 +++++++++++++++++++-----
43fe83
 src/qemu/qemu_process.h |  2 ++
43fe83
 2 files changed, 21 insertions(+), 5 deletions(-)
43fe83
43fe83
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
43fe83
index 1bd0d04..063cd78 100644
43fe83
--- a/src/qemu/qemu_process.c
43fe83
+++ b/src/qemu/qemu_process.c
43fe83
@@ -1428,8 +1428,20 @@ error:
43fe83
     return ret;
43fe83
 }
43fe83
 
43fe83
-static int
43fe83
-qemuProcessReadLog(int fd, char *buf, int buflen, int off)
43fe83
+
43fe83
+/**
43fe83
+ * qemuProcessReadLog: Read log file of a qemu VM
43fe83
+ * @fd: File descriptor of the log file
43fe83
+ * @buf: buffer to store the read messages
43fe83
+ * @buflen: allocated space available in @buf
43fe83
+ * @off: Offset to start reading from
43fe83
+ * @skipchar: Skip messages about created character devices
43fe83
+ *
43fe83
+ * Reads log of a qemu VM. Skips messages not produced by qemu or irrelevant
43fe83
+ * messages. Returns length of the message stored in @buf, or -1 on error.
43fe83
+ */
43fe83
+int
43fe83
+qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar)
43fe83
 {
43fe83
     char *filter_next = buf;
43fe83
     ssize_t bytes;
43fe83
@@ -1450,7 +1462,9 @@ qemuProcessReadLog(int fd, char *buf, int buflen, int off)
43fe83
         /* Filter out debug messages from intermediate libvirt process */
43fe83
         while ((eol = strchr(filter_next, '\n'))) {
43fe83
             *eol = '\0';
43fe83
-            if (virLogProbablyLogMessage(filter_next)) {
43fe83
+            if (virLogProbablyLogMessage(filter_next) ||
43fe83
+                (skipchar &&
43fe83
+                 STRPREFIX(filter_next, "char device redirected to"))) {
43fe83
                 memmove(filter_next, eol + 1, off - (eol - buf));
43fe83
                 off -= eol + 1 - filter_next;
43fe83
             } else {
43fe83
@@ -1493,7 +1507,7 @@ qemuProcessReadLogOutput(virDomainObjPtr vm,
43fe83
 
43fe83
         isdead = kill(vm->pid, 0) == -1 && errno == ESRCH;
43fe83
 
43fe83
-        got = qemuProcessReadLog(fd, buf, buflen, got);
43fe83
+        got = qemuProcessReadLog(fd, buf, buflen, got, false);
43fe83
         if (got < 0) {
43fe83
             virReportSystemError(errno,
43fe83
                                  _("Failure while reading %s log output"),
43fe83
@@ -1804,7 +1818,7 @@ cleanup:
43fe83
         }
43fe83
 
43fe83
         len = strlen(buf);
43fe83
-        qemuProcessReadLog(logfd, buf + len, buf_size - len - 1, 0);
43fe83
+        qemuProcessReadLog(logfd, buf + len, buf_size - len - 1, 0, true);
43fe83
         virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
                        _("process exited while connecting to monitor: %s"),
43fe83
                        buf);
43fe83
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
43fe83
index 8c81e40..2f6c4f5 100644
43fe83
--- a/src/qemu/qemu_process.h
43fe83
+++ b/src/qemu/qemu_process.h
43fe83
@@ -101,4 +101,6 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
43fe83
 virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
43fe83
                                virBitmapPtr nodemask);
43fe83
 
43fe83
+int qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar);
43fe83
+
43fe83
 #endif /* __QEMU_PROCESS_H__ */
43fe83
-- 
43fe83
1.8.4
43fe83