]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
node_device_udev: Try harder to get human readable vendor:product
authorLubomir Rintel <lkundrak@v3.sk>
Tue, 9 Sep 2014 12:20:43 +0000 (14:20 +0200)
committerCole Robinson <crobinso@redhat.com>
Thu, 30 Oct 2014 14:33:16 +0000 (10:33 -0400)
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
(cherry picked from commit 3ef77a544d4313cdfe257717708548f57e6db971)

src/node_device/node_device_udev.c

index 785c2faadd1f827fa6844034d0b04cc39f8f248c..a2f9e579f87ad545e5583278cd5d2c2da6853be1 100644 (file)
@@ -532,6 +532,7 @@ static int udevProcessUSBDevice(struct udev_device *device,
 {
     union _virNodeDevCapData *data = &def->caps->data;
     int ret = -1;
+    int err;
 
     if (udevGetUintProperty(device,
                             "BUSNUM",
@@ -554,10 +555,17 @@ static int udevProcessUSBDevice(struct udev_device *device,
         goto out;
     }
 
-    if (udevGetStringSysfsAttr(device,
-                              "manufacturer",
-                              &data->usb_dev.vendor_name) == PROPERTY_ERROR) {
+    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,
+                                  "manufacturer",
+                                  &data->usb_dev.vendor_name) == PROPERTY_ERROR) {
+            goto out;
+        }
     }
 
     if (udevGetUintProperty(device,
@@ -567,10 +575,17 @@ static int udevProcessUSBDevice(struct udev_device *device,
         goto out;
     }
 
-    if (udevGetStringSysfsAttr(device,
-                              "product",
-                              &data->usb_dev.product_name) == PROPERTY_ERROR) {
+    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,
+                                  "product",
+                                  &data->usb_dev.product_name) == PROPERTY_ERROR) {
+            goto out;
+        }
     }
 
     if (udevGenerateDeviceName(device, def, NULL) != 0) {