]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Add infrastructure to access VM logs for better err msgs
authorPeter Krempa <pkrempa@redhat.com>
Wed, 18 Sep 2013 14:12:17 +0000 (16:12 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Sep 2013 11:50:56 +0000 (13:50 +0200)
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.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h

index ecec8e27aa59ef6b502938e3f4b42ee8319f6746..c3701fecc371811d763ff8f98e462ee7c7911cae 100644 (file)
@@ -88,6 +88,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;
@@ -254,6 +257,7 @@ static void qemuMonitorDispose(void *obj)
     VIR_FREE(mon->buffer);
     virJSONValueFree(mon->options);
     VIR_FREE(mon->balloonpath);
+    VIR_FORCE_CLOSE(mon->logfd);
 }
 
 
@@ -715,6 +719,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"));
@@ -3843,3 +3848,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;
+}
index 5fe33dbc43d1c308db30daa939dde54d93bed5d1..06ba7e8717e0d9efd3fab83b6f9957cb0fc236b7 100644 (file)
@@ -761,6 +761,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