Skip to contentSkip to conversation

passthrough: Add assigned_or_requested_vslot()

PATCH Superseded Simon Horman 2 participants 3 messages May 26, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 passthrough: Add assigned_or_requested_vslot()

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

Lightly tested

---

 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(-)
tools/python/xen/util/pci.py +13 -1
Index: xen-unstable.hg/tools/python/xen/util/pci.py
===================================================================
@@ -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
tools/python/xen/xend/XendDomainInfo.py +4 -12
Index: xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py
===================================================================
@@ -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
tools/python/xen/xend/server/pciif.py +5 -5
Index: xen-unstable.hg/tools/python/xen/xend/server/pciif.py
===================================================================
@@ -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 != "":
tools/python/xen/xm/main.py +3 -9
Index: xen-unstable.hg/tools/python/xen/xm/main.py
===================================================================
@@ -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'
#1 lore raw

Hi Simon,

Great!! Your patch is of importance.
If without your patch, we cannot start domains. I found a problem about starting domains. The reproduction operations of the problem are as follows.

Step to Reproduce:
1. xm start <domain>
2. xm pci-attach <domain> **:**.* *
3. Shutdown guest OS on <domain>
4. xm start <domain> ---> fail

Your patch has solved the problem.

Trivial comment:
The following line includes Tab indent.

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) <------------ here!!
+ 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'

Best regards,
Kan

Quoted 47 lines · Simon Horman

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

Lightly tested

---

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

tools/python/xen/util/pci.py +7 -1
@@ -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:

tools/python/xen/util/pci.py +6 -0
@@ -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
+
Quoted 6 lines

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

Quoted 50 lines

14:37:18.000000000 +1000
+++ xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py 2009-05-26 16:
29:41.000000000 +1000

(quoted diff) +0 -0
@@ -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

tools/python/xen/xend/XendDomainInfo.py +1 -4
@@ -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']))

tools/python/xen/xend/XendDomainInfo.py +1 -4
@@ -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"

tools/python/xen/xend/XendDomainInfo.py +1 -4
@@ -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
Quoted 5 lines

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:

Quoted 64 lines

36.000000000 +1000

tools/python/xen/xend/server/pciif.py +4 -4
@@ -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:
tools/python/xen/xend/server/pciif.py +1 -1
@@ -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

tools/python/xen/xm/main.py +3 -9
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 7 lines · Masaki Kanno

Hi Simon,

Great!! Your patch is of importance.
If without your patch, we cannot start domains. I found a problem about starting domains. The reproduction operations of the problem are as follows.

Quoted 7 lines

Step to Reproduce:
1. xm start <domain>
2. xm pci-attach <domain> **:**.* *
3. Shutdown guest OS on <domain>
4. xm start <domain> ---> fail

Your patch has solved the problem.

Great!

Quoted 2 lines

Trivial comment:
The following line includes Tab indent.

Sorry, I will fix that and repost.

Quoted 28 lines

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

tools/python/xen/xm/main.py +3 -9
@@ -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)     <------------ here!!
+        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'