[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [patch] xend: Add serialise_pci_opts() and split_pci_opts()



This centralises some code.

Cc: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>

--- 

 tools/python/xen/util/pci.py            |    6 ++++++
 tools/python/xen/xend/XendDomainInfo.py |    8 +++-----
 tools/python/xen/xend/server/pciif.py   |   11 +++--------
 3 files changed, 12 insertions(+), 13 deletions(-)

Index: xen-unstable.hg/tools/python/xen/util/pci.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/util/pci.py   2009-05-28 
20:35:33.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/util/pci.py        2009-05-28 
21:40:55.000000000 +1000
@@ -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: xen-unstable.hg/tools/python/xen/xend/server/pciif.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/server/pciif.py  2009-05-28 
20:38:17.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/server/pciif.py       2009-05-28 
22:05:20.000000000 +1000
@@ -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)
Index: xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/XendDomainInfo.py        
2009-05-28 20:55:58.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py     2009-05-28 
22:05:45.000000000 +1000
@@ -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'],

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.