Allow USB hostdev product to be 0x0000

Product = 0 is a valid value based on this bug report:

https://www.redhat.com/archives/libvir-list/2009-May/msg00368.html

Also, throw a less ambiguous error if vendor = 0.
This commit is contained in:
Cole Robinson 2009-06-16 18:46:06 +00:00
parent ac75bd1b1e
commit 502278d5b2
4 changed files with 30 additions and 5 deletions

View File

@ -1,3 +1,10 @@
Tue Jun 16 14:30:05 EDT 2009 Cole Robinson <crobinso@redhat.com>
* src/domain_conf.c
tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args
tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml:
Allow USB hostdev product to be 0x0000
Tue Jun 16 11:43:17 EDT 2009 Cole Robinson <crobinso@redhat.com>
* src/storage_backend_fs.c: Fix FS volume creation with backing stores.

View File

@ -1660,8 +1660,14 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
int flags ATTRIBUTE_UNUSED) {
int ret = -1;
int got_product, got_vendor;
xmlNodePtr cur;
/* Product can validly be 0, so we need some extra help to determine
* if it is uninitialized*/
got_product = 0;
got_vendor = 0;
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
@ -1669,6 +1675,7 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
char *vendor = virXMLPropString(cur, "id");
if (vendor) {
got_vendor = 1;
if (virStrToLong_ui(vendor, NULL, 0,
&def->source.subsys.u.usb.vendor) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@ -1686,6 +1693,7 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
char* product = virXMLPropString(cur, "id");
if (product) {
got_product = 1;
if (virStrToLong_ui(product, NULL, 0,
&def->source.subsys.u.usb.product) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@ -1745,14 +1753,18 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
cur = cur->next;
}
if (def->source.subsys.u.usb.vendor == 0 &&
def->source.subsys.u.usb.product != 0) {
if (got_vendor && def->source.subsys.u.usb.vendor == 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("vendor cannot be 0."));
goto out;
}
if (!got_vendor && got_product) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing vendor"));
goto out;
}
if (def->source.subsys.u.usb.vendor != 0 &&
def->source.subsys.u.usb.product == 0) {
if (got_vendor && !got_product) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing product"));
goto out;

View File

@ -1 +1 @@
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -usbdevice host:0204:6025
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -usbdevice host:0204:6025 -usbdevice host:1234:0000

View File

@ -24,5 +24,11 @@
<product id='0x6025'/>
</source>
</hostdev>
<hostdev mode='subsystem' type='usb' managed='no'>
<source>
<vendor id='0x1234'/>
<product id='0x0000'/>
</source>
</hostdev>
</devices>
</domain>