WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] [IOEMU] Add date, time and pid on qemu-dm's log.

To: Keir Fraser <keir.fraser@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] [IOEMU] Add date, time and pid on qemu-dm's log.
From: Yuji Shimada <shimada-yxb@xxxxxxxxxxxxxxx>
Date: Wed, 03 Dec 2008 13:10:36 +0900
Cc:
Delivery-date: Tue, 02 Dec 2008 20:11:32 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
The qemu-dm's log message doesn't have date, time, and pid. It is
difficult to find out the message we want.

When we use guest domain for several months, date, time and pid are
necessary to analyse the log file.

This patch solves the problem without changing the codes which write
messages. 

The method is like below:
  qemu-dm creates a pipe and starts new thread for logging. qemu-dm
  associates a stream with the pipe, and sets the stream to existing
  "logfile" variable, stdout and stderr. When qemu-dm writes a message
  to them, the thread receives it through the pipe and outputs it with
  date, time and pid to the actual log file.

The log is modified like below:
(now)
  domid: 6
  qemu: the number of cpus is 1
  ...
(modify)
  [2008-12-02 17:00:06 22623] domid: 6
  [2008-12-02 17:00:06 22623] qemu: the number of cpus is 1
  [2008-12-02 17:00:06 22623] ...


This patch is not available for stubdom. So I will send patch for
stubdom.

Thanks,
--
Yuji Shimada


Signed-off-by: Yuji Shimada <shimada-yxb@xxxxxxxxxxxxxxx>

diff --git a/vl.c b/vl.c
index 182346a..55d323c 100644
--- a/vl.c
+++ b/vl.c
@@ -132,6 +132,10 @@ int inet_aton(const char *cp, struct in_addr *ia);
 #define main qemu_main
 #endif /* CONFIG_COCOA */
 
+#ifndef CONFIG_STUBDOM
+#include <pthread.h>
+#endif
+
 #include "disas.h"
 
 #include "exec-all.h"
@@ -7829,6 +7833,107 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 }
 #endif
 
+#ifndef CONFIG_STUBDOM
+FILE *pipe_read, *org_stderr;
+pthread_t log_hd;
+#endif
+
+#ifndef CONFIG_STUBDOM
+#define LOGBUFSIZ 256
+
+void *logging_thread(void *arg)
+{
+    time_t current_tm;
+    struct tm time_str;
+    char log_buffer[LOGBUFSIZ];
+
+    while (fgets(log_buffer, LOGBUFSIZ, pipe_read) != NULL) {
+        time(&current_tm);
+        localtime_r(&current_tm, &time_str);
+        fprintf(org_stderr, "[%4d-%.2d-%.2d %.2d:%.2d:%.2d %4d] %s",
+            time_str.tm_year+1900, time_str.tm_mon+1, time_str.tm_mday,
+            time_str.tm_hour, time_str.tm_min, time_str.tm_sec,
+            getpid(), log_buffer);
+        fflush(org_stderr);
+    }
+    fclose(pipe_read);
+    pthread_exit(0);
+   return NULL;
+}
+
+void stop_logging_thread(void)
+{
+    fclose(logfile);
+    logfile = NULL;
+    fclose(stdin);
+    fclose(stderr);
+    pthread_join(log_hd, NULL);
+}
+
+void start_logging_thread(void)
+{
+    pthread_attr_t log_attr;
+    int log_pipes[2];
+    int err;
+    int org_stderr_fd;
+
+    org_stderr_fd = dup(2);
+    if (org_stderr_fd == -1) {
+        fprintf(stderr, "Failed to duplicate stderr.\n");
+        exit(1);
+    }
+
+    org_stderr = fdopen(org_stderr_fd, "w");
+    if (org_stderr == NULL) {
+        fprintf(stderr,
+                "Failed to associate stream with stderr.\n");
+        exit(1);
+    }
+
+    if (pipe(log_pipes) != 0) {
+        fprintf(stderr, "Failed to create pipes.\n");
+        exit(1);
+    }
+
+    pipe_read = fdopen(log_pipes[0], "r");
+    if (pipe_read == NULL) {
+        fprintf(stderr, "Failed to associate stream with reading pipe.\n");
+        exit(1);
+    }
+
+    logfile = fdopen(log_pipes[1], "w");
+    if (logfile == NULL) {
+        fprintf(stderr, "Failed to associate stream with writing pipe.\n");
+        exit(1);
+    }
+
+    pthread_attr_init(&log_attr);
+    err = pthread_create(&log_hd, &log_attr, logging_thread, (void *)NULL);
+    if (err != 0) {
+        fprintf(stderr, "Failed to create thread for logging.\n");
+        exit(1);
+    }
+
+    err = atexit(stop_logging_thread);
+    if (err != 0) {
+        fprintf(stderr, "Failed to set stop_logging_thread function.\n");
+        exit(1);
+    }
+
+#ifndef CONFIG_SOFTMMU
+    /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
+    {
+        static uint8_t logfile_buf[4096];
+        setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
+    }
+#else
+    setvbuf(logfile, NULL, _IOLBF, 0);
+#endif
+    dup2(fileno(logfile), 1);
+    dup2(fileno(logfile), 2);
+}
+#endif /* !CONFIG_STUBDOM */
+
 #define MAX_NET_CLIENTS 32
 
 int main(int argc, char **argv)
@@ -7868,7 +7973,11 @@ int main(int argc, char **argv)
     const char *pid_file = NULL;
     VLANState *vlan;
 
+#ifdef CONFIG_STUBDOM
     logfile = stderr; /* initial value */
+#else
+    start_logging_thread();
+#endif /* CONFIG_STUBDOM */
 
 #if !defined(__sun__) && !defined(CONFIG_STUBDOM)
     /* Maximise rlimits. Needed where default constraints are tight (*BSD). */


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>