WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xend: pass-through: Move pci conversion f

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xend: pass-through: Move pci conversion functions to pci.py
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 19 Jun 2009 00:56:11 -0700
Delivery-date: Fri, 19 Jun 2009 01:03:12 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1245220607 -3600
# Node ID a4036225c1688a99cddba4e3b7cdbea0326757c9
# Parent  60588f1f055f40debf5b9f65dc012009d36c8cd1
xend: pass-through: Move pci conversion functions to pci.py

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

Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>
---
 tools/python/xen/util/pci.py            |   75 ++++++++++++++++++++++++++
 tools/python/xen/xend/XendConfig.py     |   91 +-------------------------------
 tools/python/xen/xend/XendDomainInfo.py |   10 ++-
 tools/python/xen/xend/XendSXPDev.py     |   14 ++++
 4 files changed, 100 insertions(+), 90 deletions(-)

diff -r 60588f1f055f -r a4036225c168 tools/python/xen/util/pci.py
--- a/tools/python/xen/util/pci.py      Wed Jun 17 07:35:51 2009 +0100
+++ b/tools/python/xen/util/pci.py      Wed Jun 17 07:36:47 2009 +0100
@@ -14,8 +14,10 @@ import time
 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
+from xen.xend.XendSXPDev import dev_dict_to_sxp
 
 PROC_PCI_PATH = '/proc/bus/pci/devices'
 PROC_PCI_NUM_RESOURCES = 7
@@ -138,6 +140,79 @@ 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'))
+
+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:
diff -r 60588f1f055f -r a4036225c168 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Wed Jun 17 07:35:51 2009 +0100
+++ b/tools/python/xen/xend/XendConfig.py       Wed Jun 17 07:36:47 2009 +0100
@@ -36,7 +36,8 @@ from xen.xend.server.BlktapController im
 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, pci_convert_sxp_to_dict
+from xen.xend.XendSXPDev import dev_dict_to_sxp
 from xen.util import xsconstants
 import xen.util.auxbin
 
@@ -1295,7 +1296,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.
@@ -1604,79 +1605,6 @@ class XendConfig(dict):
                 return dev_uuid
 
         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
@@ -1848,7 +1776,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
@@ -1971,15 +1899,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 = []
@@ -2002,7 +1921,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,
diff -r 60588f1f055f -r a4036225c168 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Wed Jun 17 07:35:51 2009 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py   Wed Jun 17 07:36:47 2009 +0100
@@ -40,7 +40,9 @@ import xen.util.xsm.xsm as security
 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
diff -r 60588f1f055f -r a4036225c168 tools/python/xen/xend/XendSXPDev.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/python/xen/xend/XendSXPDev.py       Wed Jun 17 07:36:47 2009 +0100
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+#
+# Helper functions for dealing with the sxp representation of devices
+
+import types
+
+# 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

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xend: pass-through: Move pci conversion functions to pci.py, Xen patchbot-unstable <=