]> xenbits.xensource.com Git - xen.git/commitdiff
xend: Add serialise_pci_opts() and split_pci_opts()
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 29 May 2009 08:33:06 +0000 (09:33 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 29 May 2009 08:33:06 +0000 (09:33 +0100)
This centralises some code.

Signed-off-by: Simon Horman <horms@verge.net.au>
tools/python/xen/util/pci.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/pciif.py

index a1df4c464f29e3f9f3c01392a2b5560dad09a6dd..c88ad25bec7723efe8e53987f6c254afe9b1514e 100644 (file)
@@ -114,6 +114,12 @@ PAGE_MASK=~(PAGE_SIZE - 1)
 def PCI_DEVFN(slot, func):
     return ((((slot) & 0x1f) << 3) | ((func) & 0x07))
 
+def serialise_pci_opts(opts):
+    return reduce(lambda x, y: x+','+y, map(lambda (x, y): x+'='+y, opts))
+
+def split_pci_opts(opts):
+    return map(lambda x: x.split('='), opts.split(','))
+
 def parse_hex(val):
     try:
         if isinstance(val, types.StringTypes):
index 2c75c91fcf2f59415ba32185f053e0c6036542f5..9d821d02fae037d4280ddfc86cf1423a15250f60 100644 (file)
@@ -39,7 +39,7 @@ from xen.util import asserts, auxbin
 from xen.util.blkif import blkdev_uname_to_file, blkdev_uname_to_taptype
 import xen.util.xsm.xsm as security
 from xen.util import xsconstants
-from xen.util.pci import assigned_or_requested_vslot
+from xen.util.pci import assigned_or_requested_vslot, serialise_pci_opts
 
 from xen.xend import balloon, sxp, uuid, image, arch
 from xen.xend import XendOptions, XendNode, XendConfig
@@ -739,10 +739,8 @@ class XendDomainInfo:
 
         if self.domid is not None:
             opts = ''
-            if 'opts' in new_dev and len(new_dev['opts']) > 0:
-                config_opts = new_dev['opts']
-                config_opts = map(lambda (x, y): x+'='+y, config_opts)
-                opts = ',' + reduce(lambda x, y: x+','+y, config_opts)
+            if new_dev.has_key('opts'):
+                opts = ',' + serialise_pci_opts(new_dev['opts'])
 
             bdf_str = "%s:%s:%s.%s@%s%s" % (new_dev['domain'],
                 new_dev['bus'],
index 3e99e6908d18363bbc84aae7863d8949bde9956c..cccdc9d4f23a9dbd8378ef1660683fcfba95a166 100644 (file)
@@ -76,10 +76,8 @@ class PciController(DevController):
             func = parse_hex(pci_config.get('func', 0))            
             vslot = parse_hex(assigned_or_requested_vslot(pci_config))
 
-            opts = pci_config.get('opts', '')
-            if len(opts) > 0:
-                opts = map(lambda (x, y): x+'='+y, opts)
-                opts = reduce(lambda x, y: x+','+y, opts)
+            if pci_config.has_key('opts'):
+                opts = serialise_pci_opts(pci_config['opts'])
                 back['opts-%i' % pcidevid] = opts
 
             back['dev-%i' % pcidevid] = "%04x:%02x:%02x.%01x" % \
@@ -226,10 +224,7 @@ class PciController(DevController):
             dev_sxpr = ['dev']
             for dev_key, dev_val in dev.items():
                 if dev_key == 'opts':
-                    opts = []
-                    for opt in dev_val.split(','):
-                        opts.append(opt.split('='))
-                    dev_sxpr.append(['opts', opts])
+                    dev_sxpr.append(['opts', split_pci_opts(dev_val)])
                 else:
                     dev_sxpr.append([dev_key, dev_val])
             sxpr.append(dev_sxpr)