|
|
404507 |
From 0b0135f00c4e17cb902ec6885648b5a4e667d56b Mon Sep 17 00:00:00 2001
|
|
|
404507 |
Message-Id: <0b0135f00c4e17cb902ec6885648b5a4e667d56b@dist-git>
|
|
|
404507 |
From: Jiri Denemark <jdenemar@redhat.com>
|
|
|
404507 |
Date: Wed, 22 Nov 2017 13:12:00 +0100
|
|
|
404507 |
Subject: [PATCH] qemu: Use the end of QEMU log for reporting errors
|
|
|
404507 |
|
|
|
404507 |
When QEMU dies, we read its output stored in a log file and use it for
|
|
|
404507 |
reporting a hopefully useful error. However, virReportError will trim
|
|
|
404507 |
the message to (VIR_ERROR_MAX_LENGTH - 1) characters, which means the
|
|
|
404507 |
end of the log (which likely contains the error message we want to
|
|
|
404507 |
report) may get lost. We should trim the beginning of the log instead.
|
|
|
404507 |
|
|
|
404507 |
https://bugzilla.redhat.com/show_bug.cgi?id=1335534
|
|
|
404507 |
|
|
|
404507 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
404507 |
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
404507 |
(cherry picked from commit 96f7a045e93ad08eb4130be97dd6d8a8c963a952)
|
|
|
404507 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
404507 |
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
404507 |
---
|
|
|
404507 |
src/qemu/qemu_process.c | 34 ++++++++++++++++++++++++++++++----
|
|
|
404507 |
1 file changed, 30 insertions(+), 4 deletions(-)
|
|
|
404507 |
|
|
|
404507 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
404507 |
index c5fa8cb4b2..f7808227a8 100644
|
|
|
404507 |
--- a/src/qemu/qemu_process.c
|
|
|
404507 |
+++ b/src/qemu/qemu_process.c
|
|
|
404507 |
@@ -1827,17 +1827,24 @@ qemuConnectMonitor(virQEMUDriverPtr driver, virDomainObjPtr vm, int asyncJob,
|
|
|
404507 |
* qemuProcessReadLog: Read log file of a qemu VM
|
|
|
404507 |
* @logCtxt: the domain log context
|
|
|
404507 |
* @msg: pointer to buffer to store the read messages in
|
|
|
404507 |
+ * @max: maximum length of the message returned in @msg
|
|
|
404507 |
*
|
|
|
404507 |
* Reads log of a qemu VM. Skips messages not produced by qemu or irrelevant
|
|
|
404507 |
- * messages. Returns returns 0 on success or -1 on error
|
|
|
404507 |
+ * messages. If @max is not zero, @msg will contain at most @max characters
|
|
|
404507 |
+ * from the end of the log and @msg will start after a new line if possible.
|
|
|
404507 |
+ *
|
|
|
404507 |
+ * Returns 0 on success or -1 on error
|
|
|
404507 |
*/
|
|
|
404507 |
static int
|
|
|
404507 |
-qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, char **msg)
|
|
|
404507 |
+qemuProcessReadLog(qemuDomainLogContextPtr logCtxt,
|
|
|
404507 |
+ char **msg,
|
|
|
404507 |
+ size_t max)
|
|
|
404507 |
{
|
|
|
404507 |
char *buf;
|
|
|
404507 |
ssize_t got;
|
|
|
404507 |
char *eol;
|
|
|
404507 |
char *filter_next;
|
|
|
404507 |
+ size_t skip;
|
|
|
404507 |
|
|
|
404507 |
if ((got = qemuDomainLogContextRead(logCtxt, &buf)) < 0)
|
|
|
404507 |
return -1;
|
|
|
404507 |
@@ -1848,7 +1855,7 @@ qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, char **msg)
|
|
|
404507 |
*eol = '\0';
|
|
|
404507 |
if (virLogProbablyLogMessage(filter_next) ||
|
|
|
404507 |
strstr(filter_next, "char device redirected to")) {
|
|
|
404507 |
- size_t skip = (eol + 1) - filter_next;
|
|
|
404507 |
+ skip = (eol + 1) - filter_next;
|
|
|
404507 |
memmove(filter_next, eol + 1, buf + got - eol);
|
|
|
404507 |
got -= skip;
|
|
|
404507 |
} else {
|
|
|
404507 |
@@ -1863,6 +1870,19 @@ qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, char **msg)
|
|
|
404507 |
buf[got - 1] = '\0';
|
|
|
404507 |
got--;
|
|
|
404507 |
}
|
|
|
404507 |
+
|
|
|
404507 |
+ if (max > 0 && got > max) {
|
|
|
404507 |
+ skip = got - max;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (buf[skip - 1] != '\n' &&
|
|
|
404507 |
+ (eol = strchr(buf + skip, '\n')) &&
|
|
|
404507 |
+ !virStringIsEmpty(eol + 1))
|
|
|
404507 |
+ skip = eol + 1 - buf;
|
|
|
404507 |
+
|
|
|
404507 |
+ memmove(buf, buf + skip, got - skip + 1);
|
|
|
404507 |
+ got -= skip;
|
|
|
404507 |
+ }
|
|
|
404507 |
+
|
|
|
404507 |
ignore_value(VIR_REALLOC_N_QUIET(buf, got + 1));
|
|
|
404507 |
*msg = buf;
|
|
|
404507 |
return 0;
|
|
|
404507 |
@@ -1874,8 +1894,14 @@ qemuProcessReportLogError(qemuDomainLogContextPtr logCtxt,
|
|
|
404507 |
const char *msgprefix)
|
|
|
404507 |
{
|
|
|
404507 |
char *logmsg = NULL;
|
|
|
404507 |
+ size_t max;
|
|
|
404507 |
|
|
|
404507 |
- if (qemuProcessReadLog(logCtxt, &logmsg) < 0)
|
|
|
404507 |
+ max = VIR_ERROR_MAX_LENGTH - 1;
|
|
|
404507 |
+ max -= strlen(msgprefix);
|
|
|
404507 |
+ /* The length of the formatting string minus two '%s' */
|
|
|
404507 |
+ max -= strlen(_("%s: %s")) - 4;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (qemuProcessReadLog(logCtxt, &logmsg, max) < 0)
|
|
|
404507 |
return -1;
|
|
|
404507 |
|
|
|
404507 |
virResetLastError();
|
|
|
404507 |
--
|
|
|
404507 |
2.15.0
|
|
|
404507 |
|