ia64/xen-unstable

changeset 2868:aeaa8b6b072d

bitkeeper revision 1.1159.1.359 (41898114F_zAayDscoCC43HUnOIsPw)

Merge labyrinth.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into labyrinth.cl.cam.ac.uk:/auto/anfs/scratch/labyrinth/iap10/xeno-clone/xeno.bk
author iap10@labyrinth.cl.cam.ac.uk
date Thu Nov 04 01:08:36 2004 +0000 (2004-11-04)
parents 8940f859d3fe e123be8ad5cc
children 94ac39a10a8d
files tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/XendConsole.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvBase.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/console.py tools/python/xen/xend/server/controller.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Thu Nov 04 00:32:58 2004 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Thu Nov 04 01:08:36 2004 +0000
     1.3 @@ -1054,13 +1054,16 @@ static PyMethodDef xu_port_methods[] = {
     1.4  
     1.5  staticforward PyTypeObject xu_port_type;
     1.6  
     1.7 -static PyObject *xu_port_new(PyObject *self, PyObject *args)
     1.8 +static PyObject *xu_port_new(PyObject *self, PyObject *args, PyObject *kwds)
     1.9  {
    1.10      xu_port_object *xup;
    1.11      u32 dom;
    1.12      int port1 = 0, port2 = 0;
    1.13  
    1.14 -    if ( !PyArg_ParseTuple(args, "i|ii", &dom, &port1, &port2) )
    1.15 +    static char *kwd_list[] = { "dom", "local_port", "remote_port", NULL };
    1.16 +
    1.17 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list,
    1.18 +                                      &dom, &port1, &port2) )
    1.19          return NULL;
    1.20  
    1.21      xup = PyObject_New(xu_port_object, &xu_port_type);
    1.22 @@ -1435,7 +1438,7 @@ static PyMethodDef xu_methods[] = {
    1.23        "Create a new notifier." },
    1.24      { "message", xu_message_new, METH_VARARGS, 
    1.25        "Create a new communications message." },
    1.26 -    { "port", xu_port_new, METH_VARARGS, 
    1.27 +    { "port", (PyCFunction)xu_port_new, METH_VARARGS | METH_KEYWORDS, 
    1.28        "Create a new communications port." },
    1.29      { "buffer", xu_buffer_new, METH_VARARGS, 
    1.30        "Create a new ring buffer." },
     2.1 --- a/tools/python/xen/xend/XendConsole.py	Thu Nov 04 00:32:58 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendConsole.py	Thu Nov 04 01:08:36 2004 +0000
     2.3 @@ -32,9 +32,8 @@ class XendConsole:
     2.4      def consoles(self):
     2.5          return daemon.get_consoles()
     2.6      
     2.7 -    def console_create(self, dom, console_port=None, remote_port=0):
     2.8 -        consinfo = daemon.console_create(dom, console_port=console_port,
     2.9 -                                         remote_port=remote_port)
    2.10 +    def console_create(self, dom, console_port=None):
    2.11 +        consinfo = daemon.console_create(dom, console_port=console_port)
    2.12          return consinfo
    2.13      
    2.14      def console_get(self, id):
     3.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Nov 04 00:32:58 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Nov 04 01:08:36 2004 +0000
     3.3 @@ -753,17 +753,34 @@ class XendDomainInfo:
     3.4          @param ramdisk: kernel ramdisk
     3.5          @param cmdline: kernel commandline
     3.6          """
     3.7 -        #self.init_domain()
     3.8 +
     3.9 +        self.create_channel()
    3.10          if self.console:
    3.11              self.console.registerChannel()
    3.12          else:
    3.13              self.console = xendConsole.console_create(
    3.14 -                self.dom, console_port=self.console_port, remote_port=1)
    3.15 +                self.dom, console_port=self.console_port)
    3.16          self.build_domain(ostype, kernel, ramdisk, cmdline)
    3.17          self.image = kernel
    3.18          self.ramdisk = ramdisk
    3.19          self.cmdline = cmdline
    3.20  
    3.21 +    def create_channel(self):
    3.22 +        """Create the channel to the domain.
    3.23 +        If saved info is available recreate the channel using the saved ports.
    3.24 +
    3.25 +        @return: channel
    3.26 +        """
    3.27 +        local = 0
    3.28 +        remote = 1
    3.29 +        if self.savedinfo:
    3.30 +            consinfo = sxp.child(self.savedinfo, "console")
    3.31 +            if consinfo:
    3.32 +                local = int(sxp.child_value(consinfo, "local_port", 0))
    3.33 +                remote = int(sxp.child_value(consinfo, "remote_port", 1))
    3.34 +        return xend.createDomChannel(self.dom, local_port=local,
    3.35 +                                     remote_port=remote)
    3.36 +
    3.37      def create_devices(self):
    3.38          """Create the devices for a vm.
    3.39  
     4.1 --- a/tools/python/xen/xend/server/SrvBase.py	Thu Nov 04 00:32:58 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/SrvBase.py	Thu Nov 04 01:08:36 2004 +0000
     4.3 @@ -8,17 +8,18 @@ import types
     4.4  import StringIO
     4.5  
     4.6  from twisted.internet import defer
     4.7 -#defer.Deferred.debug = 1
     4.8  from twisted.internet import reactor
     4.9  from twisted.protocols import http
    4.10  from twisted.web import error
    4.11  from twisted.web import resource
    4.12  from twisted.web import server
    4.13 +from twisted.python.failure import Failure
    4.14  
    4.15  from xen.xend import sxp
    4.16  from xen.xend import PrettyPrint
    4.17  from xen.xend.Args import ArgError
    4.18  from xen.xend.XendError import XendError
    4.19 +from xen.xend.XendLogging import log
    4.20  
    4.21  def uri_pathlist(p):
    4.22      """Split a path into a list.
    4.23 @@ -105,17 +106,17 @@ class SrvBase(resource.Resource):
    4.24          try:
    4.25              val = op_method(op, req)
    4.26          except Exception, err:
    4.27 -            return self._perform_err(err, req)
    4.28 +            return self._perform_err(err, op, req)
    4.29              
    4.30          if isinstance(val, defer.Deferred):
    4.31 -            val.addCallback(self._perform_cb, req, dfr=1)
    4.32 -            val.addErrback(self._perform_err, req, dfr=1)
    4.33 +            val.addCallback(self._perform_cb, op, req, dfr=1)
    4.34 +            val.addErrback(self._perform_err, op, req, dfr=1)
    4.35              return server.NOT_DONE_YET
    4.36          else:
    4.37 -            self._perform_cb(val, req, 0)
    4.38 +            self._perform_cb(val, op, req, dfr=0)
    4.39              return ''
    4.40  
    4.41 -    def _perform_cb(self, val, req, dfr):
    4.42 +    def _perform_cb(self, val, op, req, dfr=0):
    4.43          """Callback to complete the request.
    4.44          May be called from a Deferred.
    4.45  
    4.46 @@ -141,7 +142,7 @@ class SrvBase(resource.Resource):
    4.47          if dfr:
    4.48              req.finish()
    4.49  
    4.50 -    def _perform_err(self, err, req, dfr=0):
    4.51 +    def _perform_err(self, err, op, req, dfr=0):
    4.52          """Error callback to complete a request.
    4.53          May be called from a Deferred.
    4.54  
    4.55 @@ -149,13 +150,16 @@ class SrvBase(resource.Resource):
    4.56          @param req: request causing the error
    4.57          @param dfr: deferred flag
    4.58          """
    4.59 -        if not (isinstance(err, ArgError) or
    4.60 -                isinstance(err, sxp.ParseError) or
    4.61 -                isinstance(err, XendError)):
    4.62 +        if isinstance(err, Failure):
    4.63 +            err = err.getErrorMessage()
    4.64 +        elif not (isinstance(err, ArgError) or
    4.65 +                  isinstance(err, sxp.ParseError) or
    4.66 +                  isinstance(err, XendError)):
    4.67              if dfr:
    4.68                  return err
    4.69              else:
    4.70                  raise
    4.71 +        log.exception("op=%s: %s", op, str(err))
    4.72          if self.use_sxp(req):
    4.73              req.setHeader("Content-Type", sxp.mime_type)
    4.74              sxp.show(['xend.err', str(err)], out=req)
     5.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Nov 04 00:32:58 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Nov 04 01:08:36 2004 +0000
     5.3 @@ -639,12 +639,22 @@ class Daemon:
     5.4      def getDomChannel(self, dom):
     5.5          """Get the channel to a domain.
     5.6  
     5.7 -        dom domain
     5.8 -
     5.9 -        returns channel (or None)
    5.10 +        @param dom: domain
    5.11 +        @return: channel (or None)
    5.12          """
    5.13          return self.channelF.getDomChannel(dom)
    5.14  
    5.15 +    def createDomChannel(self, dom, local_port=0, remote_port=0):
    5.16 +        """Get the channel to a domain, creating if necessary.
    5.17 +
    5.18 +        @param dom: domain
    5.19 +        @param local_port: optional local port to re-use
    5.20 +        @param remote_port: optional remote port to re-use
    5.21 +        @return: channel
    5.22 +        """
    5.23 +        return self.channelF.domChannel(dom, local_port=local_port,
    5.24 +                                        remote_port=remote_port)
    5.25 +
    5.26      def blkif_create(self, dom, recreate=0):
    5.27          """Create or get a block device interface controller.
    5.28          
    5.29 @@ -672,13 +682,12 @@ class Daemon:
    5.30      def netif_get(self, dom):
    5.31          return self.netifCF.getControllerByDom(dom)
    5.32  
    5.33 -    def console_create(self, dom, console_port=None, remote_port=0):
    5.34 +    def console_create(self, dom, console_port=None):
    5.35          """Create a console for a domain.
    5.36          """
    5.37          console = self.consoleCF.getControllerByDom(dom)
    5.38          if console is None:
    5.39 -            console = self.consoleCF.createController(dom, console_port,
    5.40 -                                                      remote_port=remote_port)
    5.41 +            console = self.consoleCF.createController(dom, console_port)
    5.42          return console
    5.43  
    5.44      def consoles(self):
     6.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Thu Nov 04 00:32:58 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Thu Nov 04 01:08:36 2004 +0000
     6.3 @@ -11,6 +11,7 @@ from xen.xend import sxp
     6.4  from xen.xend import XendDomain
     6.5  from xen.xend.Args import FormFn
     6.6  from xen.xend.XendError import XendError
     6.7 +from xen.xend.XendLogging import log
     6.8  
     6.9  from SrvDir import SrvDir
    6.10  from SrvDomain import SrvDomain
    6.11 @@ -59,18 +60,15 @@ class SrvDomainDir(SrvDir):
    6.12          except sxp.ParseError, ex:
    6.13              errmsg = 'Invalid configuration ' + str(ex)
    6.14          if not ok:
    6.15 -            req.setResponseCode(http.BAD_REQUEST, errmsg)
    6.16 -            return errmsg
    6.17 +            raise XendError(errmsg)
    6.18          try:
    6.19              deferred = self.xd.domain_create(config)
    6.20              deferred.addCallback(self._op_create_cb, configstring, req)
    6.21 -            deferred.addErrback(self._op_create_err, req)
    6.22              return deferred
    6.23          except Exception, ex:
    6.24              print 'op_create> Exception creating domain:'
    6.25              traceback.print_exc()
    6.26 -            req.setResponseCode(http.BAD_REQUEST, "Error creating domain: " + str(ex))
    6.27 -            return str(ex)
    6.28 +            raise XendError("Error creating domain: " + str(ex))
    6.29  
    6.30      def _op_create_cb(self, dominfo, configstring, req):
    6.31          """Callback to handle deferred domain creation.
    6.32 @@ -92,27 +90,15 @@ class SrvDomainDir(SrvDir):
    6.33              out.close()
    6.34              return val
    6.35  
    6.36 -    def _op_create_err(self, err, req):
    6.37 -        """Callback to handle errors in deferred domain creation.
    6.38 -        """
    6.39 -        if isinstance(err, Failure):
    6.40 -            err = err.getErrorMessage()
    6.41 -        print 'op_create> Deferred Exception creating domain:', err
    6.42 -        traceback.print_exc()
    6.43 -        req.setResponseCode(http.BAD_REQUEST, "Error creating domain: " + str(err))
    6.44 -        return str(err)
    6.45 -
    6.46      def op_restore(self, op, req):
    6.47          """Restore a domain from file.
    6.48  
    6.49          @return: deferred
    6.50          """
    6.51 -        #todo: return is deferred. May need ok and err callbacks.
    6.52          fn = FormFn(self.xd.domain_restore,
    6.53                      [['file', 'str']])
    6.54          deferred = fn(req.args)
    6.55          deferred.addCallback(self._op_restore_cb, req)
    6.56 -        #deferred.addErrback(self._op_restore_err, req)
    6.57          return deferred
    6.58  
    6.59      def _op_restore_cb(self, dominfo, req):
    6.60 @@ -130,13 +116,6 @@ class SrvDomainDir(SrvDir):
    6.61              out.close()
    6.62              return val
    6.63  
    6.64 -    def _op_restore_err(self, err, req):
    6.65 -        if isinstance(err, Failure):
    6.66 -            err = err.getErrorMessage()
    6.67 -        print 'op_create> Deferred Exception restoring domain:', err
    6.68 -        req.setResponseCode(http.BAD_REQUEST, "Error restoring domain: "+ str(err))
    6.69 -        return str(err)
    6.70 -        
    6.71      def render_POST(self, req):
    6.72          return self.perform(req)
    6.73  
     7.1 --- a/tools/python/xen/xend/server/channel.py	Thu Nov 04 00:32:58 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/channel.py	Thu Nov 04 01:08:36 2004 +0000
     7.3 @@ -45,7 +45,7 @@ class ChannelFactory:
     7.4              del self.channels[idx]
     7.5              self.notifier.unbind(idx)
     7.6  
     7.7 -    def domChannel(self, dom, remote_port=0):
     7.8 +    def domChannel(self, dom, local_port=0, remote_port=0):
     7.9          """Get the channel for the given domain.
    7.10          Construct if necessary.
    7.11  
    7.12 @@ -55,7 +55,8 @@ class ChannelFactory:
    7.13          """
    7.14          chan = self.getDomChannel(dom)
    7.15          if not chan:
    7.16 -            chan = Channel(self, dom, remote_port=remote_port)
    7.17 +            chan = Channel(self, dom, local_port=local_port,
    7.18 +                           remote_port=remote_port)
    7.19              self.addChannel(chan)
    7.20          return chan
    7.21  
    7.22 @@ -91,10 +92,25 @@ class ChannelFactory:
    7.23          """
    7.24          self.delChannel(channel.idx)
    7.25  
    7.26 -    def createPort(self, dom, remote_port=0):
    7.27 +    def createPort(self, dom, local_port=0, remote_port=0):
    7.28          """Create a port for a channel to the given domain.
    7.29 +        If only the domain is specified, a new channel with new port ids is
    7.30 +        created.  If one port id is specified and the given port id is in use,
    7.31 +        the other port id is filled.  If one port id is specified and the
    7.32 +        given port id is not in use, a new channel is created with one port
    7.33 +        id equal to the given id and a new id for the other end.  If both
    7.34 +        port ids are specified, a port is reconnected using the given port
    7.35 +        ids.
    7.36 +
    7.37 +        @param dom: domain
    7.38 +        @param local: local port id to use
    7.39 +        @type  local: int
    7.40 +        @param remote: remote port id to use
    7.41 +        @type  remote: int
    7.42 +        @return: port object
    7.43          """
    7.44 -        return xu.port(dom, 0, remote_port)
    7.45 +        return xu.port(dom, local_port=int(local_port),
    7.46 +                       remote_port=int(remote_port))
    7.47  
    7.48  def channelFactory():
    7.49      """Singleton constructor for the channel factory.
    7.50 @@ -200,7 +216,7 @@ class Channel(BaseChannel):
    7.51      are multiplexed over the channel (console, block devs, net devs).
    7.52      """
    7.53  
    7.54 -    def __init__(self, factory, dom, remote_port=0):
    7.55 +    def __init__(self, factory, dom, local_port=0, remote_port=0):
    7.56          """Create a channel to the given domain using the given factory.
    7.57  
    7.58          Do not call directly, use domChannel on the factory.
    7.59 @@ -209,7 +225,8 @@ class Channel(BaseChannel):
    7.60          # Domain.
    7.61          self.dom = int(dom)
    7.62          # Domain port (object).
    7.63 -        self.port = self.factory.createPort(dom, remote_port=remote_port)
    7.64 +        self.port = self.factory.createPort(dom, local_port=local_port,
    7.65 +                                            remote_port=remote_port)
    7.66          # Channel port (int).
    7.67          self.idx = self.port.local_port
    7.68          # Registered devices.
     8.1 --- a/tools/python/xen/xend/server/console.py	Thu Nov 04 00:32:58 2004 +0000
     8.2 +++ b/tools/python/xen/xend/server/console.py	Thu Nov 04 01:08:36 2004 +0000
     8.3 @@ -48,7 +48,6 @@ class ConsoleProtocol(protocol.Protocol)
     8.4              self.loseConnection()
     8.5  
     8.6      def write(self, data):
     8.7 -        #if not self.connected: return -1
     8.8          self.transport.write(data)
     8.9          return len(data)
    8.10  
    8.11 @@ -81,14 +80,13 @@ class ConsoleControllerFactory(controlle
    8.12      """Factory for creating console controllers.
    8.13      """
    8.14  
    8.15 -    def createController(self, dom, console_port=None, remote_port=0):
    8.16 +    def createController(self, dom, console_port=None):
    8.17          if console_port is None:
    8.18              console_port = CONSOLE_PORT_BASE + dom
    8.19          for c in self.getControllers():
    8.20              if c.console_port == console_port:
    8.21                  raise XendError('console port in use: ' + str(console_port))
    8.22 -        console = ConsoleController(self, dom, console_port,
    8.23 -                                    remote_port=remote_port)
    8.24 +        console = ConsoleController(self, dom, console_port)
    8.25          self.addController(console)
    8.26          log.info("Created console id=%s domain=%d port=%d",
    8.27                   console.idx, console.dom, console.console_port)
    8.28 @@ -112,9 +110,8 @@ class ConsoleController(controller.Contr
    8.29      STATUS_CONNECTED = 'connected'
    8.30      STATUS_LISTENING = 'listening'
    8.31  
    8.32 -    def __init__(self, factory, dom, console_port, remote_port=0):
    8.33 -        controller.Controller.__init__(self, factory, dom,
    8.34 -                                       remote_port=remote_port)
    8.35 +    def __init__(self, factory, dom, console_port):
    8.36 +        controller.Controller.__init__(self, factory, dom)
    8.37          self.addMethod(CMSG_CONSOLE, 0, None)
    8.38          self.status = self.STATUS_NEW
    8.39          self.addr = None
     9.1 --- a/tools/python/xen/xend/server/controller.py	Thu Nov 04 00:32:58 2004 +0000
     9.2 +++ b/tools/python/xen/xend/server/controller.py	Thu Nov 04 01:08:36 2004 +0000
     9.3 @@ -68,7 +68,7 @@ class CtrlMsgRcvr:
     9.4      @type responders: {int:Responder}
     9.5      """
     9.6  
     9.7 -    def __init__(self, remote_port=0):
     9.8 +    def __init__(self):
     9.9          self.channelFactory = channel.channelFactory()
    9.10          self.majorTypes = {}
    9.11          self.dom = None
    9.12 @@ -76,7 +76,6 @@ class CtrlMsgRcvr:
    9.13          self.idx = None
    9.14          self.responders = {}
    9.15          self.timeout = 10
    9.16 -        self.remote_port = remote_port
    9.17  
    9.18      def setTimeout(self, timeout):
    9.19          self.timeout = timeout
    9.20 @@ -218,8 +217,7 @@ class CtrlMsgRcvr:
    9.21          channel to our domain. Once we have registered, the channel
    9.22          will call requestReceived or responseReceived for our messages.
    9.23          """
    9.24 -        self.channel = self.channelFactory.domChannel(self.dom,
    9.25 -                                                      self.remote_port)
    9.26 +        self.channel = self.channelFactory.domChannel(self.dom)
    9.27          self.idx = self.channel.getIndex()
    9.28          if self.majorTypes:
    9.29              self.channel.registerDevice(self.getMajorTypes(), self)
    9.30 @@ -364,8 +362,8 @@ class Controller(CtrlMsgRcvr):
    9.31      @type idx:     String
    9.32      """
    9.33  
    9.34 -    def __init__(self, factory, dom, remote_port=0):
    9.35 -        CtrlMsgRcvr.__init__(self, remote_port=remote_port)
    9.36 +    def __init__(self, factory, dom):
    9.37 +        CtrlMsgRcvr.__init__(self)
    9.38          self.factory = factory
    9.39          self.dom = int(dom)
    9.40          self.channel = None