From d3a9364d3c7789e3c234a361f24c20405f61216e Mon Sep 17 00:00:00 2001
Message-Id: <d3a9364d3c7789e3c234a361f24c20405f61216e@dist-git>
From: Cole Robinson <crobinso@redhat.com>
Date: Tue, 11 Jul 2017 10:57:48 +0200
Subject: [PATCH] qemu: command: support -chardev for platform devices
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.
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 426dc5eb28bade109bf27bdd10d7305a040b4a3e)
Conflicts:
* src/qemu/qemu_command.c:
caused by fcd922427cf6a264d3cb89915481be6594e6df03 not being
in the tree; resolved by removing the chardevStdioLogd argument
from the call to qemuBuildChrChardevStr().
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1435681
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_command.c | 123 ++-------------------
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, 31 insertions(+), 128 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3517329a6b..69f4323a3b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5508,106 +5508,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,
@@ -9187,25 +9087,22 @@ 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)))
+ 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)))
- 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 4d7c8d8e40..274309030e 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 4c95c32a05..9893b116f2 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 c640edc6fb..662259e229 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 eca4c4bacf..b1f7e6ea5e 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 a5bc66ecd2..28ec390a13 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 198e663d6f..73d1314b57 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 1402fead1c..850775177e 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 d391a4d02a..f051839dd1 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 182744c236..2cdb45e35a 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 87f4ee5e43..56b0a1c494 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
--
2.13.3