[libvirt PATCH 2/2] qemu: wire up support for isa-debugcon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This wires up the command line generator so that it can emit the
args needed to enable the ISA debug console in QEMU. No capability
check is required since this has been around forever in QEMU and
the conf parser rejects it on non-x86 configs already.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                       | 36 +++++++++++++++--
 src/qemu/qemu_domain_address.c                | 25 ++++++++++++
 src/qemu/qemu_validate.c                      | 18 ++++++++-
 .../debugcon.x86_64-latest.args               | 39 +++++++++++++++++++
 tests/qemuxml2argvdata/debugcon.xml           | 27 +++++++++++++
 tests/qemuxml2argvtest.c                      |  2 +
 6 files changed, 141 insertions(+), 6 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/debugcon.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/debugcon.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 030c27b963..b91998a5f5 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5634,6 +5634,27 @@ qemuBuildSclpDevProps(virDomainChrDef *dev)
 }
 
 
+static virJSONValue *
+qemuBuildISADebugDevProps(const virDomainDef *def,
+                          virDomainChrDef *dev)
+{
+    g_autoptr(virJSONValue) props = NULL;
+    g_autofree char *chardev = g_strdup_printf("char%s", dev->info.alias);
+
+    if (virJSONValueObjectAdd(&props,
+                              "s:driver", "isa-debugcon",
+                              "s:chardev", chardev,
+                              "s:id", dev->info.alias,
+                              NULL) < 0)
+        return NULL;
+
+    if (qemuBuildDeviceAddressProps(props, def, &dev->info) < 0)
+        return NULL;
+
+    return g_steal_pointer(&props);
+}
+
+
 static int
 qemuBuildRNGBackendChrdev(virCommand *cmd,
                           virDomainRNGDef *rng,
@@ -9317,7 +9338,6 @@ qemuBuildChrDeviceCommandLine(virCommand *cmd,
                               virQEMUCaps *qemuCaps)
 {
     g_autoptr(virJSONValue) props = NULL;
-
     if (!(props = qemuBuildChrDeviceProps(def, chr, qemuCaps)))
         return -1;
 
@@ -9500,10 +9520,11 @@ qemuBuildConsoleCommandLine(virCommand *cmd,
         virDomainChrDef *console = def->consoles[i];
         g_autofree char *charAlias = qemuAliasChardevFromDevAlias(console->info.alias);
 
-        switch (console->targetType) {
+        switch ((virDomainChrConsoleTargetType)console->targetType) {
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLP:
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLPLM:
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_ISA_DEBUG:
             if (qemuBuildChardevCommand(cmd,
                                         console->source,
                                         charAlias,
@@ -9517,7 +9538,12 @@ qemuBuildConsoleCommandLine(virCommand *cmd,
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL:
             break;
 
-        default:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST:
             return -1;
         }
     }
@@ -10839,13 +10865,15 @@ qemuBuildConsoleChrDeviceProps(const virDomainDef *def,
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO:
         return qemuBuildVirtioSerialPortDevProps(def, chr);
 
+    case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_ISA_DEBUG:
+        return qemuBuildISADebugDevProps(def, chr);
+
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL:
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE:
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN:
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML:
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC:
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ:
-    case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_ISA_DEBUG:
     case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported console target type %s"),
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 18fc34d049..e97c612762 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -3174,6 +3174,28 @@ qemuDomainAssignUSBAddresses(virDomainDef *def,
 }
 
 
+static int
+qemuDomainAssignISAAddresses(virDomainDef *def)
+{
+    size_t i;
+
+    for (i = 0; i < def->nconsoles; i++) {
+        virDomainChrDef *chr = def->consoles[i];
+
+        if (chr->targetType != VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_ISA_DEBUG) {
+            continue;
+        }
+
+        if (chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            chr->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA;
+            chr->info.addr.isa.iobase = 0x402;
+        }
+    }
+
+    return 0;
+}
+
+
 int
 qemuDomainAssignAddresses(virDomainDef *def,
                           virQEMUCaps *qemuCaps,
@@ -3201,6 +3223,9 @@ qemuDomainAssignAddresses(virDomainDef *def,
     if (qemuDomainAssignMemorySlots(def) < 0)
         return -1;
 
+    if (qemuDomainAssignISAAddresses(def) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index ae0ee4e744..fd25701fd3 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -862,7 +862,7 @@ qemuValidateDomainDefConsole(const virDomainDef *def,
     for (i = 0; i < def->nconsoles; i++) {
         virDomainChrDef *console = def->consoles[i];
 
-        switch (console->targetType) {
+        switch ((virDomainChrConsoleTargetType)console->targetType) {
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLP:
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCLPCONSOLE)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -879,11 +879,25 @@ qemuValidateDomainDefConsole(const virDomainDef *def,
             }
             break;
 
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_ISA_DEBUG:
+            if (console->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("isa-debug console target must has ISA address type not %s"),
+                               virDomainDeviceAddressTypeToString(console->info.type));
+                return -1;
+            }
+            break;
+
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO:
         case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL:
             break;
 
-        default:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ:
+        case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST:
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unsupported console target type %s"),
                            NULLSTR(virDomainChrConsoleTargetTypeToString(console->targetType)));
diff --git a/tests/qemuxml2argvdata/debugcon.x86_64-latest.args b/tests/qemuxml2argvdata/debugcon.x86_64-latest.args
new file mode 100644
index 0000000000..fa6c422329
--- /dev/null
+++ b/tests/qemuxml2argvdata/debugcon.x86_64-latest.args
@@ -0,0 +1,39 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \
+-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram \
+-accel tcg \
+-cpu qemu64 \
+-m 214 \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
+-device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \
+-chardev pty,id=charconsole0 \
+-device '{"driver":"isa-debugcon","chardev":"charconsole0","id":"console0","iobase":1026}' \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/debugcon.xml b/tests/qemuxml2argvdata/debugcon.xml
new file mode 100644
index 0000000000..662284c79a
--- /dev/null
+++ b/tests/qemuxml2argvdata/debugcon.xml
@@ -0,0 +1,27 @@
+<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='x86_64' 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-system-x86_64</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <console type='pty'>
+      <target type='isa-debug'/>
+      <address type='isa' iobase='0x402'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 9d2de2a569..7100a4d7f1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1257,6 +1257,8 @@ mymain(void)
     DO_TEST_NOCAPS("q35-noacpi-nouefi");
     DO_TEST_NOCAPS("q35-acpi-nouefi");
 
+    DO_TEST_CAPS_LATEST("debugcon");
+
     DO_TEST_NOCAPS("clock-utc");
     DO_TEST_NOCAPS("clock-localtime");
     DO_TEST_NOCAPS("clock-localtime-basis-localtime");
-- 
2.33.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux