render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 432c46e973b5c41951fe83dace4c07506f95a062 Mon Sep 17 00:00:00 2001
Message-Id: <432c46e973b5c41951fe83dace4c07506f95a062.1382534060.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 10 Oct 2013 13:56:30 +0200
Subject: [PATCH] qemu: monitor: Add infrastructure to access VM logs for
 better err msgs

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

Early VM startup errors usually produce a better error message in the
machine log file. Currently we were accessing it only when the process
exited during certain phases of startup. This will help adding a more
comprehensive error extraction for early qemu startup phases.

This patch adds infrastructure to keep a file descriptor for the machine
log file that will be used in case an error happens.

(cherry picked from commit 8519e9ecdcc26f9753dbd85e897daabbaa82dee8)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_monitor.c | 27 +++++++++++++++++++++++++++
 src/qemu/qemu_monitor.h |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index e22a2b2..2eb536c 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -87,6 +87,9 @@ struct _qemuMonitor {
     /* If found, path to the virtio memballoon driver */
     char *balloonpath;
     bool ballooninit;
+
+    /* Log file fd of the qemu process to dig for usable info */
+    int logfd;
 };
 
 static virClassPtr qemuMonitorClass;
@@ -255,6 +258,7 @@ static void qemuMonitorDispose(void *obj)
     VIR_FREE(mon->buffer);
     virJSONValueFree(mon->options);
     VIR_FREE(mon->balloonpath);
+    VIR_FORCE_CLOSE(mon->logfd);
 }
 
 
@@ -717,6 +721,7 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
         return NULL;
 
     mon->fd = -1;
+    mon->logfd = -1;
     if (virCondInit(&mon->notify) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot initialize monitor condition"));
@@ -3841,3 +3846,25 @@ qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
 
     return qemuMonitorJSONGetDeviceAliases(mon, aliases);
 }
+
+
+/**
+ * qemuMonitorSetDomainLog:
+ * Set the file descriptor of the open VM log file to report potential
+ * early startup errors of qemu.
+ *
+ * @mon: Monitor object to set the log file reading on
+ * @logfd: File descriptor of the already open log file
+ */
+int
+qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd)
+{
+    VIR_FORCE_CLOSE(mon->logfd);
+    if (logfd >= 0 &&
+        (mon->logfd = dup(logfd)) < 0) {
+        virReportSystemError(errno, "%s", _("failed to duplicate log fd"));
+        return -1;
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 4a55501..85ae533 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -717,6 +717,8 @@ int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
 int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
                                 char ***aliases);
 
+int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);
+
 /**
  * When running two dd process and using <> redirection, we need a
  * shell that will not truncate files.  These two strings serve that
-- 
1.8.4