[PATCH] qemu: Ignore libvirt debug messages in qemu log

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

 



qemu driver uses a 4K buffer for reading qemu log file. This is enough
when only qemu's output is present in the log file. However, when
debugging messages are turned on, intermediate libvirt process fills the
log with a bunch of debugging messages before it executes qemu binary.
In such a case the buffer may become too small. However, we are not
really interested in libvirt messages so they can be filtered out from
the buffer.
---
 src/qemu/qemu_process.c |   47 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e31e1b4..bc117a4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -762,11 +762,21 @@ qemuProcessReadLogOutput(virDomainObjPtr vm,
 {
     int retries = (timeout*10);
     int got = 0;
+    char *debug = NULL;
+    int ret = -1;
+    char *filter_next = buf;
+
     buf[0] = '\0';
 
+    if (virAsprintf(&debug, ": %d: debug : ", vm->pid) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
     while (retries) {
-        ssize_t func_ret, ret;
+        ssize_t func_ret, bytes;
         int isdead = 0;
+        char *eol;
 
         func_ret = func(vm, buf, fd);
 
@@ -775,32 +785,46 @@ qemuProcessReadLogOutput(virDomainObjPtr vm,
 
         /* Any failures should be detected before we read the log, so we
          * always have something useful to report on failure. */
-        ret = saferead(fd, buf+got, buflen-got-1);
-        if (ret < 0) {
+        bytes = saferead(fd, buf+got, buflen-got-1);
+        if (bytes < 0) {
             virReportSystemError(errno,
                                  _("Failure while reading %s log output"),
                                  what);
-            return -1;
+            goto cleanup;
         }
 
-        got += ret;
+        got += bytes;
         buf[got] = '\0';
+
+        /* Filter out debug messages from intermediate libvirt process */
+        while ((eol = strchr(filter_next, '\n'))) {
+            char *p = strstr(filter_next, debug);
+            if (p && p < eol) {
+                memmove(filter_next, eol + 1, got - (eol - buf));
+                got -= eol + 1 - filter_next;
+            } else {
+                filter_next = eol + 1;
+            }
+        }
+
         if (got == buflen-1) {
             qemuReportError(VIR_ERR_INTERNAL_ERROR,
                             _("Out of space while reading %s log output: %s"),
                             what, buf);
-            return -1;
+            goto cleanup;
         }
 
         if (isdead) {
             qemuReportError(VIR_ERR_INTERNAL_ERROR,
                             _("Process exited while reading %s log output: %s"),
                             what, buf);
-            return -1;
+            goto cleanup;
         }
 
-        if (func_ret <= 0)
-            return func_ret;
+        if (func_ret <= 0) {
+            ret = func_ret;
+            goto cleanup;
+        }
 
         usleep(100*1000);
         retries--;
@@ -809,7 +833,10 @@ qemuProcessReadLogOutput(virDomainObjPtr vm,
     qemuReportError(VIR_ERR_INTERNAL_ERROR,
                     _("Timed out while reading %s log output: %s"),
                     what, buf);
-    return -1;
+
+cleanup:
+    VIR_FREE(debug);
+    return ret;
 }
 
 
-- 
1.7.4.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]