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
This commit is contained in:
David Allan 2009-11-12 23:22:00 +01:00 committed by Daniel Veillard
parent e99fb5ed9d
commit 7023663873
3 changed files with 74 additions and 5 deletions

View 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

View 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

View 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;