[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xm, xend: passthrough: Add assigned_or_requested_vslot()



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1243328650 -3600
# Node ID dc7de36c94e355883d6736bc4f39243cea45fdaf
# Parent  caa8c0e2d6f6dc939ce4e828ff49a87793bbd6d0
xm, xend: passthrough: Add assigned_or_requested_vslot()

Add an accessor to simplify accessing vslot if available,
otherwise requested_vslot.

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(-)

diff -r caa8c0e2d6f6 -r dc7de36c94e3 tools/python/xen/util/pci.py
--- a/tools/python/xen/util/pci.py      Tue May 26 10:03:09 2009 +0100
+++ b/tools/python/xen/util/pci.py      Tue May 26 10:04:10 2009 +0100
@@ -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:
@@ -354,6 +360,12 @@ class PciDeviceAssignmentError(Exception
     def __str__(self):
         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):
diff -r caa8c0e2d6f6 -r dc7de36c94e3 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Tue May 26 10:03:09 2009 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py   Tue May 26 10:04:10 2009 +0100
@@ -38,6 +38,7 @@ from xen.util.blkif import blkdev_uname_
 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
 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
diff -r caa8c0e2d6f6 -r dc7de36c94e3 tools/python/xen/xend/server/pciif.py
--- a/tools/python/xen/xend/server/pciif.py     Tue May 26 10:03:09 2009 +0100
+++ b/tools/python/xen/xend/server/pciif.py     Tue May 26 10:04:10 2009 +0100
@@ -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 != "":
diff -r caa8c0e2d6f6 -r dc7de36c94e3 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Tue May 26 10:03:09 2009 +0100
+++ b/tools/python/xen/xm/main.py       Tue May 26 10:04:10 2009 +0100
@@ -2168,18 +2168,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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.