提交 36ff4ed1 编写于 作者: D Daniel P. Berrange

Generate a unique journald log for QEMU capabilities failure

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: NDaniel P. Berrange <berrange@redhat.com>
上级 852582ea
......@@ -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> command 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>
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册