All of lore.kernel.org
 help / color / mirror / Atom feed
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 11/16] xend: pass-through: Move pci conversion functions to pci.py
Date: Mon, 15 Jun 2009 11:55:26 +1000	[thread overview]
Message-ID: <20090615015912.912200267@vergenet.net> (raw)
In-Reply-To: 20090615015515.927085604@vergenet.net

[-- Attachment #1: move-pci_convert_dict_to_sxp.patch --]
[-- Type: text/plain, Size: 12054 bytes --]

Move dev_dict_to_sxp(), pci_convert_dict_to_sxp() and
pci_convert_sxp_to_dict() to pci.py, where other similar functions live.
This makes them accessible outside of the XendConfig class.

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            |   83 ++++++++++++++++++++++++++++
 tools/python/xen/xend/XendConfig.py     |   91 +------------------------------
 tools/python/xen/xend/XendDomainInfo.py |   10 ++-
 3 files changed, 94 insertions(+), 90 deletions(-)

Index: xen-unstable.hg/tools/python/xen/util/pci.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/util/pci.py	2009-06-13 21:39:44.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/util/pci.py	2009-06-13 21:39:56.000000000 +1000
@@ -14,6 +14,7 @@ import struct
 import time
 import threading
 from xen.util import utils
+from xen.xend import uuid
 from xen.xend import sxp
 from xen.xend.XendConstants import AUTO_PHP_SLOT
 
@@ -139,6 +140,88 @@ def pci_opts_list_to_sxp(list):
 def pci_opts_list_from_sxp(dev):
     return map(lambda x: sxp.children(x)[0], sxp.children(dev, 'opts'))
 
+# This includes a generic equivalent of pci_opts_list_to_sxp()
+def dev_dict_to_sxp(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 pci_convert_dict_to_sxp(dev, state, sub_state = None):
+    pci_sxp = ['pci', dev_dict_to_sxp(dev), ['state', state]]
+    if sub_state != None:
+        pci_sxp.append(['sub_state', sub_state])
+    return pci_sxp
+
+def pci_convert_sxp_to_dict(dev_sxp):
+    """Convert pci device sxp to dict
+    @param dev_sxp: device configuration
+    @type  dev_sxp: SXP object (parsed config)
+    @return: dev_config
+    @rtype: dictionary
+    """
+    # Parsing the device SXP's. In most cases, the SXP looks
+    # like this:
+    #
+    # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.5]]]
+    #
+    # However, for PCI devices it looks like this:
+    #
+    # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1], [func, 2]]]
+    #
+    # It seems the reasoning for this difference is because
+    # pciif.py needs all the PCI device configurations at
+    # the same time when creating the devices.
+    #
+    # To further complicate matters, Xen 2.0 configuration format
+    # uses the following for pci device configuration:
+    #
+    # [device, [pci, [domain, 0], [bus, 0], [dev, 1], [func, 2]]]
+
+    # For PCI device hotplug support, the SXP of PCI devices is
+    # extendend like this:
+    #
+    # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1], [func, 2],
+    #                      [vslot, 0]],
+    #                [state, 'Initialising']]]
+    #
+    # 'vslot' shows the virtual hotplug slot number which the PCI device
+    # is inserted in. This is only effective for HVM domains.
+    #
+    # state 'Initialising' indicates that the device is being attached,
+    # while state 'Closing' indicates that the device is being detached.
+    #
+    # The Dict looks like this:
+    #
+    # { devs: [{domain: 0, bus: 0, slot: 1, func: 2, vslot: 0}],
+    #   states: ['Initialising'] }
+
+    dev_config = {}
+
+    pci_devs = []
+    for pci_dev in sxp.children(dev_sxp, 'dev'):
+        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())
+            pci_dev_info['uuid'] = dpci_uuid
+        pci_devs.append(pci_dev_info)
+    dev_config['devs'] = pci_devs
+
+    pci_states = []
+    for pci_state in sxp.children(dev_sxp, 'state'):
+        try:
+            pci_states.append(pci_state[1])
+        except IndexError:
+            raise XendError("Error reading state while parsing pci sxp")
+    dev_config['states'] = pci_states
+
+    return dev_config
+
 def parse_hex(val):
     try:
         if isinstance(val, types.StringTypes):
Index: xen-unstable.hg/tools/python/xen/xend/XendConfig.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/XendConfig.py	2009-06-13 21:39:44.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/XendConfig.py	2009-06-13 21:39:56.000000000 +1000
@@ -36,7 +36,8 @@ 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.pci import pci_opts_list_from_sxp, dev_dict_to_sxp, \
+                         pci_convert_sxp_to_dict
 from xen.util import xsconstants
 import xen.util.auxbin
 
@@ -1296,7 +1297,7 @@ class XendConfig(dict):
                 pci_devs_uuid = sxp.child_value(config, 'uuid',
                                                 uuid.createString())
 
-                pci_dict = self.pci_convert_sxp_to_dict(config)
+                pci_dict = pci_convert_sxp_to_dict(config)
                 pci_devs = pci_dict['devs']
 
                 # create XenAPI DPCI objects.
@@ -1596,79 +1597,6 @@ class XendConfig(dict):
 
         return ''
 
-    def pci_convert_dict_to_sxp(self, dev, state, sub_state = None):
-        pci_sxp = ['pci', self.dev_dict_to_sxp(dev), ['state', state]]
-        if sub_state != None:
-            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
-        @param dev_sxp: device configuration
-        @type  dev_sxp: SXP object (parsed config)
-        @return: dev_config
-        @rtype: dictionary
-        """
-        # Parsing the device SXP's. In most cases, the SXP looks
-        # like this:
-        #
-        # [device, [vif, [mac, xx:xx:xx:xx:xx:xx], [ip 1.3.4.5]]]
-        #
-        # However, for PCI devices it looks like this:
-        #
-        # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1], [func, 2]]]
-        #
-        # It seems the reasoning for this difference is because
-        # pciif.py needs all the PCI device configurations at
-        # the same time when creating the devices.
-        #
-        # To further complicate matters, Xen 2.0 configuration format
-        # uses the following for pci device configuration:
-        #
-        # [device, [pci, [domain, 0], [bus, 0], [dev, 1], [func, 2]]]
-
-        # For PCI device hotplug support, the SXP of PCI devices is
-        # extendend like this:
-        #
-        # [device, [pci, [dev, [domain, 0], [bus, 0], [slot, 1], [func, 2],
-        #                      [vslot, 0]],
-        #                [state, 'Initialising']]]
-        #
-        # 'vslot' shows the virtual hotplug slot number which the PCI device
-        # is inserted in. This is only effective for HVM domains.
-        #
-        # state 'Initialising' indicates that the device is being attached,
-        # while state 'Closing' indicates that the device is being detached.
-        #
-        # The Dict looks like this:
-        #
-        # { devs: [{domain: 0, bus: 0, slot: 1, func: 2, vslot: 0}],
-        #   states: ['Initialising'] }
-
-        dev_config = {}
-
-        pci_devs = []
-        for pci_dev in sxp.children(dev_sxp, 'dev'):
-            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())
-                pci_dev_info['uuid'] = dpci_uuid
-            pci_devs.append(pci_dev_info)
-        dev_config['devs'] = pci_devs 
-
-        pci_states = []
-        for pci_state in sxp.children(dev_sxp, 'state'):
-            try:
-                pci_states.append(pci_state[1])
-            except IndexError:
-                raise XendError("Error reading state while parsing pci sxp")
-        dev_config['states'] = pci_states
-
-        return dev_config
-
     def vscsi_convert_sxp_to_dict(self, dev_sxp):
         """Convert vscsi device sxp to dict
         @param dev_sxp: device configuration
@@ -1839,7 +1767,7 @@ class XendConfig(dict):
             dev_type, dev_info = self['devices'][dev_uuid]
 
             if dev_type == 'pci': # Special case for pci
-                pci_dict = self.pci_convert_sxp_to_dict(config)
+                pci_dict = pci_convert_sxp_to_dict(config)
                 pci_devs = pci_dict['devs']
 
                 # destroy existing XenAPI DPCI objects
@@ -1962,15 +1890,6 @@ 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 = []
@@ -1993,7 +1912,7 @@ class XendConfig(dict):
                     if dev_info.has_key('backend'):
                         sxpr.append(['backend', dev_info['backend']])
                 for pci_dev_info in dev_info['devs']:
-                    sxpr.append(self.dev_dict_to_sxp(pci_dev_info))
+                    sxpr.append(dev_dict_to_sxp(pci_dev_info))
                 sxprs.append((dev_type, sxpr))
             else:
                 sxpr = self.device_sxpr(dev_type = dev_type,
Index: xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/XendDomainInfo.py	2009-06-13 21:39:44.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py	2009-06-13 21:40:34.000000000 +1000
@@ -40,7 +40,9 @@ from xen.util.blkif import blkdev_uname_
 import xen.util.xsm.xsm as security
 from xen.util import xsconstants
 from xen.util.pci import serialise_pci_opts, pci_opts_list_to_sxp, \
-                         pci_dict_to_bdf_str, pci_dict_to_xc_str, pci_dict_cmp
+                         pci_dict_to_bdf_str, pci_dict_to_xc_str, \
+                         pci_convert_sxp_to_dict, pci_convert_dict_to_sxp, \
+                         pci_dict_cmp
 
 from xen.xend import balloon, sxp, uuid, image, arch
 from xen.xend import XendOptions, XendNode, XendConfig
@@ -616,8 +618,8 @@ class XendDomainInfo:
         pci_conf = self.info['devices'][dev_uuid][1]
         pci_devs = pci_conf['devs']
         request = map(lambda x:
-                      self.info.pci_convert_dict_to_sxp(x, 'Initialising',
-                                                        'Booting'), pci_devs)
+                      pci_convert_dict_to_sxp(x, 'Initialising', 'Booting'),
+                      pci_devs)
 
         for i in request:
                 self.pci_device_configure(i)
@@ -815,7 +817,7 @@ class XendDomainInfo:
             raise XendError("Cannot detach when pci platform does not exist")
 
         pci_dev = sxp.children(dev_sxp, 'dev')[0]
-        dev_config = self.info.pci_convert_sxp_to_dict(dev_sxp)
+        dev_config = pci_convert_sxp_to_dict(dev_sxp)
         dev = dev_config['devs'][0]
                 
         # Do HVM specific processing

-- 

  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 ` [patch 05/16] xend: pass-through: sxp.merge() cant deal with values being a list Simon Horman
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 ` Simon Horman [this message]
2009-06-15  5:58   ` [patch 11/16] xend: pass-through: Move pci conversionfunctions to pci.py 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=20090615015912.912200267@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.