Could anyone help review this patch? thanks.
- Osier
于 2010年11月02日 15:14, Osier Yang 写道:
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
---
src/qemu/qemu_driver.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0612e69..1b03ef1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -81,6 +81,7 @@
#include "hooks.h"
#include "storage_file.h"
#include "virtaudit.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -3866,6 +3867,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
char ebuf[1024];
char *pidfile = NULL;
int logfile = -1;
+ char *timestamp;
qemuDomainObjPrivatePtr priv = vm->privateData;
struct qemudHookData hookData;
@@ -4053,7 +4055,17 @@ static int qemudStartVMDaemon(virConnectPtr conn,
goto cleanup;
}
+ if ((timestamp = virTimestamp()) == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ } else if (safewrite(logfile, timestamp, strlen(timestamp))< 0) {
+ VIR_WARN("Unable to write timestamp to logfile: %s",
+ virStrerror(errno, ebuf, sizeof ebuf));
+ VIR_FREE(timestamp);
+ }
+
tmp = progenv;
+
while (*tmp) {
if (safewrite(logfile, *tmp, strlen(*tmp))< 0)
VIR_WARN("Unable to write envv to logfile: %s",
@@ -4204,7 +4216,6 @@ cleanup:
return -1;
}
-
static void qemudShutdownVMDaemon(struct qemud_driver *driver,
virDomainObjPtr vm,
int migrated) {
@@ -4214,10 +4225,45 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
virErrorPtr orig_err;
virDomainDefPtr def;
int i;
+ int logfile = -1;
+ char *timestamp;
+ char ebuf[1024];
VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d",
vm->def->name, vm->pid, migrated);
+ VIR_DEBUG0("Creating domain log file");
+ 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 {
+ char *shutdownMsg;
+
+ if ((virAsprintf(&shutdownMsg, "%s: shutting down\n",
+ timestamp))< 0) {
+ virReportOOMError();
+ } else {
+ if (safewrite(logfile, shutdownMsg, strlen(shutdownMsg))< 0) {
+ VIR_WARN("Unable to write shutdownMsg to logfile: %s",
+ virStrerror(errno, ebuf, sizeof ebuf));
+ }
+
+ VIR_FREE(shutdownMsg);
+ }
+
+ 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
* reporting so we don't squash a legit error. */
orig_err = virSaveLastError();
@@ -4353,7 +4399,6 @@ retry:
}
}
-
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) {
--
1.7.2.3
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list