ia64/xen-unstable

changeset 19642:dc7de36c94e3

xm, xend: passthrough: Add assigned_or_requested_vslot()

Add an accessor to simplify accessing vslot if available,
otherwise requested_vslot.

Signed-off-by: Simon Horman <horms@verge.net.au>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 10:04:10 2009 +0100 (2009-05-26)
parents caa8c0e2d6f6
children 916331c26dc1
files tools/python/xen/util/pci.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/pciif.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Tue May 26 10:03:09 2009 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Tue May 26 10:04:10 2009 +0100
     1.3 @@ -138,7 +138,13 @@ def parse_pci_name(pci_name_string):
     1.4      func = parse_hex(pci_dev_info['func'])
     1.5  
     1.6      return (domain, bus, slot, func)
     1.7 - 
     1.8 +
     1.9 +def assigned_or_requested_vslot(dev):
    1.10 +    if dev.has_key("vslot"):
    1.11 +        return dev["vslot"]
    1.12 +    if dev.has_key("requested_vslot"):
    1.13 +        return dev["requested_vslot"]
    1.14 +    raise PciDeviceVslotMissing("%s" % dev)
    1.15  
    1.16  def find_sysfs_mnt():
    1.17      try:
    1.18 @@ -355,6 +361,12 @@ class PciDeviceAssignmentError(Exception
    1.19          return 'pci: impproper device assignment spcified: ' + \
    1.20              self.message
    1.21  
    1.22 +class PciDeviceVslotMissing(Exception):
    1.23 +    def __init__(self,msg):
    1.24 +        self.message = msg
    1.25 +    def __str__(self):
    1.26 +        return 'pci: no vslot or requested_vslot: ' + self.message
    1.27 +
    1.28  class PciDevice:
    1.29      def __init__(self, domain, bus, slot, func):
    1.30          self.domain = domain
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue May 26 10:03:09 2009 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue May 26 10:04:10 2009 +0100
     2.3 @@ -38,6 +38,7 @@ from xen.util import asserts, auxbin
     2.4  from xen.util.blkif import blkdev_uname_to_file, blkdev_uname_to_taptype
     2.5  import xen.util.xsm.xsm as security
     2.6  from xen.util import xsconstants
     2.7 +from xen.util.pci import assigned_or_requested_vslot
     2.8  
     2.9  from xen.xend import balloon, sxp, uuid, image, arch
    2.10  from xen.xend import XendOptions, XendNode, XendConfig
    2.11 @@ -621,10 +622,7 @@ class XendDomainInfo:
    2.12              pci_conf = self.info['devices'][dev_uuid][1]
    2.13              pci_devs = pci_conf['devs']
    2.14              for x in pci_devs:
    2.15 -                if x.has_key('vslot'):
    2.16 -                    x_vslot = x['vslot']
    2.17 -                else:
    2.18 -                    x_vslot = x['requested_vslot']
    2.19 +                x_vslot = assigned_or_requested_vslot(x)
    2.20                  if (int(x_vslot, 16) == int(new_dev['requested_vslot'], 16) and
    2.21                     int(x_vslot, 16) != AUTO_PHP_SLOT):
    2.22                      raise VmError("vslot %s already have a device." % (new_dev['requested_vslot']))
    2.23 @@ -819,10 +817,7 @@ class XendDomainInfo:
    2.24                           int(x['bus'], 16) == int(dev['bus'], 16) and
    2.25                           int(x['slot'], 16) == int(dev['slot'], 16) and
    2.26                           int(x['func'], 16) == int(dev['func'], 16) ):
    2.27 -                        if x.has_key('vslot'):
    2.28 -                            vslot = x['vslot']
    2.29 -                        else:
    2.30 -                            vslot = x['requested_vslot']
    2.31 +                        vslot = assigned_or_requested_vslot(x)
    2.32                          break
    2.33                  if vslot == AUTO_PHP_SLOT_STR:
    2.34                      raise VmError("Device %04x:%02x:%02x.%01x is not connected"
    2.35 @@ -1119,10 +1114,7 @@ class XendDomainInfo:
    2.36          #find the pass-through device with the virtual slot
    2.37          devnum = 0
    2.38          for x in pci_conf['devs']:
    2.39 -            if x.has_key('vslot'):
    2.40 -                x_vslot = x['vslot']
    2.41 -            else:
    2.42 -                x_vslot = x['requested_vslot']
    2.43 +            x_vslot = assigned_or_requested_vslot(x)
    2.44              if int(x_vslot, 16) == vslot:
    2.45                  break
    2.46              devnum += 1
     3.1 --- a/tools/python/xen/xend/server/pciif.py	Tue May 26 10:03:09 2009 +0100
     3.2 +++ b/tools/python/xen/xend/server/pciif.py	Tue May 26 10:04:10 2009 +0100
     3.3 @@ -71,15 +71,15 @@ class PciController(DevController):
     3.4          pcidevid = 0
     3.5          vslots = ""
     3.6          for pci_config in config.get('devs', []):
     3.7 -            vslot = pci_config.get('vslot')
     3.8 -            if vslot is not None:
     3.9 -                vslots = vslots + vslot + ";"
    3.10 +            attached_vslot = pci_config.get('vslot')
    3.11 +            if attached_vslot is not None:
    3.12 +                vslots = vslots + attached_vslot + ";"
    3.13  
    3.14              domain = parse_hex(pci_config.get('domain', 0))
    3.15              bus = parse_hex(pci_config.get('bus', 0))
    3.16              slot = parse_hex(pci_config.get('slot', 0))
    3.17              func = parse_hex(pci_config.get('func', 0))            
    3.18 -            requested_vslot = parse_hex(pci_config.get('requested_vslot', 0))
    3.19 +            vslot = parse_hex(assigned_or_requested_vslot(pci_config))
    3.20  
    3.21              opts = pci_config.get('opts', '')
    3.22              if len(opts) > 0:
    3.23 @@ -90,7 +90,7 @@ class PciController(DevController):
    3.24              back['dev-%i' % pcidevid] = "%04x:%02x:%02x.%01x" % \
    3.25                                          (domain, bus, slot, func)
    3.26              back['uuid-%i' % pcidevid] = pci_config.get('uuid', '')
    3.27 -            back['vslot-%i' % pcidevid] = "%02x" % requested_vslot
    3.28 +            back['vslot-%i' % pcidevid] = "%02x" % vslot
    3.29              pcidevid += 1
    3.30  
    3.31          if vslots != "":
     4.1 --- a/tools/python/xen/xm/main.py	Tue May 26 10:03:09 2009 +0100
     4.2 +++ b/tools/python/xen/xm/main.py	Tue May 26 10:04:10 2009 +0100
     4.3 @@ -2168,18 +2168,12 @@ def xm_pci_list(args):
     4.4  
     4.5      has_vslot = False
     4.6      for x in devs:
     4.7 -        if x.has_key('vslot'):
     4.8 -            if x['vslot'] == "0x%s" % AUTO_PHP_SLOT_STR:
     4.9 -                x['vslot'] = '-'
    4.10 -            else:
    4.11 -                has_vslot = True
    4.12 -        elif not x.has_key('requested_vslot'):
    4.13 -            x['vslot'] = '-'
    4.14 -        elif x['requested_vslot'] == "0x%s" % AUTO_PHP_SLOT_STR:
    4.15 +        vslot = assigned_or_requested_vslot(x)
    4.16 +        if int(vslot, 16) == AUTO_PHP_SLOT:
    4.17              x['vslot'] = '-'
    4.18          else:
    4.19 +            x['vslot'] = vslot
    4.20              has_vslot = True
    4.21 -            x['vslot'] = x['requested_vslot']
    4.22  
    4.23      if has_vslot:
    4.24          hdr_str = 'VSlt domain   bus   slot   func'