PATCH: Make QEMU send logs to stderr
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.
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.
tools/ioemu/keymaps.c +2 -2
@@ -126,11 +126,11 @@ static kbd_layout_t *parse_keyboard_layoif (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)
tools/ioemu/monitor.c +1 -1
@@ -2520,7 +2520,7 @@ static void monitor_handle_command1(voidstatic 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)
tools/ioemu/vl.c +1 -3
@@ -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 ) {
tools/python/xen/xend/image.py +28 -1
@@ -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.
Signature · 4 lines
|=- 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 -=|