[libvirt] [PATCH 8/9] Assign addresses to USB devices

Ján Tomko jtomko at redhat.com
Wed Aug 12 14:52:18 UTC 2015


Automatically assign addresses to USB devices.

Just like reserving, this is only done for newly defined domains.

https://bugzilla.redhat.com/show_bug.cgi?id=1215968
---
 src/conf/domain_addr.c                             | 88 +++++++++++++++++++++-
 src/conf/domain_addr.h                             |  6 ++
 src/libvirt_private.syms                           |  1 +
 src/qemu/qemu_command.c                            | 87 +++++++++++++++++++++
 ...qemuhotplug-console-compat-2+console-virtio.xml |  4 +-
 .../qemuxml2argvdata/qemuxml2argv-bios-nvram.args  |  2 +-
 tests/qemuxml2argvdata/qemuxml2argv-bios.args      |  2 +-
 .../qemuxml2argv-console-compat-2.xml              |  4 +-
 .../qemuxml2argv-controller-order.args             |  7 +-
 .../qemuxml2argv-controller-order.xml              |  2 +
 .../qemuxml2argv-disk-usb-device-removable.args    |  3 +-
 .../qemuxml2argv-disk-usb-device.args              |  3 +-
 .../qemuxml2argv-graphics-spice-timeout.args       |  2 +-
 ...muxml2argv-hostdev-usb-address-device-boot.args |  2 +-
 .../qemuxml2argv-hostdev-usb-address-device.args   |  3 +-
 .../qemuxml2argv-hugepages-numa.args               |  2 +-
 .../qemuxml2argv-pseries-usb-kbd.args              |  2 +-
 .../qemuxml2argv-serial-spiceport.args             |  2 +-
 .../qemuxml2argv-smartcard-controller.args         |  2 +-
 .../qemuxml2argv-smartcard-host-certificates.args  |  2 +-
 .../qemuxml2argv-smartcard-host.args               |  2 +-
 ...emuxml2argv-smartcard-passthrough-spicevmc.args |  3 +-
 .../qemuxml2argv-smartcard-passthrough-tcp.args    |  2 +-
 .../qemuxml2argv-sound-device.args                 |  2 +-
 .../qemuxml2argv-usb-port-autoassign.args          | 15 ++++
 .../qemuxml2argv-usb-port-autoassign.xml           | 27 +++++++
 tests/qemuxml2argvtest.c                           |  6 +-
 27 files changed, 260 insertions(+), 23 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.xml

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index cda6e08..15f4753 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1392,9 +1392,95 @@ int virDomainUSBAddressSetAddControllers(virDomainUSBAddressSetPtr addrs,
 }
 
 
+static int
+virDomainUSBAddressFindFreePort(virDomainUSBAddressHubPtr hub,
+                                unsigned int *portpath,
+                                unsigned int idx)
+{
+    size_t i;
+
+    /* Look for free ports on the current hub */
+    for (i = 1; i < hub->nports; i++) {
+        if (!hub->ports[i]) {
+            VIR_DEBUG("Found a free port %zu at level %u", i, idx);
+            portpath[idx] = i;
+            return 0;
+        }
+    }
+
+    VIR_DEBUG("No ports found on hub %p, trying the hubs on it", hub);
+
+    if (idx >= VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH - 1)
+        return -1;
+
+    /* Recursively search through the ports
+     * that contain another hub */
+    for (i = 1; i < hub->nports; i++) {
+        VIR_DEBUG("level: %u port: %zu, nports: %zu", idx, i,
+                  hub->ports[i]->nports);
+
+        if (hub->ports[i]->nports &&
+            virDomainUSBAddressFindFreePort(hub->ports[i],
+                                            portpath,
+                                            idx + 1) == 0) {
+            portpath[idx] = i;
+            return 0;
+        }
+
+    }
+    return -1;
+}
+
+
+int
+virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs,
+                          virDomainDeviceInfoPtr info,
+                          bool isHub)
+{
+    unsigned int portpath[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH] = { 0 };
+    virDomainDeviceDefPtr dev = NULL;
+    char *portstr;
+    size_t i;
+    int ret = -1;
+
+    if (isHub) {
+        if (VIR_ALLOC(dev) < 0)
+            goto cleanup;
+        dev->type = VIR_DOMAIN_DEVICE_HUB;
+        if (VIR_ALLOC(dev->data.hub) < 0)
+            goto cleanup;
+        dev->data.hub->type = VIR_DOMAIN_HUB_TYPE_USB;
+    }
+
+    for (i = 0; i < addrs->nbuses; i++) {
+        virDomainUSBAddressHubPtr hub = addrs->buses[i];
+        if (!hub)
+            continue;
+
+        if (virDomainUSBAddressFindFreePort(hub, portpath, 0) == 0) {
+            info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB;
+            info->addr.usb.bus = i;
+            portstr = virDomainUSBAddressGetPortString(portpath);
+            memcpy(info->addr.usb.port, portpath, VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH);
+            VIR_DEBUG("Assigning USB addr bus=%u port=%s",
+                      info->addr.usb.bus, portstr);
+            if (virDomainUSBAddressReserve(NULL, dev, info, addrs) == 0)
+                ret = 0;
+            VIR_FREE(portstr);
+            goto cleanup;
+        }
+    }
+
+    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No free USB ports"));
+ cleanup:
+    virDomainDeviceDefFree(dev);
+    return ret;
+}
+
+
 int
 virDomainUSBAddressReserve(virDomainDefPtr def ATTRIBUTE_UNUSED,
-                           virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED,
+                           virDomainDeviceDefPtr dev,
                            virDomainDeviceInfoPtr info,
                            void *data)
 {
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index 8f866ae..8ecf588 100644
--- a/src/conf/domain_addr.h
+++ b/src/conf/domain_addr.h
@@ -270,6 +270,12 @@ int virDomainUSBAddressSetAddControllers(virDomainUSBAddressSetPtr addrs,
 void virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs);
 
 int
+virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs,
+                          virDomainDeviceInfoPtr info,
+                          bool hub)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int
 virDomainUSBAddressReserve(virDomainDefPtr def,
                            virDomainDeviceDefPtr dev,
                            virDomainDeviceInfoPtr info,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1420b19..048ec68 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -106,6 +106,7 @@ virDomainPCIAddressSetFree;
 virDomainPCIAddressSetGrow;
 virDomainPCIAddressSlotInUse;
 virDomainPCIAddressValidate;
+virDomainUSBAddressAssign;
 virDomainUSBAddressGetPortBuf;
 virDomainUSBAddressGetPortString;
 virDomainUSBAddressReserve;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a6a3438..9df542e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1648,6 +1648,88 @@ qemuDomainCountUSBAddresses(virDomainDefPtr def,
     *total = tot;
 }
 
+
+static int
+qemuDomainAssignUSBPorts(virDomainUSBAddressSetPtr addrs,
+                         virDomainDefPtr def)
+{
+    size_t i;
+
+    /* usb-hub */
+    for (i = 0; i < def->nhubs; i++) {
+        virDomainHubDefPtr hub = def->hubs[i];
+        if (hub->type == VIR_DOMAIN_HUB_TYPE_USB &&
+            hub->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, &hub->info, true) < 0)
+                return -1;
+        }
+    }
+
+    /* usb-host */
+    for (i = 0; i < def->nhostdevs; i++) {
+        virDomainHostdevDefPtr hostdev = def->hostdevs[i];
+        if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
+            hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, hostdev->info, false) < 0)
+                return -1;
+        }
+    }
+
+    /* usb-storage */
+    for (i = 0; i < def->ndisks; i++) {
+        virDomainDiskDefPtr disk = def->disks[i];
+        if (disk->bus == VIR_DOMAIN_DISK_BUS_USB &&
+            disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, &disk->info, false) < 0)
+                return -1;
+        }
+    }
+
+    /* TODO: usb-net */
+
+    /* usb-ccid */
+    for (i = 0; i < def->ncontrollers; i++) {
+        virDomainControllerDefPtr cont = def->controllers[i];
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_CCID &&
+            cont->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, &cont->info, false) < 0)
+                return -1;
+        }
+    }
+
+    /* usb-kbd, usb-mouse, usb-tablet */
+    for (i = 0; i < def->ninputs; i++) {
+        virDomainInputDefPtr input = def->inputs[i];
+
+        if (input->bus == VIR_DOMAIN_INPUT_BUS_USB &&
+            input->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, &input->info, false) < 0)
+                return -1;
+        }
+    }
+
+    /* usb-serial */
+    for (i = 0; i < def->nserials; i++) {
+        virDomainChrDefPtr serial = def->serials[i];
+        if (serial->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB &&
+            serial->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, &serial->info, false) < 0)
+                return -1;
+        }
+    }
+
+    /* usb-audio model=usb */
+    for (i = 0; i < def->nsounds; i++) {
+        virDomainSoundDefPtr sound = def->sounds[i];
+        if (sound->model == VIR_DOMAIN_SOUND_MODEL_USB &&
+            sound->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (virDomainUSBAddressAssign(addrs, &sound->info, false) < 0)
+                return -1;
+        }
+    }
+    return 0;
+}
+
 static int
 qemuDomainAssignUSBAddresses(virDomainDefPtr def,
                              virDomainObjPtr obj,
@@ -1679,6 +1761,11 @@ qemuDomainAssignUSBAddresses(virDomainDefPtr def,
 
     VIR_DEBUG("Existing USB addresses have been reserved");
 
+    if (qemuDomainAssignUSBPorts(addrs, def) < 0)
+        goto cleanup;
+
+    VIR_DEBUG("Finished assigning USB ports");
+
     if (obj && obj->privateData) {
         priv = obj->privateData;
         /* if this is the live domain object, we persist the addresses */
diff --git a/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml b/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml
index d848677..9bc01e5 100644
--- a/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml
+++ b/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml
@@ -81,7 +81,9 @@
       <target type='virtio' name='org.qemu.guest_agent.0'/>
       <address type='virtio-serial' controller='0' bus='0' port='1'/>
     </channel>
-    <input type='tablet' bus='usb'/>
+    <input type='tablet' bus='usb'>
+      <address type='usb' bus='0' port='1'/>
+    </input>
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
     <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.args b/tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.args
index b51e8f3..d71ad5d 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.args
@@ -6,5 +6,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 -monitor unix:/tmp/test-monitor,server,nowait -boot c -usb \
 -drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0,format=raw \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
--serial pty -device usb-tablet,id=input0 \
+-serial pty -device usb-tablet,id=input0,bus=usb.0,port=1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-bios.args b/tests/qemuxml2argvdata/qemuxml2argv-bios.args
index e8ef763..ea7d631 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-bios.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-bios.args
@@ -3,5 +3,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 -m 1024 -smp 1 -nographic -nodefaults -device sga \
 -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
 -usb -hda /dev/HostVG/QEMUGuest1 -serial pty \
--device usb-tablet,id=input0 \
+-device usb-tablet,id=input0,bus=usb.0,port=1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-console-compat-2.xml b/tests/qemuxml2argvdata/qemuxml2argv-console-compat-2.xml
index a7209b2..c9f943f 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-console-compat-2.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-console-compat-2.xml
@@ -78,7 +78,9 @@
       <target type='virtio' name='org.qemu.guest_agent.0'/>
       <address type='virtio-serial' controller='0' bus='0' port='1'/>
     </channel>
-    <input type='tablet' bus='usb'/>
+    <input type='tablet' bus='usb'>
+      <address type='usb' bus='0' port='1'/>
+    </input>
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
     <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-controller-order.args b/tests/qemuxml2argvdata/qemuxml2argv-controller-order.args
index d68011d..d0c10c5 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-controller-order.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-controller-order.args
@@ -5,7 +5,8 @@ socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \
 chardev=charmonitor,id=monitor,mode=readline -boot order=cna,menu=off \
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device \
 virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x7 -device \
-usb-ccid,id=ccid0 -drive \
+usb-ccid,id=ccid0,bus=usb.0,port=1.1 \
+-device usb-hub,id=hub0,bus=usb.0,port=1 -drive \
 file=/tmp/fdr.img,if=none,id=drive-virtio-disk0,cache=off,aio=native \
 -device \
 virtio-blk-pci,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0 \
@@ -22,9 +23,9 @@ isa-serial,chardev=charserial0,id=serial0 -chardev \
 spicevmc,id=charchannel0,name=vdagent \
 -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,\
 id=channel0,name=com.redhat.spice.0 \
--device usb-tablet,id=input0 -spice \
+-device usb-tablet,id=input0,bus=usb.0,port=1.2 -spice \
 port=0,addr=0.0.0.0 -device \
 intel-hda,id=sound0,bus=pci.0,addr=0x4 -device \
 hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device \
-usb-host,hostbus=14,hostaddr=6,id=hostdev0 -device \
+usb-host,hostbus=14,hostaddr=6,id=hostdev0,bus=usb.0,port=2 -device \
 virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-controller-order.xml b/tests/qemuxml2argvdata/qemuxml2argv-controller-order.xml
index 07db77e..10f5558 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-controller-order.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-controller-order.xml
@@ -84,6 +84,8 @@
     <memballoon model='virtio'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
     </memballoon>
+    <hub type='usb'>
+    </hub>
   </devices>
   <seclabel type='dynamic' model='selinux' relabel='yes'/>
 </domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device-removable.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device-removable.args
index 793c597..53bbdb4 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device-removable.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device-removable.args
@@ -4,6 +4,7 @@ pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \
 unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -drive \
 file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0 -device ide-drive,\
 bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -drive file=/tmp/usbdisk.img,\
-if=none,id=drive-usb-disk0 -device usb-storage,drive=drive-usb-disk0,\
+if=none,id=drive-usb-disk0 \
+-device usb-storage,bus=usb.0,port=1,drive=drive-usb-disk0,\
 id=usb-disk0,removable=on -device virtio-balloon-pci,id=balloon0,bus=pci.0,\
 addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
index d2b80d7..88727fa 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
@@ -4,5 +4,6 @@ pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \
 unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -drive \
 file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0 -device ide-drive,\
 bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -drive file=/tmp/usbdisk.img,\
-if=none,id=drive-usb-disk0 -device usb-storage,drive=drive-usb-disk0,\
+if=none,id=drive-usb-disk0 \
+-device usb-storage,bus=usb.0,port=1,drive=drive-usb-disk0,\
 id=usb-disk0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args
index 8b5d9ee..2e74a24 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args
@@ -11,7 +11,7 @@ media=cdrom,id=drive-ide0-1-0 \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \
 -device rtl8139,vlan=0,id=net0,mac=52:54:00:71:70:89,bus=pci.0,addr=0x7 \
 -net tap,script=/etc/qemu-ifup,vlan=0,name=hostnet0 -serial pty \
--device usb-tablet,id=input0 \
+-device usb-tablet,id=input0,bus=usb.0,port=1 \
 -spice port=5900 -vga std \
 -device AC97,id=sound0,bus=pci.0,addr=0x3 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device-boot.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device-boot.args
index f2cc35d..6b89b79 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device-boot.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device-boot.args
@@ -3,5 +3,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \
 unix:/tmp/test-monitor,server,nowait -no-acpi -usb -hda \
 /dev/HostVG/QEMUGuest1 \
--device usb-host,hostbus=14,hostaddr=6,id=hostdev0,bootindex=1 \
+-device usb-host,hostbus=14,hostaddr=6,id=hostdev0,bootindex=1,bus=usb.0,port=1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args
index 4c73a51..78fed2b 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args
@@ -2,5 +2,6 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 /usr/bin/qemu -S -M \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \
 unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -hda \
-/dev/HostVG/QEMUGuest1 -device usb-host,hostbus=14,hostaddr=6,id=hostdev0 \
+/dev/HostVG/QEMUGuest1 \
+-device usb-host,hostbus=14,hostaddr=6,id=hostdev0,bus=usb.0,port=1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args
index 37511b1..2a15a87 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args
@@ -34,7 +34,7 @@ chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 \
 -chardev spicevmc,id=charchannel1,name=vdagent \
 -device virtserialport,bus=virtio-serial0.0,nr=2,\
 chardev=charchannel1,id=channel1,name=com.redhat.spice.0 \
--device usb-tablet,id=input0 \
+-device usb-tablet,id=input0,bus=usb.0,port=1 \
 -spice port=0 \
 -vga qxl \
 -global qxl-vga.ram_size=67108864 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
index 373c72a..c46eb2d 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
@@ -6,4 +6,4 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 -device pci-ohci,id=usb,bus=pci,addr=0x1 \
 -chardev pty,id=charserial0 \
 -device spapr-vty,chardev=charserial0,reg=0x30000000 \
--device usb-kbd,id=input0
+-device usb-kbd,id=input0,bus=usb.0,port=1
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-spiceport.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-spiceport.args
index a806d63..e6cff64 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-serial-spiceport.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-spiceport.args
@@ -6,7 +6,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=spice \
 -hda /dev/HostVG/QEMUGuest1 \
 -chardev spiceport,id=charserial0,name=org.qemu.console.serial.0 \
 -device isa-serial,chardev=charserial0,id=serial0 \
--device usb-tablet,id=input0 \
+-device usb-tablet,id=input0,bus=usb.0,port=1 \
 -spice port=5903,tls-port=5904,addr=127.0.0.1,x509-dir=/etc/pki/libvirt-spice \
 -device \
 qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,bus=pci.0,addr=0x2 \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.args b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.args
index 5e58867..c1d126a 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.args
@@ -3,6 +3,6 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \
 socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \
 chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c -device \
-usb-ccid,id=ccid0 -usb -device \
+usb-ccid,id=ccid0,bus=usb.0,port=1 -usb -device \
 ccid-card-emulated,backend=nss-emulated,id=smartcard0,bus=ccid0.0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.args b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.args
index 33d3b08..bc8b23a 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.args
@@ -3,7 +3,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \
 socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \
 chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c -device \
-usb-ccid,id=ccid0 -usb -device \
+usb-ccid,id=ccid0,bus=usb.0,port=1 -usb -device \
 ccid-card-emulated,backend=certificates,cert1=cert1,cert2=cert2,cert3=cert3\
 ,db=/etc/pki/nssdb,id=smartcard0,bus=ccid0.0 -device \
 virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.args b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.args
index 5e58867..c1d126a 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.args
@@ -3,6 +3,6 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \
 socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \
 chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c -device \
-usb-ccid,id=ccid0 -usb -device \
+usb-ccid,id=ccid0,bus=usb.0,port=1 -usb -device \
 ccid-card-emulated,backend=nss-emulated,id=smartcard0,bus=ccid0.0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-spicevmc.args b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-spicevmc.args
index eed319c..11998d3 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-spicevmc.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-spicevmc.args
@@ -3,6 +3,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \
 socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \
 chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c -device \
-usb-ccid,id=ccid0 -usb -chardev spicevmc,id=charsmartcard0,name=smartcard \
+usb-ccid,id=ccid0,bus=usb.0,port=1 -usb \
+-chardev spicevmc,id=charsmartcard0,name=smartcard \
 -device ccid-card-passthru,chardev=charsmartcard0,id=smartcard0,bus=ccid0.0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-tcp.args b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-tcp.args
index c350977..284eb58 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-tcp.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-passthrough-tcp.args
@@ -3,7 +3,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \
 socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \
 chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c -device \
-usb-ccid,id=ccid0 -usb -chardev \
+usb-ccid,id=ccid0,bus=usb.0,port=1 -usb -chardev \
 socket,id=charsmartcard0,host=127.0.0.1,port=2001,server,nowait \
 -device ccid-card-passthru,chardev=charsmartcard0,id=smartcard0,bus=ccid0.0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args b/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args
index 3e2b293..bb0c845 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args
@@ -14,5 +14,5 @@ id=sound6-codec0,bus=sound6.0,cad=0 \
 -device ich9-intel-hda,id=sound7,bus=pci.0,addr=0x8 \
 -device hda-micro,id=sound7-codec0,bus=sound7.0,cad=0 \
 -device hda-duplex,id=sound7-codec1,bus=sound7.0,cad=1 \
--device usb-audio,id=sound8 \
+-device usb-audio,id=sound8,bus=usb.0,port=1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.args
new file mode 100644
index 0000000..d61cb29
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.args
@@ -0,0 +1,15 @@
+LC_ALL=C PATH=/bin HOME=/home/test \
+USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu -S -M pc -m 214 \
+-smp 1 -nographic -nodefconfig -nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/test-monitor,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-mouse,id=input0,bus=usb.0,port=1.1 \
+-device usb-mouse,id=input1,bus=usb.0,port=1.2 \
+-device usb-mouse,id=input2,bus=usb.0,port=1.3 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.xml
new file mode 100644
index 0000000..a2fe34e
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.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='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <controller type='usb' index='0'/>
+    <memballoon model='virtio'/>
+    <hub type='usb'>
+      <address type='usb' bus='0' port='1'/>
+    </hub>
+    <input type='mouse' bus='usb'>
+    </input>
+    <hub type='usb'>
+    </hub>
+    <input type='mouse' bus='usb'>
+    </input>
+    <input type='mouse' bus='usb'>
+    </input>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index feb1d85..39ce7e2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -678,7 +678,8 @@ mymain(void)
             QEMU_CAPS_BOOT_MENU, QEMU_CAPS_PIIX3_USB_UHCI,
             QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_DRIVE_AIO,
             QEMU_CAPS_CCID_PASSTHRU, QEMU_CAPS_CHARDEV,
-            QEMU_CAPS_CHARDEV_SPICEVMC, QEMU_CAPS_SPICE, QEMU_CAPS_HDA_DUPLEX);
+            QEMU_CAPS_CHARDEV_SPICEVMC, QEMU_CAPS_SPICE, QEMU_CAPS_HDA_DUPLEX,
+            QEMU_CAPS_USB_HUB);
     DO_TEST("eoi-disabled", NONE);
     DO_TEST("eoi-enabled", NONE);
     DO_TEST("pv-spinlock-disabled", NONE);
@@ -1177,6 +1178,9 @@ mymain(void)
     DO_TEST("usb-ports",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_USB_HUB,
             QEMU_CAPS_NODEFCONFIG);
+    DO_TEST("usb-port-autoassign",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_USB_HUB,
+            QEMU_CAPS_NODEFCONFIG);
     DO_TEST("usb-redir",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_USB_HUB,
-- 
2.4.6




More information about the libvir-list mailing list