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-devel

[Xen-devel] [patch] [xm, xend] passthrough: Add assigned_or_requested_vs

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [patch] [xm, xend] passthrough: Add assigned_or_requested_vslot()
From: Simon Horman <horms@xxxxxxxxxxxx>
Date: Tue, 26 May 2009 16:33:42 +1000
Cc: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
Delivery-date: Mon, 25 May 2009 23:34:07 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.18 (2008-05-17)
Add an accessor to simplify accessing vslot if available,
otherwise requested_vslot.

Lightly tested

Cc: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>

--- 

 tools/python/xen/util/pci.py            |   14 +++++++++++++-
 tools/python/xen/xend/XendDomainInfo.py |   16 ++++------------
 tools/python/xen/xend/server/pciif.py   |   10 +++++-----
 tools/python/xen/xm/main.py             |   12 +++---------
 4 files changed, 25 insertions(+), 27 deletions(-)

Index: xen-unstable.hg/tools/python/xen/util/pci.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/util/pci.py   2009-05-26 
14:17:52.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/util/pci.py        2009-05-26 
14:38:36.000000000 +1000
@@ -138,7 +138,13 @@ def parse_pci_name(pci_name_string):
     func = parse_hex(pci_dev_info['func'])
 
     return (domain, bus, slot, func)
- 
+
+def assigned_or_requested_vslot(dev):
+    if dev.has_key("vslot"):
+        return dev["vslot"]
+    if dev.has_key("requested_vslot"):
+        return dev["requested_vslot"]
+    raise PciDeviceVslotMissing("%s" % dev)
 
 def find_sysfs_mnt():
     try:
@@ -355,6 +361,12 @@ class PciDeviceAssignmentError(Exception
         return 'pci: impproper device assignment spcified: ' + \
             self.message
 
+class PciDeviceVslotMissing(Exception):
+    def __init__(self,msg):
+        self.message = msg
+    def __str__(self):
+        return 'pci: no vslot or requested_vslot: ' + self.message
+
 class PciDevice:
     def __init__(self, domain, bus, slot, func):
         self.domain = domain
Index: xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/XendDomainInfo.py        
2009-05-26 14:37:18.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py     2009-05-26 
16:29:41.000000000 +1000
@@ -38,6 +38,7 @@ from xen.util import asserts
 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.xend import balloon, sxp, uuid, image, arch, osdep
 from xen.xend import XendOptions, XendNode, XendConfig
@@ -621,10 +622,7 @@ class XendDomainInfo:
             pci_conf = self.info['devices'][dev_uuid][1]
             pci_devs = pci_conf['devs']
             for x in pci_devs:
-                if x.has_key('vslot'):
-                    x_vslot = x['vslot']
-                else:
-                    x_vslot = x['requested_vslot']
+                x_vslot = assigned_or_requested_vslot(x)
                 if (int(x_vslot, 16) == int(new_dev['requested_vslot'], 16) and
                    int(x_vslot, 16) != AUTO_PHP_SLOT):
                     raise VmError("vslot %s already have a device." % 
(new_dev['requested_vslot']))
@@ -819,10 +817,7 @@ class XendDomainInfo:
                          int(x['bus'], 16) == int(dev['bus'], 16) and
                          int(x['slot'], 16) == int(dev['slot'], 16) and
                          int(x['func'], 16) == int(dev['func'], 16) ):
-                        if x.has_key('vslot'):
-                            vslot = x['vslot']
-                        else:
-                            vslot = x['requested_vslot']
+                        vslot = assigned_or_requested_vslot(x)
                         break
                 if vslot == AUTO_PHP_SLOT_STR:
                     raise VmError("Device %04x:%02x:%02x.%01x is not connected"
@@ -1119,10 +1114,7 @@ class XendDomainInfo:
         #find the pass-through device with the virtual slot
         devnum = 0
         for x in pci_conf['devs']:
-            if x.has_key('vslot'):
-                x_vslot = x['vslot']
-            else:
-                x_vslot = x['requested_vslot']
+            x_vslot = assigned_or_requested_vslot(x)
             if int(x_vslot, 16) == vslot:
                 break
             devnum += 1
Index: xen-unstable.hg/tools/python/xen/xend/server/pciif.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/server/pciif.py  2009-05-26 
14:37:15.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/server/pciif.py       2009-05-26 
14:38:36.000000000 +1000
@@ -71,15 +71,15 @@ class PciController(DevController):
         pcidevid = 0
         vslots = ""
         for pci_config in config.get('devs', []):
-            vslot = pci_config.get('vslot')
-            if vslot is not None:
-                vslots = vslots + vslot + ";"
+            attached_vslot = pci_config.get('vslot')
+            if attached_vslot is not None:
+                vslots = vslots + attached_vslot + ";"
 
             domain = parse_hex(pci_config.get('domain', 0))
             bus = parse_hex(pci_config.get('bus', 0))
             slot = parse_hex(pci_config.get('slot', 0))
             func = parse_hex(pci_config.get('func', 0))            
-            requested_vslot = parse_hex(pci_config.get('requested_vslot', 0))
+            vslot = parse_hex(assigned_or_requested_vslot(pci_config))
 
             opts = pci_config.get('opts', '')
             if len(opts) > 0:
@@ -90,7 +90,7 @@ class PciController(DevController):
             back['dev-%i' % pcidevid] = "%04x:%02x:%02x.%01x" % \
                                         (domain, bus, slot, func)
             back['uuid-%i' % pcidevid] = pci_config.get('uuid', '')
-            back['vslot-%i' % pcidevid] = "%02x" % requested_vslot
+            back['vslot-%i' % pcidevid] = "%02x" % vslot
             pcidevid += 1
 
         if vslots != "":
Index: xen-unstable.hg/tools/python/xen/xm/main.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xm/main.py    2009-05-26 
14:37:15.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xm/main.py 2009-05-26 14:38:36.000000000 
+1000
@@ -2167,18 +2167,12 @@ def xm_pci_list(args):
 
     has_vslot = False
     for x in devs:
-        if x.has_key('vslot'):
-            if x['vslot'] == "0x%s" % AUTO_PHP_SLOT_STR:
-                x['vslot'] = '-'
-            else:
-                has_vslot = True
-        elif not x.has_key('requested_vslot'):
-            x['vslot'] = '-'
-        elif x['requested_vslot'] == "0x%s" % AUTO_PHP_SLOT_STR:
+       vslot = assigned_or_requested_vslot(x)
+        if int(vslot, 16) == AUTO_PHP_SLOT:
             x['vslot'] = '-'
         else:
+            x['vslot'] = vslot
             has_vslot = True
-            x['vslot'] = x['requested_vslot']
 
     if has_vslot:
         hdr_str = 'VSlt domain   bus   slot   func'

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

<Prev in Thread] Current Thread [Next in Thread>