ia64/xen-unstable

changeset 4124:d4fa637dbd23

bitkeeper revision 1.1236.28.1 (42340a42zVMF1dHpLj0Rzok7P9t48Q)

Manual merge.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@scramble.cl.cam.ac.uk
date Sun Mar 13 09:39:14 2005 +0000 (2005-03-13)
parents 3236c27b9832 108ea6682e8a
children e29a885e4d0b
files linux-2.6.11-xen-sparse/include/asm-xen/hypervisor.h tools/examples/xend-config.sxp tools/python/xen/xend/Args.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/SrvBase.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDir.py tools/python/xen/xend/server/console.py tools/python/xen/xend/server/params.py xen/common/domain.c xen/include/public/io/domain_controller.h xen/include/public/xen.h
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/include/asm-xen/hypervisor.h	Sun Mar 13 00:35:14 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/include/asm-xen/hypervisor.h	Sun Mar 13 09:39:14 2005 +0000
     1.3 @@ -311,6 +311,22 @@ HYPERVISOR_suspend(
     1.4      return ret;
     1.5  }
     1.6  
     1.7 +static inline int
     1.8 +HYPERVISOR_crash(
     1.9 +    void)
    1.10 +{
    1.11 +    int ret;
    1.12 +    unsigned long ign1;
    1.13 +    __asm__ __volatile__ (
    1.14 +        TRAP_INSTR
    1.15 +        : "=a" (ret), "=b" (ign1)
    1.16 +	: "0" (__HYPERVISOR_sched_op),
    1.17 +	  "1" (SCHEDOP_shutdown | (SHUTDOWN_crash << SCHEDOP_reasonshift))
    1.18 +        : "memory" );
    1.19 +
    1.20 +    return ret;
    1.21 +}
    1.22 +
    1.23  static inline long
    1.24  HYPERVISOR_set_timer_op(
    1.25      u64 timeout)
     2.1 --- a/tools/examples/xend-config.sxp	Sun Mar 13 00:35:14 2005 +0000
     2.2 +++ b/tools/examples/xend-config.sxp	Sun Mar 13 09:39:14 2005 +0000
     2.3 @@ -3,10 +3,22 @@
     2.4  # Port xend should use for the HTTP interface.
     2.5  (xend-port         8000)
     2.6  
     2.7 -# Address xend should listen on.
     2.8 +# Port xend should use for the event interface.
     2.9 +(xend-event-port   8001)
    2.10 +
    2.11 +# Address xend should listen on for HTTP connections.
    2.12  # Specifying 'localhost' prevents remote connections.
    2.13  # Specifying the empty string '' allows all connections.
    2.14 -(xend-address      '')
    2.15 +(xend-address      'localhost')
    2.16 +
    2.17 +# The port xend should start from when allocating a port
    2.18 +# for a domain console.
    2.19 +(console-port-base 9600)
    2.20 +
    2.21 +# Address xend should listen on for console connections.
    2.22 +# Specifying 'localhost' prevents remote connections.
    2.23 +# Specifying the empty string '' allows all connections.
    2.24 +(console-address   'localhost')
    2.25  
    2.26  ## Use the following if VIF traffic is routed.
    2.27  # The script used to start/stop networking for xend.
     3.1 --- a/tools/python/xen/xend/Args.py	Sun Mar 13 00:35:14 2005 +0000
     3.2 +++ b/tools/python/xen/xend/Args.py	Sun Mar 13 09:39:14 2005 +0000
     3.3 @@ -78,6 +78,8 @@ class Args:
     3.4                  val = str(v)
     3.5              elif type == 'sxpr':
     3.6                  val = self.sxpr(v)
     3.7 +            elif type == 'bool':
     3.8 +                val = self.bool(v)
     3.9              else:
    3.10                  raise ArgError('invalid type:' + str(type))
    3.11              return val
    3.12 @@ -86,6 +88,9 @@ class Args:
    3.13          except StandardError, ex:
    3.14              raise ArgError(str(ex))
    3.15  
    3.16 +    def bool(self, v):
    3.17 +        return (v.lower() in ['on', 'yes', '1', 'true'])
    3.18 +
    3.19      def sxpr(self, v):
    3.20          if isinstance(v, types.ListType):
    3.21              val = v
     4.1 --- a/tools/python/xen/xend/XendRoot.py	Sun Mar 13 00:35:14 2005 +0000
     4.2 +++ b/tools/python/xen/xend/XendRoot.py	Sun Mar 13 09:39:14 2005 +0000
     4.3 @@ -2,6 +2,11 @@
     4.4  
     4.5  """Xend root class.
     4.6  Creates the event server and handles configuration.
     4.7 +
     4.8 +Other classes get config variables by importing this module,
     4.9 +using instance() to get a XendRoot instance, and then
    4.10 +the config functions (e.g. get_xend_port()) to get
    4.11 +configured values.
    4.12  """
    4.13  
    4.14  import os
    4.15 @@ -34,17 +39,33 @@ class XendRoot:
    4.16      """Where block control scripts live."""
    4.17      block_script_dir = "/etc/xen/scripts"
    4.18  
    4.19 +    """Default path to the log file. """
    4.20      logfile_default = "/var/log/xend.log"
    4.21  
    4.22      loglevel_default = 'DEBUG'
    4.23  
    4.24 +    """Default interface address xend listens at. """
    4.25 +    xend_address_default      = ''
    4.26 +
    4.27 +    """Default port xend serves HTTP at. """
    4.28 +    xend_port_default         = '8000'
    4.29 +
    4.30 +    """Default port xend serves events at. """
    4.31 +    xend_event_port_default   = '8001'
    4.32 +
    4.33 +    """Default inteface address xend listens at for consoles."""
    4.34 +    console_address_default   = ''
    4.35 +
    4.36 +    """Default port xend serves consoles at. """
    4.37 +    console_port_base_default = '9600'
    4.38 +
    4.39      components = {}
    4.40  
    4.41      def __init__(self):
    4.42          self.dbroot = None
    4.43          self.config_path = None
    4.44          self.config = None
    4.45 -        self.logger = None
    4.46 +        self.logging = None
    4.47          self.configure()
    4.48          eserver.subscribe('xend.*', self.event_handler)
    4.49          #eserver.subscribe('xend.domain.created', self.event_handler)
    4.50 @@ -73,9 +94,9 @@ class XendRoot:
    4.51  
    4.52      def _format(self, msg, args):
    4.53          if args:
    4.54 -            return str(msg)
    4.55 +            return str(msg) % args
    4.56          else:
    4.57 -            return str(msg) % args
    4.58 +            return str(msg)
    4.59  
    4.60      def _log(self, mode, fmt, args):
    4.61          """Logging function that uses the logger if it exists, otherwise
    4.62 @@ -90,7 +111,7 @@ class XendRoot:
    4.63          if log:
    4.64              getattr(log, mode)(fmt, *args)
    4.65          else:
    4.66 -            print >>stderr, "xend", "[%s]" % level, self._format(msg, args)
    4.67 +            print >>sys.stderr, "xend", "[%s]" % level, self._format(fmt, args)
    4.68  
    4.69      def logDebug(self, fmt, *args):
    4.70          """Log a debug message.
    4.71 @@ -132,7 +153,6 @@ class XendRoot:
    4.72          self.configure_logger()
    4.73          self.dbroot = self.get_config_value("dbroot", self.dbroot_default)
    4.74  
    4.75 -
    4.76      def configure_logger(self):
    4.77          logfile = self.get_config_value("logfile", self.logfile_default)
    4.78          loglevel = self.get_config_value("loglevel", self.loglevel_default)
    4.79 @@ -146,7 +166,7 @@ class XendRoot:
    4.80      def get_logger(self):
    4.81          """Get the logger.
    4.82          """
    4.83 -        return self.logging.getLogger()
    4.84 +        return self.logging and self.logging.getLogger()
    4.85  
    4.86      def get_dbroot(self):
    4.87          """Get the path to the database root.
    4.88 @@ -160,14 +180,20 @@ class XendRoot:
    4.89          """
    4.90          self.config_path = os.getenv(self.config_var, self.config_default)
    4.91          if os.path.exists(self.config_path):
    4.92 -            fin = file(self.config_path, 'rb')
    4.93 +            #self.logInfo('Reading config file %s', self.config_path)
    4.94              try:
    4.95 -                config = sxp.parse(fin)
    4.96 +                fin = file(self.config_path, 'rb')
    4.97 +                try:
    4.98 +                    config = sxp.parse(fin)
    4.99 +                finally:
   4.100 +                    fin.close()
   4.101                  config.insert(0, 'xend-config')
   4.102                  self.config = config
   4.103 -            finally:
   4.104 -                fin.close()
   4.105 +            except Exception, ex:
   4.106 +                self.logError('Reading config file %s: %s', self.config_path, str(ex))
   4.107 +                raise
   4.108          else:
   4.109 +            self.logError('Config file does not exist: %s', self.config_path)
   4.110              self.config = ['xend-config']
   4.111  
   4.112      def get_config(self, name=None):
   4.113 @@ -193,10 +219,35 @@ class XendRoot:
   4.114          return sxp.child_value(self.config, name, val=val)
   4.115  
   4.116      def get_xend_port(self):
   4.117 -        return int(self.get_config_value('xend-port', '8000'))
   4.118 +        """Get the port xend listens at for its HTTP interface.
   4.119 +        """
   4.120 +        return int(self.get_config_value('xend-port', self.xend_port_default))
   4.121 +
   4.122 +    def get_xend_event_port(self):
   4.123 +        """Get the port xend listens at for connection to its event server.
   4.124 +        """
   4.125 +        return int(self.get_config_value('xend-event-port', self.xend_event_port_default))
   4.126  
   4.127      def get_xend_address(self):
   4.128 -        return self.get_config_value('xend-address', '')
   4.129 +        """Get the address xend listens at for its HTTP and event ports.
   4.130 +        This defaults to the empty string which allows all hosts to connect.
   4.131 +        If this is set to 'localhost' only the localhost will be able to connect
   4.132 +        to the HTTP and event ports.
   4.133 +        """
   4.134 +        return self.get_config_value('xend-address', self.xend_address_default)
   4.135 +
   4.136 +    def get_console_address(self):
   4.137 +        """Get the address xend listens at for its console ports.
   4.138 +        This defaults to the empty string which allows all hosts to connect.
   4.139 +        If this is set to 'localhost' only the localhost will be able to connect
   4.140 +        to the console ports.
   4.141 +        """
   4.142 +        return self.get_config_value('console-address', self.console_address_default)
   4.143 +
   4.144 +    def get_console_port_base(self):
   4.145 +        """Get the base port number used to generate console ports for domains.
   4.146 +        """
   4.147 +        return int(self.get_config_value('console-port-base', self.console_port_base_default))
   4.148  
   4.149      def get_block_script(self, type):
   4.150          return self.get_config_value('block-%s' % type, '')
     5.1 --- a/tools/python/xen/xend/server/SrvBase.py	Sun Mar 13 00:35:14 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/SrvBase.py	Sun Mar 13 09:39:14 2005 +0000
     5.3 @@ -106,7 +106,8 @@ class SrvBase(resource.Resource):
     5.4          try:
     5.5              val = op_method(op, req)
     5.6          except Exception, err:
     5.7 -            return self._perform_err(err, op, req)
     5.8 +            self._perform_err(err, op, req)
     5.9 +            return ''
    5.10              
    5.11          if isinstance(val, defer.Deferred):
    5.12              val.addCallback(self._perform_cb, op, req, dfr=1)
     6.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Sun Mar 13 00:35:14 2005 +0000
     6.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Sun Mar 13 09:39:14 2005 +0000
     6.3 @@ -598,10 +598,10 @@ class Daemon:
     6.4      def set_user(self):
     6.5          # Set the UID.
     6.6          try:
     6.7 -            os.setuid(pwd.getpwnam(USER)[2])
     6.8 +            os.setuid(pwd.getpwnam(XEND_USER)[2])
     6.9              return 0
    6.10          except KeyError, error:
    6.11 -            print "Error: no such user '%s'" % USER
    6.12 +            print "Error: no such user '%s'" % XEND_USER
    6.13              return 1
    6.14  
    6.15      def stop(self):
    6.16 @@ -611,7 +611,7 @@ class Daemon:
    6.17          xroot = XendRoot.instance()
    6.18          log.info("Xend Daemon started")
    6.19          self.createFactories()
    6.20 -        self.listenEvent()
    6.21 +        self.listenEvent(xroot)
    6.22          self.listenNotifier()
    6.23          self.listenVirq()
    6.24          SrvServer.create(bridge=1)
    6.25 @@ -625,9 +625,11 @@ class Daemon:
    6.26          self.usbifCF = usbif.UsbifControllerFactory()
    6.27          self.consoleCF = console.ConsoleControllerFactory()
    6.28  
    6.29 -    def listenEvent(self):
    6.30 +    def listenEvent(self, xroot):
    6.31          protocol = EventFactory(self)
    6.32 -        return reactor.listenTCP(EVENT_PORT, protocol)
    6.33 +        port = xroot.get_xend_event_port()
    6.34 +        interface = xroot.get_xend_address()
    6.35 +        return reactor.listenTCP(port, protocol, interface=interface)
    6.36  
    6.37      def listenNotifier(self):
    6.38          protocol = NotifierProtocol(self.channelF)
     7.1 --- a/tools/python/xen/xend/server/SrvDir.py	Sun Mar 13 00:35:14 2005 +0000
     7.2 +++ b/tools/python/xen/xend/server/SrvDir.py	Sun Mar 13 09:39:14 2005 +0000
     7.3 @@ -88,7 +88,7 @@ class SrvDir(SrvBase):
     7.4                  req.write('</body></html>')
     7.5              return ''
     7.6          except Exception, ex:
     7.7 -            self._perform_err(ex, req)
     7.8 +            self._perform_err(ex, "GET", req)
     7.9              
    7.10      def ls(self, req, use_sxp=0):
    7.11          url = req.prePathURL()
     8.1 --- a/tools/python/xen/xend/server/console.py	Sun Mar 13 00:35:14 2005 +0000
     8.2 +++ b/tools/python/xen/xend/server/console.py	Sun Mar 13 09:39:14 2005 +0000
     8.3 @@ -11,6 +11,8 @@ from xen.xend.XendError import XendError
     8.4  from xen.xend import EventServer
     8.5  eserver = EventServer.instance()
     8.6  from xen.xend.XendLogging import log
     8.7 +from xen.xend import XendRoot
     8.8 +xroot = XendRoot.instance()
     8.9  
    8.10  import controller
    8.11  from messages import *
    8.12 @@ -191,7 +193,8 @@ class ConsoleController(controller.Contr
    8.13              pass
    8.14          else:
    8.15              f = ConsoleFactory(self, self.idx)
    8.16 -            self.listener = reactor.listenTCP(self.console_port, f)
    8.17 +            interface = xroot.get_console_address()
    8.18 +            self.listener = reactor.listenTCP(self.console_port, f, interface=interface)
    8.19  
    8.20      def connect(self, addr, conn):
    8.21          """Connect a TCP connection to the console.
     9.1 --- a/tools/python/xen/xend/server/params.py	Sun Mar 13 00:35:14 2005 +0000
     9.2 +++ b/tools/python/xen/xend/server/params.py	Sun Mar 13 09:39:14 2005 +0000
     9.3 @@ -3,9 +3,5 @@ XEND_PID_FILE = '/var/run/xend.pid'
     9.4  XFRD_PID_FILE = '/var/run/xfrd.pid'
     9.5  XEND_TRACE_FILE = '/var/log/xend.trace'
     9.6  
     9.7 -USER = 'root'
     9.8 +XEND_USER = 'root'
     9.9  
    9.10 -EVENT_PORT = 8001
    9.11 -
    9.12 -CONSOLE_PORT_BASE = 9600
    9.13 -
    12.1 --- a/xen/include/public/xen.h	Sun Mar 13 00:35:14 2005 +0000
    12.2 +++ b/xen/include/public/xen.h	Sun Mar 13 09:39:14 2005 +0000
    12.3 @@ -191,6 +191,16 @@
    12.4  #define SCHEDOP_reasonshift     8   /* 8-bit reason code. (SCHEDOP_shutdown) */
    12.5  
    12.6  /*
    12.7 + * Reason codes for SCHEDOP_shutdown. These may be interpreted by control 
    12.8 + * software to determine the appropriate action. For the most part, Xen does
    12.9 + * not care about the shutdown code (SHUTDOWN_crash excepted).
   12.10 + */
   12.11 +#define SHUTDOWN_poweroff   0  /* Domain exited normally. Clean up and kill. */
   12.12 +#define SHUTDOWN_reboot     1  /* Clean up, kill, and then restart.          */
   12.13 +#define SHUTDOWN_suspend    2  /* Clean up, save suspend info, kill.         */
   12.14 +#define SHUTDOWN_crash      3  /* Tell controller we've crashed.             */
   12.15 +
   12.16 +/*
   12.17   * Commands to HYPERVISOR_console_io().
   12.18   */
   12.19  #define CONSOLEIO_write         0