Blame SOURCES/libvirt-qemu-monitor-Add-infrastructure-to-access-VM-logs-for-better-err-msgs.patch

43fe83
From 432c46e973b5c41951fe83dace4c07506f95a062 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <432c46e973b5c41951fe83dace4c07506f95a062.1382534060.git.jdenemar@redhat.com>
43fe83
From: Peter Krempa <pkrempa@redhat.com>
43fe83
Date: Thu, 10 Oct 2013 13:56:30 +0200
43fe83
Subject: [PATCH] qemu: monitor: Add infrastructure to access VM logs for
43fe83
 better err msgs
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1001738
43fe83
43fe83
Early VM startup errors usually produce a better error message in the
43fe83
machine log file. Currently we were accessing it only when the process
43fe83
exited during certain phases of startup. This will help adding a more
43fe83
comprehensive error extraction for early qemu startup phases.
43fe83
43fe83
This patch adds infrastructure to keep a file descriptor for the machine
43fe83
log file that will be used in case an error happens.
43fe83
43fe83
(cherry picked from commit 8519e9ecdcc26f9753dbd85e897daabbaa82dee8)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/qemu/qemu_monitor.c | 27 +++++++++++++++++++++++++++
43fe83
 src/qemu/qemu_monitor.h |  2 ++
43fe83
 2 files changed, 29 insertions(+)
43fe83
43fe83
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
43fe83
index e22a2b2..2eb536c 100644
43fe83
--- a/src/qemu/qemu_monitor.c
43fe83
+++ b/src/qemu/qemu_monitor.c
43fe83
@@ -87,6 +87,9 @@ struct _qemuMonitor {
43fe83
     /* If found, path to the virtio memballoon driver */
43fe83
     char *balloonpath;
43fe83
     bool ballooninit;
43fe83
+
43fe83
+    /* Log file fd of the qemu process to dig for usable info */
43fe83
+    int logfd;
43fe83
 };
43fe83
 
43fe83
 static virClassPtr qemuMonitorClass;
43fe83
@@ -255,6 +258,7 @@ static void qemuMonitorDispose(void *obj)
43fe83
     VIR_FREE(mon->buffer);
43fe83
     virJSONValueFree(mon->options);
43fe83
     VIR_FREE(mon->balloonpath);
43fe83
+    VIR_FORCE_CLOSE(mon->logfd);
43fe83
 }
43fe83
 
43fe83
 
43fe83
@@ -717,6 +721,7 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
43fe83
         return NULL;
43fe83
 
43fe83
     mon->fd = -1;
43fe83
+    mon->logfd = -1;
43fe83
     if (virCondInit(&mon->notify) < 0) {
43fe83
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
43fe83
                        _("cannot initialize monitor condition"));
43fe83
@@ -3841,3 +3846,25 @@ qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
43fe83
 
43fe83
     return qemuMonitorJSONGetDeviceAliases(mon, aliases);
43fe83
 }
43fe83
+
43fe83
+
43fe83
+/**
43fe83
+ * qemuMonitorSetDomainLog:
43fe83
+ * Set the file descriptor of the open VM log file to report potential
43fe83
+ * early startup errors of qemu.
43fe83
+ *
43fe83
+ * @mon: Monitor object to set the log file reading on
43fe83
+ * @logfd: File descriptor of the already open log file
43fe83
+ */
43fe83
+int
43fe83
+qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd)
43fe83
+{
43fe83
+    VIR_FORCE_CLOSE(mon->logfd);
43fe83
+    if (logfd >= 0 &&
43fe83
+        (mon->logfd = dup(logfd)) < 0) {
43fe83
+        virReportSystemError(errno, "%s", _("failed to duplicate log fd"));
43fe83
+        return -1;
43fe83
+    }
43fe83
+
43fe83
+    return 0;
43fe83
+}
43fe83
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
43fe83
index 4a55501..85ae533 100644
43fe83
--- a/src/qemu/qemu_monitor.h
43fe83
+++ b/src/qemu/qemu_monitor.h
43fe83
@@ -717,6 +717,8 @@ int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
43fe83
 int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
43fe83
                                 char ***aliases);
43fe83
 
43fe83
+int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);
43fe83
+
43fe83
 /**
43fe83
  * When running two dd process and using <> redirection, we need a
43fe83
  * shell that will not truncate files.  These two strings serve that
43fe83
-- 
43fe83
1.8.4
43fe83