xend, pci passthru: Relax the requirement of co-assignment.
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 28 Jul 2008 10:28:45 +0000 (11:28 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 28 Jul 2008 10:28:45 +0000 (11:28 +0100)
Certain PCI or PCIe devices needs to be co-assigned. Currently we
require all the related devices be assigned to the same guest. This
can be relaxed to: part of them can be assgined to the same guest, and
after that, the left ones can't be assigned.

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
tools/python/xen/util/pci.py
tools/python/xen/xend/server/pciif.py

index 42a0f81d8aaf13c1a5086c92f73bbb2d39aa9ba9..1985a133ae87056864ab42e33de6f058c36602e4 100644 (file)
@@ -105,7 +105,7 @@ def parse_hex(val):
         return None
 
 def parse_pci_name(pci_name_string):
-    # Format: xxxx:xx:xx:x
+    # Format: xxxx:xx:xx.x
     s = pci_name_string
     s = s.split(':')
     dom = parse_hex(s[0])
index 9946377d9fdfb1af849a197634fb23499779881b..da115679a7b1a19a7126f697f256715a9d11c734 100644 (file)
@@ -378,8 +378,14 @@ class PciController(DevController):
                 funcs = dev.find_all_the_multi_functions()
                 for f in funcs:
                     if not f in pci_str_list:
-                        err_msg = 'pci: % must be co-assigned to guest with %s'
-                        raise VmError(err_msg % (f, dev.name))
+                        (f_dom, f_bus, f_slot, f_func) = parse_pci_name(f)
+                        f_pci_str = '0x%x,0x%x,0x%x,0x%x' % \
+                            (f_dom, f_bus, f_slot, f_func)
+                        # f has been assigned to other guest?
+                        if xc.test_assign_device(0, f_pci_str) != 0:
+                            err_msg = 'pci: %s must be co-assigned to the' + \
+                                ' same guest with %s'
+                            raise VmError(err_msg % (f, dev.name))
             elif dev.dev_type == DEV_TYPE_PCI:
                 if dev.bus == 0:
                     if not dev.pci_af_flr:
@@ -395,8 +401,14 @@ class PciController(DevController):
 
                     for s in devs_str:
                         if not s in pci_str_list:
-                            err_msg = 'pci: %s must be co-assigned to guest with %s'
-                            raise VmError(err_msg % (s, dev.name))
+                            (s_dom, s_bus, s_slot, s_func) = parse_pci_name(s)
+                            s_pci_str = '0x%x,0x%x,0x%x,0x%x' % \
+                                (s_dom, s_bus, s_slot, s_func)
+                            # s has been assigned to other guest?
+                            if xc.test_assign_device(0, s_pci_str) != 0:
+                                err_msg = 'pci: %s must be co-assigned to the'+\
+                                    ' same guest with %s'
+                                raise VmError(err_msg % (s, dev.name))
 
         for (domain, bus, slot, func) in pci_dev_list:
             self.setupOneDevice(domain, bus, slot, func)