mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
qemu: Add enough USB hubs to accomodate all devices
Commit 815d98a started auto-adding one hub if there are more USB devices than available USB ports. This was a strange choice, since there might be even more devices. Before USB address allocation was implemented in libvirt, QEMU automatically added a new USB hub if the old one was full. Adjust the logic to try adding as many hubs as will be needed to plug in all the specified devices. https://bugzilla.redhat.com/show_bug.cgi?id=1410188
This commit is contained in:
parent
077c6d450f
commit
3ac97c2ded
@ -2300,19 +2300,24 @@ qemuDomainUSBAddressAddHubs(virDomainDefPtr def)
|
||||
struct qemuAssignUSBIteratorInfo data = { .count = 0 };
|
||||
virDomainHubDefPtr hub = NULL;
|
||||
size_t available_ports;
|
||||
size_t hubs_needed = 0;
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
|
||||
available_ports = virDomainUSBAddressCountAllPorts(def);
|
||||
ignore_value(virDomainUSBDeviceDefForeach(def,
|
||||
qemuDomainAssignUSBPortsCounter,
|
||||
&data,
|
||||
false));
|
||||
VIR_DEBUG("Found %zu USB devices and %zu provided USB ports",
|
||||
data.count, available_ports);
|
||||
|
||||
/* Add one hub if there are more devices than ports
|
||||
* otherwise it's up to the user to specify more hubs/controllers */
|
||||
if (data.count > available_ports) {
|
||||
if (data.count > available_ports)
|
||||
hubs_needed = VIR_DIV_UP(data.count - available_ports + 1,
|
||||
VIR_DOMAIN_USB_HUB_PORTS - 1);
|
||||
|
||||
VIR_DEBUG("Found %zu USB devices and %zu provided USB ports; adding %zu hubs",
|
||||
data.count, available_ports, hubs_needed);
|
||||
|
||||
for (i = 0; i < hubs_needed; i++) {
|
||||
if (VIR_ALLOC(hub) < 0)
|
||||
return -1;
|
||||
hub->type = VIR_DOMAIN_HUB_TYPE_USB;
|
||||
|
@ -0,0 +1,42 @@
|
||||
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,port=1 \
|
||||
-device usb-hub,id=hub1,bus=usb.0,port=2 \
|
||||
-device usb-hub,id=hub2,bus=usb.0,port=1.1 \
|
||||
-device usb-mouse,id=input0,bus=usb.0,port=1.2 \
|
||||
-device usb-mouse,id=input1,bus=usb.0,port=1.3 \
|
||||
-device usb-mouse,id=input2,bus=usb.0,port=1.4 \
|
||||
-device usb-tablet,id=input3,bus=usb.0,port=1.5 \
|
||||
-device usb-tablet,id=input4,bus=usb.0,port=1.6 \
|
||||
-device usb-tablet,id=input5,bus=usb.0,port=1.7 \
|
||||
-device usb-tablet,id=input6,bus=usb.0,port=1.8 \
|
||||
-device usb-tablet,id=input7,bus=usb.0,port=1.1.1 \
|
||||
-device usb-tablet,id=input8,bus=usb.0,port=1.1.2 \
|
||||
-device usb-tablet,id=input9,bus=usb.0,port=1.1.3 \
|
||||
-device usb-tablet,id=input10,bus=usb.0,port=1.1.4 \
|
||||
-device usb-tablet,id=input11,bus=usb.0,port=1.1.5 \
|
||||
-device usb-tablet,id=input12,bus=usb.0,port=1.1.6 \
|
||||
-device usb-tablet,id=input13,bus=usb.0,port=1.1.7 \
|
||||
-device usb-tablet,id=input14,bus=usb.0,port=1.1.8 \
|
||||
-device usb-tablet,id=input15,bus=usb.0,port=2.1 \
|
||||
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
|
@ -0,0 +1,35 @@
|
||||
<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'>
|
||||
</input>
|
||||
<input type='mouse' bus='usb'>
|
||||
</input>
|
||||
<input type='mouse' bus='usb'>
|
||||
</input>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
<input type='tablet' bus='usb'/>
|
||||
</devices>
|
||||
</domain>
|
@ -1332,6 +1332,9 @@ mymain(void)
|
||||
DO_TEST("usb-hub-autoadd",
|
||||
QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
|
||||
QEMU_CAPS_NODEFCONFIG);
|
||||
DO_TEST("usb-hub-autoadd-deluxe",
|
||||
QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
|
||||
QEMU_CAPS_NODEFCONFIG);
|
||||
DO_TEST_PARSE_ERROR("usb-hub-conflict",
|
||||
QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
|
||||
QEMU_CAPS_NODEFCONFIG);
|
||||
|
Loading…
x
Reference in New Issue
Block a user