node_device_udev: Try harder to get human readable vendor:product

The manufacurer and product from USB device itself are usually not particularly
useful -- they tend to be missing, or ugly (all-uppercase, padded with spaces,
etc.). Prefer what's in the usb id database and fall back to descriptors only
if the device is too new to be in database.

https://bugzilla.redhat.com/show_bug.cgi?id=1138887
This commit is contained in:
Lubomir Rintel 2014-09-09 14:20:43 +02:00 committed by Ján Tomko
parent 7e649c5450
commit 3ef77a544d

View File

@ -580,6 +580,7 @@ static int udevProcessUSBDevice(struct udev_device *device,
{ {
union _virNodeDevCapData *data = &def->caps->data; union _virNodeDevCapData *data = &def->caps->data;
int ret = -1; int ret = -1;
int err;
if (udevGetUintProperty(device, if (udevGetUintProperty(device,
"BUSNUM", "BUSNUM",
@ -602,11 +603,18 @@ static int udevProcessUSBDevice(struct udev_device *device,
goto out; goto out;
} }
err = udevGetStringProperty(device,
"ID_VENDOR_FROM_DATABASE",
&data->usb_dev.vendor_name);
if (err == PROPERTY_ERROR)
goto out;
if (err == PROPERTY_MISSING) {
if (udevGetStringSysfsAttr(device, if (udevGetStringSysfsAttr(device,
"manufacturer", "manufacturer",
&data->usb_dev.vendor_name) == PROPERTY_ERROR) { &data->usb_dev.vendor_name) == PROPERTY_ERROR) {
goto out; goto out;
} }
}
if (udevGetUintProperty(device, if (udevGetUintProperty(device,
"ID_MODEL_ID", "ID_MODEL_ID",
@ -615,11 +623,18 @@ static int udevProcessUSBDevice(struct udev_device *device,
goto out; goto out;
} }
err = udevGetStringProperty(device,
"ID_MODEL_FROM_DATABASE",
&data->usb_dev.product_name);
if (err == PROPERTY_ERROR)
goto out;
if (err == PROPERTY_MISSING) {
if (udevGetStringSysfsAttr(device, if (udevGetStringSysfsAttr(device,
"product", "product",
&data->usb_dev.product_name) == PROPERTY_ERROR) { &data->usb_dev.product_name) == PROPERTY_ERROR) {
goto out; goto out;
} }
}
if (udevGenerateDeviceName(device, def, NULL) != 0) { if (udevGenerateDeviceName(device, def, NULL) != 0) {
goto out; goto out;