From: Simon Horman <horms@verge.net.au>
To: xen-devel@lists.xensource.com
Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com>,
Dexuan Cui <dexuan.cui@intel.com>
Subject: [patch 05/16] xend: pass-through: sxp.merge() cant deal with values being a list
Date: Mon, 15 Jun 2009 11:55:20 +1000 [thread overview]
Message-ID: <20090615015911.779246541@vergenet.net> (raw)
In-Reply-To: 20090615015515.927085604@vergenet.net
[-- Attachment #1: opts-sxp.patch --]
[-- Type: text/plain, Size: 11017 bytes --]
sxp.merge() can't deal with values being a list so instead
of storing pci options as:
[ 'opts', [ 'key1' 'value1'], [ 'key2', 'value2'], ...]
store them as:
[ 'opts', [ 'key1' 'value1'], ['opts', [ 'key2', 'value2']], ...
Cc: Dexuan Cui <dexuan.cui@intel.com>
Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
tools/python/xen/util/pci.py | 18 +++++++++++++--
tools/python/xen/xend/XendConfig.py | 38 +++++++++++++++------------------
tools/python/xen/xend/server/pciif.py | 3 +-
tools/python/xen/xm/create.py | 23 ++++++++-----------
tools/python/xen/xm/main.py | 11 ++++++---
tools/python/xen/xm/xenapi_create.py | 12 +++++-----
6 files changed, 58 insertions(+), 47 deletions(-)
Index: xen-unstable.hg/tools/python/xen/util/pci.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/util/pci.py 2009-06-13 10:32:59.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/util/pci.py 2009-06-13 10:33:14.000000000 +1000
@@ -118,14 +118,26 @@ def PCI_BDF(domain, bus, slot, func):
return (((domain & 0xffff) << 16) | ((bus & 0xff) << 8) |
PCI_DEVFN(slot, func))
+def check_pci_opts(opts):
+ def f((k, v)):
+ if k not in ['msitranslate', 'power_mgmt'] or \
+ not v.lower() in ['0', '1', 'yes', 'no']:
+ raise PciDeviceParseError('Invalid pci option %s=%s: ' % (k, v))
+
+ map(f, opts)
+
def serialise_pci_opts(opts):
- return reduce(lambda x, y: x+','+y, map(lambda (x, y): x+'='+y, opts))
+ return ','.join(map(lambda x: '='.join(x), opts))
def split_pci_opts(opts):
- return map(lambda x: x.split('='), opts.split(','))
+ return map(lambda x: x.split('='),
+ filter(lambda x: x != '', opts.split(',')))
def pci_opts_list_to_sxp(list):
- ['dev'] + map(lambda x: ['opts', x], list)
+ return ['dev'] + map(lambda x: ['opts', x], list)
+
+def pci_opts_list_from_sxp(dev):
+ return map(lambda x: sxp.children(x)[0], sxp.children(dev, 'opts'))
def parse_hex(val):
try:
Index: xen-unstable.hg/tools/python/xen/xend/XendConfig.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/XendConfig.py 2009-06-13 10:32:59.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/XendConfig.py 2009-06-13 10:33:04.000000000 +1000
@@ -36,6 +36,7 @@ from xen.xend.xenstore.xstransact import
from xen.xend.server.BlktapController import blktap_disk_types
from xen.xend.server.netif import randomMAC
from xen.util.blkif import blkdev_name_to_number, blkdev_uname_to_file
+from xen.util.pci import pci_opts_list_from_sxp
from xen.util import xsconstants
import xen.util.auxbin
@@ -1596,11 +1597,10 @@ class XendConfig(dict):
return ''
def pci_convert_dict_to_sxp(self, dev, state, sub_state = None):
- sxp = ['pci', ['dev'] + map(lambda (x, y): [x, y], dev.items()),
- ['state', state]]
+ pci_sxp = ['pci', self.dev_dict_to_sxp(dev), ['state', state]]
if sub_state != None:
- sxp.append(['sub_state', sub_state])
- return sxp
+ pci_sxp.append(['sub_state', sub_state])
+ return pci_sxp
def pci_convert_sxp_to_dict(self, dev_sxp):
"""Convert pci device sxp to dict
@@ -1649,13 +1649,9 @@ class XendConfig(dict):
pci_devs = []
for pci_dev in sxp.children(dev_sxp, 'dev'):
- pci_dev_info = {}
- for opt_val in pci_dev[1:]:
- try:
- opt, val = opt_val
- pci_dev_info[opt] = val
- except (TypeError, ValueError):
- pass
+ pci_dev_info = dict(pci_dev[1:])
+ if 'opts' in pci_dev_info:
+ pci_dev_info['opts'] = pci_opts_list_from_sxp(pci_dev)
# append uuid to each pci device that does't already have one.
if not pci_dev_info.has_key('uuid'):
dpci_uuid = pci_dev_info.get('uuid', uuid.createString())
@@ -1966,6 +1962,15 @@ class XendConfig(dict):
result.extend([u for u in target['devices'].keys() if u not in result])
return result
+ # This includes a generic equivalent of pci_opts_list_to_sxp()
+ def dev_dict_to_sxp(self, dev):
+ def f((key, val)):
+ if isinstance(val, types.ListType):
+ return map(lambda x: [key, x], val)
+ return [[key, val]]
+ dev_sxp = ['dev'] + reduce(lambda x, y: x + y, map(f, dev.items()))
+ return dev_sxp
+
def all_devices_sxpr(self, target = None):
"""Returns the SXPR for all devices in the current configuration."""
sxprs = []
@@ -1988,10 +1993,7 @@ class XendConfig(dict):
if dev_info.has_key('backend'):
sxpr.append(['backend', dev_info['backend']])
for pci_dev_info in dev_info['devs']:
- pci_dev_sxpr = ['dev']
- for opt, val in pci_dev_info.items():
- pci_dev_sxpr.append([opt, val])
- sxpr.append(pci_dev_sxpr)
+ sxpr.append(self.dev_dict_to_sxp(pci_dev_info))
sxprs.append((dev_type, sxpr))
else:
sxpr = self.device_sxpr(dev_type = dev_type,
@@ -2118,11 +2120,7 @@ class XendConfig(dict):
slot = sxp.child_value(dev, 'slot')
func = sxp.child_value(dev, 'func')
vslot = sxp.child_value(dev, 'vslot')
- opts = ''
- for opt in sxp.child_value(dev, 'opts', []):
- if opts:
- opts += ','
- opts += '%s=%s' % (opt[0], str(opt[1]))
+ opts = pci_opts_list_from_sxp(dev)
pci.append([domain, bus, slot, func, vslot, opts])
self['platform']['pci'] = pci
Index: xen-unstable.hg/tools/python/xen/xend/server/pciif.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/server/pciif.py 2009-06-13 10:32:59.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/server/pciif.py 2009-06-13 10:33:04.000000000 +1000
@@ -222,7 +222,8 @@ class PciController(DevController):
dev_sxpr = ['dev']
for dev_key, dev_val in dev.items():
if dev_key == 'opts':
- dev_sxpr.append(['opts', split_pci_opts(dev_val)])
+ opts_sxpr = pci_opts_list_to_sxp(split_pci_opts(dev_val))
+ dev_sxpr = sxp.merge(dev_sxpr, opts_sxpr)
else:
dev_sxpr.append([dev_key, dev_val])
sxpr.append(dev_sxpr)
Index: xen-unstable.hg/tools/python/xen/xm/create.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xm/create.py 2009-06-13 10:32:59.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xm/create.py 2009-06-13 10:33:04.000000000 +1000
@@ -38,6 +38,8 @@ from xen.util import vscsi_util
import xen.util.xsm.xsm as security
from xen.xm.main import serverType, SERVER_XEN_API, get_single_vm
from xen.util import utils, auxbin
+from xen.util.pci import split_pci_opts, check_pci_opts, \
+ pci_opts_list_to_sxp
from xen.xm.opts import *
@@ -705,23 +707,18 @@ def configure_pci(config_devs, vals):
"""
config_pci = []
for (domain, bus, slot, func, vslot, opts) in vals.pci:
- config_pci_opts = []
- d = comma_sep_kv_to_dict(opts)
-
- def f(k):
- if k not in ['msitranslate', 'power_mgmt']:
- err('Invalid pci option: ' + k)
-
- config_pci_opts.append([k, d[k]])
-
config_pci_bdf = ['dev', ['domain', domain], ['bus', bus], \
['slot', slot], ['func', func],
['vslot', vslot]]
- map(f, d.keys())
- if len(config_pci_opts)>0:
- config_pci_bdf.append(['opts', config_pci_opts])
- config_pci.append(config_pci_bdf)
+ opts_list = split_pci_opts(opts)
+ try:
+ check_pci_opts(opts_list)
+ except PciDeviceParseError, ex:
+ err(str(ex))
+
+ config_opts = pci_opts_list_to_sxp(split_pci_opts(opts))
+ config_pci.append(sxp.merge(config_pci_bdf, config_opts))
if len(config_pci)>0:
config_pci.insert(0, 'pci')
Index: xen-unstable.hg/tools/python/xen/xm/main.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xm/main.py 2009-06-13 10:32:59.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xm/main.py 2009-06-13 10:33:04.000000000 +1000
@@ -2504,12 +2504,15 @@ def parse_pci_configuration(args, state,
['slot', '0x'+ pci_dev_info['slot']],
['func', '0x'+ pci_dev_info['func']],
['vslot', '0x%x' % int(vslot, 16)]]
- if len(opts) > 0:
- pci_bdf.append(['opts', opts])
- pci.append(pci_bdf)
-
except:
raise OptionError("Invalid argument: %s %s" % (pci_dev_str, vslot))
+
+ try:
+ check_pci_opts(opts)
+ except PciDeviceParseError, ex:
+ raise OptionError(str(ex))
+
+ pci.append(sxp.merge(pci_bdf, pci_opts_list_to_sxp(opts)))
pci.append(['state', state])
return (dom, pci)
Index: xen-unstable.hg/tools/python/xen/xm/xenapi_create.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xm/xenapi_create.py 2009-06-13 10:32:59.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xm/xenapi_create.py 2009-06-13 10:33:04.000000000 +1000
@@ -26,6 +26,7 @@ from xen.xend.XendAPIConstants import XE
XEN_API_ON_CRASH_BEHAVIOUR
from xen.xm.opts import OptionError
from xen.util import xsconstants
+from xen.util.pci import pci_opts_list_from_sxp
from xen.util.path import SHAREDIR
import xen.util.xsm.xsm as security
@@ -945,12 +946,11 @@ class sxp2xml:
= get_child_by_name(dev_sxp, "func", "0")
pci.attributes["vslot"] \
= get_child_by_name(dev_sxp, "vslot", "0")
- for opt in get_child_by_name(dev_sxp, "opts", ""):
- if len(opt) > 0:
- pci_opt = document.createElement("pci_opt")
- pci_opt.attributes["key"] = opt[0]
- pci_opt.attributes["value"] = opt[1]
- pci.appendChild(pci_opt)
+ for opt in pci_opts_list_from_sxp(dev_sxp):
+ pci_opt = document.createElement("pci_opt")
+ pci_opt.attributes["key"] = opt[0]
+ pci_opt.attributes["value"] = opt[1]
+ pci.appendChild(pci_opt)
pcis.append(pci)
--
next prev parent reply other threads:[~2009-06-15 1:55 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-15 1:55 [patch 00/16] xend: pass-through: various clean-ups and infrastructure Simon Horman
2009-06-15 1:55 ` [patch 01/16] xend: pass-through: Only call setupOneDevice() once per device Simon Horman
2009-06-15 1:55 ` [patch 02/16] xend: pass-through: fix typo: spx -> sxp Simon Horman
2009-06-15 1:55 ` [patch 03/16] xend: pass-through: tidy up PciController() Simon Horman
2009-06-15 1:55 ` [patch 04/16] xend: pass-through: cleanupDevice: move and remove recently added vslot entry Simon Horman
2009-06-15 1:55 ` Simon Horman [this message]
2009-06-15 1:55 ` [patch 06/16] xend: pass-through: Remove PciDeviceNotFoundError, it is never used Simon Horman
2009-06-15 1:55 ` [patch 07/16] xend: pass-through: Use PCIDevice as the parameter for the constructor for PCIQuirk Simon Horman
2009-06-15 1:55 ` [patch 08/16] xend: pass-through: Common parse_pci_name() Simon Horman
2009-06-16 10:43 ` Keir Fraser
2009-06-16 11:20 ` Simon Horman
2009-06-16 12:22 ` Keir Fraser
2009-06-16 12:38 ` Simon Horman
2009-06-15 1:55 ` [patch 09/16] xend: pass-through: Use common parsing code in preprocess_pci() Simon Horman
2009-06-15 1:55 ` [patch 10/16] xend: pass-through: Add pci_dict_cmp() Simon Horman
2009-06-15 1:55 ` [patch 11/16] xend: pass-through: Move pci conversion functions to pci.py Simon Horman
2009-06-15 5:58 ` [patch 11/16] xend: pass-through: Move pci conversionfunctions " Masaki Kanno
2009-06-15 6:15 ` Simon Horman
2009-06-15 7:02 ` [patch 11/16] xend: pass-through: Move pciconversionfunctions " Masaki Kanno
2009-06-15 9:04 ` Simon Horman
2009-06-15 11:58 ` [patch v2] xend: pass-through: Move pci conversion functions " Simon Horman
2009-06-15 23:36 ` [patch 11/16 v3] " Simon Horman
2009-06-15 1:55 ` [patch 12/16] xend: pass-through: Use generic code in pci_opts_list_to_sxp() Simon Horman
2009-06-15 11:59 ` [patch v2] " Simon Horman
2009-06-15 1:55 ` [patch 13/16] xend: pass-through: Add pci_tuple_to_dict() Simon Horman
2009-06-15 1:55 ` [patch 14/16] xend: pass-through: Use common parsing code in parse_pci_configuration() Simon Horman
2009-06-15 1:55 ` [patch 15/16] xend: pass-through: Use common parsing code in getDeviceConfiguration() Simon Horman
2009-06-15 1:55 ` [patch 16/16] xend: pass-through: Clean up hvm_destroyPCIDevice() Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090615015911.779246541@vergenet.net \
--to=horms@verge.net.au \
--cc=dexuan.cui@intel.com \
--cc=kanno.masaki@jp.fujitsu.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.