ia64/xen-unstable
changeset 19681:f6dab6ff90c8
xend: Add serialise_pci_opts() and split_pci_opts()
This centralises some code.
Signed-off-by: Simon Horman <horms@verge.net.au>
This centralises some code.
Signed-off-by: Simon Horman <horms@verge.net.au>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Fri May 29 09:33:06 2009 +0100 (2009-05-29) |
parents | 401a793c4b42 |
children | bfa933a4628d |
files | tools/python/xen/util/pci.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/pciif.py |
line diff
1.1 --- a/tools/python/xen/util/pci.py Fri May 29 09:32:40 2009 +0100 1.2 +++ b/tools/python/xen/util/pci.py Fri May 29 09:33:06 2009 +0100 1.3 @@ -114,6 +114,12 @@ PAGE_MASK=~(PAGE_SIZE - 1) 1.4 def PCI_DEVFN(slot, func): 1.5 return ((((slot) & 0x1f) << 3) | ((func) & 0x07)) 1.6 1.7 +def serialise_pci_opts(opts): 1.8 + return reduce(lambda x, y: x+','+y, map(lambda (x, y): x+'='+y, opts)) 1.9 + 1.10 +def split_pci_opts(opts): 1.11 + return map(lambda x: x.split('='), opts.split(',')) 1.12 + 1.13 def parse_hex(val): 1.14 try: 1.15 if isinstance(val, types.StringTypes):
2.1 --- a/tools/python/xen/xend/XendDomainInfo.py Fri May 29 09:32:40 2009 +0100 2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Fri May 29 09:33:06 2009 +0100 2.3 @@ -39,7 +39,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 +from xen.util.pci import assigned_or_requested_vslot, serialise_pci_opts 2.9 2.10 from xen.xend import balloon, sxp, uuid, image, arch 2.11 from xen.xend import XendOptions, XendNode, XendConfig 2.12 @@ -739,10 +739,8 @@ class XendDomainInfo: 2.13 2.14 if self.domid is not None: 2.15 opts = '' 2.16 - if 'opts' in new_dev and len(new_dev['opts']) > 0: 2.17 - config_opts = new_dev['opts'] 2.18 - config_opts = map(lambda (x, y): x+'='+y, config_opts) 2.19 - opts = ',' + reduce(lambda x, y: x+','+y, config_opts) 2.20 + if new_dev.has_key('opts'): 2.21 + opts = ',' + serialise_pci_opts(new_dev['opts']) 2.22 2.23 bdf_str = "%s:%s:%s.%s@%s%s" % (new_dev['domain'], 2.24 new_dev['bus'],
3.1 --- a/tools/python/xen/xend/server/pciif.py Fri May 29 09:32:40 2009 +0100 3.2 +++ b/tools/python/xen/xend/server/pciif.py Fri May 29 09:33:06 2009 +0100 3.3 @@ -76,10 +76,8 @@ class PciController(DevController): 3.4 func = parse_hex(pci_config.get('func', 0)) 3.5 vslot = parse_hex(assigned_or_requested_vslot(pci_config)) 3.6 3.7 - opts = pci_config.get('opts', '') 3.8 - if len(opts) > 0: 3.9 - opts = map(lambda (x, y): x+'='+y, opts) 3.10 - opts = reduce(lambda x, y: x+','+y, opts) 3.11 + if pci_config.has_key('opts'): 3.12 + opts = serialise_pci_opts(pci_config['opts']) 3.13 back['opts-%i' % pcidevid] = opts 3.14 3.15 back['dev-%i' % pcidevid] = "%04x:%02x:%02x.%01x" % \ 3.16 @@ -226,10 +224,7 @@ class PciController(DevController): 3.17 dev_sxpr = ['dev'] 3.18 for dev_key, dev_val in dev.items(): 3.19 if dev_key == 'opts': 3.20 - opts = [] 3.21 - for opt in dev_val.split(','): 3.22 - opts.append(opt.split('=')) 3.23 - dev_sxpr.append(['opts', opts]) 3.24 + dev_sxpr.append(['opts', split_pci_opts(dev_val)]) 3.25 else: 3.26 dev_sxpr.append([dev_key, dev_val]) 3.27 sxpr.append(dev_sxpr)