All of lore.kernel.org
 help / color / mirror / Atom feed
* PATCH: Make QEMU send logs to stderr
@ 2008-02-27 20:28 Daniel P. Berrange
  0 siblings, 0 replies; only message in thread
From: Daniel P. Berrange @ 2008-02-27 20:28 UTC (permalink / raw)
  To: xen-devel


The QEMU code in Xen has a custom patch which stops QEMU sending its log
messages to stderr as vanilla QEMU would.  Instead it dup()s FD 2 on to
/var/log/xen/qemu-dm-{DOMID}.log

This is fine in principle, but it assumes that XenD is the only thing that
will ever  want to run qemu-dm. With the use of Xenner, qemu-dm processes
may be run by the 'xenner' program directly. Xenner in turn can be managed
by libvirt's QEMU/KVM driver which expects all QEMU log messages to be on
stderr, so that it can capture the logs. The Xen patch to QEMU breaks this
use case.

So this patch moves responsibility for configuring persistent logging out
of qemu-dm, and into  XenD. qemu-dm now just outputs to stderr as per 
regular upstream QEMU, and callers can choose how to process stderr.

At the same time, this patch renames the logfile to be 'qemu-dm-{NAME}.log'
instead of qemu-dm-{ID}.log.  This makes it easier to track/find the QEMU
logfile associated with a VM. It will also save 1 backup qemu-dm-{NAME}.log.1
so if a domain crashes & restart, you don't loose/overwrite the logfile
immediately.

Finally it changes the QEMU monitor prompt back to '(qemu)' instead of 
'(HVMXen)' because automated tools /scripts interacting with QEMU's
monitor need a consistent prompt to look for & changing it for Xen serves
no useful purpose.

  Signed-off-by: Daniel P. Berrange <berrange@redhat.com>

 ioemu/keymaps.c          |    4 ++--
 ioemu/monitor.c          |    2 +-
 ioemu/vl.c               |    4 +---
 python/xen/xend/image.py |   29 ++++++++++++++++++++++++++++-
 4 files changed, 32 insertions(+), 7 deletions(-)

Dan.

diff -r 2a8eaba24bf0 tools/ioemu/keymaps.c
--- a/tools/ioemu/keymaps.c	Tue Feb 26 15:11:51 2008 +0000
+++ b/tools/ioemu/keymaps.c	Wed Feb 27 15:26:53 2008 -0500
@@ -126,11 +126,11 @@ static kbd_layout_t *parse_keyboard_layo
 		    if (rest && strstr(rest, "numlock")) {
 			add_to_key_range(&k->keypad_range, keycode);
 			add_to_key_range(&k->numlock_range, keysym);
-			fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode);
+			//fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode);
 		    }
 		    if (rest && strstr(rest, "shift")) {
 			add_to_key_range(&k->shift_range, keysym);
-			fprintf(stderr, "shift keysym %04x keycode %d\n", keysym, keycode);
+			//fprintf(stderr, "shift keysym %04x keycode %d\n", keysym, keycode);
 		    }
 
 		    /* if(keycode&0x80)
diff -r 2a8eaba24bf0 tools/ioemu/monitor.c
--- a/tools/ioemu/monitor.c	Tue Feb 26 15:11:51 2008 +0000
+++ b/tools/ioemu/monitor.c	Wed Feb 27 15:26:53 2008 -0500
@@ -2520,7 +2520,7 @@ static void monitor_handle_command1(void
 
 static void monitor_start_input(void)
 {
-    readline_start("(HVMXen) ", 0, monitor_handle_command1, NULL);
+    readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
 }
 
 static void term_event(void *opaque, int event)
diff -r 2a8eaba24bf0 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c	Tue Feb 26 15:11:51 2008 +0000
+++ b/tools/ioemu/vl.c	Wed Feb 27 15:26:53 2008 -0500
@@ -7611,9 +7611,7 @@ int main(int argc, char **argv)
         }
     }
 
-    /* Now send logs to our named config */
-    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm-%d.log", domid);
-    cpu_set_log_filename(qemu_dm_logfilename);
+    cpu_set_log(0);
 
 #ifndef NO_DAEMONIZE
     if (daemonize && !nographic && vnc_display == NULL && vncunused == 0) {
diff -r 2a8eaba24bf0 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py	Tue Feb 26 15:11:51 2008 +0000
+++ b/tools/python/xen/xend/image.py	Wed Feb 27 15:26:53 2008 -0500
@@ -296,7 +296,34 @@ class ImageHandler:
                         { 'dom': self.vm.getDomid(), 'read': True, 'write': True })
         log.info("spawning device models: %s %s", self.device_model, args)
         # keep track of pid and spawned options to kill it later
-        self.pid = os.spawnve(os.P_NOWAIT, self.device_model, args, env)
+
+        logfile = "/var/log/xen/qemu-dm-%s.log" %  str(self.vm.info['name_label'])
+        if os.path.exists(logfile):
+            if os.path.exists(logfile + ".1"):
+                os.unlink(logfile + ".1")
+            os.rename(logfile, logfile + ".1")
+
+        null = os.open("/dev/null", os.O_RDONLY)
+        logfd = os.open(logfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
+        
+        pid = os.fork()
+        if pid == 0: #child
+            try:
+                os.dup2(null, 0)
+                os.dup2(logfd, 1)
+                os.dup2(logfd, 2)
+                os.close(null)
+                os.close(logfd)
+                try:
+                    os.execve(self.device_model, args, env)
+                except:
+                    os._exit(127)
+            except:
+                os._exit(127)
+        else:
+            self.pid = pid
+            os.close(null)
+            os.close(logfd)
         self.vm.storeDom("image/device-model-pid", self.pid)
         log.info("device model pid: %d", self.pid)
 


Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-27 20:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-27 20:28 PATCH: Make QEMU send logs to stderr Daniel P. Berrange

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.