ia64/xen-unstable

changeset 18047:2463e2ef602f

xend: A small cleanup to the find_sysfs_mnt() of pci.py
Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jul 14 10:09:25 2008 +0100 (2008-07-14)
parents d14c017e8163
children caba894b265f
files tools/python/xen/util/pci.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Mon Jul 14 10:07:11 2008 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Mon Jul 14 10:09:25 2008 +0100
     1.3 @@ -40,6 +40,9 @@ MSIX_SIZE_MASK = 0x7ff
     1.4  # Global variable to store information from lspci
     1.5  lspci_info = None
     1.6  
     1.7 +# Global variable to store the sysfs mount point
     1.8 +sysfs_mnt_point = None
     1.9 +
    1.10  #Calculate PAGE_SHIFT: number of bits to shift an address to get the page number
    1.11  PAGE_SIZE = resource.getpagesize()
    1.12  PAGE_SHIFT = 0
    1.13 @@ -63,27 +66,28 @@ def parse_hex(val):
    1.14          return None
    1.15  
    1.16  def find_sysfs_mnt():
    1.17 -    mounts_file = open(PROC_MNT_PATH,'r')
    1.18 +    global sysfs_mnt_point
    1.19 +    if not sysfs_mnt_point is None:
    1.20 +        return sysfs_mnt_point
    1.21  
    1.22 -    for line in mounts_file:
    1.23 -        sline = line.split()
    1.24 -        if len(sline)<3:
    1.25 -            continue
    1.26 +    try:
    1.27 +        mounts_file = open(PROC_MNT_PATH,'r')
    1.28  
    1.29 -        if sline[2]=='sysfs':
    1.30 -            return sline[1]
    1.31 -
    1.32 +        for line in mounts_file:
    1.33 +            sline = line.split()
    1.34 +            if len(sline)<3:
    1.35 +                continue
    1.36 +            if sline[2]=='sysfs':
    1.37 +                sysfs_mnt_point= sline[1]
    1.38 +                return sysfs_mnt_point
    1.39 +    except IOError, (errno, strerr):
    1.40 +        raise PciDeviceParseError(('Failed to locate sysfs mount: %s: %s (%d)'%
    1.41 +            (PROC_PCI_PATH, strerr, errno)))
    1.42      return None
    1.43  
    1.44  def get_all_pci_names():
    1.45 -    try:
    1.46 -        sysfs_mnt = find_sysfs_mnt()
    1.47 -    except IOError, (errno, strerr):
    1.48 -        raise PciDeviceParseError(('Failed to locate sysfs mount: %s (%d)' %
    1.49 -            (PROC_PCI_PATH, strerr, errno)))
    1.50 -
    1.51 +    sysfs_mnt = find_sysfs_mnt()
    1.52      pci_names = os.popen('ls ' + sysfs_mnt + SYSFS_PCI_DEVS_PATH).read().split()
    1.53 -
    1.54      return pci_names
    1.55  
    1.56  def get_all_pci_devices():
    1.57 @@ -175,12 +179,7 @@ class PciDevice:
    1.58          self.get_info_from_lspci()
    1.59  
    1.60      def find_capability(self, type):
    1.61 -        try:
    1.62 -            sysfs_mnt = find_sysfs_mnt()
    1.63 -        except IOError, (errno, strerr):
    1.64 -            raise PciDeviceParseError(('Failed to locate sysfs mount: %s (%d)' %
    1.65 -                (PROC_PCI_PATH, strerr, errno)))
    1.66 -
    1.67 +        sysfs_mnt = find_sysfs_mnt()
    1.68          if sysfs_mnt == None:
    1.69              return False
    1.70          path = sysfs_mnt+SYSFS_PCI_DEVS_PATH+'/'+ \
    1.71 @@ -218,7 +217,7 @@ class PciDevice:
    1.72                          self.pba_offset = self.pba_offset & ~MSIX_BIR_MASK
    1.73                          break
    1.74          except IOError, (errno, strerr):
    1.75 -            raise PciDeviceParseError(('Failed to locate sysfs mount: %s (%d)' %
    1.76 +            raise PciDeviceParseError(('Failed to locate sysfs mount: %s: %s (%d)' %
    1.77                  (PROC_PCI_PATH, strerr, errno)))
    1.78  
    1.79      def remove_msix_iomem(self, index, start, size):
    1.80 @@ -237,12 +236,7 @@ class PciDevice:
    1.81  
    1.82      def get_info_from_sysfs(self):
    1.83          self.find_capability(0x11)
    1.84 -        try:
    1.85 -            sysfs_mnt = find_sysfs_mnt()
    1.86 -        except IOError, (errno, strerr):
    1.87 -            raise PciDeviceParseError(('Failed to locate sysfs mount: %s (%d)' %
    1.88 -                (PROC_PCI_PATH, strerr, errno)))
    1.89 -
    1.90 +        sysfs_mnt = find_sysfs_mnt()
    1.91          if sysfs_mnt == None:
    1.92              return False
    1.93