diff options
author | David Allan <dallan@redhat.com> | 2009-11-12 23:22:00 +0100 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2009-11-12 23:22:00 +0100 |
commit | 702366387305318c0c5362ac8a0997529caf2d22 (patch) | |
tree | 93d042174d312285ccf109ddcb59ce5722630ac7 | |
parent | Remove DevKit node device backend (diff) | |
download | libvirt-702366387305318c0c5362ac8a0997529caf2d22.tar.gz libvirt-702366387305318c0c5362ac8a0997529caf2d22.tar.bz2 libvirt-702366387305318c0c5362ac8a0997529caf2d22.zip |
Add translation of PCI vendor and product IDs
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
-rw-r--r-- | configure.in | 11 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/node_device/node_device_udev.c | 64 |
3 files changed, 74 insertions, 5 deletions
diff --git a/configure.in b/configure.in index c16738127..df8eba2e5 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index 4aaad6b52..d22a103b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 010ff7548..4ddf360fe 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -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; |