ia64/xen-unstable

changeset 19777:60588f1f055f

Subject: xend: pass-through: Add pci_dict_cmp()

pci_dict_cmp() compares the two pci devices in dict format.

Signed-off-by: Simon Horman <horms@verge.net.au>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 17 07:35:51 2009 +0100 (2009-06-17)
parents 9e36ef77f658
children a4036225c168
files tools/python/xen/util/pci.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Wed Jun 17 07:34:59 2009 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Wed Jun 17 07:35:51 2009 +0100
     1.3 @@ -205,6 +205,10 @@ def pci_dict_to_bdf_str(dev):
     1.4  def pci_dict_to_xc_str(dev):
     1.5      return __pci_dict_to_fmt_str('0x%x, 0x%x, 0x%x, 0x%x', dev)
     1.6  
     1.7 +def pci_dict_cmp(a, b, keys=['domain', 'bus', 'slot', 'func']):
     1.8 +    return reduce(lambda x, y: x and y,
     1.9 +                  map(lambda k: int(a[k], 16) == int(b[k], 16), keys))
    1.10 +
    1.11  def extract_the_exact_pci_names(pci_names):
    1.12      result = []
    1.13  
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Jun 17 07:34:59 2009 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Jun 17 07:35:51 2009 +0100
     2.3 @@ -40,7 +40,7 @@ from xen.util.blkif import blkdev_uname_
     2.4  import xen.util.xsm.xsm as security
     2.5  from xen.util import xsconstants
     2.6  from xen.util.pci import serialise_pci_opts, pci_opts_list_to_sxp, \
     2.7 -                         pci_dict_to_bdf_str, pci_dict_to_xc_str
     2.8 +                         pci_dict_to_bdf_str, pci_dict_to_xc_str, pci_dict_cmp
     2.9  
    2.10  from xen.xend import balloon, sxp, uuid, image, arch
    2.11  from xen.xend import XendOptions, XendNode, XendConfig
    2.12 @@ -645,10 +645,7 @@ class XendDomainInfo:
    2.13                     int(x['vslot'], 16) != AUTO_PHP_SLOT):
    2.14                      raise VmError("vslot %s already have a device." % (new_dev['vslot']))
    2.15  
    2.16 -                if (int(x['domain'], 16) == int(new_dev['domain'], 16) and
    2.17 -                   int(x['bus'], 16)    == int(new_dev['bus'], 16) and
    2.18 -                   int(x['slot'], 16)   == int(new_dev['slot'], 16) and
    2.19 -                   int(x['func'], 16)   == int(new_dev['func'], 16) ):
    2.20 +                if (pci_dict_cmp(x, new_dev)):
    2.21                      raise VmError("device is already inserted")
    2.22  
    2.23          # Test whether the devices can be assigned with VT-d
    2.24 @@ -839,23 +836,18 @@ class XendDomainInfo:
    2.25                  existing_dev_uuid = sxp.child_value(existing_dev_info, 'uuid')
    2.26                  existing_pci_conf = self.info['devices'][existing_dev_uuid][1]
    2.27                  existing_pci_devs = existing_pci_conf['devs']
    2.28 -                vslot = ""
    2.29 -                for x in existing_pci_devs:
    2.30 -                    if ( int(x['domain'], 16) == int(dev['domain'], 16) and
    2.31 -                         int(x['bus'], 16) == int(dev['bus'], 16) and
    2.32 -                         int(x['slot'], 16) == int(dev['slot'], 16) and
    2.33 -                         int(x['func'], 16) == int(dev['func'], 16) ):
    2.34 -                        vslot = x['vslot']
    2.35 -                        break
    2.36 -                if vslot == "":
    2.37 +                new_devs = filter(lambda x: pci_dict_cmp(x, dev),
    2.38 +                                  existing_pci_devs)
    2.39 +                if len(new_devs) < 0:
    2.40                      raise VmError("Device %s is not connected" %
    2.41                                    pci_dict_to_bdf_str(dev))
    2.42 -                self.hvm_destroyPCIDevice(int(vslot, 16))
    2.43 +                new_dev = new_devs[0]
    2.44 +                self.hvm_destroyPCIDevice(int(new_dev['vslot'], 16))
    2.45                  # Update vslot
    2.46 -                dev['vslot'] = vslot
    2.47 +                dev['vslot'] = new_dev['vslot']
    2.48                  for n in sxp.children(pci_dev):
    2.49                      if(n[0] == 'vslot'):
    2.50 -                        n[1] = vslot
    2.51 +                        n[1] = new_dev['vslot']
    2.52  
    2.53          # If pci platform does not exist, create and exit.
    2.54          if existing_dev_info is None: