direct-io.hg

changeset 12468:fc25a6eadccd

[XEND] Fix PCI configuration parsing and SXP output

PCI configuration is formatted differently from other device
configurations because of the requirement that all pci devices need to
be present when it is initialised.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Thu Nov 16 13:49:05 2006 +0000 (2006-11-16)
parents 9c9dbc5df557
children 992723a0ceb1
files tools/python/xen/xend/XendConfig.py tools/python/xen/xend/server/pciif.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Nov 16 13:13:55 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Nov 16 13:49:05 2006 +0000
     1.3 @@ -17,6 +17,7 @@
     1.4  
     1.5  import re
     1.6  import time
     1.7 +import types
     1.8  
     1.9  from xen.xend import sxp
    1.10  from xen.xend import uuid
    1.11 @@ -450,11 +451,36 @@ class XendConfig(dict):
    1.12          for c in sxp.children(parsed, 'backend'):
    1.13              cfg['backend'].append(sxp.name(sxp.child0(c)))
    1.14  
    1.15 +        # Parsing the device SXP's. In most cases, the SXP looks
    1.16 +        # like this:
    1.17 +        #
    1.18 +        # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.5]]]
    1.19 +        #
    1.20 +        # However, for PCI devices it looks like this:
    1.21 +        #
    1.22 +        # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1]]]]
    1.23 +        #
    1.24 +        # It seems the reasoning for this difference is because
    1.25 +        # pciif.py needs all the PCI device configurations at
    1.26 +        # the same time when creating the devices.
    1.27 +        #
    1.28 +        # To further complicate matters, Xen 2.0 configuration format
    1.29 +        # uses the following for pci device configuration:
    1.30 +        #
    1.31 +        # [device, [pci, [domain, 0], [bus, 0], [dev, 1], [func, 2]]]
    1.32 +        #
    1.33 +        # Hence we deal with pci device configurations outside of
    1.34 +        # the regular device parsing.
    1.35 +        
    1.36          cfg['device'] = {}
    1.37          for dev in sxp.children(parsed, 'device'):
    1.38              config = sxp.child0(dev)
    1.39              dev_type = sxp.name(config)
    1.40              dev_info = {}
    1.41 +            
    1.42 +            if dev_type == 'pci':
    1.43 +                continue 
    1.44 +            
    1.45              for opt, val in config[1:]:
    1.46                  dev_info[opt] = val
    1.47              log.debug("XendConfig: reading device: %s" % dev_info)
    1.48 @@ -462,9 +488,34 @@ class XendConfig(dict):
    1.49              dev_uuid = dev_info.get('uuid', uuid.createString())
    1.50              dev_info['uuid'] = dev_uuid
    1.51              cfg['device'][dev_uuid] = (dev_type, dev_info)
    1.52 +
    1.53 +        # deal with PCI device configurations if they exist
    1.54 +        for dev in sxp.children(parsed, 'device'):
    1.55 +            config = sxp.child0(dev)
    1.56 +            dev_type = sxp.name(config)
    1.57 +
    1.58 +            if dev_type != 'pci':
    1.59 +                continue
    1.60              
    1.61 -            #cfg['device'].append((sxp.name(config), config))
    1.62 -
    1.63 +            dev_attr = sxp.child_value(config, 'dev')
    1.64 +            if isinstance(dev_attr, (types.ListType, types.TupleType)):
    1.65 +                for pci_dev in sxp.children(config, 'dev'):
    1.66 +                    dev_info = {}
    1.67 +                    for opt, val in pci_dev[1:]:
    1.68 +                        dev_info[opt] = val
    1.69 +                    log.debug("XendConfig: reading device: %s" % dev_info)
    1.70 +                    dev_uuid = dev_info.get('uuid', uuid.createString())
    1.71 +                    dev_info['uuid'] = dev_uuid
    1.72 +                    cfg['device'][dev_uuid] = (dev_type, dev_info)
    1.73 +                    
    1.74 +            else: # Xen 2.0 PCI device configuration
    1.75 +                for opt, val in config[1:]:
    1.76 +                    dev_info[opt] = val
    1.77 +                log.debug("XendConfig: reading device: %s" % dev_info)
    1.78 +                # create uuid if it doesn't
    1.79 +                dev_uuid = dev_info.get('uuid', uuid.createString())
    1.80 +                dev_info['uuid'] = dev_uuid
    1.81 +                cfg['device'][dev_uuid] = (dev_type, dev_info)
    1.82  
    1.83          # Extract missing data from configuration entries
    1.84          if 'image' in cfg:
    1.85 @@ -859,10 +910,27 @@ class XendConfig(dict):
    1.86          return sxpr
    1.87  
    1.88      def all_devices_sxpr(self):
    1.89 +        """Returns the SXPR for all devices in the current configuration."""
    1.90          sxprs = []
    1.91 +        pci_devs = []
    1.92          for dev_type, dev_info in self['device'].values():
    1.93 -            sxpr =  self.device_sxpr(dev_type = dev_type, dev_info = dev_info)
    1.94 -            sxprs.append((dev_type, sxpr))
    1.95 +            if dev_type == 'pci': # special case for pci devices
    1.96 +                pci_devs.append(dev_info)
    1.97 +            else:
    1.98 +                sxpr =  self.device_sxpr(dev_type = dev_type,
    1.99 +                                         dev_info = dev_info)
   1.100 +                sxprs.append((dev_type, sxpr))
   1.101 +
   1.102 +        # if we have any pci_devs, we parse them differently into
   1.103 +        # one single pci SXP entry.
   1.104 +        if pci_devs:
   1.105 +            sxpr = ['pci',]
   1.106 +            for dev_info in pci_devs:
   1.107 +                dev_sxpr = self.device_sxpr(dev_type = 'dev',
   1.108 +                                            dev_info = dev_info)
   1.109 +                sxpr.append(dev_sxpr)
   1.110 +            sxprs.append(('pci', sxpr))
   1.111 +            
   1.112          return sxprs
   1.113  
   1.114                       
     2.1 --- a/tools/python/xen/xend/server/pciif.py	Thu Nov 16 13:13:55 2006 +0000
     2.2 +++ b/tools/python/xen/xend/server/pciif.py	Thu Nov 16 13:49:05 2006 +0000
     2.3 @@ -65,7 +65,7 @@ class PciController(DevController):
     2.4                      else:
     2.5                          return default
     2.6  
     2.7 -                if isinstance(val, types.StringType):
     2.8 +                if isinstance(val, types.StringTypes):
     2.9                      return int(val, 16)
    2.10                  else:
    2.11                      return val
    2.12 @@ -79,7 +79,7 @@ class PciController(DevController):
    2.13          back = {}
    2.14  
    2.15          val = sxp.child_value(config, 'dev')
    2.16 -        if isinstance(val, list):
    2.17 +        if isinstance(val, (types.ListType, types.TupleType)):
    2.18              pcidevid = 0
    2.19              for dev_config in sxp.children(config, 'dev'):
    2.20                  domain = get_param(dev_config, 'domain', 0)
    2.21 @@ -89,7 +89,7 @@ class PciController(DevController):
    2.22  
    2.23                  self.setupDevice(domain, bus, slot, func)
    2.24  
    2.25 -                back['dev-%i'%(pcidevid)]="%04x:%02x:%02x.%02x"% \
    2.26 +                back['dev-%i' % pcidevid]="%04x:%02x:%02x.%02x"% \
    2.27                          (domain, bus, slot, func)
    2.28                  pcidevid+=1
    2.29              
    2.30 @@ -115,19 +115,19 @@ class PciController(DevController):
    2.31          pci_devs = []
    2.32          
    2.33          for i in range(int(num_devs)):
    2.34 -            (dev_config,) = self.readBackend(devid, 'dev-%d'%(i))
    2.35 +            dev_config = self.readBackend(devid, 'dev-%d' % i)
    2.36  
    2.37 -            pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
    2.38 -                    r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
    2.39 -                    r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
    2.40 -                    r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
    2.41 +            pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" +
    2.42 +                                 r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + 
    2.43 +                                 r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + 
    2.44 +                                 r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
    2.45              
    2.46              if pci_match!=None:
    2.47 -                pci_dev_info = pci_match.groupdict('0')
    2.48 +                pci_dev_info = pci_match.groupdict()
    2.49                  pci_devs.append({'domain': '0x%(domain)s' % pci_dev_info,
    2.50                                   'bus': '0x%(bus)s' % pci_dev_info,
    2.51 -                                 'slot': '0x(slot)s' % pci_dev_info,
    2.52 -                                 'func': '0x(func)s' % pci_dev_info})
    2.53 +                                 'slot': '0x%(slot)s' % pci_dev_info,
    2.54 +                                 'func': '0x%(func)s' % pci_dev_info})
    2.55  
    2.56          result['dev'] = pci_devs
    2.57          return result