[PATCH v2 8/8] Generate a unique journald log for QEMU capabilities failure

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

 



When probing QEMU capabilities fails for a binary generate a
log message with MESSAGE_ID==8ae2f3fb-2dbe-498e-8fbd-012d40afa361.

This can be directly queried from journald based on the UUID
instead of needing string grep. This lets tools like libguestfs'
bug reporting tool trivially do automated sanity tests on the
host they're running on.

 $ journalctl MESSAGE_ID=8ae2f3fb-2dbe-498e-8fbd-012d40afa361
 Feb 21 17:11:01 localhost.localdomain lt-libvirtd[9196]:
 Failed to probe capabilities for /bin/qemu-system-alpha:
 internal error: Child process (LC_ALL=C LD_LIBRARY_PATH=
 /home/berrange/src/virt/libvirt/src/.libs PATH=/usr/lib64/
 ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:
 /usr/bin:/root/bin HOME=/root USER=root LOGNAME=root
 /bin/qemu-system-alpha -help) unexpected exit status 127:
 /bin/qemu-system-alpha: error while loading shared libraries:
 libglapi.so.0: cannot open shared object file: No such file
 or directory

 $ journalctl MESSAGE_ID=8ae2f3fb-2dbe-498e-8fbd-012d40afa361 --output=json
 { ...snip...
  "LIBVIRT_SOURCE" : "file",
  "PRIORITY" : "3",
  "CODE_FILE" : "qemu/qemu_capabilities.c",
  "CODE_LINE" : "2770",
  "CODE_FUNC" : "virQEMUCapsLogProbeFailure",
  "MESSAGE_ID" : "8ae2f3fb-2dbe-498e-8fbd-012d40afa361",
  "LIBVIRT_QEMU_BINARY" : "/bin/qemu-system-xtensa",
  "MESSAGE" : "Failed to probe capabilities for /bin/qemu-system-xtensa:
   internal error: Child process (LC_ALL=C LD_LIBRARY_PATH=/home/berrange
   /src/virt/libvirt/src/.libs PATH=/usr/lib64/ccache:/usr/local/sbin:
   /usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin HOME=/root
   USER=root LOGNAME=root /bin/qemu-system-xtensa -help) unexpected
   exit status 127: /bin/qemu-system-xtensa: error while loading shared
   libraries: libglapi.so.0: cannot open shared object file: No such
    file or directory\n" }

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 docs/logging.html.in         | 44 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_capabilities.c | 30 ++++++++++++++++++++++++++++--
 2 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/docs/logging.html.in b/docs/logging.html.in
index f8c57f8..ed8e7e3 100644
--- a/docs/logging.html.in
+++ b/docs/logging.html.in
@@ -179,6 +179,50 @@
       <dd>The libvirt error code (values from virErrorCode enum), if LIBVIRT_SOURCE="error"</dd>
     </dl>
 
+    <h3><a name="journaldids">Well known message ID values</a></h3>
+
+    <p>
+      Certain areas of the code will emit log records tagged with well known
+      unique id values, which are guaranteed never to change in the future.
+      This allows applications to identify critical log events without doing
+      string matching on the <code>MESSAGE</code> field.
+    </p>
+
+    <dl>
+      <dt><code>MESSAGE_ID=8ae2f3fb-2dbe-498e-8fbd-012d40afa361</code></dt>
+      <dd>Generated by the QEMU driver when it identifies a QEMU system
+        emulator binary, but is unable to extract information about its
+        capabilities. This is usually an indicator of a broken QEMU
+        build or installation. When this is emitted, the <code>LIBVIRT_QEMU_BINARY</code>
+        message field will provide the full path of the QEMU binary that failed.
+      </dd>
+    </dl>
+
+    <p>
+      The <code>journalctl</code> commnd can be used to search the journal
+      matching on specific message ID values
+    </p>
+
+    <pre>
+ $ journalctl MESSAGE_ID=8ae2f3fb-2dbe-498e-8fbd-012d40afa361 --output=json
+ { ...snip...
+   "LIBVIRT_SOURCE" : "file",
+   "PRIORITY" : "3",
+   "CODE_FILE" : "qemu/qemu_capabilities.c",
+   "CODE_LINE" : "2770",
+   "CODE_FUNC" : "virQEMUCapsLogProbeFailure",
+   "MESSAGE_ID" : "8ae2f3fb-2dbe-498e-8fbd-012d40afa361",
+   "LIBVIRT_QEMU_BINARY" : "/bin/qemu-system-xtensa",
+   "MESSAGE" : "Failed to probe capabilities for /bin/qemu-system-xtensa:" \
+               "internal error: Child process (LC_ALL=C LD_LIBRARY_PATH=/home/berrange" \
+               "/src/virt/libvirt/src/.libs PATH=/usr/lib64/ccache:/usr/local/sbin:" \
+               "/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin HOME=/root " \
+               "USER=root LOGNAME=root /bin/qemu-system-xtensa -help) unexpected " \
+               "exit status 127: /bin/qemu-system-xtensa: error while loading shared " \
+               "libraries: libglapi.so.0: cannot open shared object file: No such " \
+               "file or directory\n" }
+    </pre>
+
     <h2>
       <a name="log_examples">Examples</a>
     </h2>
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index d618b3f..76a8c73 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2754,6 +2754,28 @@ cleanup:
 }
 
 
+#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa361"
+
+static void
+virQEMUCapsLogProbeFailure(const char *binary)
+{
+    virLogMetadata meta[] = {
+        { .key = "MESSAGE_ID", .s = MESSAGE_ID_CAPS_PROBE_FAILURE, .iv = 0 },
+        { .key = "LIBVIRT_QEMU_BINARY", .s = binary, .iv = 0 },
+        { .key = NULL },
+    };
+    virErrorPtr err = virGetLastError();
+
+    virLogMessage(VIR_LOG_FROM_FILE,
+                  VIR_LOG_WARN,
+                  __FILE__, __LINE__, __func__,
+                  meta,
+                  _("Failed to probe capabilities for %s: %s"),
+                  binary, err && err->message ? err->message :
+                  _("unknown failure"));
+}
+
+
 virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
                                        const char *libDir,
                                        uid_t runUid,
@@ -2785,12 +2807,16 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
         goto error;
     }
 
-    if ((rv = virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid)) < 0)
+    if ((rv = virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid)) < 0) {
+        virQEMUCapsLogProbeFailure(binary);
         goto error;
+    }
 
     if (!qemuCaps->usedQMP &&
-        virQEMUCapsInitHelp(qemuCaps, runUid, runGid) < 0)
+        virQEMUCapsInitHelp(qemuCaps, runUid, runGid) < 0) {
+        virQEMUCapsLogProbeFailure(binary);
         goto error;
+    }
 
     return qemuCaps;
 
-- 
1.8.5.3

--
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]