The current behavior is to error out, but that's not very helpful.
Automatically add the necessary USB controller instead.
Resolves: https://issues.redhat.com/browse/RHEL-2455
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
src/qemu/qemu_postparse.c | 11 ++++++
...h-devices-virt-aarch64.aarch64-latest.args | 36 +++++++++++++++++++
...th-devices-virt-aarch64.aarch64-latest.err | 1 -
...th-devices-virt-aarch64.aarch64-latest.xml | 13 +++++++
tests/qemuxmlconftest.c | 2 +-
5 files changed, 61 insertions(+), 2 deletions(-)
create mode 100644 tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.args
delete mode 100644 tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.err
diff --git a/src/qemu/qemu_postparse.c b/src/qemu/qemu_postparse.c
index 8940cb09b3..d3548b24d8 100644
--- a/src/qemu/qemu_postparse.c
+++ b/src/qemu/qemu_postparse.c
@@ -1329,6 +1329,17 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver,
return -1;
}
+ /* If the default UBS controller would normally not be added for the
+ * machine but USB devices are present in the configuration, it's more
+ * user-friendly to automatically add the USB controller instead of
+ * requiring the user to take care of that manually. Of course this is
+ * still subject to the logic below, i.e. we will only add the
+ * controller if a suitable model can be figured out and an explicit
+ * one was not already present */
+ if (!addDefaultUSB && virDomainDefHasUSBDevices(def)) {
+ addDefaultUSB = true;
+ }
+
if (addDefaultUSB && usbModel == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT) {
usbModel = qemuDomainDefaultUSBControllerModelAutoAdded(def, qemuCaps);
diff --git a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.args b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.args
new file mode 100644
index 0000000000..850eaa7ec0
--- /dev/null
+++ b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.args
@@ -0,0 +1,36 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/var/lib/libvirt/qemu/domain--1-test \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-test/.local/share \
+XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-test/.cache \
+XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-test/.config \
+/usr/bin/qemu-system-aarch64 \
+-name guest=test,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-test/master-key.aes"}' \
+-machine virt,usb=off,gic-version=2,dump-guest-core=off,memory-backend=mach-virt.ram,acpi=off \
+-accel tcg \
+-cpu cortex-a15 \
+-m size=219136k \
+-object '{"qom-type":"memory-backend-ram","id":"mach-virt.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 \
+-boot strict=on \
+-device '{"driver":"pcie-root-port","port":8,"chassis":1,"id":"pci.1","bus":"pcie.0","multifunction":true,"addr":"0x1"}' \
+-device '{"driver":"pcie-root-port","port":9,"chassis":2,"id":"pci.2","bus":"pcie.0","addr":"0x1.0x1"}' \
+-device '{"driver":"qemu-xhci","id":"usb","bus":"pci.1","addr":"0x0"}' \
+-device '{"driver":"usb-tablet","id":"input0","bus":"usb.0","port":"1"}' \
+-device '{"driver":"usb-kbd","id":"input1","bus":"usb.0","port":"2"}' \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.err b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.err
deleted file mode 100644
index 90050be94b..0000000000
--- a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.err
+++ /dev/null
@@ -1 +0,0 @@
-unsupported configuration: USB is disabled for this domain, but USB devices are present in the domain XML
diff --git a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.xml b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.xml
index 431ff6703b..7923087433 100644
--- a/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.xml
+++ b/tests/qemuxmlconfdata/usb-controller-automatic-with-devices-virt-aarch64.aarch64-latest.xml
@@ -20,7 +20,20 @@
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-aarch64</emulator>
+ <controller type='usb' index='0' model='qemu-xhci'>
+ <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
+ </controller>
<controller type='pci' index='0' model='pcie-root'/>
+ <controller type='pci' index='1' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='1' port='0x8'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
+ </controller>
+ <controller type='pci' index='2' model='pcie-root-port'>
+ <model name='pcie-root-port'/>
+ <target chassis='2' port='0x9'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
<input type='tablet' bus='usb'/>
<input type='keyboard' bus='usb'/>
<audio id='1' type='none'/>
diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c
index 835a388263..4c1ecddc4a 100644
--- a/tests/qemuxmlconftest.c
+++ b/tests/qemuxmlconftest.c
@@ -2141,7 +2141,7 @@ mymain(void)
ARG_QEMU_CAPS_DEL, QEMU_CAPS_DEVICE_QEMU_XHCI, QEMU_CAPS_NEC_USB_XHCI, QEMU_CAPS_PCI_OHCI, QEMU_CAPS_LAST,
ARG_END);
- DO_TEST_CAPS_ARCH_LATEST_FAILURE("usb-controller-automatic-with-devices-virt-aarch64", "aarch64");
+ DO_TEST_CAPS_ARCH_LATEST("usb-controller-automatic-with-devices-virt-aarch64", "aarch64");
DO_TEST_CAPS_LATEST_PARSE_ERROR("usb-controller-default-isapc");
DO_TEST_CAPS_LATEST_PARSE_ERROR("usb-controller-default-microvm");
--
2.52.0
© 2016 - 2026 Red Hat, Inc.