render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From aaffe43897ee06be10aca64861022dfeea735ed3 Mon Sep 17 00:00:00 2001
Message-Id: <aaffe43897ee06be10aca64861022dfeea735ed3.1382534060.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 10 Oct 2013 13:56:29 +0200
Subject: [PATCH] qemu_process: Make qemuProcessReadLog() more versatile and
 reusable

https://bugzilla.redhat.com/show_bug.cgi?id=1001738

Teach the function to skip character device definitions printed by qemu
at startup in addition to libvirt log messages and make it usable from
outside of qemu_process.c. Also add documentation about the func.

(cherry picked from commit 310651a5e346b23db9015061452b1887335aed67)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_process.c | 24 +++++++++++++++++++-----
 src/qemu/qemu_process.h |  2 ++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 1bd0d04..063cd78 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1428,8 +1428,20 @@ error:
     return ret;
 }
 
-static int
-qemuProcessReadLog(int fd, char *buf, int buflen, int off)
+
+/**
+ * qemuProcessReadLog: Read log file of a qemu VM
+ * @fd: File descriptor of the log file
+ * @buf: buffer to store the read messages
+ * @buflen: allocated space available in @buf
+ * @off: Offset to start reading from
+ * @skipchar: Skip messages about created character devices
+ *
+ * Reads log of a qemu VM. Skips messages not produced by qemu or irrelevant
+ * messages. Returns length of the message stored in @buf, or -1 on error.
+ */
+int
+qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar)
 {
     char *filter_next = buf;
     ssize_t bytes;
@@ -1450,7 +1462,9 @@ qemuProcessReadLog(int fd, char *buf, int buflen, int off)
         /* Filter out debug messages from intermediate libvirt process */
         while ((eol = strchr(filter_next, '\n'))) {
             *eol = '\0';
-            if (virLogProbablyLogMessage(filter_next)) {
+            if (virLogProbablyLogMessage(filter_next) ||
+                (skipchar &&
+                 STRPREFIX(filter_next, "char device redirected to"))) {
                 memmove(filter_next, eol + 1, off - (eol - buf));
                 off -= eol + 1 - filter_next;
             } else {
@@ -1493,7 +1507,7 @@ qemuProcessReadLogOutput(virDomainObjPtr vm,
 
         isdead = kill(vm->pid, 0) == -1 && errno == ESRCH;
 
-        got = qemuProcessReadLog(fd, buf, buflen, got);
+        got = qemuProcessReadLog(fd, buf, buflen, got, false);
         if (got < 0) {
             virReportSystemError(errno,
                                  _("Failure while reading %s log output"),
@@ -1804,7 +1818,7 @@ cleanup:
         }
 
         len = strlen(buf);
-        qemuProcessReadLog(logfd, buf + len, buf_size - len - 1, 0);
+        qemuProcessReadLog(logfd, buf + len, buf_size - len - 1, 0, true);
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("process exited while connecting to monitor: %s"),
                        buf);
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 8c81e40..2f6c4f5 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -101,4 +101,6 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
 virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
                                virBitmapPtr nodemask);
 
+int qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar);
+
 #endif /* __QEMU_PROCESS_H__ */
-- 
1.8.4