]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add translation of PCI vendor and product IDs
authorDavid Allan <dallan@redhat.com>
Thu, 12 Nov 2009 22:22:00 +0000 (23:22 +0100)
committerDaniel Veillard <veillard@redhat.com>
Thu, 12 Nov 2009 22:22:00 +0000 (23:22 +0100)
uses libpciaccess to provide human readable names for PCI vendor and
device IDs
* configure.in: add a requirement for libpciaccess >= 0.10.0
* src/Makefile.am: add the associated compilation flags and link
* src/node_device/node_device_udev.c: lookup the libpciaccess for
  vendor name and product name based on their ids

configure.in
src/Makefile.am
src/node_device/node_device_udev.c

index c16738127319f4b848bf4855bbf719ab4b051fd1..df8eba2e5a0f7bd2f53633b6876e4427edd4c757 100644 (file)
@@ -1781,10 +1781,19 @@ if test "x$with_udev" = "xyes" -o "x$with_udev" = "xcheck"; then
     CFLAGS="$old_CFLAGS"
     LDFLAGS="$old_LDFLAGS"
   fi
+  PCIACCESS_REQUIRED=0.10.0
+  PCIACCESS_CFLAGS=
+  PCIACCESS_LIBS=
+  PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= $PCIACCESS_REQUIRED], [], [PCIACCESS_FOUND=no])
+  if test "$PCIACCESS_FOUND" = "no" ; then
+     AC_MSG_ERROR([You must install libpciaccess/libpciaccess-devel >= $PCIACCESS_REQUIRED to compile libvirt])
+   fi
 fi
 AM_CONDITIONAL([HAVE_UDEV], [test "x$with_udev" = "xyes"])
 AC_SUBST([UDEV_CFLAGS])
 AC_SUBST([UDEV_LIBS])
+AC_SUBST([PCIACCESS_CFLAGS])
+AC_SUBST([PCIACCESS_LIBS])
 
 with_nodedev=no;
 if test "$with_hal" = "yes" -o "$with_udev" = "yes";
@@ -1948,7 +1957,7 @@ else
 AC_MSG_NOTICE([     hal: no])
 fi
 if test "$with_udev" = "yes" ; then
-AC_MSG_NOTICE([    udev: $UDEV_CFLAGS $UDEV_LIBS])
+AC_MSG_NOTICE([    udev: $UDEV_CFLAGS $UDEV_LIBS $PCIACCESS_CFLAGS PCIACCESS_LIBS])
 else
 AC_MSG_NOTICE([    udev: no])
 fi
index 4aaad6b52779fcb7c8d0ec562a0e94894ed83ff3..d22a103b22cdcadec0313bd2aa8b9291b0bb2ea0 100644 (file)
@@ -645,8 +645,8 @@ libvirt_driver_nodedev_la_LDFLAGS += $(HAL_LIBS)
 endif
 if HAVE_UDEV
 libvirt_driver_nodedev_la_SOURCES += $(NODE_DEVICE_DRIVER_UDEV_SOURCES)
-libvirt_driver_nodedev_la_CFLAGS += $(UDEV_CFLAGS)
-libvirt_driver_nodedev_la_LDFLAGS += $(UDEV_LIBS)
+libvirt_driver_nodedev_la_CFLAGS += $(UDEV_CFLAGS) $(PCIACCESS_CFLAGS)
+libvirt_driver_nodedev_la_LDFLAGS += $(UDEV_LIBS) $(PCIACCESS_LIBS)
 endif
 
 if WITH_DRIVER_MODULES
index 010ff75489cda17b1e4f7a91c5db9a37fe016fa9..4ddf360fe61818632f6ffac16951f0ea027cbc4a 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <config.h>
 #include <libudev.h>
+#include <pciaccess.h>
 #include <scsi/scsi.h>
 #include <c-ctype.h>
 
@@ -351,6 +352,61 @@ static void udevLogFunction(struct udev *udev ATTRIBUTE_UNUSED,
 }
 
 
+static int udevTranslatePCIIds(unsigned int vendor,
+                               unsigned int product,
+                               char **vendor_string,
+                               char **product_string)
+{
+    int ret = -1;
+    struct pci_id_match m;
+    const char *vendor_name = NULL, *device_name = NULL;
+
+    if (pci_system_init() != 0) {
+        VIR_ERROR0("Failed to initialize libpciaccess\n");
+        goto out;
+    }
+
+    m.vendor_id = vendor;
+    m.device_id = product;
+    m.subvendor_id = PCI_MATCH_ANY;
+    m.subdevice_id = PCI_MATCH_ANY;
+    m.device_class = 0;
+    m.device_class_mask = 0;
+    m.match_data = 0;
+
+    /* pci_get_strings returns void */
+    pci_get_strings(&m,
+                    &vendor_name,
+                    &device_name,
+                    NULL,
+                    NULL);
+
+    if (vendor_name != NULL) {
+        *vendor_string = strdup(vendor_name);
+        if (*vendor_string == NULL) {
+            virReportOOMError(NULL);
+            goto out;
+        }
+    }
+
+    if (device_name != NULL) {
+        *product_string = strdup(device_name);
+        if (*product_string == NULL) {
+            virReportOOMError(NULL);
+            goto out;
+        }
+    }
+
+    /* pci_system_cleanup returns void */
+    pci_system_cleanup();
+
+    ret = 0;
+
+out:
+    return ret;
+}
+
+
 static int udevProcessPCI(struct udev_device *device,
                           virNodeDeviceDefPtr def)
 {
@@ -411,8 +467,12 @@ static int udevProcessPCI(struct udev_device *device,
         goto out;
     }
 
-    /* XXX FIXME: to do the vendor name and product name, we have to
-     * parse /usr/share/hwdata/pci.ids.  Use libpciaccess perhaps? */
+    if (udevTranslatePCIIds(data->pci_dev.vendor,
+                            data->pci_dev.product,
+                            &data->pci_dev.vendor_name,
+                            &data->pci_dev.product_name) != 0) {
+        goto out;
+    }
 
     if (udevGenerateDeviceName(device, def, NULL) != 0) {
         goto out;