ia64/xen-unstable

changeset 19763:45ca3f3c3f98

xend: support for older pciutils without -vmm option, and improve
error handling in get_info_from_lspci().

Signed-off-by: Zhigang Wang <zhigang.x.wang@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jun 16 11:53:47 2009 +0100 (2009-06-16)
parents d96cf4c974d5
children 775afcdc2759
files tools/python/xen/util/pci.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Tue Jun 16 11:47:09 2009 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Tue Jun 16 11:53:47 2009 +0100
     1.3 @@ -233,11 +233,16 @@ def _create_lspci_info():
     1.4      for paragraph in os.popen(LSPCI_CMD + ' -vmm').read().split('\n\n'):
     1.5          device_name = None
     1.6          device_info = {}
     1.7 +        # FIXME: workaround for pciutils without the -mm option.
     1.8 +        # see: git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git
     1.9 +        # commit: 3fd6b4d2e2fda814047664ffc67448ac782a8089
    1.10 +        first_device = True
    1.11          for line in paragraph.split('\n'):
    1.12              try:
    1.13                  (opt, value) = line.split(':\t')
    1.14 -                if opt == 'Slot':
    1.15 +                if opt == 'Slot' or (opt == 'Device' and first_device):
    1.16                      device_name = PCI_DEV_FORMAT_STR % parse_pci_name(value)
    1.17 +                    first_device = False
    1.18                  else:
    1.19                      device_info[opt] = value
    1.20              except:
    1.21 @@ -980,18 +985,18 @@ class PciDevice:
    1.22              if lspci_info is None:
    1.23                  _create_lspci_info()
    1.24  
    1.25 -            try:
    1.26 -                device_info = lspci_info[self.name]
    1.27 -                self.revision = int(device_info['Rev'], 16)
    1.28 -                self.vendorname = device_info['Vendor']
    1.29 -                self.devicename = device_info['Device']
    1.30 -                self.classname = device_info['Class']
    1.31 -                self.subvendorname = device_info['SVendor']
    1.32 -                self.subdevicename = device_info['SDevice']
    1.33 -            except KeyError:
    1.34 -                pass
    1.35 -
    1.36 -            return True
    1.37 +            device_info = lspci_info.get(self.name)
    1.38 +            if device_info:
    1.39 +                try:
    1.40 +                    self.revision = int(device_info.get('Rev', '0'), 16)
    1.41 +                except ValueError:
    1.42 +                    pass
    1.43 +                self.vendorname = device_info.get('Vendor', '')
    1.44 +                self.devicename = device_info.get('Device', '')
    1.45 +                self.classname = device_info.get('Class', '')
    1.46 +                self.subvendorname = device_info.get('SVendor', '')
    1.47 +                self.subdevicename = device_info.get('SDevice', '')
    1.48 +                return True
    1.49          finally:
    1.50              lspci_info_lock.release()
    1.51