mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
xend: Add serialise_pci_opts() and split_pci_opts()
This centralises some code. Signed-off-by: Simon Horman <horms@verge.net.au>
This commit is contained in:
1 parent
9995f10739
commit
69cf305aa7
3 files changed
+12
-13
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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)
|
||||
|
||||