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 3/6] pci: add pci option support for XML-RPC server

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 3/6] pci: add pci option support for XML-RPC server
From: Qing He <qing.he@xxxxxxxxx>
Date: Thu, 8 Jan 2009 17:06:46 +0800
Cc: Qing He <qing.he@xxxxxxxxx>
Delivery-date: Thu, 08 Jan 2009 01:10:26 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1231405609-23138-1-git-send-email-qing.he@xxxxxxxxx>
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>
References: <1231405609-23138-1-git-send-email-qing.he@xxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
pci: add pci option support for XML-RPC server

Allow the per-device options for passthrough pci devices
for exmaple, in domain config file:
    pci = ['01:00.0,opt1=val1,opt2=val2', '01:00.1' ]
or in the PCI hotplug case:
    xm pci-attach -o opt1=val1 --options=opt2=val2 <domid> 01:00.0 6

This patch is for xml-rpc server

Signed-off-by: Qing He <qing.he@xxxxxxxxx>
---

diff -r d11b806ed94f -r 02ebed7b45d0 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Sun Jan 04 17:41:53 2009 +0800
+++ b/tools/python/xen/xend/XendDomainInfo.py   Thu Jan 08 01:57:58 2009 +0800
@@ -645,10 +645,17 @@
                           " already been assigned to other domain, or maybe"
                           " it doesn't exist." % (bus, dev, func))
 
-        bdf_str = "%s:%s:%s.%s@%s" % (new_dev['domain'],
+        opts = ''
+        if 'opts' in new_dev and len(new_dev['opts']) > 0:
+            config_opts = new_dev['opts']
+            config_opts = map(lambda (x, y): x+'='+y, config_opts)
+            opts = ',' + reduce(lambda x, y: x+','+y, config_opts)
+
+        bdf_str = "%s:%s:%s.%s%s@%s" % (new_dev['domain'],
                 new_dev['bus'],
                 new_dev['slot'],
                 new_dev['func'],
+                opts,
                 new_dev['vslt'])
         self.image.signalDeviceModel('pci-ins', 'pci-inserted', bdf_str)
 
@@ -2154,7 +2161,11 @@
         xc.domain_max_vcpus(self.domid, int(self.info['VCPUs_max']))
 
         # Test whether the devices can be assigned with VT-d
-        pci_str = str(self.info["platform"].get("pci"))
+        pci = self.info["platform"].get("pci")
+        pci_str = ''
+        if pci and len(pci) > 0:
+            pci = map(lambda x: x[0:4], pci)  # strip options 
+            pci_str = str(pci)
         if hvm and pci_str:
             bdf = xc.test_assign_device(self.domid, pci_str)
             if bdf != 0:
diff -r d11b806ed94f -r 02ebed7b45d0 tools/python/xen/xend/server/pciif.py
--- a/tools/python/xen/xend/server/pciif.py     Sun Jan 04 17:41:53 2009 +0800
+++ b/tools/python/xen/xend/server/pciif.py     Thu Jan 08 01:57:58 2009 +0800
@@ -75,6 +75,12 @@
             slot = parse_hex(pci_config.get('slot', 0))
             func = parse_hex(pci_config.get('func', 0))            
 
+            opts = pci_config.get('opts', '')
+            if len(opts) > 0:
+                opts = map(lambda (x, y): x+'='+y, opts)
+                opts = reduce(lambda x, y: x+','+y, opts)
+                back['opts-%i' % pcidevid] = opts
+
             vslt = pci_config.get('vslt')
             if vslt is not None:
                 vslots = vslots + vslt + ";"
@@ -108,6 +114,9 @@
                 dev = back['dev-%i' % i]
                 state = states[i]
                 uuid = back['uuid-%i' %i]
+                opts = ''
+                if 'opts-%i' % i in back:
+                    opts = back['opts-%i' % i]
             except:
                 raise XendError('Error reading config')
 
@@ -129,6 +138,8 @@
                 self.writeBackend(devid, 'state-%i' % (num_olddevs + i),
                                   str(xenbusState['Initialising']))
                 self.writeBackend(devid, 'uuid-%i' % (num_olddevs + i), uuid)
+                if len(opts) > 0:
+                    self.writeBackend(devid, 'opts-%i' % (num_olddevs + i), 
opts)
                 self.writeBackend(devid, 'num_devs', str(num_olddevs + i + 1))
 
                 # Update vslots
@@ -540,6 +551,9 @@
                 self.removeBackend(devid, 'vdev-%i' % i)
                 self.removeBackend(devid, 'state-%i' % i)
                 self.removeBackend(devid, 'uuid-%i' % i)
+                tmpopts = self.readBackend(devid, 'opts-%i' % i)
+                if tmpopts is not None:
+                    self.removeBackend(devid, 'opts-%i' % i)
             else:
                 if new_num_devs != i:
                     tmpdev = self.readBackend(devid, 'dev-%i' % i)
@@ -556,6 +570,9 @@
                     tmpuuid = self.readBackend(devid, 'uuid-%i' % i)
                     self.writeBackend(devid, 'uuid-%i' % new_num_devs, tmpuuid)
                     self.removeBackend(devid, 'uuid-%i' % i)
+                    tmpopts = self.readBackend(devid, 'opts-%i' % i)
+                    if tmpopts is not None:
+                        self.removeBackend(devid, 'opts-%i' % i)
                 new_num_devs = new_num_devs + 1
 
         self.writeBackend(devid, 'num_devs', str(new_num_devs))
diff -r d11b806ed94f -r 02ebed7b45d0 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Sun Jan 04 17:41:53 2009 +0800
+++ b/tools/python/xen/xm/create.py     Thu Jan 08 01:57:58 2009 +0800
@@ -667,9 +667,20 @@
     """Create the config for pci devices.
     """
     config_pci = []
-    for (domain, bus, slot, func) in vals.pci:
-        config_pci.append(['dev', ['domain', domain], ['bus', bus], \
-                        ['slot', slot], ['func', func]])
+    for (domain, bus, slot, func, opts) in vals.pci:
+        config_pci_opts = []
+        d = comma_sep_kv_to_dict(opts)
+
+        def f(k):
+            config_pci_opts.append([k, d[k]])
+
+        config_pci_bdf = ['dev', ['domain', domain], ['bus', bus], \
+                          ['slot', slot], ['func', func]]
+        map(f, d.keys())
+        if len(config_pci_opts)>0:
+            config_pci_bdf.append(['opts', config_pci_opts])
+
+        config_pci.append(config_pci_bdf)
 
     if len(config_pci)>0:
         config_pci.insert(0, 'pci')
@@ -991,14 +1002,18 @@
         pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
                 r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
                 r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
-                r"(?P<func>[0-7])$", pci_dev_str)
+                r"(?P<func>[0-7])" + \
+                r"(,(?P<opts>.*))?$", pci_dev_str)
         if pci_match!=None:
-            pci_dev_info = pci_match.groupdict('0')
+            pci_dev_info = pci_match.groupdict('')
+            if pci_dev_info['domain']=='':
+                pci_dev_info['domain']='0'
             try:
                 pci.append( ('0x'+pci_dev_info['domain'], \
                         '0x'+pci_dev_info['bus'], \
                         '0x'+pci_dev_info['slot'], \
-                        '0x'+pci_dev_info['func']))
+                        '0x'+pci_dev_info['func'], \
+                        pci_dev_info['opts']))
             except IndexError:
                 err('Error in PCI slot syntax "%s"'%(pci_dev_str))
     vals.pci = pci
diff -r d11b806ed94f -r 02ebed7b45d0 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Sun Jan 04 17:41:53 2009 +0800
+++ b/tools/python/xen/xm/main.py       Thu Jan 08 01:57:58 2009 +0800
@@ -187,7 +187,7 @@
     'vnet-delete'   :  ('<VnetId>', 'Delete a Vnet.'),
     'vnet-list'     :  ('[-l|--long]', 'List Vnets.'),
     'vtpm-list'     :  ('<Domain> [--long]', 'List virtual TPM devices.'),
-    'pci-attach'    :  ('<Domain> <domain:bus:slot.func> [virtual slot]',
+    'pci-attach'    :  ('[-o|--options=<opt>] <Domain> <domain:bus:slot.func> 
[virtual slot]',
                         'Insert a new pass-through pci device.'),
     'pci-detach'    :  ('<Domain> <domain:bus:slot.func>',
                         'Remove a domain\'s pass-through pci device.'),
@@ -2428,7 +2428,7 @@
             vif.append(vif_param)
         server.xend.domain.device_create(dom, vif)
 
-def parse_pci_configuration(args, state):
+def parse_pci_configuration(args, state, opts = ''):
     dom = args[0]
     pci_dev_str = args[1]
     if len(args) == 3:
@@ -2443,12 +2443,17 @@
     if pci_match == None:
         raise OptionError("Invalid argument: %s %s" % (pci_dev_str,vslt))
     pci_dev_info = pci_match.groupdict('0')
+
     try:
-        pci.append(['dev', ['domain', '0x'+ pci_dev_info['domain']], \
+        pci_bdf =['dev', ['domain', '0x'+ pci_dev_info['domain']], \
                 ['bus', '0x'+ pci_dev_info['bus']],
                 ['slot', '0x'+ pci_dev_info['slot']],
                 ['func', '0x'+ pci_dev_info['func']],
-                ['vslt', '0x%x' % int(vslt, 16)]])
+                ['vslt', '0x%x' % int(vslt, 16)]]
+        if len(opts) > 0:
+            pci_bdf.append(['opts', opts])
+        pci.append(pci_bdf)
+
     except:
         raise OptionError("Invalid argument: %s %s" % (pci_dev_str,vslt))
     pci.append(['state', state])
@@ -2456,8 +2461,22 @@
     return (dom, pci)
 
 def xm_pci_attach(args):
-    arg_check(args, 'pci-attach', 2, 3)
-    (dom, pci) = parse_pci_configuration(args, 'Initialising')
+    config_pci_opts = []
+    (options, params) = getopt.gnu_getopt(args, 'o:', ['options='])
+    for (k, v) in options:
+        if k in ('-o', '--options'):
+            if len(v.split('=')) != 2:
+                err("Invalid pci attach option: %s" % v)
+                usage('pci-attach')
+            config_pci_opts.append(v.split('='))
+
+    n = len([i for i in params if i != '--'])
+    if n < 2 or n > 3:
+        err("Invalid argument for 'xm pci-attach'")
+        usage('pci-attach')
+
+    (dom, pci) = parse_pci_configuration(params, 'Initialising',
+                     config_pci_opts)
 
     if serverType == SERVER_XEN_API:
 

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