diff mbox series

[11/12] qemu: command: support -chardev for platform devices

Message ID d7e61acab4f830c96d49fd156061c210bb7c1b9d.1498499392.git.crobinso@redhat.com
State Accepted
Commit 426dc5eb28bade109bf27bdd10d7305a040b4a3e
Headers show
Series qemu: support chardev for all machvirt config | expand

Commit Message

Cole Robinson June 26, 2017, 6:01 p.m. UTC
Some qemu arch/machine types have built in platform devices that
are always implicitly available. For platform serial devices, the
current code assumes that only old style -serial config can be
used for these devices.

Apparently though since -chardev was introduced, we can use -chardev
in these cases, like this:

  -chardev pty,id=foo
  -serial chardev:foo

Since -chardev enables all sorts of modern features, use this method
for platform devices.

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
note: I only gave this light testing with a very new qemu, just made sure
console output was still working. I'd appreciate if other folks can test
it as well to make sure extra features like <log> work as expected

 src/qemu/qemu_command.c                            | 125 ++-------------------
 src/qemu/qemu_process.c                            |   9 +-
 .../qemuxml2argv-aarch64-kvm-32-on-64.args         |   3 +-
 ...l2argv-aarch64-virt-2.6-virtio-pci-default.args |   3 +-
 .../qemuxml2argv-aarch64-virt-virtio.args          |   3 +-
 .../qemuxml2argv-aarch64-virtio-pci-default.args   |   3 +-
 .../qemuxml2argv-arm-vexpressa9-basic.args         |   3 +-
 .../qemuxml2argv-arm-vexpressa9-virtio.args        |   3 +-
 .../qemuxml2argv-arm-virt-virtio.args              |   3 +-
 tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args   |   3 +-
 .../qemuxml2argv-ppce500-serial.args               |   3 +-
 11 files changed, 32 insertions(+), 129 deletions(-)

-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Andrea Bolognani July 7, 2017, 4:32 p.m. UTC | #1
On Mon, 2017-06-26 at 14:01 -0400, Cole Robinson wrote:
> @@ -1877,8 +1877,8 @@ qemuProcessMonitorReportLogError(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
>  
>  
>  static int
> -qemuProcessLookupPTYs(virDomainDefPtr def,
> -                      virQEMUCapsPtr qemuCaps,
> +qemuProcessLookupPTYs(virDomainDefPtr def ATTRIBUTE_UNUSED,
> +                      virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED,
>                        virDomainChrDefPtr *devices,
>                        int count,
>                        virHashTablePtr info)

I don't see a reason to turn these into ATTRIBUTE_UNUSED,
just update the callers and get rid of them entirely.


Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 056e62129..3e82ca086 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5514,106 +5514,6 @@  qemuBuildHostdevCommandLine(virCommandPtr cmd,
     return 0;
 }
 
-static char *
-qemuBuildChrArgStr(const virDomainChrSourceDef *dev,
-                   const char *prefix)
-{
-    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));
-
-    switch ((virDomainChrType)dev->type) {
-    case VIR_DOMAIN_CHR_TYPE_NULL:
-        virBufferAddLit(&buf, "null");
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_VC:
-        virBufferAddLit(&buf, "vc");
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_PTY:
-        virBufferAddLit(&buf, "pty");
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_DEV:
-        virBufferStrcat(&buf, dev->data.file.path, NULL);
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_FILE:
-        virBufferAsprintf(&buf, "file:%s", dev->data.file.path);
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_PIPE:
-        virBufferAsprintf(&buf, "pipe:%s", dev->data.file.path);
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_STDIO:
-        virBufferAddLit(&buf, "stdio");
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_UDP: {
-        const char *connectHost = dev->data.udp.connectHost;
-        const char *bindHost = dev->data.udp.bindHost;
-        const char *bindService  = dev->data.udp.bindService;
-
-        if (connectHost == NULL)
-            connectHost = "";
-        if (bindHost == NULL)
-            bindHost = "";
-        if (bindService == NULL)
-            bindService = "0";
-
-        virBufferAsprintf(&buf, "udp:%s:%s@%s:%s",
-                          connectHost,
-                          dev->data.udp.connectService,
-                          bindHost,
-                          bindService);
-        break;
-    }
-    case VIR_DOMAIN_CHR_TYPE_TCP:
-        if (dev->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET) {
-            virBufferAsprintf(&buf, "telnet:%s:%s%s",
-                              dev->data.tcp.host,
-                              dev->data.tcp.service,
-                              dev->data.tcp.listen ? ",server,nowait" : "");
-        } else {
-            virBufferAsprintf(&buf, "tcp:%s:%s%s",
-                              dev->data.tcp.host,
-                              dev->data.tcp.service,
-                              dev->data.tcp.listen ? ",server,nowait" : "");
-        }
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_UNIX:
-        virBufferAsprintf(&buf, "unix:%s%s",
-                          dev->data.nix.path,
-                          dev->data.nix.listen ? ",server,nowait" : "");
-        break;
-
-    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
-    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
-    case VIR_DOMAIN_CHR_TYPE_NMDM:
-    case VIR_DOMAIN_CHR_TYPE_LAST:
-        break;
-    }
-
-    if (virBufferCheckError(&buf) < 0)
-        goto error;
-
-    return virBufferContentAndReset(&buf);
-
- error:
-    virBufferFreeAndReset(&buf);
-    return NULL;
-}
-
 
 static int
 qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
@@ -9226,26 +9126,23 @@  qemuBuildSerialCommandLine(virLogManagerPtr logManager,
         if (serial->source->type == VIR_DOMAIN_CHR_TYPE_SPICEPORT && !havespice)
             continue;
 
+        if (!(devstr = qemuBuildChrChardevStr(logManager, cmd, cfg, def,
+                                              serial->source,
+                                              serial->info.alias,
+                                              qemuCaps, true,
+                                              chardevStdioLogd)))
+            return -1;
+        virCommandAddArg(cmd, "-chardev");
+        virCommandAddArg(cmd, devstr);
+        VIR_FREE(devstr);
+
         /* Use -chardev with -device if they are available */
         if (virQEMUCapsSupportsChardev(def, qemuCaps, serial)) {
-            if (!(devstr = qemuBuildChrChardevStr(logManager, cmd, cfg, def,
-                                                  serial->source,
-                                                  serial->info.alias,
-                                                  qemuCaps, true,
-                                                  chardevStdioLogd)))
-                return -1;
-            virCommandAddArg(cmd, "-chardev");
-            virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
-
             if (qemuBuildChrDeviceCommandLine(cmd, def, serial, qemuCaps) < 0)
                 return -1;
         } else {
             virCommandAddArg(cmd, "-serial");
-            if (!(devstr = qemuBuildChrArgStr(serial->source, NULL)))
-                return -1;
-            virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
+            virCommandAddArgFormat(cmd, "chardev:char%s", serial->info.alias);
         }
     }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d669dfb32..2341f0ab1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1877,8 +1877,8 @@  qemuProcessMonitorReportLogError(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
 
 
 static int
-qemuProcessLookupPTYs(virDomainDefPtr def,
-                      virQEMUCapsPtr qemuCaps,
+qemuProcessLookupPTYs(virDomainDefPtr def ATTRIBUTE_UNUSED,
+                      virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED,
                       virDomainChrDefPtr *devices,
                       int count,
                       virHashTablePtr info)
@@ -1887,14 +1887,11 @@  qemuProcessLookupPTYs(virDomainDefPtr def,
 
     for (i = 0; i < count; i++) {
         virDomainChrDefPtr chr = devices[i];
-        bool chardevfmt = virQEMUCapsSupportsChardev(def, qemuCaps, chr);
-
         if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
             char id[32];
             qemuMonitorChardevInfoPtr entry;
 
-            if (snprintf(id, sizeof(id), "%s%s",
-                         chardevfmt ? "char" : "",
+            if (snprintf(id, sizeof(id), "char%s",
                          chr->info.alias) >= sizeof(id)) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("failed to format device alias "
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-kvm-32-on-64.args b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-kvm-32-on-64.args
index 3af4564ad..693b48931 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-kvm-32-on-64.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-kvm-32-on-64.args
@@ -26,4 +26,5 @@  server,nowait \
 -device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
 -device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
 -net user,vlan=0,name=hostnet0 \
--serial pty
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args
index c640edc6f..662259e22 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args
@@ -33,7 +33,8 @@  path=/tmp/lib/domain--1-aarch64test/monitor.sock,server,nowait \
 id=virtio-disk0 \
 -device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:09:a4:37,bus=pci.2,addr=0x1 \
 -net user,vlan=0,name=hostnet0 \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -chardev pty,id=charconsole1 \
 -device virtconsole,chardev=charconsole1,id=console1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x4 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-virtio.args b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-virtio.args
index eca4c4bac..b1f7e6ea5 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-virtio.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-virtio.args
@@ -29,7 +29,8 @@  path=/tmp/lib/domain--1-aarch64test/monitor.sock,server,nowait \
 -device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
 -device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
 -net user,vlan=0,name=hostnet0 \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -chardev pty,id=charconsole1 \
 -device virtconsole,chardev=charconsole1,id=console1 \
 -device virtio-balloon-device,id=balloon0 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args
index a5bc66ecd..28ec390a1 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args
@@ -37,7 +37,8 @@  addr=0x1 \
 id=virtio-disk0 \
 -device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:09:a4:37,bus=pci.1,addr=0x0 \
 -net user,vlan=0,name=hostnet0 \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -chardev pty,id=charconsole1 \
 -device virtconsole,chardev=charconsole1,id=console1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.4,addr=0x0 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-basic.args b/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-basic.args
index 198e663d6..73d1314b5 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-basic.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-basic.args
@@ -27,4 +27,5 @@  server,nowait \
 -drive file=/arm.raw,format=raw,if=sd,index=0 \
 -net nic,macaddr=52:54:00:09:a4:37,vlan=0,model=lan9118,name=net0 \
 -net user,vlan=0,name=hostnet0 \
--serial pty
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-virtio.args b/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-virtio.args
index 1402fead1..850775177 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-virtio.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-virtio.args
@@ -29,7 +29,8 @@  server,nowait \
 -device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
 -device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
 -net user,vlan=0,name=hostnet0 \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -chardev pty,id=charconsole1 \
 -device virtconsole,chardev=charconsole1,id=console1 \
 -device virtio-balloon-device,id=balloon0 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-arm-virt-virtio.args b/tests/qemuxml2argvdata/qemuxml2argv-arm-virt-virtio.args
index d391a4d02..f051839dd 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-arm-virt-virtio.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-arm-virt-virtio.args
@@ -27,7 +27,8 @@  server,nowait \
 -device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
 -device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
 -net user,vlan=0,name=hostnet0 \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -chardev pty,id=charconsole1 \
 -device virtconsole,chardev=charconsole1,id=console1 \
 -device virtio-balloon-device,id=balloon0 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args
index 182744c23..2cdb45e35 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args
@@ -22,5 +22,6 @@  server,nowait \
 -append 'root=/dev/ram rw console=ttyS0,115200' \
 -dtb /media/ram/test.dtb \
 -usb \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-ppce500-serial.args b/tests/qemuxml2argvdata/qemuxml2argv-ppce500-serial.args
index 87f4ee5e4..56b0a1c49 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-ppce500-serial.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-ppce500-serial.args
@@ -21,5 +21,6 @@  server,nowait \
 -initrd /media/ram/ramdisk \
 -append 'root=/dev/ram rw console=ttyS0,115200' \
 -usb \
--serial pty \
+-chardev pty,id=charserial0 \
+-serial chardev:charserial0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2