ia64/xen-unstable

changeset 18216:8182a85460f7

xend: Fix portability issue of lspci option.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jul 31 12:39:56 2008 +0100 (2008-07-31)
parents a23f0d91e2fc
children 1f338c90d60f
files tools/python/xen/util/pci.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Thu Jul 31 12:38:32 2008 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Thu Jul 31 12:39:56 2008 +0100
     1.3 @@ -111,15 +111,22 @@ def parse_hex(val):
     1.4          return None
     1.5  
     1.6  def parse_pci_name(pci_name_string):
     1.7 -    # Format: xxxx:xx:xx.x
     1.8 -    s = pci_name_string
     1.9 -    s = s.split(':')
    1.10 -    dom = parse_hex(s[0])
    1.11 -    bus = parse_hex(s[1])
    1.12 -    s = s[2].split('.')
    1.13 -    dev = parse_hex(s[0])
    1.14 -    func =  parse_hex(s[1])
    1.15 -    return (dom, bus, dev, func)
    1.16 +    pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
    1.17 +            r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
    1.18 +            r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
    1.19 +            r"(?P<func>[0-7])$", pci_name_string)
    1.20 +    if pci_match is None:
    1.21 +        raise PciDeviceParseError(('Failed to parse pci device name: %s' %
    1.22 +            pci_name_string))
    1.23 +    pci_dev_info = pci_match.groupdict('0')
    1.24 +
    1.25 +    domain = parse_hex(pci_dev_info['domain'])
    1.26 +    bus = parse_hex(pci_dev_info['bus'])
    1.27 +    slot = parse_hex(pci_dev_info['slot'])
    1.28 +    func = parse_hex(pci_dev_info['func'])
    1.29 +
    1.30 +    return (domain, bus, slot, func)
    1.31 + 
    1.32  
    1.33  def find_sysfs_mnt():
    1.34      global sysfs_mnt_point
    1.35 @@ -175,14 +182,14 @@ def create_lspci_info():
    1.36  
    1.37      # Execute 'lspci' command and parse the result.
    1.38      # If the command does not exist, lspci_info will be kept blank ({}).
    1.39 -    for paragraph in os.popen(LSPCI_CMD + ' -vmmD').read().split('\n\n'):
    1.40 +    for paragraph in os.popen(LSPCI_CMD + ' -vmm').read().split('\n\n'):
    1.41          device_name = None
    1.42          device_info = {}
    1.43          for line in paragraph.split('\n'):
    1.44              try:
    1.45                  (opt, value) = line.split(':\t')
    1.46                  if opt == 'Slot':
    1.47 -                    device_name = value
    1.48 +                    device_name = PCI_DEV_FORMAT_STR % parse_pci_name(value)
    1.49                  else:
    1.50                      device_info[opt] = value
    1.51              except: