]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: add support for logging chardev output to a file
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 23 Feb 2016 11:56:34 +0000 (11:56 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 10 Mar 2016 15:33:51 +0000 (15:33 +0000)
Honour the <log file='...'/> element in chardevs to output
data to a file. This requires QEMU >= 2.6

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-serial-file-log.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-serial-file-log.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index 355b76e1f82c7f1589b7bff21b3bc45c6563ff6e..fce79f8b8b66f2013d449bb8ae2c58ffd00493f0 100644 (file)
@@ -319,6 +319,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "qxl.vram64_size_mb",
 
               "qxl-vga.vram64_size_mb", /* 215 */
+              "chardev-logfile",
     );
 
 
@@ -2634,6 +2635,7 @@ static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = {
     { "machine", "dea-key-wrap", QEMU_CAPS_DEA_KEY_WRAP },
     { "chardev", "append", QEMU_CAPS_CHARDEV_FILE_APPEND },
     { "spice", "gl", QEMU_CAPS_SPICE_GL },
+    { "chardev", "logfile", QEMU_CAPS_CHARDEV_LOGFILE },
 };
 
 static int
index 9aa79aa395933f14110ee8f9bb0c65f6eaaae10e..af8d15be55b2d085ada73b349bec395f1a439204 100644 (file)
@@ -349,6 +349,7 @@ typedef enum {
 
     /* 215 */
     QEMU_CAPS_QXL_VGA_VRAM64, /* -device qxl-vga.vram64_size_mb */
+    QEMU_CAPS_CHARDEV_LOGFILE, /* -chardev logfile=xxxx */
 
     QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
index 000c29d3e97663a24b965d9f8d0f6699e092fe8b..94ea78db275f707f551a1307f0ac87966d408fab 100644 (file)
@@ -3976,6 +3976,19 @@ qemuBuildChrChardevStr(const virDomainChrSourceDef *dev,
         goto error;
     }
 
+    if (dev->logfile) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_LOGFILE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("logfile not supported in this QEMU binary"));
+            goto error;
+        }
+        virBufferAsprintf(&buf, ",logfile=%s", dev->logfile);
+        if (dev->logappend != VIR_TRISTATE_SWITCH_ABSENT) {
+            virBufferAsprintf(&buf, ",logappend=%s",
+                              virTristateSwitchTypeToString(dev->logappend));
+        }
+    }
+
     if (virBufferCheckError(&buf) < 0)
         goto error;
 
@@ -3993,6 +4006,12 @@ qemuBuildChrArgStr(const virDomainChrSourceDef *dev,
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
+    if (dev->logfile) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("logfile not supported in this QEMU binary"));
+        goto error;
+    }
+
     if (prefix)
         virBufferAdd(&buf, prefix, strlen(prefix));
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-file-log.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-file-log.args
new file mode 100644 (file)
index 0000000..de313e5
--- /dev/null
@@ -0,0 +1,25 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 \
+-S \
+-M pc \
+-m 214 \
+-smp 1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/test-monitor,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=readline \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-chardev file,id=charserial0,path=/tmp/serial.log,\
+logfile=/var/lib/libvirt/qemu/demo-serial.log,logappend=off \
+-device isa-serial,chardev=charserial0,id=serial0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-file-log.xml b/tests/qemuxml2argvdata/qemuxml2argv-serial-file-log.xml
new file mode 100644 (file)
index 0000000..adb3b78
--- /dev/null
@@ -0,0 +1,39 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <serial type='file'>
+      <source path='/tmp/serial.log'/>
+      <log file='/var/lib/libvirt/qemu/demo-serial.log' append='off'/>
+      <target port='0'/>
+    </serial>
+    <console type='file'>
+      <source path='/tmp/serial.log'/>
+      <target type='serial' port='0'/>
+    </console>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
index d29073dda5e637d3e108c6d0cf85fe4c6ab36784..d54c93f0cd1ea39a199dc2119efddccae2710952 100644 (file)
@@ -1044,6 +1044,8 @@ mymain(void)
     DO_TEST("serial-pty", NONE);
     DO_TEST("serial-dev", NONE);
     DO_TEST("serial-file", NONE);
+    DO_TEST("serial-file-log", QEMU_CAPS_CHARDEV, QEMU_CAPS_CHARDEV_FILE_APPEND,
+            QEMU_CAPS_CHARDEV_LOGFILE);
     DO_TEST("serial-unix", NONE);
     DO_TEST("serial-tcp", NONE);
     DO_TEST("serial-udp", NONE);