[libvirt] [PATCH] pci: Give an explicit error if device not found

Cole Robinson crobinso at redhat.com
Fri Apr 30 15:44:19 UTC 2010


Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
 src/util/pci.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/util/pci.c b/src/util/pci.c
index 81193b7..e1e11bc 100644
--- a/src/util/pci.c
+++ b/src/util/pci.c
@@ -1028,6 +1028,7 @@ pciGetDevice(unsigned domain,
              unsigned function)
 {
     pciDevice *dev;
+    char devdir[PATH_MAX];
     char *vendor, *product;
 
     if (VIR_ALLOC(dev) < 0) {
@@ -1043,8 +1044,17 @@ pciGetDevice(unsigned domain,
 
     snprintf(dev->name, sizeof(dev->name), "%.4x:%.2x:%.2x.%.1x",
              dev->domain, dev->bus, dev->slot, dev->function);
+    snprintf(devdir, sizeof(devdir),
+             PCI_SYSFS "devices/%s", dev->name);
     snprintf(dev->path, sizeof(dev->path),
-             PCI_SYSFS "devices/%s/config", dev->name);
+             "%s/%s/config", devdir, dev->name);
+
+    if (access(devdir, X_OK) != 0) {
+        pciReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Device %s not found"), dev->name);
+        pciFreeDevice(dev);
+        return NULL;
+    }
 
     vendor  = pciReadDeviceID(dev, "vendor");
     product = pciReadDeviceID(dev, "device");
-- 
1.7.0.1




More information about the libvir-list mailing list