ia64/xen-unstable

changeset 16639:ca461349620a

xend: Fix PCI Device Configuration

Xend doesn't correctly work after restart, when there is a domU which
owns a pci device (driver domain). This patch fixes the problem.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 19 14:50:37 2007 +0000 (2007-12-19)
parents 28921e83000b
children e08c4cab65c8
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	Wed Dec 19 14:45:45 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Wed Dec 19 14:50:37 2007 +0000
     1.3 @@ -533,55 +533,13 @@ class XendConfig(dict):
     1.4              cfg['HVM_boot_policy'] = 'BIOS order'
     1.5              cfg['HVM_boot_params'] = { 'order' : boot_order }
     1.6  
     1.7 -        # Parsing the device SXP's. In most cases, the SXP looks
     1.8 -        # like this:
     1.9 -        #
    1.10 -        # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.5]]]
    1.11 -        #
    1.12 -        # However, for PCI devices it looks like this:
    1.13 -        #
    1.14 -        # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1]]]]
    1.15 -        #
    1.16 -        # It seems the reasoning for this difference is because
    1.17 -        # pciif.py needs all the PCI device configurations at
    1.18 -        # the same time when creating the devices.
    1.19 -        #
    1.20 -        # To further complicate matters, Xen 2.0 configuration format
    1.21 -        # uses the following for pci device configuration:
    1.22 -        #
    1.23 -        # [device, [pci, [domain, 0], [bus, 0], [dev, 1], [func, 2]]]
    1.24 -        #
    1.25 -        # Hence we deal with pci device configurations outside of
    1.26 -        # the regular device parsing.
    1.27 -        
    1.28 +       
    1.29 +        # Parsing the device SXP's.
    1.30          cfg['devices'] = {}
    1.31          for dev in sxp.children(sxp_cfg, 'device'):
    1.32              config = sxp.child0(dev)
    1.33              dev_type = sxp.name(config)
    1.34 -            dev_info = {}
    1.35 -            
    1.36 -            if dev_type == 'pci':
    1.37 -                pci_devs_uuid = sxp.child_value(config, 'uuid',
    1.38 -                                                uuid.createString())
    1.39 -                pci_devs = []
    1.40 -                for pci_dev in sxp.children(config, 'dev'):
    1.41 -                    pci_dev_info = {}
    1.42 -                    for opt_val in pci_dev[1:]:
    1.43 -                        try:
    1.44 -                            opt, val = opt_val
    1.45 -                            pci_dev_info[opt] = val
    1.46 -                        except TypeError:
    1.47 -                            pass
    1.48 -                    pci_devs.append(pci_dev_info)
    1.49 -                
    1.50 -                cfg['devices'][pci_devs_uuid] = (dev_type,
    1.51 -                                                 {'devs': pci_devs,
    1.52 -                                                  'uuid': pci_devs_uuid})
    1.53 -                
    1.54 -                log.debug("XendConfig: reading device: %s" % pci_devs)
    1.55 -            else:
    1.56 -                self.device_add(dev_type, cfg_sxp = config, target = cfg)
    1.57 -                log.debug("XendConfig: reading device: %s" % scrub_password(dev_info))
    1.58 +            self.device_add(dev_type, cfg_sxp = config, target = cfg)
    1.59  
    1.60          # Extract missing data from configuration entries
    1.61          image_sxp = sxp.child_value(sxp_cfg, 'image', [])
    1.62 @@ -1096,6 +1054,44 @@ class XendConfig(dict):
    1.63              dev_type = sxp.name(config)
    1.64              dev_info = {}
    1.65  
    1.66 +            # Parsing the device SXP's. In most cases, the SXP looks
    1.67 +            # like this:
    1.68 +            #
    1.69 +            # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.5]]]
    1.70 +            #
    1.71 +            # However, for PCI devices it looks like this:
    1.72 +            #
    1.73 +            # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1]]]]
    1.74 +            #
    1.75 +            # It seems the reasoning for this difference is because
    1.76 +            # pciif.py needs all the PCI device configurations at
    1.77 +            # the same time when creating the devices.
    1.78 +            #
    1.79 +            # To further complicate matters, Xen 2.0 configuration format
    1.80 +            # uses the following for pci device configuration:
    1.81 +            #
    1.82 +            # [device, [pci, [domain, 0], [bus, 0], [dev, 1], [func, 2]]]
    1.83 +
    1.84 +            if dev_type == 'pci':
    1.85 +                pci_devs_uuid = sxp.child_value(config, 'uuid',
    1.86 +                                                uuid.createString())
    1.87 +                pci_devs = []
    1.88 +                for pci_dev in sxp.children(config, 'dev'):
    1.89 +                    pci_dev_info = {}
    1.90 +                    for opt_val in pci_dev[1:]:
    1.91 +                        try:
    1.92 +                            opt, val = opt_val
    1.93 +                            pci_dev_info[opt] = val
    1.94 +                        except TypeError:
    1.95 +                            pass
    1.96 +                    pci_devs.append(pci_dev_info)
    1.97 +                target['devices'][pci_devs_uuid] = (dev_type,
    1.98 +                                                    {'devs': pci_devs,
    1.99 +                                                     'uuid': pci_devs_uuid})
   1.100 +
   1.101 +                log.debug("XendConfig: reading device: %s" % pci_devs)
   1.102 +                return pci_devs_uuid
   1.103 +
   1.104              for opt_val in config[1:]:
   1.105                  try:
   1.106                      opt, val = opt_val
   1.107 @@ -1177,6 +1173,7 @@ class XendConfig(dict):
   1.108                  if dev_uuid not in target['console_refs']:
   1.109                      target['console_refs'].append(dev_uuid)
   1.110                      
   1.111 +            log.debug("XendConfig: reading device: %s" % scrub_password(dev_info))
   1.112              return dev_uuid
   1.113  
   1.114          if cfg_xenapi:
     2.1 --- a/tools/python/xen/xend/server/pciif.py	Wed Dec 19 14:45:45 2007 +0000
     2.2 +++ b/tools/python/xen/xend/server/pciif.py	Wed Dec 19 14:50:37 2007 +0000
     2.3 @@ -102,13 +102,13 @@ class PciController(DevController):
     2.4          result['uuid'] = self.readBackend(devid, 'uuid')
     2.5          return result
     2.6  
     2.7 -    def configuration(self, devid):
     2.8 +    def configuration(self, devid, transaction = None):
     2.9          """Returns SXPR for devices on domain.
    2.10  
    2.11          @note: we treat this dict especially to convert to
    2.12          SXP because it is not a straight dict of strings."""
    2.13          
    2.14 -        configDict = self.getDeviceConfiguration(devid)
    2.15 +        configDict = self.getDeviceConfiguration(devid, transaction)
    2.16          sxpr = [self.deviceClass]
    2.17  
    2.18          # remove devs