[PATCH 2/2] qemu: error out on USB ports out of range

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

 



My overly sophisticated address reservation code forgot
to add an error message for user-requested ports out of range.

https://bugzilla.redhat.com/show_bug.cgi?id=1399260
---
 src/conf/domain_addr.c                             |  7 ++++++
 .../qemuxml2argv-usb-ports-out-of-range.xml        | 25 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  3 +++
 3 files changed, 35 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-ports-out-of-range.xml

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 4d3eabc..b64fc18 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1987,6 +1987,13 @@ virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
                                                   portStr)))
         goto cleanup;
 
+    if (targetPort >= virBitmapSize(targetHub->portmap)) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("requested USB port %s not present on USB bus %u"),
+                       portStr, info->addr.usb.bus);
+        goto cleanup;
+    }
+
     if (virBitmapIsBitSet(targetHub->portmap, targetPort)) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("Duplicate USB address bus %u port %s"),
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-ports-out-of-range.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-ports-out-of-range.xml
new file mode 100644
index 0000000..5415b88
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-ports-out-of-range.xml
@@ -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'/>
+    <hub type='usb'>
+      <address type='usb' bus='0' port='1'/>
+    </hub>
+    <input type='mouse' bus='usb'>
+      <address type='usb' bus='0' port='4'/>
+    </input>
+    <hub type='usb'>
+      <address type='usb' bus='0' port='1.9'/>
+    </hub>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 8d1bdb7..d12077c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1320,6 +1320,9 @@ mymain(void)
     DO_TEST("usb-ports",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
             QEMU_CAPS_NODEFCONFIG);
+    DO_TEST_PARSE_ERROR("usb-ports-out-of-range",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
+            QEMU_CAPS_NODEFCONFIG);
     DO_TEST("usb-port-autoassign",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
             QEMU_CAPS_NODEFCONFIG);
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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