[libvirt] [PATCH] qemu: record timestamp in qemu domain log

2010-11-16 Thread 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 (qemudStartVMDaemon, qemudShutdownVMDaemon
  introduced two macros - START_POSTFIX, SHUTDOWN_POSTFIX)
---
 src/qemu/qemu_driver.c |   46 --
 1 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fd61864..3c833d2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3855,6 +3855,8 @@ static void qemuDomainSecurityLabelAudit(virDomainObjPtr 
vm, bool success)
 VIR_FREE(vmname);
 }

+#define START_POSTFIX : starting up\n
+#define SHUTDOWN_POSTFIX : shutting down\n

 static int qemudStartVMDaemon(virConnectPtr conn,
   struct qemud_driver *driver,
@@ -3877,6 +3879,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 char ebuf[1024];
 char *pidfile = NULL;
 int logfile = -1;
+char *timestamp;
 qemuDomainObjPrivatePtr priv = vm-privateData;

 struct qemudHookData hookData;
@@ -4084,7 +4087,21 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 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;
+
 while (*tmp) {
 if (safewrite(logfile, *tmp, strlen(*tmp))  0)
 VIR_WARN(Unable to write envv to logfile: %s,
@@ -4233,7 +4250,6 @@ cleanup:
 return -1;
 }

-
 static void qemudShutdownVMDaemon(struct qemud_driver *driver,
   virDomainObjPtr vm,
   int migrated) {
@@ -4243,10 +4259,37 @@ 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);

+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
  * reporting so we don't squash a legit error. */
 orig_err = virSaveLastError();
@@ -4382,7 +4425,6 @@ retry:
 }
 }

-
 static virDrvOpenStatus qemudOpen(virConnectPtr conn,
   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
   int flags ATTRIBUTE_UNUSED) {
--
1.7.3.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: record timestamp in qemu domain log

2010-11-16 Thread Daniel P. Berrange
On Tue, Nov 16, 2010 at 11:39:26PM +0800, Osier Yang wrote:
 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)
 ---
  src/qemu/qemu_driver.c |   46 --
  1 files changed, 44 insertions(+), 2 deletions(-)
 
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index fd61864..3c833d2 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -3855,6 +3855,8 @@ static void 
 qemuDomainSecurityLabelAudit(virDomainObjPtr vm, bool success)
  VIR_FREE(vmname);
  }
 
 +#define START_POSTFIX : starting up\n
 +#define SHUTDOWN_POSTFIX : shutting down\n
 
  static int qemudStartVMDaemon(virConnectPtr conn,
struct qemud_driver *driver,
 @@ -3877,6 +3879,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
  char ebuf[1024];
  char *pidfile = NULL;
  int logfile = -1;
 +char *timestamp;
  qemuDomainObjPrivatePtr priv = vm-privateData;
 
  struct qemudHookData hookData;
 @@ -4084,7 +4087,21 @@ static int qemudStartVMDaemon(virConnectPtr conn,
  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;
 +
  while (*tmp) {
  if (safewrite(logfile, *tmp, strlen(*tmp))  0)
  VIR_WARN(Unable to write envv to logfile: %s,
 @@ -4233,7 +4250,6 @@ cleanup:
  return -1;
  }
 
 -
  static void qemudShutdownVMDaemon(struct qemud_driver *driver,
virDomainObjPtr vm,
int migrated) {
 @@ -4243,10 +4259,37 @@ 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);
 
 +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
   * reporting so we don't squash a legit error. */
  orig_err = virSaveLastError();
 @@ -4382,7 +4425,6 @@ retry:
  }
  }
 
 -
  static virDrvOpenStatus qemudOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) {
 --

ACK

Daniel
-- 
|: Red Hat, Engineering, London-o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org-o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: record timestamp in qemu domain log

2010-11-16 Thread Eric Blake
On 11/16/2010 08:47 AM, Daniel P. Berrange wrote:
 On Tue, Nov 16, 2010 at 11:39:26PM +0800, Osier Yang wrote:
 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)
 ---
  src/qemu/qemu_driver.c |   46 --
  1 files changed, 44 insertions(+), 2 deletions(-)

 
 ACK

Pushed.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] qemu: Record timestamp for qemu domain log

2010-11-01 Thread 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 (VIR_CLOSE(logfile)  0)
+VIR_WARN(Unable to close logfile: %s,
+ virStrerror(errno, ebuf, sizeof ebuf));
 }


--
1.7.2.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: Record timestamp for qemu domain log

2010-11-01 Thread Eric Blake
On 11/01/2010 06:46 AM, Osier Yang wrote:
 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(-)
 
 +} 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));

VIR_FREE might clobber errno.  Swap these two lines.

 @@ -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;

Hmm.  The rest of this function is best-effort cleanup, since there is
no return value.  If you run out of memory while trying to cleanup, you
should STILL try and clean up the rest of the resources freed later in
this function, rather than immediately jumping to your cleanup: handler.

 +} else {
 +strcat(timestamp, shutting down\n);

Ouch. Buffer overflow - you can't guarantee whether timestamp was
overallocated with enough memory for you to blindly strcat() data onto
the end of it.

 +
 +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);

Also, I think you want your attempts to write to a log file to occur
after this VIR_DEBUG statement.

 @@ -4315,6 +4350,11 @@ retry:
  virSetError(orig_err);
  virFreeError(orig_err);
  }
 +
 +cleanup:
 +if (VIR_CLOSE(logfile)  0)
 +VIR_WARN(Unable to close logfile: %s,
 + virStrerror(errno, ebuf, sizeof ebuf));
  }

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list