qemu: add support for logging chardev output to a file

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>
This commit is contained in:
Daniel P. Berrange 2016-02-23 11:56:34 +00:00
parent 00ce10c700
commit 06cb0cf7ce
6 changed files with 88 additions and 0 deletions

View 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

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

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

View File

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

View File

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

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