direct-io.hg

changeset 1664:2e084d76fbf4

bitkeeper revision 1.1041.3.3 (40e52970DgkhtxD_Mq--sUEE6uPUZg)

Change console cleanup for domains so that it gets called
when the domain channel goes away. Stops console listeners
hanging around.
author mjw@wray-m-3.hpl.hp.com
date Fri Jul 02 09:22:56 2004 +0000 (2004-07-02)
parents 6edc06968b87
children bbd6af62af53
files tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/console.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Jul 01 14:16:50 2004 +0000
     1.2 +++ b/tools/python/xen/xend/server/blkif.py	Fri Jul 02 09:22:56 2004 +0000
     1.3 @@ -210,9 +210,6 @@ class BlkifController(controller.Control
     1.4                          self.evtchn['port2']])
     1.5          return val
     1.6  
     1.7 -    def lostChannel(self):
     1.8 -        controller.Controller.lostChannel(self)
     1.9 -
    1.10      def getDevices(self):
    1.11          return self.devices.values()
    1.12  
     2.1 --- a/tools/python/xen/xend/server/channel.py	Thu Jul 01 14:16:50 2004 +0000
     2.2 +++ b/tools/python/xen/xend/server/channel.py	Fri Jul 02 09:22:56 2004 +0000
     2.3 @@ -174,9 +174,9 @@ class VirqChannel(BaseChannel):
     2.4          """Close the channel. Calls lostChannel(self) on all its clients and
     2.5          channelClosed() on the factory.
     2.6          """
     2.7 -        for c in self.clients:
     2.8 +        for c in self.clients[:]:
     2.9              c.lostChannel(self)
    2.10 -        del self.clients
    2.11 +        self.clients = []
    2.12          BaseChannel.close(self)
    2.13  
    2.14      def registerClient(self, client):
    2.15 @@ -238,7 +238,7 @@ class Channel(BaseChannel):
    2.16          """
    2.17          if self.closed: return
    2.18          self.closed = 1
    2.19 -        for d in self.devs:
    2.20 +        for d in self.devs[:]:
    2.21              d.lostChannel()
    2.22          self.factory.channelClosed(self)
    2.23          self.devs = []
     3.1 --- a/tools/python/xen/xend/server/console.py	Thu Jul 01 14:16:50 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/console.py	Fri Jul 02 09:22:56 2004 +0000
     3.3 @@ -93,10 +93,15 @@ class ConsoleController(controller.Contr
     3.4      output and the connected TCP sockets to post console input.
     3.5      """
     3.6  
     3.7 +    STATUS_NEW       = 'new'
     3.8 +    STATUS_CLOSED    = 'closed'
     3.9 +    STATUS_CONNECTED = 'connected'
    3.10 +    STATUS_LISTENING = 'listening'
    3.11 +
    3.12      def __init__(self, factory, dom, console_port):
    3.13          controller.Controller.__init__(self, factory, dom)
    3.14          self.majorTypes = [ CMSG_CONSOLE ]
    3.15 -        self.status = "new"
    3.16 +        self.status = self.STATUS_NEW
    3.17          self.addr = None
    3.18          self.conn = None
    3.19          self.rbuf = xu.buffer()
    3.20 @@ -123,28 +128,31 @@ class ConsoleController(controller.Contr
    3.21          return not (self.closed() or self.rbuf.empty())
    3.22  
    3.23      def closed(self):
    3.24 -        return self.status == 'closed'
    3.25 +        return self.status == self.STATUS_CLOSED
    3.26  
    3.27      def connected(self):
    3.28 -        return self.status == 'connected'
    3.29 +        return self.status == self.STATUS_CONNECTED
    3.30  
    3.31      def close(self):
    3.32 -        try:
    3.33 -            self.status = "closed"
    3.34 -            if self.conn:
    3.35 -                self.conn.loseConnection()
    3.36 -            self.listener.stopListening()
    3.37 -            self.deregisterChannel()
    3.38 -            self.lostChannel()
    3.39 -        except Exception, ex:
    3.40 -            print 'ConsoleController>close>', ex
    3.41 -            raise
    3.42 +        """Close the console controller.
    3.43 +        """
    3.44 +        self.lostChannel()
    3.45 +
    3.46 +    def lostChannel(self):
    3.47 +        """The channel to the domain has been lost.
    3.48 +        Cleanup: disconnect TCP connections and listeners, notify the controller.
    3.49 +        """
    3.50 +        self.status = self.STATUS_CLOSED
    3.51 +        if self.conn:
    3.52 +            self.conn.loseConnection()
    3.53 +        self.listener.stopListening()
    3.54 +        controller.Controller.lostChannel(self)
    3.55  
    3.56      def listen(self):
    3.57          """Listen for TCP connections to the console port..
    3.58          """
    3.59          if self.closed(): return
    3.60 -        self.status = "listening"
    3.61 +        self.status = self.STATUS_LISTENING
    3.62          if self.listener:
    3.63              #self.listener.startListening()
    3.64              pass
    3.65 @@ -153,15 +161,25 @@ class ConsoleController(controller.Contr
    3.66              self.listener = reactor.listenTCP(self.console_port, f)
    3.67  
    3.68      def connect(self, addr, conn):
    3.69 +        """Connect a TCP connection to the console.
    3.70 +        Fails if closed or already connected.
    3.71 +
    3.72 +        addr peer address
    3.73 +        conn connection
    3.74 +
    3.75 +        returns 0 if ok, negative otherwise
    3.76 +        """
    3.77          if self.closed(): return -1
    3.78          if self.connected(): return -1
    3.79          self.addr = addr
    3.80          self.conn = conn
    3.81 -        self.status = "connected"
    3.82 +        self.status = self.STATUS_CONNECTED
    3.83          self.handleOutput()
    3.84          return 0
    3.85  
    3.86      def disconnect(self):
    3.87 +        """Disconnect the TCP connection to the console.
    3.88 +        """
    3.89          if self.conn:
    3.90              self.conn.loseConnection()
    3.91          self.addr = None
    3.92 @@ -169,15 +187,29 @@ class ConsoleController(controller.Contr
    3.93          self.listen()
    3.94  
    3.95      def requestReceived(self, msg, type, subtype):
    3.96 +        """Receive console data from the console channel.
    3.97 +
    3.98 +        msg     console message
    3.99 +        type    major message type
   3.100 +        subtype minor message typ
   3.101 +        """
   3.102          self.rbuf.write(msg.get_payload())
   3.103          self.handleOutput()
   3.104          
   3.105      def responseReceived(self, msg, type, subtype):
   3.106 -        # Just ignore responses.
   3.107 +        """Handle a response to a request written to the console channel.
   3.108 +        Just ignore it because the return values are not interesting.
   3.109 +
   3.110 +        msg     console message
   3.111 +        type    major message type
   3.112 +        subtype minor message typ
   3.113 +        """
   3.114          pass
   3.115  
   3.116      def produceRequests(self):
   3.117 -        # Send as much pending console data as there is room for.
   3.118 +        """Write pending console data to the console channel.
   3.119 +        Writes as much to the channel as it can.
   3.120 +        """
   3.121          work = 0
   3.122          while not self.wbuf.empty() and self.channel.writeReady():
   3.123              msg = xu.message(CMSG_CONSOLE, 0, 0)
   3.124 @@ -187,7 +219,12 @@ class ConsoleController(controller.Contr
   3.125  
   3.126      def handleInput(self, conn, data):
   3.127          """Handle some external input aimed at the console.
   3.128 -        Called from a TCP connection (conn).
   3.129 +        Called from a TCP connection (conn). Ignores the input
   3.130 +        if the calling connection (conn) is not the one connected
   3.131 +        to the console (self.conn).
   3.132 +
   3.133 +        conn connection
   3.134 +        data input data
   3.135          """
   3.136          if self.closed(): return -1
   3.137          if conn != self.conn: return 0
     4.1 --- a/tools/python/xen/xend/server/controller.py	Thu Jul 01 14:16:50 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/controller.py	Fri Jul 02 09:22:56 2004 +0000
     4.3 @@ -205,12 +205,12 @@ class Controller(CtrlMsgRcvr):
     4.4      def close(self):
     4.5          """Close the controller.
     4.6          """
     4.7 -        self.deregisterChannel()
     4.8          self.lostChannel()
     4.9  
    4.10      def lostChannel(self):
    4.11          """The controller channel has been lost.
    4.12          """
    4.13 +        self.deregisterChannel()
    4.14          self.factory.instanceClosed(self)
    4.15  
    4.16  class Dev:
     5.1 --- a/tools/python/xen/xend/server/netif.py	Thu Jul 01 14:16:50 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/netif.py	Fri Jul 02 09:22:56 2004 +0000
     5.3 @@ -198,8 +198,9 @@ class NetifController(controller.Control
     5.4      def randomMAC(self):
     5.5          """Generate a random MAC address.
     5.6  
     5.7 -        The OUI (Organisation Unique Identifier) used is AA:00:00, which
     5.8 -        is a currently unassigned one that used to belong to DEC.
     5.9 +        Uses OUI (Organizationally Unique Identifier) AA:00:00, an
    5.10 +        unassigned one that used to belong to DEC. The OUI list is
    5.11 +        available at 'standards.ieee.org'.
    5.12  
    5.13          The remaining 3 fields are random, with the first bit of the first
    5.14          random field set 0.