ia64/xen-unstable

changeset 19726:d8b7b51f482b

xend: pci: only extract the exact pci BDFs

On some hosts:
[root@localhost ~]# ls /sys/bus/pci/devices/0000:00:05.0/
0000:00:05.0:pcie00 0000:05:00.0 class driver local_cpus
resource subsystem_vendor
0000:00:05.0:pcie01 broken_parity_status config enable modalias
subsystem uevent
0000:00:05.0:pcie02 bus device irq power
subsystem_device vendor

Here we should only get 0000:05:00.0, but we also get 0000:00:05.0
unexpectedly. With this patch, xend only extracts the exact BDF(s).

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:47:56 2009 +0100 (2009-06-04)
parents 265de5701b82
children abdd365e2ec3
files tools/python/xen/util/pci.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Thu Jun 04 10:46:13 2009 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Thu Jun 04 10:47:56 2009 +0100
     1.3 @@ -153,6 +153,18 @@ def parse_pci_name(pci_name_string):
     1.4  
     1.5      return (domain, bus, slot, func)
     1.6  
     1.7 +def extract_the_exact_pci_names(pci_names):
     1.8 +    result = []
     1.9 +    pci_names = pci_names.split()
    1.10 +    for pci in pci_names:
    1.11 +        # The length of DDDD:bb:dd.f is 12.
    1.12 +        if len(pci) !=  12:
    1.13 +            continue
    1.14 +        if re.match(PCI_DEV_REG_EXPRESS_STR, pci) is None:
    1.15 +            continue
    1.16 +        result = result + [pci]
    1.17 +    return result
    1.18 +
    1.19  def find_sysfs_mnt():
    1.20      try:
    1.21          return utils.find_sysfs_mount()
    1.22 @@ -253,7 +265,7 @@ def find_all_devices_owned_by_pciback():
    1.23      sysfs_mnt = find_sysfs_mnt()
    1.24      pciback_path = sysfs_mnt + SYSFS_PCIBACK_PATH
    1.25      pci_names = os.popen('ls ' + pciback_path).read()
    1.26 -    pci_list = re.findall(PCI_DEV_REG_EXPRESS_STR, pci_names)
    1.27 +    pci_list = extract_the_exact_pci_names(pci_names)
    1.28      dev_list = []
    1.29      for pci in pci_list:
    1.30          (dom, b, d, f) = parse_pci_name(pci)
    1.31 @@ -454,7 +466,7 @@ class PciDevice:
    1.32          sysfs_mnt = find_sysfs_mnt()
    1.33          self_path = sysfs_mnt + SYSFS_PCI_DEVS_PATH + '/' + self.name
    1.34          pci_names = os.popen('ls ' + self_path).read()
    1.35 -        dev_list = re.findall(PCI_DEV_REG_EXPRESS_STR, pci_names)
    1.36 +        dev_list = extract_the_exact_pci_names(pci_names)
    1.37  
    1.38          list = [self.name]
    1.39          for pci_str in dev_list:
    1.40 @@ -491,7 +503,7 @@ class PciDevice:
    1.41              return [self.name]
    1.42  
    1.43          dev_list = dev.find_all_devices_behind_the_bridge(ignore_bridge)
    1.44 -        dev_list = re.findall(PCI_DEV_REG_EXPRESS_STR, '%s' % dev_list)
    1.45 +        dev_list = extract_the_exact_pci_names('%s' % dev_list)
    1.46          return dev_list
    1.47  
    1.48      def do_secondary_bus_reset(self, target_bus, devs):
    1.49 @@ -578,7 +590,7 @@ class PciDevice:
    1.50          parent = PCI_DEV_FORMAT_STR % self.find_parent()
    1.51          pci_names = os.popen('ls ' + sysfs_mnt + SYSFS_PCI_DEVS_PATH + '/' + \
    1.52              parent + '/').read()
    1.53 -        funcs = re.findall(PCI_DEV_REG_EXPRESS_STR, pci_names)
    1.54 +        funcs = extract_the_exact_pci_names(pci_names)
    1.55          return funcs
    1.56  
    1.57      def find_coassigned_devices(self):