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,9 +4008,12 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
{ {
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
bool closeLog = false; bool closeLog = false;
char *timestamp = NULL;
if (virDomainObjTaint(obj, taint)) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!virDomainObjTaint(obj, taint))
return;
virUUIDFormat(obj->def->uuid, uuidstr); virUUIDFormat(obj->def->uuid, uuidstr);
VIR_WARN("Domain id=%d name='%s' uuid=%s is tainted: %s", VIR_WARN("Domain id=%d name='%s' uuid=%s is tainted: %s",
@ -4023,25 +4026,29 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
* preserve original error, and clear any error that * preserve original error, and clear any error that
* is raised */ * is raised */
orig_err = virSaveLastError(); orig_err = virSaveLastError();
if (!(timestamp = virTimeStringNow()))
goto cleanup;
if (logCtxt == NULL) { if (logCtxt == NULL) {
logCtxt = qemuDomainLogContextNew(driver, obj, logCtxt = qemuDomainLogContextNew(driver, obj,
QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH); QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH);
if (!logCtxt) { if (!logCtxt) {
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
}
VIR_WARN("Unable to open domainlog"); VIR_WARN("Unable to open domainlog");
return; goto cleanup;
} }
closeLog = true; closeLog = true;
} }
if (qemuDomainLogContextWrite(logCtxt, if (qemuDomainLogContextWrite(logCtxt,
"Domain id=%d is tainted: %s\n", "%s: Domain id=%d is tainted: %s\n",
timestamp,
obj->def->id, obj->def->id,
virDomainTaintTypeToString(taint)) < 0) virDomainTaintTypeToString(taint)) < 0)
virResetLastError(); virResetLastError();
cleanup:
VIR_FREE(timestamp);
if (closeLog) if (closeLog)
qemuDomainLogContextFree(logCtxt); qemuDomainLogContextFree(logCtxt);
if (orig_err) { if (orig_err) {
@ -4049,7 +4056,6 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
virFreeError(orig_err); virFreeError(orig_err);
} }
} }
}
void qemuDomainObjCheckTaint(virQEMUDriverPtr driver, void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,