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] Fix 'xm pci_list_assignable_devices'

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] Fix 'xm pci_list_assignable_devices'
From: Yosuke Iwamatsu <y-iwamatsu@xxxxxxxxxxxxx>
Date: Wed, 25 Mar 2009 16:47:10 +0900
Delivery-date: Wed, 25 Mar 2009 00:48:15 -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: Thunderbird 2.0.0.21 (Windows/20090302)
The current implementation of 'xm pci-list-assignable-devices' command
has a problem that it directly invokes hypercall using xen.lowlevel.xc.
This is probably based on an assumption that the command is executed on
the host itself, but in fact there are cases xm commands can be executed
on a remote server through xmlrpc.
So this patch makes the xm command just inquire of xend about the
information of available devices.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@xxxxxxxxxxxxx>

diff -r 0b13d9787622 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Tue Mar 24 06:55:29 2009 +0000
+++ b/tools/python/xen/xend/XendNode.py Wed Mar 25 10:48:24 2009 +0900
@@ -802,6 +802,43 @@
 
         return [[k, info[k]] for k in ITEM_ORDER]
 
+
+    def pciinfo(self):
+        # Each element of dev_list is a PciDevice
+        dev_list = PciUtil.find_all_devices_owned_by_pciback()
+ 
+        # Each element of devs_list is a list of PciDevice
+        devs_list = PciUtil.check_FLR_capability(dev_list)
+ 
+        devs_list = PciUtil.check_mmio_bar(devs_list)
+ 
+        # Check if the devices have been assigned to guests.
+        final_devs_list = []
+        for dev_list in devs_list:
+            available = True
+            for d in dev_list:
+                pci_str = '0x%x,0x%x,0x%x,0x%x' %(d.domain, d.bus, d.slot, 
d.func)
+                # Xen doesn't care what the domid is, so we pass 0 here...
+                domid = 0
+                bdf = self.xc.test_assign_device(domid, pci_str)
+                if bdf != 0:
+                    available = False
+                    break
+            if available:
+                final_devs_list = final_devs_list + [dev_list]
+
+        pci_sxp_list = []
+        for dev_list in final_devs_list:
+            for d in dev_list:
+                pci_sxp = ['dev', ['domain', '0x%04x' % d.domain],
+                                  ['bus', '0x%02x' % d.bus],
+                                  ['slot', '0x%02x' % d.slot],
+                                  ['func', '0x%x' % d.func]]
+                pci_sxp_list.append(pci_sxp)
+
+        return pci_sxp_list
+ 
+
     def xenschedinfo(self):
         sched_id = self.xc.sched_id_get()
         if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
diff -r 0b13d9787622 tools/python/xen/xend/server/XMLRPCServer.py
--- a/tools/python/xen/xend/server/XMLRPCServer.py      Tue Mar 24 06:55:29 
2009 +0000
+++ b/tools/python/xen/xend/server/XMLRPCServer.py      Wed Mar 25 10:48:24 
2009 +0900
@@ -198,7 +198,8 @@
                     self.server.register_function(fn, "xend.domain.%s" % 
name[7:])
 
         # Functions in XendNode and XendDmesg
-        for type, lst, n in [(XendNode, ['info', 'send_debug_keys'], 'node'),
+        for type, lst, n in [(XendNode, ['info', 'pciinfo', 'send_debug_keys'],
+                             'node'),
                              (XendDmesg, ['info', 'clear'], 'node.dmesg')]:
             inst = type.instance()
             for name in lst:
diff -r 0b13d9787622 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Tue Mar 24 06:55:29 2009 +0000
+++ b/tools/python/xen/xm/main.py       Wed Mar 25 10:48:24 2009 +0900
@@ -57,13 +57,6 @@
 from xen.util.acmpolicy import ACM_LABEL_UNLABELED_DISPLAY
 
 import XenAPI
-
-import xen.lowlevel.xc
-try:
-    xc = xen.lowlevel.xc.xc()
-except Exception, ex:
-    print >>sys.stderr, ("Is xen kernel running?")
-    sys.exit(1)
 
 import inspect
 from xen.xend import XendOptions
@@ -2188,34 +2181,28 @@
             hdr = 1
         print ( fmt_str % x )
 
+
+def parse_pci_info(info):
+    def get_info(n, t, d):
+        return t(sxp.child_value(info, n, d))
+    return {
+        'domain' : get_info('domain', parse_hex, 0),
+        'bus'    : get_info('bus', parse_hex, -1),
+        'slot'   : get_info('slot', parse_hex, -1),
+        'func'   : get_info('func', parse_hex, -1)
+        }
+
 def xm_pci_list_assignable_devices(args):
-    # Each element of dev_list is a PciDevice
-    dev_list = find_all_devices_owned_by_pciback()
+    xenapi_unsupported()
+    arg_check(args, "pci-list-assignable-devices", 0)
 
-    # Each element of devs_list is a list of PciDevice
-    devs_list = check_FLR_capability(dev_list)
+    devs =  server.xend.node.pciinfo()
+ 
+    fmt_str = "%(domain)04x:%(bus)02x:%(slot)02x:%(func)01x"
+    for x in devs:
+        pci = parse_pci_info(x)
+        print fmt_str % pci
 
-    devs_list = check_mmio_bar(devs_list)
-
-    # Check if the devices have been assigned to guests.
-    final_devs_list = []
-    for dev_list in devs_list:
-        available = True
-        for d in dev_list:
-            pci_str = '0x%x,0x%x,0x%x,0x%x' %(d.domain, d.bus, d.slot, d.func)
-            # Xen doesn't care what the domid is, so we pass 0 here...
-            domid = 0
-            bdf = xc.test_assign_device(domid, pci_str)
-            if bdf != 0:
-                available = False
-                break
-        if available:
-            final_devs_list = final_devs_list + [dev_list]
-
-    for dev_list in final_devs_list:
-        for d in dev_list:
-            print d.name,
-        print
 
 def vscsi_sort(devs):
     def sort_hctl(ds, l):




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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] Fix 'xm pci_list_assignable_devices', Yosuke Iwamatsu <=