ia64/xen-unstable

changeset 2865:8a60d9e79b3c

bitkeeper revision 1.1159.155.6 (418960fcc8HEe_ZDfftWd3gpkqGjnw)

Cleanup code to reconnect domain control channel after xend restart.
Based on code by Mike Wray.
author cl349@freefall.cl.cam.ac.uk
date Wed Nov 03 22:51:40 2004 +0000 (2004-11-03)
parents 0e11a91b4002
children e123be8ad5cc
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/SrvDaemon.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	Wed Nov 03 20:19:27 2004 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Wed Nov 03 22:51:40 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	Wed Nov 03 20:19:27 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendConsole.py	Wed Nov 03 22:51:40 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	Wed Nov 03 20:19:27 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Nov 03 22:51:40 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/SrvDaemon.py	Wed Nov 03 20:19:27 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Wed Nov 03 22:51:40 2004 +0000
     4.3 @@ -638,12 +638,22 @@ class Daemon:
     4.4      def getDomChannel(self, dom):
     4.5          """Get the channel to a domain.
     4.6  
     4.7 -        dom domain
     4.8 -
     4.9 -        returns channel (or None)
    4.10 +        @param dom: domain
    4.11 +        @return: channel (or None)
    4.12          """
    4.13          return self.channelF.getDomChannel(dom)
    4.14  
    4.15 +    def createDomChannel(self, dom, local_port=0, remote_port=0):
    4.16 +        """Get the channel to a domain, creating if necessary.
    4.17 +
    4.18 +        @param dom: domain
    4.19 +        @param local_port: optional local port to re-use
    4.20 +        @param remote_port: optional remote port to re-use
    4.21 +        @return: channel
    4.22 +        """
    4.23 +        return self.channelF.domChannel(dom, local_port=local_port,
    4.24 +                                        remote_port=remote_port)
    4.25 +
    4.26      def blkif_create(self, dom, recreate=0):
    4.27          """Create or get a block device interface controller.
    4.28          
    4.29 @@ -671,13 +681,12 @@ class Daemon:
    4.30      def netif_get(self, dom):
    4.31          return self.netifCF.getControllerByDom(dom)
    4.32  
    4.33 -    def console_create(self, dom, console_port=None, remote_port=0):
    4.34 +    def console_create(self, dom, console_port=None):
    4.35          """Create a console for a domain.
    4.36          """
    4.37          console = self.consoleCF.getControllerByDom(dom)
    4.38          if console is None:
    4.39 -            console = self.consoleCF.createController(dom, console_port,
    4.40 -                                                      remote_port=remote_port)
    4.41 +            console = self.consoleCF.createController(dom, console_port)
    4.42          return console
    4.43  
    4.44      def consoles(self):
     5.1 --- a/tools/python/xen/xend/server/channel.py	Wed Nov 03 20:19:27 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/channel.py	Wed Nov 03 22:51:40 2004 +0000
     5.3 @@ -45,7 +45,7 @@ class ChannelFactory:
     5.4              del self.channels[idx]
     5.5              self.notifier.unbind(idx)
     5.6  
     5.7 -    def domChannel(self, dom, remote_port=0):
     5.8 +    def domChannel(self, dom, local_port=0, remote_port=0):
     5.9          """Get the channel for the given domain.
    5.10          Construct if necessary.
    5.11  
    5.12 @@ -55,7 +55,8 @@ class ChannelFactory:
    5.13          """
    5.14          chan = self.getDomChannel(dom)
    5.15          if not chan:
    5.16 -            chan = Channel(self, dom, remote_port=remote_port)
    5.17 +            chan = Channel(self, dom, local_port=local_port,
    5.18 +                           remote_port=remote_port)
    5.19              self.addChannel(chan)
    5.20          return chan
    5.21  
    5.22 @@ -91,10 +92,25 @@ class ChannelFactory:
    5.23          """
    5.24          self.delChannel(channel.idx)
    5.25  
    5.26 -    def createPort(self, dom, remote_port=0):
    5.27 +    def createPort(self, dom, local_port=0, remote_port=0):
    5.28          """Create a port for a channel to the given domain.
    5.29 +        If only the domain is specified, a new channel with new port ids is
    5.30 +        created.  If one port id is specified and the given port id is in use,
    5.31 +        the other port id is filled.  If one port id is specified and the
    5.32 +        given port id is not in use, a new channel is created with one port
    5.33 +        id equal to the given id and a new id for the other end.  If both
    5.34 +        port ids are specified, a port is reconnected using the given port
    5.35 +        ids.
    5.36 +
    5.37 +        @param dom: domain
    5.38 +        @param local: local port id to use
    5.39 +        @type  local: int
    5.40 +        @param remote: remote port id to use
    5.41 +        @type  remote: int
    5.42 +        @return: port object
    5.43          """
    5.44 -        return xu.port(dom, 0, remote_port)
    5.45 +        return xu.port(dom, local_port=int(local_port),
    5.46 +                       remote_port=int(remote_port))
    5.47  
    5.48  def channelFactory():
    5.49      """Singleton constructor for the channel factory.
    5.50 @@ -200,7 +216,7 @@ class Channel(BaseChannel):
    5.51      are multiplexed over the channel (console, block devs, net devs).
    5.52      """
    5.53  
    5.54 -    def __init__(self, factory, dom, remote_port=0):
    5.55 +    def __init__(self, factory, dom, local_port=0, remote_port=0):
    5.56          """Create a channel to the given domain using the given factory.
    5.57  
    5.58          Do not call directly, use domChannel on the factory.
    5.59 @@ -209,7 +225,8 @@ class Channel(BaseChannel):
    5.60          # Domain.
    5.61          self.dom = int(dom)
    5.62          # Domain port (object).
    5.63 -        self.port = self.factory.createPort(dom, remote_port=remote_port)
    5.64 +        self.port = self.factory.createPort(dom, local_port=local_port,
    5.65 +                                            remote_port=remote_port)
    5.66          # Channel port (int).
    5.67          self.idx = self.port.local_port
    5.68          # Registered devices.
     6.1 --- a/tools/python/xen/xend/server/console.py	Wed Nov 03 20:19:27 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/console.py	Wed Nov 03 22:51:40 2004 +0000
     6.3 @@ -48,7 +48,6 @@ class ConsoleProtocol(protocol.Protocol)
     6.4              self.loseConnection()
     6.5  
     6.6      def write(self, data):
     6.7 -        #if not self.connected: return -1
     6.8          self.transport.write(data)
     6.9          return len(data)
    6.10  
    6.11 @@ -81,14 +80,13 @@ class ConsoleControllerFactory(controlle
    6.12      """Factory for creating console controllers.
    6.13      """
    6.14  
    6.15 -    def createController(self, dom, console_port=None, remote_port=0):
    6.16 +    def createController(self, dom, console_port=None):
    6.17          if console_port is None:
    6.18              console_port = CONSOLE_PORT_BASE + dom
    6.19          for c in self.getControllers():
    6.20              if c.console_port == console_port:
    6.21                  raise XendError('console port in use: ' + str(console_port))
    6.22 -        console = ConsoleController(self, dom, console_port,
    6.23 -                                    remote_port=remote_port)
    6.24 +        console = ConsoleController(self, dom, console_port)
    6.25          self.addController(console)
    6.26          log.info("Created console id=%s domain=%d port=%d",
    6.27                   console.idx, console.dom, console.console_port)
    6.28 @@ -112,9 +110,8 @@ class ConsoleController(controller.Contr
    6.29      STATUS_CONNECTED = 'connected'
    6.30      STATUS_LISTENING = 'listening'
    6.31  
    6.32 -    def __init__(self, factory, dom, console_port, remote_port=0):
    6.33 -        controller.Controller.__init__(self, factory, dom,
    6.34 -                                       remote_port=remote_port)
    6.35 +    def __init__(self, factory, dom, console_port):
    6.36 +        controller.Controller.__init__(self, factory, dom)
    6.37          self.addMethod(CMSG_CONSOLE, 0, None)
    6.38          self.status = self.STATUS_NEW
    6.39          self.addr = None
     7.1 --- a/tools/python/xen/xend/server/controller.py	Wed Nov 03 20:19:27 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/controller.py	Wed Nov 03 22:51:40 2004 +0000
     7.3 @@ -68,7 +68,7 @@ class CtrlMsgRcvr:
     7.4      @type responders: {int:Responder}
     7.5      """
     7.6  
     7.7 -    def __init__(self, remote_port=0):
     7.8 +    def __init__(self):
     7.9          self.channelFactory = channel.channelFactory()
    7.10          self.majorTypes = {}
    7.11          self.dom = None
    7.12 @@ -76,7 +76,6 @@ class CtrlMsgRcvr:
    7.13          self.idx = None
    7.14          self.responders = {}
    7.15          self.timeout = 10
    7.16 -        self.remote_port = remote_port
    7.17  
    7.18      def setTimeout(self, timeout):
    7.19          self.timeout = timeout
    7.20 @@ -218,8 +217,7 @@ class CtrlMsgRcvr:
    7.21          channel to our domain. Once we have registered, the channel
    7.22          will call requestReceived or responseReceived for our messages.
    7.23          """
    7.24 -        self.channel = self.channelFactory.domChannel(self.dom,
    7.25 -                                                      self.remote_port)
    7.26 +        self.channel = self.channelFactory.domChannel(self.dom)
    7.27          self.idx = self.channel.getIndex()
    7.28          if self.majorTypes:
    7.29              self.channel.registerDevice(self.getMajorTypes(), self)
    7.30 @@ -364,8 +362,8 @@ class Controller(CtrlMsgRcvr):
    7.31      @type idx:     String
    7.32      """
    7.33  
    7.34 -    def __init__(self, factory, dom, remote_port=0):
    7.35 -        CtrlMsgRcvr.__init__(self, remote_port=remote_port)
    7.36 +    def __init__(self, factory, dom):
    7.37 +        CtrlMsgRcvr.__init__(self)
    7.38          self.factory = factory
    7.39          self.dom = int(dom)
    7.40          self.channel = None