Simon Horman
2009-May-26  06:33 UTC
[Xen-devel] [patch] [xm, xend] passthrough: Add assigned_or_requested_vslot()
Add an accessor to simplify accessing vslot if available,
otherwise requested_vslot.
Lightly tested
Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
--- 
 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@lists.xensource.com
http://lists.xensource.com/xen-devel
Masaki Kanno
2009-May-26  07:24 UTC
Re: [Xen-devel] [patch] [xm, xend] passthrough: Add assigned_or_requested_vslot()
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
Tue, 26 May 2009 16:33:42 +1000, Simon Horman wrote:
>Add an accessor to simplify accessing vslot if available,
>otherwise requested_vslot.
>
>Lightly tested
>
>Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
>Signed-off-by: Simon Horman <horms@verge.net.au>
>
>--- 
>
> 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@lists.xensource.com
>http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Simon Horman
2009-May-26  08:41 UTC
Re: [Xen-devel] [patch] [xm, xend] passthrough: Add assigned_or_requested_vslot()
On Tue, May 26, 2009 at 04:24:05PM +0900, Masaki Kanno wrote:> 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.Great!> Trivial comment: > The following line includes Tab indent.Sorry, I will fix that and repost.> 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''_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel