]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix usb device version parsing issues
authorJán Tomko <jtomko@redhat.com>
Fri, 10 Apr 2015 13:49:42 +0000 (15:49 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 13 Apr 2015 10:33:41 +0000 (12:33 +0200)
Request that the number be parsed as decimal, to allow 08
and 09.

Format it with the leading zero, 1.01 and 1.10 are two
different versions.

https://bugzilla.redhat.com/show_bug.cgi?id=1210650

src/conf/domain_conf.c
tests/qemuxml2argvdata/qemuxml2argv-usb-redir-filter-version.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-usb-redir-filter-version.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-redir-filter-version.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c

index 880b89cc435432d0d053207a39c6e246e36729bc..5005d2e16712a34755bdfd2e61ba2cff1516dd1a 100644 (file)
@@ -11386,8 +11386,8 @@ virDomainRedirFilterUSBVersionHelper(const char *version,
     *temp = '\0';
     temp++;
 
-    if ((virStrToLong_ui(version_copy, NULL, 0, &major)) < 0 ||
-        (virStrToLong_ui(temp, NULL, 0, &minor)) < 0) {
+    if ((virStrToLong_ui(version_copy, NULL, 10, &major)) < 0 ||
+        (virStrToLong_ui(temp, NULL, 10, &minor)) < 0) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("Cannot parse USB version %s"), version);
         goto cleanup;
@@ -20256,7 +20256,7 @@ virDomainRedirFilterDefFormat(virBufferPtr buf,
             virBufferAsprintf(buf, " product='0x%04X'", usbdev->product);
 
         if (usbdev->version >= 0)
-            virBufferAsprintf(buf, " version='%d.%d'",
+            virBufferAsprintf(buf, " version='%d.%02d'",
                                  ((usbdev->version & 0xf000) >> 12) * 10 +
                                  ((usbdev->version & 0x0f00) >>  8),
                                  ((usbdev->version & 0x00f0) >>  4) * 10 +
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir-filter-version.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir-filter-version.args
new file mode 100644 (file)
index 0000000..463e9de
--- /dev/null
@@ -0,0 +1,14 @@
+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 -chardev spicevmc,id=charredir0,name=usbredir \
+-device 'usb-redir,chardev=charredir0,id=redir0,\
+filter=0x08:0x15E1:0x2007:0x0109:1|0x08:0x15E1:0x2007:0x0940:1|\
+-1:-1:-1:-1:0,bus=usb.0,port=4' \
+-chardev spicevmc,id=charredir1,name=usbredir \
+-device 'usb-redir,chardev=charredir1,id=redir1,\
+filter=0x08:0x15E1:0x2007:0x0109:1|0x08:0x15E1:0x2007:0x0940:1|\
+-1:-1:-1:-1:0,bus=usb.0,port=5' \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir-filter-version.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir-filter-version.xml
new file mode 100644 (file)
index 0000000..c07cddd
--- /dev/null
@@ -0,0 +1,32 @@
+<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'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <redirdev bus='usb' type='spicevmc'>
+      <address type='usb' bus='0' port='4'/>
+    </redirdev>
+    <redirdev bus='usb' type='spicevmc'>
+      <address type='usb' bus='0' port='5'/>
+    </redirdev>
+    <redirfilter>
+      <usbdev class='0x08' vendor='0x15E1' product='0x2007' version='1.09' allow='yes'/>
+      <usbdev class='0x08' vendor='0x15E1' product='0x2007' version='9.4' allow='yes'/>
+      <usbdev allow='no'/>
+    </redirfilter>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index c02555dcd4ac54c69b6d2bf3b08ca06fa3064dee..8d0a4aa319347e62649b46d5b6a6a0263fd996f7 100644 (file)
@@ -1153,6 +1153,11 @@ mymain(void)
             QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_USB_REDIR,
             QEMU_CAPS_SPICE, QEMU_CAPS_CHARDEV_SPICEVMC,
             QEMU_CAPS_USB_REDIR_FILTER);
+    DO_TEST("usb-redir-filter-version",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_USB_REDIR,
+            QEMU_CAPS_SPICE, QEMU_CAPS_CHARDEV_SPICEVMC,
+            QEMU_CAPS_USB_REDIR_FILTER);
     DO_TEST("usb1-usb2",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_PIIX3_USB_UHCI,
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-redir-filter-version.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-redir-filter-version.xml
new file mode 100644 (file)
index 0000000..f111755
--- /dev/null
@@ -0,0 +1,32 @@
+<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'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <redirdev bus='usb' type='spicevmc'>
+      <address type='usb' bus='0' port='4'/>
+    </redirdev>
+    <redirdev bus='usb' type='spicevmc'>
+      <address type='usb' bus='0' port='5'/>
+    </redirdev>
+    <redirfilter>
+      <usbdev class='0x08' vendor='0x15E1' product='0x2007' version='1.09' allow='yes'/>
+      <usbdev class='0x08' vendor='0x15E1' product='0x2007' version='9.40' allow='yes'/>
+      <usbdev allow='no'/>
+    </redirfilter>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index dce7a83feec45634f9bb9db3b1ea9af0df5c8e8c..5a5812fae09fc4680f12dc639d68fd7a5f74dbe8 100644 (file)
@@ -505,6 +505,7 @@ mymain(void)
 
     DO_TEST("usb-redir");
     DO_TEST_DIFFERENT("usb-redir-filter");
+    DO_TEST_DIFFERENT("usb-redir-filter-version");
     DO_TEST("blkdeviotune");
 
     DO_TEST_FULL("seclabel-dynamic-baselabel", false, WHEN_INACTIVE);