qemu_domain: add timestamp in tainting of guests log

We lacked of timestamp in tainting of guests log,
which bring troubles for finding guest issues:
such as whether a guest powerdown caused by qemu-monitor-command
or others issues inside guests.
If we had timestamp in tainting of guests log,
it would be helpful when checking guest's /var/log/messages.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
This commit is contained in:
Chen Hanxiao 2017-01-20 16:46:02 +08:00 committed by John Ferlan
parent 0cacdc6f24
commit 980f2a35c7

View File

@ -4008,46 +4008,52 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
{ {
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
bool closeLog = false; bool closeLog = false;
char *timestamp = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainObjTaint(obj, taint)) { if (!virDomainObjTaint(obj, taint))
char uuidstr[VIR_UUID_STRING_BUFLEN]; return;
virUUIDFormat(obj->def->uuid, uuidstr);
VIR_WARN("Domain id=%d name='%s' uuid=%s is tainted: %s", virUUIDFormat(obj->def->uuid, uuidstr);
obj->def->id,
obj->def->name,
uuidstr,
virDomainTaintTypeToString(taint));
/* We don't care about errors logging taint info, so VIR_WARN("Domain id=%d name='%s' uuid=%s is tainted: %s",
* preserve original error, and clear any error that obj->def->id,
* is raised */ obj->def->name,
orig_err = virSaveLastError(); uuidstr,
if (logCtxt == NULL) { virDomainTaintTypeToString(taint));
logCtxt = qemuDomainLogContextNew(driver, obj,
QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH); /* We don't care about errors logging taint info, so
if (!logCtxt) { * preserve original error, and clear any error that
if (orig_err) { * is raised */
virSetError(orig_err); orig_err = virSaveLastError();
virFreeError(orig_err);
} if (!(timestamp = virTimeStringNow()))
VIR_WARN("Unable to open domainlog"); goto cleanup;
return;
} if (logCtxt == NULL) {
closeLog = true; logCtxt = qemuDomainLogContextNew(driver, obj,
QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH);
if (!logCtxt) {
VIR_WARN("Unable to open domainlog");
goto cleanup;
} }
closeLog = true;
}
if (qemuDomainLogContextWrite(logCtxt, if (qemuDomainLogContextWrite(logCtxt,
"Domain id=%d is tainted: %s\n", "%s: Domain id=%d is tainted: %s\n",
obj->def->id, timestamp,
virDomainTaintTypeToString(taint)) < 0) obj->def->id,
virResetLastError(); virDomainTaintTypeToString(taint)) < 0)
if (closeLog) virResetLastError();
qemuDomainLogContextFree(logCtxt);
if (orig_err) { cleanup:
virSetError(orig_err); VIR_FREE(timestamp);
virFreeError(orig_err); if (closeLog)
} qemuDomainLogContextFree(logCtxt);
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
} }
} }