ia64/xen-unstable

changeset 7642:1f57d567cf4b

Add support for the ioport_permission dom0 op to xend and xm

xm now accepts a parameter 'ioports' that accepts a hex ioport
or ioport range, in the form 02f8[-02ff]

Signed-off-by: Jody Belka <knew (at) pimb (dot) org>
author kaf24@firebug.cl.cam.ac.uk
date Mon Nov 07 12:05:15 2005 +0100 (2005-11-07)
parents 270469d40f02
children 19a226d8db16 19e5385bc5b3
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/iopif.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Sun Nov 06 19:50:33 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Nov 07 12:05:15 2005 +0100
     1.3 @@ -492,6 +492,40 @@ class XendDomain:
     1.4          except Exception, ex:
     1.5              raise XendError(str(ex))
     1.6  
     1.7 +    def domain_ioport_range_enable(self, domid, first, last):
     1.8 +        """Enable access to a range of IO ports for a domain
     1.9 +
    1.10 +        @param first: first IO port
    1.11 +        @param last: last IO port
    1.12 +        @return: 0 on success, -1 on error
    1.13 +        """
    1.14 +        dominfo = self.domain_lookup(domid)
    1.15 +        nr_ports = last - first + 1
    1.16 +        try:
    1.17 +            return xc.domain_ioport_permission(dominfo.getDomid(),
    1.18 +                                               first_port = first,
    1.19 +                                               nr_ports = nr_ports,
    1.20 +                                               allow_access = 1)
    1.21 +        except Exception, ex:
    1.22 +            raise XendError(str(ex))
    1.23 +
    1.24 +    def domain_ioport_range_disable(self, domid, first, last):
    1.25 +        """Disable access to a range of IO ports for a domain
    1.26 +
    1.27 +        @param first: first IO port
    1.28 +        @param last: last IO port
    1.29 +        @return: 0 on success, -1 on error
    1.30 +        """
    1.31 +        dominfo = self.domain_lookup(domid)
    1.32 +        nr_ports = last - first + 1
    1.33 +        try:
    1.34 +            return xc.domain_ioport_permission(dominfo.getDomid(),
    1.35 +                                               first_port = first,
    1.36 +                                               nr_ports = nr_ports,
    1.37 +                                               allow_access = 0)
    1.38 +        except Exception, ex:
    1.39 +            raise XendError(str(ex))
    1.40 +
    1.41  
    1.42  def instance():
    1.43      """Singleton constructor. Use this instead of the class constructor.
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Sun Nov 06 19:50:33 2005 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Nov 07 12:05:15 2005 +0100
     2.3 @@ -1400,9 +1400,10 @@ def addControllerClass(device_class, cls
     2.4      controllerClasses[device_class] = cls
     2.5  
     2.6  
     2.7 -from xen.xend.server import blkif, netif, tpmif, pciif, usbif
     2.8 +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, usbif
     2.9  addControllerClass('vbd',  blkif.BlkifController)
    2.10  addControllerClass('vif',  netif.NetifController)
    2.11  addControllerClass('vtpm', tpmif.TPMifController)
    2.12  addControllerClass('pci',  pciif.PciController)
    2.13 +addControllerClass('ioports', iopif.IOPortsController)
    2.14  addControllerClass('usb',  usbif.UsbifController)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/python/xen/xend/server/iopif.py	Mon Nov 07 12:05:15 2005 +0100
     3.3 @@ -0,0 +1,86 @@
     3.4 +#============================================================================
     3.5 +# This library is free software; you can redistribute it and/or
     3.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     3.7 +# License as published by the Free Software Foundation.
     3.8 +#
     3.9 +# This library is distributed in the hope that it will be useful,
    3.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.12 +# Lesser General Public License for more details.
    3.13 +#
    3.14 +# You should have received a copy of the GNU Lesser General Public
    3.15 +# License along with this library; if not, write to the Free Software
    3.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.17 +#============================================================================
    3.18 +# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
    3.19 +# Copyright (C) 2005 XenSource Ltd
    3.20 +# Copyright (C) 2005 Jody Belka
    3.21 +#============================================================================
    3.22 +
    3.23 +
    3.24 +import types
    3.25 +
    3.26 +import xen.lowlevel.xc;
    3.27 +
    3.28 +from xen.xend import sxp
    3.29 +from xen.xend.XendError import VmError
    3.30 +
    3.31 +from xen.xend.server.DevController import DevController
    3.32 +
    3.33 +
    3.34 +xc = xen.lowlevel.xc.new()
    3.35 +
    3.36 +
    3.37 +def parse_ioport(val):
    3.38 +    """Parse an i/o port field.
    3.39 +    """
    3.40 +    if isinstance(val, types.StringType):
    3.41 +        radix = 10
    3.42 +        if val.startswith('0x') or val.startswith('0X'):
    3.43 +            radix = 16
    3.44 +        v = int(val, radix)
    3.45 +    else:
    3.46 +        v = val
    3.47 +    return v
    3.48 +
    3.49 +
    3.50 +class IOPortsController(DevController):
    3.51 +
    3.52 +    def __init__(self, vm):
    3.53 +        DevController.__init__(self, vm)
    3.54 +
    3.55 +
    3.56 +    def getDeviceDetails(self, config):
    3.57 +        """@see DevController.getDeviceDetails"""
    3.58 +
    3.59 +        def get_param(field):
    3.60 +            try:
    3.61 +                val = sxp.child_value(config, field)
    3.62 +
    3.63 +                if not val:
    3.64 +                    raise VmError('ioports: Missing %s config setting' % field)
    3.65 +
    3.66 +                return parse_ioport(val)
    3.67 +            except:
    3.68 +                raise VmError('ioports: Invalid config setting %s: %s' %
    3.69 +                              (field, val))
    3.70 +       
    3.71 +        io_from = get_param('from')
    3.72 +        io_to = get_param('to') 
    3.73 +
    3.74 +        if io_to < io_from or io_to >= 65536:
    3.75 +            raise VmError('ioports: Invalid i/o range: %s - %s' %
    3.76 +                          (io_from, io_to))
    3.77 +
    3.78 +        rc = xc.domain_ioport_permission(dom          = self.getDomid(),
    3.79 +                                         first_port   = io_from,
    3.80 +                                         nr_ports     = io_to - io_from + 1,
    3.81 +                                         allow_access = True)
    3.82 +
    3.83 +        if rc < 0:
    3.84 +            #todo non-fatal
    3.85 +            raise VmError(
    3.86 +                'ioports: Failed to configure legacy i/o range: %s - %s' %
    3.87 +                (io_from, io_to))
    3.88 +
    3.89 +        return (dev, {}, {})
     4.1 --- a/tools/python/xen/xm/create.py	Sun Nov 06 19:50:33 2005 +0100
     4.2 +++ b/tools/python/xen/xm/create.py	Mon Nov 07 12:05:15 2005 +0100
     4.3 @@ -241,6 +241,12 @@ gopts.var('pci', val='BUS,DEV,FUNC',
     4.4           For example '-pci c0,02,1a'.
     4.5           The option may be repeated to add more than one pci device.""")
     4.6  
     4.7 +gopts.var('ioports', val='FROM[-TO]',
     4.8 +          fn=append_value, default=[],
     4.9 +          use="""Add a legacy I/O range to a domain, using given params (in hex).
    4.10 +         For example '-ioports 02f8-02ff'.
    4.11 +         The option may be repeated to add more than one i/o range.""")
    4.12 +
    4.13  gopts.var('usb', val='PATH',
    4.14            fn=append_value, default=[],
    4.15            use="""Add a physical USB port to a domain, as specified by the path
    4.16 @@ -439,6 +445,13 @@ def configure_pci(config_devs, vals):
    4.17          config_pci = ['pci', ['bus', bus], ['dev', dev], ['func', func]]
    4.18          config_devs.append(['device', config_pci])
    4.19  
    4.20 +def configure_ioports(config_devs, vals):
    4.21 +    """Create the config for legacy i/o ranges.
    4.22 +    """
    4.23 +    for (io_from, io_to) in vals.ioports:
    4.24 +        config_ioports = ['ioports', ['from', io_from], ['to', io_to]]
    4.25 +        config_devs.append(['device', config_ioports])
    4.26 +
    4.27  def configure_usb(config_devs, vals):
    4.28      for path in vals.usb:
    4.29          config_usb = ['usb', ['path', path]]
    4.30 @@ -611,6 +624,7 @@ def make_config(vals):
    4.31      config_devs = []
    4.32      configure_disks(config_devs, vals)
    4.33      configure_pci(config_devs, vals)
    4.34 +    configure_ioports(config_devs, vals)
    4.35      configure_vifs(config_devs, vals)
    4.36      configure_usb(config_devs, vals)
    4.37      configure_vtpm(config_devs, vals)
    4.38 @@ -645,6 +659,20 @@ def preprocess_pci(vals):
    4.39          pci.append(hexd)
    4.40      vals.pci = pci
    4.41  
    4.42 +def preprocess_ioports(vals):
    4.43 +    if not vals.ioports: return
    4.44 +    ioports = []
    4.45 +    for v in vals.ioports:
    4.46 +        d = v.split('-')
    4.47 +        if len(d) < 1 || len(d) > 2:
    4.48 +            err('Invalid i/o port range specifier: ' + v)
    4.49 +        if len(d) == 1:
    4.50 +            d.append(d[0])
    4.51 +        # Components are in hex: add hex specifier.
    4.52 +        hexd = map(lambda v: '0x'+v, d)
    4.53 +        ioports.append(hexd)
    4.54 +    vals.ioports = ioports
    4.55 +        
    4.56  def preprocess_vifs(vals):
    4.57      if not vals.vif: return
    4.58      vifs = []
    4.59 @@ -777,6 +805,7 @@ def preprocess(vals):
    4.60          err("No kernel specified")
    4.61      preprocess_disk(vals)
    4.62      preprocess_pci(vals)
    4.63 +    preprocess_ioports(vals)
    4.64      preprocess_vifs(vals)
    4.65      preprocess_ip(vals)
    4.66      preprocess_nfs(vals)