提交 93bc093a 编写于 作者: O Osier Yang 提交者: Eric Blake

qemu: record timestamp in qemu domain log

Currently only support domain start and shutdown, for domain start,
record timestamp before the qemu command line, and for domain shutdown,
just say it's shutting down with timestamp.

* src/qemu/qemu_driver.c (qemudStartVMDaemon, qemudShutdownVMDaemon
  introduced two macros - START_POSTFIX, SHUTDOWN_POSTFIX)
上级 21f52833
...@@ -3855,6 +3855,8 @@ static void qemuDomainSecurityLabelAudit(virDomainObjPtr vm, bool success) ...@@ -3855,6 +3855,8 @@ static void qemuDomainSecurityLabelAudit(virDomainObjPtr vm, bool success)
VIR_FREE(vmname); VIR_FREE(vmname);
} }
#define START_POSTFIX ": starting up\n"
#define SHUTDOWN_POSTFIX ": shutting down\n"
static int qemudStartVMDaemon(virConnectPtr conn, static int qemudStartVMDaemon(virConnectPtr conn,
struct qemud_driver *driver, struct qemud_driver *driver,
...@@ -3877,6 +3879,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, ...@@ -3877,6 +3879,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
char ebuf[1024]; char ebuf[1024];
char *pidfile = NULL; char *pidfile = NULL;
int logfile = -1; int logfile = -1;
char *timestamp;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
struct qemudHookData hookData; struct qemudHookData hookData;
...@@ -4084,7 +4087,21 @@ static int qemudStartVMDaemon(virConnectPtr conn, ...@@ -4084,7 +4087,21 @@ static int qemudStartVMDaemon(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if ((timestamp = virTimestamp()) == NULL) {
virReportOOMError();
goto cleanup;
} else {
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
safewrite(logfile, START_POSTFIX, strlen(START_POSTFIX)) < 0) {
VIR_WARN("Unable to write timestamp to logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
}
VIR_FREE(timestamp);
}
tmp = progenv; tmp = progenv;
while (*tmp) { while (*tmp) {
if (safewrite(logfile, *tmp, strlen(*tmp)) < 0) if (safewrite(logfile, *tmp, strlen(*tmp)) < 0)
VIR_WARN("Unable to write envv to logfile: %s", VIR_WARN("Unable to write envv to logfile: %s",
...@@ -4233,7 +4250,6 @@ cleanup: ...@@ -4233,7 +4250,6 @@ cleanup:
return -1; return -1;
} }
static void qemudShutdownVMDaemon(struct qemud_driver *driver, static void qemudShutdownVMDaemon(struct qemud_driver *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
int migrated) { int migrated) {
...@@ -4243,10 +4259,37 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver, ...@@ -4243,10 +4259,37 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
virErrorPtr orig_err; virErrorPtr orig_err;
virDomainDefPtr def; virDomainDefPtr def;
int i; int i;
int logfile = -1;
char *timestamp;
char ebuf[1024];
VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d", VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d",
vm->def->name, vm->pid, migrated); vm->def->name, vm->pid, migrated);
if ((logfile = qemudLogFD(driver, vm->def->name)) < 0) {
/* To not break the normal domain shutdown process, skip the
* timestamp log writing if failed on opening log file. */
VIR_WARN("Unable to open logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
} else {
if ((timestamp = virTimestamp()) == NULL) {
virReportOOMError();
} else {
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
safewrite(logfile, SHUTDOWN_POSTFIX,
strlen(SHUTDOWN_POSTFIX)) < 0) {
VIR_WARN("Unable to write timestamp to logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
}
VIR_FREE(timestamp);
}
if (VIR_CLOSE(logfile) < 0)
VIR_WARN("Unable to close logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
}
/* This method is routinely used in clean up paths. Disable error /* This method is routinely used in clean up paths. Disable error
* reporting so we don't squash a legit error. */ * reporting so we don't squash a legit error. */
orig_err = virSaveLastError(); orig_err = virSaveLastError();
...@@ -4382,7 +4425,6 @@ retry: ...@@ -4382,7 +4425,6 @@ retry:
} }
} }
static virDrvOpenStatus qemudOpen(virConnectPtr conn, static virDrvOpenStatus qemudOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) { int flags ATTRIBUTE_UNUSED) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册