]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Process new 'append' attribute for char dev with output to a file
authorDmitry Mishin <dim@virtuozzo.com>
Thu, 24 Dec 2015 14:27:55 +0000 (17:27 +0300)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 24 Dec 2015 14:50:33 +0000 (14:50 +0000)
By default, QEMU truncates serial file on open. Sometimes, it could be weird -
for example, when we are trying to investigate some event, which occured several
restarts ago. This patch adds an ability to preserve previous content.

Signed-off-by: Dmitry Mishin <dim@virtuozzo.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_command.c
tests/qemucapabilitiesdata/caps_2.6.0-1.caps
tests/qemuxml2argvdata/qemuxml2argv-serial-file-chardev.args
tests/qemuxml2argvdata/qemuxml2argv-serial-file-chardev.xml
tests/qemuxml2argvtest.c

index 6e5d203f0667c006ae1e57e1e2081eeffa26b29a..7b30441ac7e71f3ae84e1b2b07bc3cab843fb971 100644 (file)
@@ -308,6 +308,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
 
               "virtio-tablet", /* 205 */
               "virtio-input-host",
+              "chardev-file-append",
     );
 
 
@@ -2600,6 +2601,7 @@ static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = {
     { "drive", "throttling.bps-total-max", QEMU_CAPS_DRIVE_IOTUNE_MAX},
     { "machine", "aes-key-wrap", QEMU_CAPS_AES_KEY_WRAP },
     { "machine", "dea-key-wrap", QEMU_CAPS_DEA_KEY_WRAP },
+    { "chardev", "append", QEMU_CAPS_CHARDEV_FILE_APPEND },
 };
 
 static int
index 61d637997de16287dde058875527d51b99bbbb34..c148f2d9d34dd35595513d5dd875eff71ad5b1d8 100644 (file)
@@ -335,6 +335,7 @@ typedef enum {
     /* 205 */
     QEMU_CAPS_VIRTIO_TABLET, /* -device virtio-tablet-{device,pci} */
     QEMU_CAPS_VIRTIO_INPUT_HOST, /* -device virtio-input-host-{device,pci} */
+    QEMU_CAPS_CHARDEV_FILE_APPEND, /* -chardev file,append=on|off */
 
     QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
index 9822cf7898f414d345ea4d4fdd4ed22846c37bb7..d40198128d4d04f94c18d16d02f768cad64a2fab 100644 (file)
@@ -6555,6 +6555,16 @@ qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias,
     case VIR_DOMAIN_CHR_TYPE_FILE:
         virBufferAsprintf(&buf, "file,id=char%s,path=%s", alias,
                           dev->data.file.path);
+        if (dev->data.file.append) {
+            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_FILE_APPEND)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("append not supported in this QEMU binary"));
+                goto error;
+            }
+
+            virBufferAsprintf(&buf, ",append=%s",
+                              virTristateSwitchTypeToString(dev->data.file.append));
+        }
         break;
 
     case VIR_DOMAIN_CHR_TYPE_PIPE:
index d9a8f3f7a421a0c2a97ce97d06f5e8bb253f5cc1..e296efc90d882a61d22e95f49fbfca0e816b85a0 100644 (file)
     <flag name='virtio-mouse'/>
     <flag name='virtio-tablet'/>
     <flag name='virtio-input-host'/>
+    <flag name='chardev-file-append'/>
   </qemuCaps>
index 64fcd297c6284d2b7a0ef00eaf8e3561c990dcfb..4345eb02c29e841c9320618d50a7c70d5081a24a 100644 (file)
@@ -21,6 +21,6 @@ QEMU_AUDIO_DRV=none \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0,format=raw \
 -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 \
+-chardev file,id=charserial0,path=/tmp/serial.log,append=on \
 -device isa-serial,chardev=charserial0,id=serial0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
index 2527e7d2b658d7e1beb917464994edf446304cda..08ddfaa427513ff1f5604ce0c1d2afe1c12eca39 100644 (file)
@@ -22,7 +22,7 @@
     <controller type='usb' index='0'/>
     <controller type='ide' index='0'/>
     <serial type='file'>
-      <source path='/tmp/serial.log'/>
+      <source path='/tmp/serial.log' append='on'/>
       <target port='0'/>
     </serial>
     <console type='file'>
index 37f806edd3c0f71dce021fc58af4dbe363f5f667..63480ce8af19a2615ed81582ac41d5fcd0bc4734 100644 (file)
@@ -1047,7 +1047,8 @@ mymain(void)
     DO_TEST("serial-dev-chardev-iobase",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
     DO_TEST("serial-file-chardev",
-            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_CHARDEV_FILE_APPEND);
     DO_TEST("serial-unix-chardev",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
     DO_TEST("serial-tcp-chardev",