mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-02 15:22:19 +00:00
Allow omitting USB port
We were requiring a USB port path in the schema, but not enforcing it. Omitting the USB port would lead to libvirt formatting it as (null). Such domain cannot be started and will disappear after libvirtd restart (since it cannot parse back the XML). Only format the port if it has been specified and mark it as optional in the XML schema.
This commit is contained in:
parent
08d566a0cf
commit
4f90364318
@ -4068,9 +4068,11 @@
|
||||
<attribute name="bus">
|
||||
<ref name="usbAddr"/>
|
||||
</attribute>
|
||||
<attribute name="port">
|
||||
<ref name="usbPort"/>
|
||||
</attribute>
|
||||
<optional>
|
||||
<attribute name="port">
|
||||
<ref name="usbPort"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="spaprvioaddress">
|
||||
<optional>
|
||||
|
@ -4839,9 +4839,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
|
||||
virBufferAsprintf(buf, " bus='%d' port='%s'",
|
||||
info->addr.usb.bus,
|
||||
info->addr.usb.port);
|
||||
virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
|
||||
virBufferEscapeString(buf, " port='%s'", info->addr.usb.port);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
|
||||
|
@ -375,7 +375,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_USB,
|
||||
info->addr.usb.bus)))
|
||||
goto cleanup;
|
||||
virBufferAsprintf(buf, ",bus=%s.0,port=%s", contAlias, info->addr.usb.port);
|
||||
virBufferAsprintf(buf, ",bus=%s.0", contAlias);
|
||||
virBufferEscapeString(buf, ",port=%s", info->addr.usb.port);
|
||||
} else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
|
||||
if (info->addr.spaprvio.has_reg)
|
||||
virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg);
|
||||
|
26
tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args
Normal file
26
tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args
Normal file
@ -0,0 +1,26 @@
|
||||
LC_ALL=C \
|
||||
PATH=/bin \
|
||||
HOME=/home/test \
|
||||
USER=test \
|
||||
LOGNAME=test \
|
||||
QEMU_AUDIO_DRV=none \
|
||||
/usr/bin/qemu \
|
||||
-name QEMUGuest1 \
|
||||
-S \
|
||||
-M pc \
|
||||
-m 214 \
|
||||
-smp 1,sockets=1,cores=1,threads=1 \
|
||||
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
|
||||
-nographic \
|
||||
-nodefconfig \
|
||||
-nodefaults \
|
||||
-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
|
||||
server,nowait \
|
||||
-mon chardev=charmonitor,id=monitor,mode=readline \
|
||||
-no-acpi \
|
||||
-boot c \
|
||||
-usb \
|
||||
-device usb-hub,id=hub0,bus=usb.0 \
|
||||
-device usb-hub,id=hub1,bus=usb.0 \
|
||||
-device usb-mouse,id=input0,bus=usb.0 \
|
||||
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
|
25
tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml
Normal file
25
tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<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='i686' machine='pc'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu</emulator>
|
||||
<controller type='usb' index='0'/>
|
||||
<memballoon model='virtio'/>
|
||||
<input type='mouse' bus='usb'>
|
||||
<address type='usb' bus='0'/>
|
||||
</input>
|
||||
<hub type='usb'>
|
||||
<address type='usb' bus='0'/>
|
||||
</hub>
|
||||
<hub type='usb'>
|
||||
<address type='usb' bus='0'/>
|
||||
</hub>
|
||||
</devices>
|
||||
</domain>
|
@ -1163,6 +1163,9 @@ mymain(void)
|
||||
DO_TEST("usb-hub",
|
||||
QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
|
||||
QEMU_CAPS_NODEFCONFIG);
|
||||
DO_TEST("usb-port-missing",
|
||||
QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
|
||||
QEMU_CAPS_NODEFCONFIG);
|
||||
DO_TEST("usb-ports",
|
||||
QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
|
||||
QEMU_CAPS_NODEFCONFIG);
|
||||
|
36
tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml
Normal file
36
tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<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='i686' 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</emulator>
|
||||
<controller type='usb' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='usb'>
|
||||
<address type='usb' bus='0'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<hub type='usb'>
|
||||
<address type='usb' bus='0'/>
|
||||
</hub>
|
||||
<hub type='usb'>
|
||||
<address type='usb' bus='0'/>
|
||||
</hub>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
@ -591,6 +591,7 @@ mymain(void)
|
||||
DO_TEST("interface-server");
|
||||
DO_TEST("virtio-lun");
|
||||
|
||||
DO_TEST("usb-port-missing");
|
||||
DO_TEST("usb-redir");
|
||||
DO_TEST("usb-redir-filter");
|
||||
DO_TEST("usb-redir-filter-version");
|
||||
|
Loading…
x
Reference in New Issue
Block a user