[libvirt] [PATCH 2/2] qemu: Record timestamp for qemu domain log
Osier
jyang at redhat.com
Mon Nov 1 12:38:05 UTC 2010
于 2010年11月01日 12:17, Osier Yang 写道:
> Currently only support domain start and domain shutdown, for domain
> start, adding timestamp before qemu command line, for domain shutdown,
> just say it's shutting down with timestamp.
>
> * src/qemu/qemu_driver.c
> ---
> src/qemu/qemu_driver.c | 42 +++++++++++++++++++++++++++++++++++++++++-
> 1 files changed, 41 insertions(+), 1 deletions(-)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index a7cce6a..963b70c 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -3830,6 +3830,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
> char ebuf[1024];
> char *pidfile = NULL;
> int logfile = -1;
> + char *timestamp;
> qemuDomainObjPrivatePtr priv = vm->privateData;
>
> struct qemudHookData hookData;
> @@ -4017,7 +4018,17 @@ static int qemudStartVMDaemon(virConnectPtr conn,
> goto cleanup;
> }
>
> + if ((timestamp = virTimestamp()) == NULL) {
> + virReportOOMError();
> + goto cleanup;
> + } else if (safewrite(logfile, timestamp, strlen(timestamp))< 0) {
> + VIR_FREE(timestamp);
> + VIR_WARN("Unable to write timestamp to logfile: %s",
> + virStrerror(errno, ebuf, sizeof ebuf));
> + }
> +
> tmp = progenv;
> +
> while (*tmp) {
> if (safewrite(logfile, *tmp, strlen(*tmp))< 0)
> VIR_WARN("Unable to write envv to logfile: %s",
> @@ -4168,7 +4179,6 @@ cleanup:
> return -1;
> }
>
> -
> static void qemudShutdownVMDaemon(struct qemud_driver *driver,
> virDomainObjPtr vm,
> int migrated) {
> @@ -4178,6 +4188,31 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
> virErrorPtr orig_err;
> virDomainDefPtr def;
> int i;
> + int logfile = -1;
> + char *timestamp;
> + char ebuf[1024];
> +
> + 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();
> + goto cleanup;
> + } else {
> + strcat(timestamp, "shutting down\n");
> +
> + if (safewrite(logfile, timestamp, strlen(timestamp))< 0) {
> + VIR_WARN("Unable to write timestamp to logfile: %s",
> + virStrerror(errno, ebuf, sizeof ebuf));
> + }
> +
> + VIR_FREE(timestamp);
> + }
> + }
>
> VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d",
> vm->def->name, vm->pid, migrated);
> @@ -4315,6 +4350,11 @@ retry:
> virSetError(orig_err);
> virFreeError(orig_err);
> }
> +
> +cleanup:
> + if (close(logfile)< 0)
ah, I need to use VIR_CLOSE instead.. will update.
- Osier
> + VIR_WARN("Unable to close logfile: %s",
> + virStrerror(errno, ebuf, sizeof ebuf));
> }
>
>
> --
> 1.7.2.3
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
More information about the libvir-list
mailing list