ia64/xen-unstable

changeset 1470:cb46d894f7e6

bitkeeper revision 1.946.1.5 (40cd8a8d3IQInJEQQbhKVEH-ShSisA)

Remove some debug prints and fix/add comments.
author mjw@wray-m-3.hpl.hp.com
date Mon Jun 14 11:22:53 2004 +0000 (2004-06-14)
parents 1c03ec9209f0
children 961d5215a403
files tools/xenmgr/lib/server/blkif.py tools/xenmgr/lib/server/channel.py tools/xenmgr/lib/server/messages.py tools/xenmgr/lib/server/netif.py
line diff
     1.1 --- a/tools/xenmgr/lib/server/blkif.py	Mon Jun 14 10:55:59 2004 +0000
     1.2 +++ b/tools/xenmgr/lib/server/blkif.py	Mon Jun 14 11:22:53 2004 +0000
     1.3 @@ -4,12 +4,9 @@ from messages import *
     1.4  
     1.5  class BlkifControllerFactory(controller.ControllerFactory):
     1.6      """Factory for creating block device interface controllers.
     1.7 -    Also handles the 'back-end' channel to dom0.
     1.8 +    Also handles the 'back-end' channel to the device driver domain.
     1.9      """
    1.10  
    1.11 -    # todo: add support for setting dom controlling blkifs (don't assume 0).
    1.12 -    # todo: add support for 'recovery'.
    1.13 -
    1.14      def __init__(self):
    1.15          controller.ControllerFactory.__init__(self)
    1.16  
     2.1 --- a/tools/xenmgr/lib/server/channel.py	Mon Jun 14 10:55:59 2004 +0000
     2.2 +++ b/tools/xenmgr/lib/server/channel.py	Mon Jun 14 11:22:53 2004 +0000
     2.3 @@ -9,13 +9,17 @@ class ChannelFactory:
     2.4      """Factory for creating channels.
     2.5      Maintains a table of channels.
     2.6      """
     2.7 -    
     2.8 +
     2.9 +    """ Channels indexed by index. """
    2.10      channels = {}
    2.11  
    2.12      def __init__(self):
    2.13 +        """Constructor - do not use. Use the channelFactory function."""
    2.14          self.notifier = xend.utils.notifier()
    2.15      
    2.16      def addChannel(self, channel):
    2.17 +        """Add a channel.
    2.18 +        """
    2.19          idx = channel.idx
    2.20          self.channels[idx] = channel
    2.21          self.notifier.bind(idx)
    2.22 @@ -24,14 +28,20 @@ class ChannelFactory:
    2.23          #channel.notify()
    2.24  
    2.25      def getChannel(self, idx):
    2.26 +        """Get the channel with the given index (if any).
    2.27 +        """
    2.28          return self.channels.get(idx)
    2.29  
    2.30      def delChannel(self, idx):
    2.31 +        """Remove the channel with the given index (if any).
    2.32 +        """
    2.33          if idx in self.channels:
    2.34              del self.channels[idx]
    2.35              self.notifier.unbind(idx)
    2.36  
    2.37      def domChannel(self, dom):
    2.38 +        """Get the channel for the given domain.
    2.39 +        """
    2.40          for chan in self.channels.values():
    2.41              if chan.dom == dom:
    2.42                  return chan
    2.43 @@ -40,12 +50,19 @@ class ChannelFactory:
    2.44          return chan
    2.45  
    2.46      def channelClosed(self, channel):
    2.47 +        """The given channel has been closed - remove it.
    2.48 +        """
    2.49          self.delChannel(channel.idx)
    2.50  
    2.51      def createPort(self, dom):
    2.52 +        """Create a port for a channel to the given domain.
    2.53 +        """
    2.54          return xend.utils.port(dom)
    2.55  
    2.56  def channelFactory():
    2.57 +    """Singleton constructor for the channel factory.
    2.58 +    Use this instead of the class constructor.
    2.59 +    """
    2.60      global inst
    2.61      try:
    2.62          inst
    2.63 @@ -59,6 +76,8 @@ class Channel:
    2.64      """
    2.65  
    2.66      def __init__(self, factory, dom):
    2.67 +        """Create a channel to the given domain using the given factory.
    2.68 +        """
    2.69          self.factory = factory
    2.70          self.dom = dom
    2.71          self.port = self.factory.createPort(dom)
    2.72 @@ -69,15 +88,24 @@ class Channel:
    2.73          self.queue = []
    2.74  
    2.75      def getIndex(self):
    2.76 +        """Get the channel index.
    2.77 +        """
    2.78          return self.idx
    2.79  
    2.80      def getLocalPort(self):
    2.81 +        """Get the local port.
    2.82 +        """
    2.83          return self.port.local_port
    2.84  
    2.85      def getRemotePort(self):
    2.86 +        """Get the remote port.
    2.87 +        """
    2.88          return self.port.remote_port
    2.89  
    2.90      def close(self):
    2.91 +        """Close the channel. Calls lostChannel() on all its devices and
    2.92 +        channelClosed() on the factory.
    2.93 +        """
    2.94          for d in self.devs:
    2.95              d.lostChannel()
    2.96          self.factory.channelClosed(self)
    2.97 @@ -114,6 +142,8 @@ class Channel:
    2.98          return self.devs_by_type.get(type)
    2.99  
   2.100      def getMessageType(self, msg):
   2.101 +        """Get a 2-tuple of the message type and subtype.
   2.102 +        """
   2.103          hdr = msg.get_header()
   2.104          return (hdr['type'], hdr.get('subtype'))
   2.105  
   2.106 @@ -142,25 +172,19 @@ class Channel:
   2.107          #print 'notificationReceived<', work
   2.108  
   2.109      def notify(self):
   2.110 -        #print 'notify>', self
   2.111          self.port.notify()
   2.112  
   2.113      def handleRequests(self):
   2.114 -        #print 'handleRequests>'
   2.115          work = 0
   2.116          while 1:
   2.117 -            #print 'handleRequests>', work
   2.118              msg = self.readRequest()
   2.119 -            #print 'handleRequests> msg=', msg
   2.120              if not msg: break
   2.121              self.requestReceived(msg)
   2.122              work += 1
   2.123 -        #print 'handleRequests<', work
   2.124          return work
   2.125  
   2.126      def requestReceived(self, msg):
   2.127          (ty, subty) = self.getMessageType(msg)
   2.128 -        #print 'requestReceived>', ty, subty, self
   2.129          #todo:  Must respond before writing any more messages.
   2.130          #todo:  Should automate this (respond on write)
   2.131          self.port.write_response(msg)
   2.132 @@ -172,21 +196,16 @@ class Channel:
   2.133                     % (msgTypeName(ty, subty), ty, subty)), self
   2.134  
   2.135      def handleResponses(self):
   2.136 -        #print 'handleResponses>', self
   2.137          work = 0
   2.138          while 1:
   2.139 -            #print 'handleResponses>', work
   2.140              msg = self.readResponse()
   2.141 -            #print 'handleResponses> msg=', msg
   2.142              if not msg: break
   2.143              self.responseReceived(msg)
   2.144              work += 1
   2.145 -        #print 'handleResponses<', work
   2.146          return work
   2.147  
   2.148      def responseReceived(self, msg):
   2.149          (ty, subty) = self.getMessageType(msg)
   2.150 -        #print 'responseReceived>', ty, subty
   2.151          dev = self.getDevice(ty)
   2.152          if dev:
   2.153              dev.responseReceived(msg, ty, subty)
   2.154 @@ -195,23 +214,18 @@ class Channel:
   2.155                     % (msgTypeName(ty, subty), ty, subty)), self
   2.156  
   2.157      def handleWrites(self):
   2.158 -        #print 'handleWrites>', self
   2.159          work = 0
   2.160          # Pull data from producers.
   2.161 -        #print 'handleWrites> pull...'
   2.162          for dev in self.devs:
   2.163              work += dev.produceRequests()
   2.164          # Flush the queue.
   2.165 -        #print 'handleWrites> flush...'
   2.166          while self.queue and self.port.space_to_write_request():
   2.167              msg = self.queue.pop(0)
   2.168              self.port.write_request(msg)
   2.169              work += 1
   2.170 -        #print 'handleWrites<', work
   2.171          return work
   2.172  
   2.173      def writeRequest(self, msg, notify=1):
   2.174 -        #print 'writeRequest>', self
   2.175          if self.closed:
   2.176              val = -1
   2.177          elif self.writeReady():
   2.178 @@ -221,11 +235,9 @@ class Channel:
   2.179          else:
   2.180              self.queue.append(msg)
   2.181              val = 0
   2.182 -        #print 'writeRequest<', val
   2.183          return val
   2.184  
   2.185      def writeResponse(self, msg):
   2.186 -        #print 'writeResponse>', self
   2.187          if self.closed: return -1
   2.188          self.port.write_response(msg)
   2.189          return 1
   2.190 @@ -235,25 +247,19 @@ class Channel:
   2.191          return self.port.space_to_write_request()
   2.192  
   2.193      def readRequest(self):
   2.194 -        #print 'readRequest>', self
   2.195          if self.closed:
   2.196 -            #print 'readRequest> closed'
   2.197              return None
   2.198          if self.port.request_to_read():
   2.199              val = self.port.read_request()
   2.200          else:
   2.201              val = None
   2.202 -        #print 'readRequest< ', val
   2.203          return val
   2.204          
   2.205      def readResponse(self):
   2.206 -        #print 'readResponse>', self
   2.207          if self.closed:
   2.208 -            #print 'readResponse> closed'
   2.209              return None
   2.210          if self.port.response_to_read():
   2.211              val = self.port.read_response()
   2.212          else:
   2.213              val = None
   2.214 -        #print 'readResponse<', val
   2.215          return val
     3.1 --- a/tools/xenmgr/lib/server/messages.py	Mon Jun 14 10:55:59 2004 +0000
     3.2 +++ b/tools/xenmgr/lib/server/messages.py	Mon Jun 14 11:22:53 2004 +0000
     3.3 @@ -2,6 +2,8 @@ import struct
     3.4  
     3.5  import xend.utils
     3.6  
     3.7 +DEBUG = 0
     3.8 +
     3.9  """ All message formats.
    3.10  Added to incrementally for the various message types.
    3.11  See below.
    3.12 @@ -145,7 +147,7 @@ class Msg:
    3.13      pass
    3.14  
    3.15  def packMsg(ty, params):
    3.16 -    print '>packMsg', ty, params
    3.17 +    if DEBUG: print '>packMsg', ty, params
    3.18      (major, minor, packing) = msg_formats[ty]
    3.19      args = {}
    3.20      for (k, v) in params.items():
    3.21 @@ -154,8 +156,9 @@ def packMsg(ty, params):
    3.22                  args['mac[%d]' % i] = v[i]
    3.23          else:
    3.24              args[k] = v
    3.25 -    for (k, v) in args.items():
    3.26 -        print 'packMsg>', k, v, type(v)
    3.27 +    if DEBUG:
    3.28 +        for (k, v) in args.items():
    3.29 +            print 'packMsg>', k, v, type(v)
    3.30      msgid = 0
    3.31      msg = xend.utils.message(major, minor, msgid, args)
    3.32      return msg
    3.33 @@ -175,7 +178,7 @@ def unpackMsg(ty, msg):
    3.34          args['mac'] = mac
    3.35          for k in macs:
    3.36              del args[k]
    3.37 -    print '<unpackMsg', ty, args
    3.38 +    if DEBUG: print '<unpackMsg', ty, args
    3.39      return args
    3.40  
    3.41  def msgTypeName(ty, subty):
     4.1 --- a/tools/xenmgr/lib/server/netif.py	Mon Jun 14 10:55:59 2004 +0000
     4.2 +++ b/tools/xenmgr/lib/server/netif.py	Mon Jun 14 11:22:53 2004 +0000
     4.3 @@ -6,10 +6,8 @@ from messages import *
     4.4  
     4.5  class NetifControllerFactory(controller.ControllerFactory):
     4.6      """Factory for creating network interface controllers.
     4.7 -    Also handles the 'back-end' channel to dom0.
     4.8 +    Also handles the 'back-end' channel to the device driver domain.
     4.9      """
    4.10 -    # todo: add support for setting dom controlling blkifs (don't assume 0).
    4.11 -    # todo: add support for 'recovery'.
    4.12  
    4.13      def __init__(self):
    4.14          controller.ControllerFactory.__init__(self)
    4.15 @@ -25,6 +23,8 @@ class NetifControllerFactory(controller.
    4.16          self.registerChannel()
    4.17  
    4.18      def createInstance(self, dom):
    4.19 +        """Create or find the network interface controller for a domain.
    4.20 +        """
    4.21          #print 'netif>createInstance> dom=', dom
    4.22          netif = self.getInstanceByDom(dom)
    4.23          if netif is None:
    4.24 @@ -33,6 +33,8 @@ class NetifControllerFactory(controller.
    4.25          return netif
    4.26          
    4.27      def setControlDomain(self, dom):
    4.28 +        """Set the 'back-end' device driver domain.
    4.29 +        """
    4.30          self.deregisterChannel()
    4.31          self.attached = 0
    4.32          self.dom = dom
    4.33 @@ -129,6 +131,12 @@ class NetifController(controller.Control
    4.34          return mac
    4.35  
    4.36      def attach_device(self, vif, vmac):
    4.37 +        """Attach a network device.
    4.38 +        If vmac is None a random mac address is assigned.
    4.39 +
    4.40 +        @param vif interface index
    4.41 +        @param vmac mac address (string)
    4.42 +        """
    4.43          if vmac is None:
    4.44              mac = self.randomMAC()
    4.45          else: