ia64/xen-unstable

changeset 12732:000609d8c93f

[PVFB][TOOLS] Change the configuration syntax for PVFB backends to more
closely match that of other devices.

This involves moving the logic for backend creation out of the image
handlers and in to the device handler, which is a much more sensible
place for it.

Signed-off-by: Steven Smith <sos22@cam.ac.uk>
author Steven Smith <ssmith@xensource.com>
date Fri Dec 01 11:49:30 2006 +0000 (2006-12-01)
parents 260426e3924f
children d5d8aeb4fa34
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xend/server/vfbif.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Dec 01 09:48:32 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Dec 01 11:49:30 2006 +0000
     1.3 @@ -458,7 +458,7 @@ class XendDomainInfo:
     1.4              try:
     1.5                  self._constructDomain()
     1.6                  self._storeVmDetails()
     1.7 -                self._restoreDomain()
     1.8 +                self._createDevices()
     1.9                  self._createChannels()
    1.10                  self._storeDomDetails()
    1.11                  self._endRestore()
    1.12 @@ -1387,23 +1387,6 @@ class XendDomainInfo:
    1.13              raise VmError(str(exn))
    1.14  
    1.15  
    1.16 -    def _restoreDomain(self):
    1.17 -        log.debug('XendDomainInfo.restoreDomain: %s %s',
    1.18 -                  self.domid,
    1.19 -                  self.info['cpu_weight'])
    1.20 -
    1.21 -        if not self.infoIsSet('image'):
    1.22 -            raise VmError('Missing image in configuration')
    1.23 -
    1.24 -        try:
    1.25 -            self.image = image.create(self,
    1.26 -                                      self.info['image'],
    1.27 -                                      self.info['device'])
    1.28 -
    1.29 -            self._createDevices()
    1.30 -        except RuntimeError, exn:
    1.31 -            raise VmError(str(exn))
    1.32 -
    1.33      def cleanupDomain(self):
    1.34          """Cleanup domain resources; release devices.  Idempotent.  Nothrow
    1.35          guarantee."""
     2.1 --- a/tools/python/xen/xend/image.py	Fri Dec 01 09:48:32 2006 +0000
     2.2 +++ b/tools/python/xen/xend/image.py	Fri Dec 01 11:49:30 2006 +0000
     2.3 @@ -23,7 +23,6 @@ import math
     2.4  import signal
     2.5  
     2.6  import xen.lowlevel.xc
     2.7 -import xen.util.auxbin
     2.8  from xen.xend.XendConstants import REVERSE_DOMAIN_SHUTDOWN_REASONS
     2.9  from xen.xend.XendError import VmError, XendError
    2.10  from xen.xend.XendLogging import log
    2.11 @@ -200,72 +199,6 @@ class LinuxImageHandler(ImageHandler):
    2.12                                ramdisk        = self.ramdisk,
    2.13                                features       = self.vm.getFeatures())
    2.14  
    2.15 -    def configure(self, imageConfig, deviceConfig):
    2.16 -        ImageHandler.configure(self, imageConfig, deviceConfig)
    2.17 -
    2.18 -        self.pid = 0
    2.19 -        log.info("configuring linux guest")
    2.20 -
    2.21 -        # set up the graphics bits.
    2.22 -        # FIXME: this is much like what we do for HVM, should it be 
    2.23 -        # for all image types now?
    2.24 -        self.display = sxp.child_value(imageConfig, 'display')
    2.25 -        self.xauthority = sxp.child_value(imageConfig, 'xauthority')
    2.26 -        self.vncconsole = sxp.child_value(imageConfig, 'vncconsole')
    2.27 -        vncpasswd = sxp.child_value(imageConfig, 'vncpasswd')
    2.28 -        self.vncpasswd = vncpasswd
    2.29 -
    2.30 -        self.vnc = sxp.child_value(imageConfig, 'vnc')
    2.31 -        self.sdl = sxp.child_value(imageConfig, 'sdl')
    2.32 -        if self.vnc:
    2.33 -            self.vncdisplay = int(sxp.child_value(imageConfig, 'vncdisplay',
    2.34 -                                                  self.vm.getDomid()))
    2.35 -            self.vncunused = sxp.child_value(imageConfig, 'vncunused')
    2.36 -            self.vnclisten = sxp.child_value(imageConfig, 'vnclisten')
    2.37 -            if not(self.vnclisten):
    2.38 -                self.vnclisten = xen.xend.XendRoot.instance().get_vnclisten_address()
    2.39 -
    2.40 -    def createDeviceModel(self):
    2.41 -        if self.pid:
    2.42 -            return
    2.43 -        # Execute device model (for us, it's just the fb frontend)
    2.44 -        if not self.vnc and not self.sdl:
    2.45 -            return
    2.46 -
    2.47 -        if self.vnc:
    2.48 -            args = [xen.util.auxbin.pathTo("xen-vncfb")]
    2.49 -            if self.vncunused:
    2.50 -                args += ['--unused']
    2.51 -            elif self.vncdisplay:
    2.52 -                args += [ "--vncport", "%d" %(5900 + self.vncdisplay,) ]
    2.53 -            if self.vnclisten:
    2.54 -                args += [ "--listen", self.vnclisten ]
    2.55 -
    2.56 -            # password check
    2.57 -            if self.vncpasswd is None:
    2.58 -                # get password from xend-config(if password omitted, None)
    2.59 -                self.vncpasswd = xen.xend.XendRoot.instance().get_vncpasswd_default()
    2.60 -
    2.61 -                if self.vncpasswd is None:
    2.62 -                    raise VmError('vncpasswd is not setup in the guest config or xend-config.')
    2.63 -            if self.vncpasswd != '':
    2.64 -                self.vm.storeVm("vncpasswd", self.vncpasswd)
    2.65 -                log.info("vncpassword set to '%s'", self.vncpasswd)
    2.66 -
    2.67 -        elif self.sdl:
    2.68 -            args = [xen.util.auxbin.pathTo("xen-sdlfb")]
    2.69 -        args = args + [ "--domid", "%d" % self.vm.getDomid(),
    2.70 -                        "--title", self.vm.info['name'] ]
    2.71 -
    2.72 -        env = dict(os.environ)
    2.73 -        if self.display:
    2.74 -            env['DISPLAY'] = self.display
    2.75 -        if self.xauthority:
    2.76 -            env['XAUTHORITY'] = self.xauthority
    2.77 -        log.info("spawning video: %s", args)
    2.78 -        self.pid = os.spawnve(os.P_NOWAIT, args[0], args, env)
    2.79 -        log.info("device model pid: %d", self.pid)
    2.80 -
    2.81      def destroy(self):
    2.82          if not self.pid:
    2.83              return
     3.1 --- a/tools/python/xen/xend/server/vfbif.py	Fri Dec 01 09:48:32 2006 +0000
     3.2 +++ b/tools/python/xen/xend/server/vfbif.py	Fri Dec 01 11:49:30 2006 +0000
     3.3 @@ -1,5 +1,9 @@
     3.4  from xen.xend.server.DevController import DevController
     3.5  
     3.6 +from xen.xend.XendError import VmError
     3.7 +import xen.xend
     3.8 +import os
     3.9 +
    3.10  class VfbifController(DevController):
    3.11      """Virtual frame buffer controller. Handles all vfb devices for a domain.
    3.12      """
    3.13 @@ -14,13 +18,37 @@ class VfbifController(DevController):
    3.14          front = {}
    3.15          return (devid, back, front)
    3.16  
    3.17 +    def createDevice(self, config):
    3.18 +        DevController.createDevice(self, config)
    3.19 +        std_args = [ "--domid", "%d" % self.vm.getDomid(),
    3.20 +                     "--title", self.vm.getName() ]
    3.21 +        t = config.get("type", None)
    3.22 +        if t == "vnc":
    3.23 +            # Try to start the vnc backend
    3.24 +            args = [xen.util.auxbin.pathTo("xen-vncfb")]
    3.25 +            if config.has_key("vncunused"):
    3.26 +                args += ["--unused"]
    3.27 +            elif config.has_key("vncdisplay"):
    3.28 +                args += ["--vncport", "%d" % (5900 + config["vncdisplay"])]
    3.29 +            vnclisten = config.get("vnclisten",
    3.30 +                                   xen.xend.XendRoot.instance().get_vnclisten_address())
    3.31 +            args += [ "--listen", vnclisten ]
    3.32 +            os.spawnve(os.P_NOWAIT, args[0], args + std_args, os.environ)
    3.33 +        elif t == "sdl":
    3.34 +            args = [xen.util.auxbin.pathTo("xen-sdlfb")]
    3.35 +            env = dict(os.environ)
    3.36 +            if config.has_key("display"):
    3.37 +                env['DISPLAY'] = config["display"]
    3.38 +            if config.has_key("xauthority"):
    3.39 +                env['XAUTHORITY'] = config["xauthority"]
    3.40 +            os.spawnve(os.P_NOWAIT, args[0], args + std_args, env)
    3.41 +        else:
    3.42 +            raise VmError('Unknown vfb type %s (%s)' % (t, repr(config)))
    3.43 +
    3.44  class VkbdifController(DevController):
    3.45      """Virtual keyboard controller. Handles all vkbd devices for a domain.
    3.46      """
    3.47  
    3.48 -    def __init__(self, vm):
    3.49 -        DevController.__init__(self, vm)
    3.50 -
    3.51      def getDeviceDetails(self, config):
    3.52          """@see DevController.getDeviceDetails"""
    3.53          devid = 0
     4.1 --- a/tools/python/xen/xm/create.py	Fri Dec 01 09:48:32 2006 +0000
     4.2 +++ b/tools/python/xen/xm/create.py	Fri Dec 01 11:49:30 2006 +0000
     4.3 @@ -284,13 +284,17 @@ gopts.var('usbport', val='PATH',
     4.4            use="""Add a physical USB port to a domain, as specified by the path
     4.5            to that port.  This option may be repeated to add more than one port.""")
     4.6  
     4.7 -gopts.var('vfb', val="no|yes'",
     4.8 -          fn=set_bool, default=0,
     4.9 -          use="Make the domain a framebuffer backend.")
    4.10 -
    4.11 -gopts.var('vkbd', val="no|yes'",
    4.12 -          fn=set_bool, default=0,
    4.13 -          use="Make the domain a keyboard backend.")
    4.14 +gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY",
    4.15 +          fn=append_value, default=[],
    4.16 +          use="""Make the domain a framebuffer backend.
    4.17 +          The backend type should be either sdl or vnc.
    4.18 +          For type=vnc, connect an external vncviewer.  The server will listen
    4.19 +          on ADDR (default 127.0.0.1) on port N+5900.  N defaults to the
    4.20 +          domain id.  If vncunused=1, the server will try to find an arbitrary
    4.21 +          unused port above 5900.
    4.22 +          For type=sdl, a viewer will be started automatically using the
    4.23 +          given DISPLAY and XAUTHORITY, which default to the current user's
    4.24 +          ones.""")
    4.25  
    4.26  gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT,backend=DOM,vifname=NAME",
    4.27            fn=append_value, default=[],
    4.28 @@ -521,8 +525,6 @@ def configure_image(vals):
    4.29  
    4.30      if vals.builder == 'hvm':
    4.31          configure_hvm(config_image, vals) 
    4.32 -
    4.33 -    configure_graphics(config_image, vals)        
    4.34         
    4.35      return config_image
    4.36      
    4.37 @@ -575,12 +577,22 @@ def configure_usb(config_devs, vals):
    4.38          config_devs.append(['device', config_usb])
    4.39  
    4.40  def configure_vfbs(config_devs, vals):
    4.41 -    if vals.vfb:
    4.42 -        config_devs.append(['device', ['vfb', []]])
    4.43 -
    4.44 -def configure_vkbds(config_devs, vals):
    4.45 -    if vals.vkbd:
    4.46 -        config_devs.append(['device', ['vkbd', []]])
    4.47 +    for f in vals.vfb:
    4.48 +        d = comma_sep_kv_to_dict(f)
    4.49 +        config = ['vfb']
    4.50 +        if not d.has_key("type"):
    4.51 +            d['type'] = 'sdl'
    4.52 +        for (k,v) in d.iteritems():
    4.53 +            if not k in [ 'vnclisten', 'vncunused', 'vncdisplay', 'display',
    4.54 +                          'xauthority', 'type' ]:
    4.55 +                err("configuration option %s unknown to vfbs" % k)
    4.56 +            config.append([k,v])
    4.57 +        if not d.has_key("display") and os.environ.has_key("DISPLAY"):
    4.58 +            config.append(["display", os.environ['DISPLAY']])
    4.59 +        if not d.has_key("xauthority"):
    4.60 +            config.append(["xauthority", get_xauthority()])
    4.61 +        config_devs.append(['device', ['vkbd']])
    4.62 +        config_devs.append(['device', config])
    4.63  
    4.64  def configure_security(config, vals):
    4.65      """Create the config for ACM security labels.
    4.66 @@ -678,20 +690,13 @@ def configure_vifs(config_devs, vals):
    4.67          config_devs.append(['device', config_vif])
    4.68  
    4.69  
    4.70 -def configure_graphics(config_image, vals):
    4.71 -    """Create the config for graphic consoles.
    4.72 -    """
    4.73 -    args = [ 'vnc', 'vncdisplay', 'vncconsole', 'vncunused',
    4.74 -             'sdl', 'display', 'xauthority', 'vnclisten', 'vncpasswd']
    4.75 -    for a in args:
    4.76 -        if (vals.__dict__[a]):
    4.77 -            config_image.append([a, vals.__dict__[a]])
    4.78 -
    4.79  def configure_hvm(config_image, vals):
    4.80      """Create the config for HVM devices.
    4.81      """
    4.82      args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
    4.83               'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
    4.84 +             'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
    4.85 +             'sdl', 'display', 'xauthority',
    4.86               'acpi', 'apic', 'usb', 'usbdevice', 'keymap' ]
    4.87      for a in args:
    4.88          if a in vals.__dict__ and vals.__dict__[a] is not None:
    4.89 @@ -767,7 +772,6 @@ def make_config(vals):
    4.90      configure_usb(config_devs, vals)
    4.91      configure_vtpm(config_devs, vals)
    4.92      configure_vfbs(config_devs, vals)
    4.93 -    configure_vkbds(config_devs, vals)
    4.94      configure_security(config, vals)
    4.95      config += config_devs
    4.96