ia64/xen-unstable

changeset 2350:5f62249f3584

bitkeeper revision 1.1159.1.109 (412e1015AWvg5PGCnYrXQ63XhU18YQ)

Merge http://xen.bkbits.net:8080/xeno-unstable.bk
into gandalf.hpl.hp.com:/var/bk/xeno-unstable.bk
author xenbk@gandalf.hpl.hp.com
date Thu Aug 26 16:30:13 2004 +0000 (2004-08-26)
parents cdffed58ec5d fc11d71ea64d
children 5db55dc7f66a 631de0f7529b
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/console.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/domain.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 26 15:53:08 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 26 16:30:13 2004 +0000
     1.3 @@ -948,7 +948,7 @@ class XendDomainInfo:
     1.4          @return: deferred
     1.5          """
     1.6          ctrl = xend.blkif_create(self.dom, recreate=self.recreate)
     1.7 -        back = ctrl.getBackend(0)
     1.8 +        back = ctrl.getBackendInterface(0)
     1.9          return back.connect(recreate=self.recreate)
    1.10      
    1.11      def dom_construct(self, dom, config):
    1.12 @@ -1049,8 +1049,6 @@ def vm_dev_vif(vm, val, index):
    1.13      @param index:     vif index
    1.14      @return: deferred
    1.15      """
    1.16 -    #if vm.netif_backend:
    1.17 -    #    raise VmError('vif: vif in netif backend domain')
    1.18      vif = vm.next_device_index('vif')
    1.19      vmac = sxp.child_value(val, "mac")
    1.20      ctrl = xend.netif_create(vm.dom, recreate=vm.recreate)
    1.21 @@ -1071,8 +1069,6 @@ def vm_dev_vbd(vm, val, index):
    1.22      @param index:     vbd index
    1.23      @return: deferred
    1.24      """
    1.25 -    #if vm.blkif_backend:
    1.26 -    #    raise VmError('vbd: vbd in blkif backend domain')
    1.27      uname = sxp.child_value(val, 'uname')
    1.28      if not uname:
    1.29          raise VmError('vbd: Missing uname')
     2.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Aug 26 15:53:08 2004 +0000
     2.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Aug 26 16:30:13 2004 +0000
     2.3 @@ -374,6 +374,7 @@ class EventProtocol(protocol.Protocol):
     2.4          id = sxp.child_value(req, 'id')
     2.5          if not id:
     2.6              raise XendError('Missing console id')
     2.7 +        id = int(id)
     2.8          self.daemon.console_disconnect(id)
     2.9          return ['ok']
    2.10  
    2.11 @@ -652,17 +653,17 @@ class Daemon:
    2.12          return self.channelF.getDomChannel(dom)
    2.13  
    2.14      def blkif_create(self, dom, recreate=0):
    2.15 -        """Create a block device interface controller.
    2.16 +        """Create or get a block device interface controller.
    2.17          
    2.18          Returns controller
    2.19          """
    2.20 -        return self.blkifCF.createInstance(dom, recreate=recreate)
    2.21 +        return self.blkifCF.getController(dom)
    2.22  
    2.23      def blkifs(self):
    2.24 -        return [ x.sxpr() for x in self.blkifCF.getInstances() ]
    2.25 +        return [ x.sxpr() for x in self.blkifCF.getControllers() ]
    2.26  
    2.27      def blkif_get(self, dom):
    2.28 -        return self.blkifCF.getInstanceByDom(dom)
    2.29 +        return self.blkifCF.getControllerByDom(dom)
    2.30  
    2.31      def blkif_dev(self, dom, vdev):
    2.32          return self.blkifCF.getDomainDevice(dom, vdev)
    2.33 @@ -672,29 +673,29 @@ class Daemon:
    2.34          
    2.35          Returns Deferred
    2.36          """
    2.37 -        ctrl = self.blkifCF.getInstanceByDom(dom)
    2.38 +        ctrl = self.blkifCF.getControllerByDom(dom)
    2.39          if not ctrl:
    2.40              raise XendError('No blkif controller: %d' % dom)
    2.41          d = ctrl.attachDevice(config, vdev, mode, segment, recreate=recreate)
    2.42          return d
    2.43  
    2.44      def netif_create(self, dom, recreate=0):
    2.45 -        """Create a network interface controller.
    2.46 +        """Create or get a network interface controller.
    2.47          
    2.48          """
    2.49 -        return self.netifCF.createInstance(dom, recreate=recreate)
    2.50 +        return self.netifCF.getController(dom)
    2.51  
    2.52      def netifs(self):
    2.53 -        return [ x.sxpr() for x in self.netifCF.getInstances() ]
    2.54 +        return [ x.sxpr() for x in self.netifCF.getControllers() ]
    2.55  
    2.56      def netif_get(self, dom):
    2.57 -        return self.netifCF.getInstanceByDom(dom)
    2.58 +        return self.netifCF.getControllerByDom(dom)
    2.59  
    2.60      def netif_dev_create(self, dom, vif, config, recreate=0):
    2.61          """Create a network device.
    2.62  
    2.63          """
    2.64 -        ctrl = self.netifCF.getInstanceByDom(dom)
    2.65 +        ctrl = self.netifCF.getControllerByDom(dom)
    2.66          if not ctrl:
    2.67              raise XendError('No netif controller: %d' % dom)
    2.68          d = ctrl.attachDevice(vif, config, recreate=recreate)
    2.69 @@ -706,22 +707,22 @@ class Daemon:
    2.70      def console_create(self, dom, console_port=None):
    2.71          """Create a console for a domain.
    2.72          """
    2.73 -        console = self.consoleCF.getInstanceByDom(dom)
    2.74 +        console = self.consoleCF.getControllerByDom(dom)
    2.75          if console is None:
    2.76 -            console = self.consoleCF.createInstance(dom, console_port)
    2.77 +            console = self.consoleCF.createController(dom, console_port)
    2.78          return console
    2.79  
    2.80      def consoles(self):
    2.81 -        return [ c.sxpr() for c in self.consoleCF.getInstances() ]
    2.82 +        return [ c.sxpr() for c in self.consoleCF.getControllers() ]
    2.83  
    2.84      def get_consoles(self):
    2.85 -        return self.consoleCF.getInstances()
    2.86 +        return self.consoleCF.getControllers()
    2.87  
    2.88      def get_console(self, id):
    2.89 -        return self.consoleCF.getInstance(id)
    2.90 +        return self.consoleCF.getControllerByIndex(id)
    2.91  
    2.92      def get_domain_console(self, dom):
    2.93 -        return self.consoleCF.getInstanceByDom(dom)
    2.94 +        return self.consoleCF.getControllerByDom(dom)
    2.95  
    2.96      def console_disconnect(self, id):
    2.97          """Disconnect any connected console client.
    2.98 @@ -734,9 +735,10 @@ class Daemon:
    2.99      def domain_shutdown(self, dom, reason):
   2.100          """Shutdown a domain.
   2.101          """
   2.102 -        ctrl = self.domainCF.getInstanceByDom(dom)
   2.103 +        dom = int(dom)
   2.104 +        ctrl = self.domainCF.getController(dom)
   2.105          if not ctrl:
   2.106 -            raise XendError('No domain controller: %d' % dom)
   2.107 +            raise XendError('No domain controller: %s' % dom)
   2.108          ctrl.shutdown(reason)
   2.109          return 0
   2.110          
     3.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Aug 26 15:53:08 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Aug 26 16:30:13 2004 +0000
     3.3 @@ -14,24 +14,16 @@ import controller
     3.4  from messages import *
     3.5  
     3.6  class BlkifBackendController(controller.BackendController):
     3.7 -    """ Handler for the 'back-end' channel to a device driver domain.
     3.8 -    Must be connected using connect() before it can be used.
     3.9 -    Do not create directly - use getBackend() on the BlkifController.
    3.10 +    """ Handler for the 'back-end' channel to a block device driver domain.
    3.11      """
    3.12  
    3.13 -    def __init__(self, ctrl, dom, handle):
    3.14 -        controller.BackendController.__init__(self, ctrl, dom, handle)
    3.15 -        self.connected = 0
    3.16 -        self.evtchn = None
    3.17 -        self.handle = handle
    3.18 +    def __init__(self, factory, dom):
    3.19 +        controller.BackendController.__init__(self, factory, dom)
    3.20          self.addMethod(CMSG_BLKIF_BE,
    3.21                         CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED,
    3.22                         self.recv_be_driver_status_changed)
    3.23          self.registerChannel()
    3.24  
    3.25 -    def __str__(self):
    3.26 -        return '<BlkifBackendController %d %d>' % (self.controller.dom, self.dom)
    3.27 -
    3.28      def recv_be_driver_status_changed(self, msg, req):
    3.29          """Request handler for be_driver_status_changed messages.
    3.30          
    3.31 @@ -43,8 +35,23 @@ class BlkifBackendController(controller.
    3.32          val = unpackMsg('blkif_be_driver_status_changed_t', msg)
    3.33          status = val['status']
    3.34  
    3.35 +class BlkifBackendInterface(controller.BackendInterface):
    3.36 +    """ Handler for the 'back-end' channel to a block device driver domain
    3.37 +    on behalf of a front-end domain.
    3.38 +    Must be connected using connect() before it can be used.
    3.39 +    Do not create directly - use getBackendInterface() on the BlkifController.
    3.40 +    """
    3.41 +
    3.42 +    def __init__(self, ctrl, dom, handle):
    3.43 +        controller.BackendInterface.__init__(self, ctrl, dom, handle)
    3.44 +        self.connected = 0
    3.45 +        self.evtchn = None
    3.46 +
    3.47 +    def __str__(self):
    3.48 +        return '<BlkifBackendInterface %d %d>' % (self.controller.dom, self.dom)
    3.49 +
    3.50      def connect(self, recreate=0):
    3.51 -        """Connect the controller to the blkif control interface.
    3.52 +        """Connect to the blkif control interface.
    3.53  
    3.54          @param recreate: true if after xend restart
    3.55          @return: deferred
    3.56 @@ -76,6 +83,7 @@ class BlkifBackendController(controller.
    3.57          """
    3.58          def cb_destroy(val):
    3.59              self.send_be_destroy()
    3.60 +            self.close()
    3.61          d = defer.Deferred()
    3.62          d.addCallback(cb_destroy)
    3.63          self.send_be_disconnect(response=d)
    3.64 @@ -125,14 +133,14 @@ class BlkifBackendController(controller.
    3.65                          'evtchn' : self.evtchn['port2'] })
    3.66          self.controller.writeRequest(msg, response=response)
    3.67          
    3.68 -class BlkifControllerFactory(controller.ControllerFactory):
    3.69 +class BlkifControllerFactory(controller.SplitControllerFactory):
    3.70      """Factory for creating block device interface controllers.
    3.71      """
    3.72  
    3.73      def __init__(self):
    3.74 -        controller.ControllerFactory.__init__(self)
    3.75 +        controller.SplitControllerFactory.__init__(self)
    3.76  
    3.77 -    def createInstance(self, dom, recreate=0):
    3.78 +    def createController(self, dom, recreate=0):
    3.79          """Create a block device controller for a domain.
    3.80  
    3.81          @param dom: domain
    3.82 @@ -142,12 +150,30 @@ class BlkifControllerFactory(controller.
    3.83          @return: block device controller
    3.84          @rtype: BlkifController
    3.85          """
    3.86 -        blkif = self.getInstanceByDom(dom)
    3.87 +        blkif = self.getControllerByDom(dom)
    3.88          if blkif is None:
    3.89              blkif = BlkifController(self, dom)
    3.90 -            self.addInstance(blkif)
    3.91 +            self.addController(blkif)
    3.92          return blkif
    3.93  
    3.94 +    def createBackendController(self, dom):
    3.95 +        """Create a block device backend controller.
    3.96 +
    3.97 +        @param dom: backend domain
    3.98 +        @return: backend controller
    3.99 +        """
   3.100 +        return BlkifBackendController(self, dom)
   3.101 +
   3.102 +    def createBackendInterface(self, ctrl, dom, handle):
   3.103 +        """Create a block device backend interface.
   3.104 +
   3.105 +        @param ctrl: controller
   3.106 +        @param dom: backend domain
   3.107 +        @param handle: interface handle
   3.108 +        @return: backend interface
   3.109 +        """
   3.110 +        return BlkifBackendInterface(ctrl, dom, handle)
   3.111 +
   3.112      def getDomainDevices(self, dom):
   3.113          """Get the block devices for a domain.
   3.114  
   3.115 @@ -156,7 +182,7 @@ class BlkifControllerFactory(controller.
   3.116          @return: devices
   3.117          @rtype:  [device]
   3.118          """
   3.119 -        blkif = self.getInstanceByDom(dom)
   3.120 +        blkif = self.getControllerByDom(dom)
   3.121          return (blkif and blkif.getDevices()) or []
   3.122  
   3.123      def getDomainDevice(self, dom, vdev):
   3.124 @@ -169,7 +195,7 @@ class BlkifControllerFactory(controller.
   3.125          @return: device
   3.126          @rtype:  device
   3.127          """
   3.128 -        blkif = self.getInstanceByDom(dom)
   3.129 +        blkif = self.getControllerByDom(dom)
   3.130          return (blkif and blkif.getDevice(vdev)) or None
   3.131  
   3.132  class BlkDev(controller.SplitDev):
   3.133 @@ -214,7 +240,7 @@ class BlkDev(controller.SplitDev):
   3.134          """Attach the device to its controller.
   3.135  
   3.136          """
   3.137 -        backend = self.getBackend()
   3.138 +        backend = self.getBackendInterface()
   3.139          d1 = backend.connect()
   3.140          d2 = defer.Deferred()
   3.141          d2.addCallback(self.send_be_vbd_create)
   3.142 @@ -224,7 +250,7 @@ class BlkDev(controller.SplitDev):
   3.143      def send_be_vbd_create(self, val):
   3.144          d = defer.Deferred()
   3.145          d.addCallback(self.respond_be_vbd_create)
   3.146 -        backend = self.getBackend()
   3.147 +        backend = self.getBackendInterface()
   3.148          msg = packMsg('blkif_be_vbd_create_t',
   3.149                        { 'domid'        : self.controller.dom,
   3.150                          'blkif_handle' : backend.handle,
   3.151 @@ -247,7 +273,7 @@ class BlkDev(controller.SplitDev):
   3.152      
   3.153      def send_be_vbd_grow(self):
   3.154          d = defer.Deferred()
   3.155 -        backend = self.getBackend()
   3.156 +        backend = self.getBackendInterface()
   3.157          msg = packMsg('blkif_be_vbd_grow_t',
   3.158                        { 'domid'                : self.controller.dom,
   3.159                          'blkif_handle'         : backend.handle,
   3.160 @@ -274,7 +300,7 @@ class BlkDev(controller.SplitDev):
   3.161      def send_be_vbd_destroy(self, response=None):
   3.162          log.debug('>BlkDev>send_be_vbd_destroy> dom=%d vdev=%d',
   3.163                    self.controller.dom, self.vdev)
   3.164 -        backend = self.getBackend()
   3.165 +        backend = self.getBackendInterface()
   3.166          msg = packMsg('blkif_be_vbd_destroy_t',
   3.167                        { 'domid'                : self.controller.dom,
   3.168                          'blkif_handle'         : backend.handle,
   3.169 @@ -290,7 +316,7 @@ class BlkifController(controller.SplitCo
   3.170      
   3.171      def __init__(self, factory, dom):
   3.172          """Create a block device controller.
   3.173 -        Do not call directly - use createInstance() on the factory instead.
   3.174 +        Do not call directly - use createController() on the factory instead.
   3.175          """
   3.176          controller.SplitController.__init__(self, factory, dom)
   3.177          self.devices = {}
   3.178 @@ -306,9 +332,6 @@ class BlkifController(controller.SplitCo
   3.179          val = ['blkif', ['dom', self.dom]]
   3.180          return val
   3.181  
   3.182 -    def createBackend(self, dom, handle):
   3.183 -        return BlkifBackendController(self, dom, handle)
   3.184 -
   3.185      def getDevices(self):
   3.186          return self.devices.values()
   3.187  
   3.188 @@ -373,7 +396,7 @@ class BlkifController(controller.SplitCo
   3.189              dev.destroy()
   3.190  
   3.191      def destroyBackends(self):
   3.192 -        for backend in self.getBackends():
   3.193 +        for backend in self.getBackendInterfaces():
   3.194              backend.destroy()
   3.195  
   3.196      def recv_fe_driver_status_changed(self, msg, req):
   3.197 @@ -390,7 +413,7 @@ class BlkifController(controller.SplitCo
   3.198      def recv_fe_interface_connect(self, msg, req):
   3.199          val = unpackMsg('blkif_fe_interface_connect_t', msg)
   3.200          handle = val['handle']
   3.201 -        backend = self.getBackendByHandle(handle)
   3.202 +        backend = self.getBackendInterfaceByHandle(handle)
   3.203          if backend:
   3.204              backend.connectInterface(val)
   3.205          else:
     4.1 --- a/tools/python/xen/xend/server/console.py	Thu Aug 26 15:53:08 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/console.py	Thu Aug 26 16:30:13 2004 +0000
     4.3 @@ -81,14 +81,14 @@ class ConsoleControllerFactory(controlle
     4.4      """Factory for creating console controllers.
     4.5      """
     4.6  
     4.7 -    def createInstance(self, dom, console_port=None):
     4.8 +    def createController(self, dom, console_port=None):
     4.9          if console_port is None:
    4.10              console_port = CONSOLE_PORT_BASE + dom
    4.11 -        for c in self.getInstances():
    4.12 +        for c in self.getControllers():
    4.13              if c.console_port == console_port:
    4.14                  raise XendError('console port in use: ' + str(console_port))
    4.15          console = ConsoleController(self, dom, console_port)
    4.16 -        self.addInstance(console)
    4.17 +        self.addController(console)
    4.18          log.info("Created console id=%s domain=%d port=%d",
    4.19                   console.idx, console.dom, console.console_port)
    4.20          eserver.inject('xend.console.create',
    4.21 @@ -98,7 +98,7 @@ class ConsoleControllerFactory(controlle
    4.22      def consoleClosed(self, console):
    4.23          log.info("Closed console id=%s", console.idx)
    4.24          eserver.inject('xend.console.close', console.idx)
    4.25 -        self.delInstance(console)
    4.26 +        self.delController(console)
    4.27  
    4.28  class ConsoleController(controller.Controller):
    4.29      """Console controller for a domain.
     5.1 --- a/tools/python/xen/xend/server/controller.py	Thu Aug 26 15:53:08 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/controller.py	Thu Aug 26 16:30:13 2004 +0000
     5.3 @@ -274,72 +274,80 @@ class CtrlMsgRcvr:
     5.4              
     5.5  class ControllerFactory:
     5.6      """Abstract class for factories creating controllers for a domain.
     5.7 -    Maintains a table of instances.
     5.8 +    Maintains a table of controllers.
     5.9  
    5.10 -    @ivar instances: mapping of index to controller instance
    5.11 -    @type instances: {String: Controller}
    5.12 +    @ivar controllers: mapping of index to controller instance
    5.13 +    @type controllers: {String: Controller}
    5.14      @ivar dom: domain
    5.15      @type dom: int
    5.16      """
    5.17  
    5.18      def __init__(self):
    5.19 -        self.instances = {}
    5.20 -        self.backends = {}
    5.21 -        self.dom = 0
    5.22 +        self.controllers = {}
    5.23          
    5.24 -    def addInstance(self, instance):
    5.25 +    def addController(self, controller):
    5.26          """Add a controller instance (under its index).
    5.27          """
    5.28 -        self.instances[instance.idx] = instance
    5.29 +        self.controllers[controller.idx] = controller
    5.30  
    5.31 -    def getInstance(self, idx):
    5.32 -        """Get a controller instance from its index.
    5.33 +    def getControllers(self):
    5.34 +        """Get a list of all controllers.
    5.35          """
    5.36 -        return self.instances.get(idx)
    5.37 +        return self.controllers.values()
    5.38  
    5.39 -    def getInstances(self):
    5.40 -        """Get a list of all controller instances.
    5.41 +    def getControllerByIndex(self, idx):
    5.42 +        """Get a controller from its index.
    5.43          """
    5.44 -        return self.instances.values()
    5.45 +        return self.controllers.get(idx)
    5.46  
    5.47 -    def getInstanceByDom(self, dom):
    5.48 -        """Get the controller instance for the given domain.
    5.49 +    def getControllerByDom(self, dom):
    5.50 +        """Get the controller for the given domain.
    5.51  
    5.52          @param dom: domain id
    5.53          @type  dom: int
    5.54          @return: controller or None
    5.55          """
    5.56 -        for inst in self.instances.values():
    5.57 +        for inst in self.controllers.values():
    5.58              if inst.dom == dom:
    5.59                  return inst
    5.60          return None
    5.61  
    5.62 -    def delInstance(self, instance):
    5.63 -        """Delete a controller instance from the table.
    5.64 +    def getController(self, dom):
    5.65 +        """Create or find the controller for a domain.
    5.66  
    5.67 -        @param instance: controller instance
    5.68 +        @param dom:      domain
    5.69 +        @return: controller
    5.70          """
    5.71 -        if instance.idx in self.instances:
    5.72 -            del self.instances[instance.idx]
    5.73 -
    5.74 -    def createInstance(self, dom, recreate=0):
    5.75 -        """Create an instance. Define in a subclass.
    5.76 +        ctrl = self.getControllerByDom(dom)
    5.77 +        if ctrl is None:
    5.78 +            ctrl = self.createController(dom)
    5.79 +            self.addController(ctrl)
    5.80 +        return ctrl
    5.81 +    
    5.82 +    def createController(self, dom):
    5.83 +        """Create a controller. Define in a subclass.
    5.84  
    5.85          @param dom: domain
    5.86          @type  dom: int
    5.87 -        @param recreate: true if the instance is being recreated (after xend restart)
    5.88 -        @type  recreate: int
    5.89          @return: controller instance
    5.90          @rtype:  Controller (or subclass)
    5.91          """
    5.92          raise NotImplementedError()
    5.93  
    5.94 -    def instanceClosed(self, instance):
    5.95 -        """Callback called when an instance is closed (usually by the instance).
    5.96 +    def delController(self, controller):
    5.97 +        """Delete a controller instance from the table.
    5.98 +
    5.99 +        @param controller: controller instance
   5.100 +        """
   5.101 +        if controller.idx in self.controllers:
   5.102 +            del self.controllers[controller.idx]
   5.103 +
   5.104 +    def controllerClosed(self, controller):
   5.105 +        """Callback called when a controller is closed (usually by the controller).
   5.106          
   5.107 -        @param instance: controller instance
   5.108 +        @param controller: controller instance
   5.109          """
   5.110 -        self.delInstance(instance)
   5.111 +        self.delController(controller)
   5.112  
   5.113  class Controller(CtrlMsgRcvr):
   5.114      """Abstract class for a device controller attached to a domain.
   5.115 @@ -370,91 +378,204 @@ class Controller(CtrlMsgRcvr):
   5.116          """The controller channel has been lost.
   5.117          """
   5.118          self.deregisterChannel()
   5.119 -        self.factory.instanceClosed(self)
   5.120 +        self.factory.controllerClosed(self)
   5.121 +
   5.122 +class SplitControllerFactory(ControllerFactory):
   5.123 +    """Abstract class for factories creating split controllers for a domain.
   5.124 +    Maintains a table of backend controllers.
   5.125 +    """
   5.126 +
   5.127 +    def __init__(self):
   5.128 +        ControllerFactory.__init__(self)
   5.129 +        self.backendControllers = {}
   5.130 +
   5.131 +    def getBackendControllers(self):
   5.132 +        return self.backendControllers.values()
   5.133 +
   5.134 +    def getBackendControllerByDomain(self, dom):
   5.135 +        """Get the backend controller for a domain if there is one.
   5.136 +
   5.137 +        @param dom: backend domain
   5.138 +        @return: backend controller
   5.139 +        """
   5.140 +        return self.backendControllers.get(dom)
   5.141 +
   5.142 +    def getBackendController(self, dom):
   5.143 +        """Get the backend controller for a domain, creating
   5.144 +        if necessary.
   5.145  
   5.146 -class BackendController(CtrlMsgRcvr):
   5.147 +        @param dom: backend domain
   5.148 +        @return: backend controller
   5.149 +        """
   5.150 +        b = self.getBackendControllerByDomain(dom)
   5.151 +        if b is None:
   5.152 +            b = self.createBackendController(dom)
   5.153 +            self.backendControllers[b.dom] = b
   5.154 +        return b
   5.155 +
   5.156 +    def createBackendController(self, dom):
   5.157 +        """Create a backend controller. Define in a subclass.
   5.158 +
   5.159 +        @param dom: backend domain
   5.160 +        @return: backend controller
   5.161 +        """
   5.162 +        raise NotImplementedError()
   5.163 +
   5.164 +    def delBackendController(self, ctrlr):
   5.165 +        """Remove a backend controller.
   5.166 +
   5.167 +        @param ctrlr: backend controller
   5.168 +        """
   5.169 +        if ctrlr.dom in self.backendControllers:
   5.170 +            del self.backendControllers[ctrlr.dom]
   5.171 +
   5.172 +    def backendControllerClosed(self, ctrlr):
   5.173 +        """Callback called when a backend is closed.
   5.174 +        """
   5.175 +        self.delBackendController(ctrlr)
   5.176 +        
   5.177 +    def createBackendInterface(self, ctrl, dom, handle):
   5.178 +        """Create a backend interface. Define in a subclass.
   5.179 +
   5.180 +        @param ctrl: frontend controller
   5.181 +        @param dom: backend domain
   5.182 +        @return: backend interface
   5.183 +        """
   5.184 +        raise NotImplementedError()
   5.185 +
   5.186 +class BackendController(Controller):
   5.187      """Abstract class for a backend device controller attached to a domain.
   5.188  
   5.189 -    @ivar controller: frontend controller
   5.190 -    @type controller: Controller
   5.191 -    @ivar dom:     domain
   5.192 +    @ivar factory: backend controller factory
   5.193 +    @type factory: BackendControllerFactory
   5.194 +    @ivar dom:     backend domain
   5.195      @type dom:     int
   5.196      @ivar channel: channel to the domain
   5.197      @type channel: Channel
   5.198      """
   5.199  
   5.200      
   5.201 -    def __init__(self, controller, dom, handle):
   5.202 +    def __init__(self, factory, dom):
   5.203          CtrlMsgRcvr.__init__(self)
   5.204 -        self.controller = controller
   5.205 +        self.factory = factory
   5.206          self.dom = int(dom)
   5.207 -        self.handle = handle
   5.208          self.channel = None
   5.209 +        self.backendInterfaces = {}
   5.210          
   5.211      def close(self):
   5.212          self.lostChannel()
   5.213  
   5.214      def lostChannel(self):
   5.215          self.deregisterChannel()
   5.216 -        self.controller.backendClosed(self)
   5.217 +        self.backend.backendClosed(self)
   5.218 +
   5.219 +    def registerInterface(self, intf):
   5.220 +        key = intf.getInterfaceKey()
   5.221 +        self.backendInterfaces[key] = intf
   5.222 +
   5.223 +    def deregisterInterface(self, intf):
   5.224 +        key = intf.getInterfaceKey()
   5.225 +        if key in self.backendInterfaces:
   5.226 +            del self.backendInterfaces[key]
   5.227 +
   5.228 +    def getInterface(self, dom, handle):
   5.229 +        key = (dom, handle)
   5.230 +        return self.backendInterfaces.get(key)
   5.231 +
   5.232 +        
   5.233 +    def createBackendInterface(self, ctrl, dom, handle):
   5.234 +        """Create a backend interface. Define in a subclass.
   5.235 +
   5.236 +        @param ctrl: controller
   5.237 +        @param dom: backend domain
   5.238 +        @param handle: backend handle
   5.239 +        """
   5.240 +        raise NotImplementedError()
   5.241 +
   5.242 +    
   5.243 +class BackendInterface:
   5.244 +    """Abstract class for a domain's interface onto a backend controller.
   5.245 +    """
   5.246 +
   5.247 +    def __init__(self, controller, dom, handle):
   5.248 +        """
   5.249 +
   5.250 +        @param controller: front-end controller
   5.251 +        @param dom:        back-end domain
   5.252 +        @param handle:     back-end interface handle
   5.253 +        """
   5.254 +        self.factory = controller.factory
   5.255 +        self.controller = controller
   5.256 +        self.dom = int(dom)
   5.257 +        self.handle = handle
   5.258 +        self.backend = self.getBackendController()
   5.259 +
   5.260 +    def registerInterface(self):
   5.261 +        self.backend.registerInterface(self)
   5.262 +
   5.263 +    def getInterfaceKey(self):
   5.264 +        return (self.controller.dom, self.handle)
   5.265 +
   5.266 +    def getBackendController(self):
   5.267 +        return self.factory.getBackendController(self.dom)
   5.268 +
   5.269 +    def writeRequest(self, msg, response=None):
   5.270 +        return self.backend.writeRequest(msg, response=response)
   5.271 +
   5.272 +    def close(self):
   5.273 +        self.backend.deregisterInterface(self)
   5.274 +        self.controller.backendInterfaceClosed(self)
   5.275          
   5.276  class SplitController(Controller):
   5.277      """Abstract class for a device controller attached to a domain.
   5.278 -    A SplitController manages a BackendController for each backend domain
   5.279 +    A SplitController manages a BackendInterface for each backend domain
   5.280      it has at least one device for.
   5.281      """
   5.282  
   5.283      def __init__(self, factory, dom):
   5.284          Controller.__init__(self, factory, dom)
   5.285 -        self.backends = {}
   5.286 +        self.backendInterfaces = {}
   5.287          self.backendHandle = 0
   5.288          
   5.289 -    def getBackends(self):
   5.290 -        return self.backends.values()
   5.291 +    def getBackendInterfaces(self):
   5.292 +        return self.backendInterfaces.values()
   5.293  
   5.294 -    def getBackendByHandle(self, handle):
   5.295 -        for b in self.getBackends():
   5.296 +    def getBackendInterfaceByHandle(self, handle):
   5.297 +        for b in self.getBackendInterfaces():
   5.298              if b.handle == handle:
   5.299                  return b
   5.300          return None
   5.301  
   5.302 -    def getBackendByDomain(self, dom):
   5.303 -        return self.backends.get(dom)
   5.304 +    def getBackendInterfaceByDomain(self, dom):
   5.305 +        return self.backendInterfaces.get(dom)
   5.306  
   5.307 -    def getBackend(self, dom):
   5.308 -        """Get the backend controller for a domain.
   5.309 +    def getBackendInterface(self, dom):
   5.310 +        """Get the backend interface for a domain.
   5.311  
   5.312          @param dom: domain
   5.313          @return: backend controller
   5.314          """
   5.315 -        b = self.getBackendByDomain(dom)
   5.316 +        b = self.getBackendInterfaceByDomain(dom)
   5.317          if b is None:
   5.318              handle = self.backendHandle
   5.319              self.backendHandle += 1
   5.320 -            b = self.createBackend(dom, handle)
   5.321 -            self.backends[b.dom] = b
   5.322 +            b = self.factory.createBackendInterface(self, dom, handle)
   5.323 +            b.registerInterface()
   5.324 +            self.backendInterfaces[b.dom] = b
   5.325          return b
   5.326  
   5.327 -    def createBackend(self, dom, handle):
   5.328 -        """Create a backend controller. Define in a subclass.
   5.329 -
   5.330 -        @param dom: domain
   5.331 -        @param handle: controller handle
   5.332 -        """
   5.333 -        raise NotImplementedError()
   5.334 -
   5.335 -    def delBackend(self, ctrlr):
   5.336 +    def delBackendInterface(self, ctrlr):
   5.337          """Remove a backend controller.
   5.338  
   5.339          @param ctrlr: backend controller
   5.340          """
   5.341 -        if ctrlr.dom in self.backends:
   5.342 -            del self.backends[ctrlr.dom]
   5.343 +        if ctrlr.dom in self.backendInterfaces:
   5.344 +            del self.backendInterfaces[ctrlr.dom]
   5.345  
   5.346 -    def backendClosed(self, ctrlr):
   5.347 +    def backendInterfaceClosed(self, ctrlr):
   5.348          """Callback called when a backend is closed.
   5.349          """
   5.350 -        self.delBackend(ctrlr)
   5.351 +        self.delBackendInterface(ctrlr)
   5.352          
   5.353  class Dev:
   5.354      """Abstract class for a device attached to a device controller.
   5.355 @@ -502,8 +623,8 @@ class SplitDev(Dev):
   5.356          Dev.__init__(self, idx, controller)
   5.357          self.backendDomain = 0
   5.358  
   5.359 -    def getBackend(self):
   5.360 -        return self.controller.getBackend(self.backendDomain)
   5.361 +    def getBackendInterface(self):
   5.362 +        return self.controller.getBackendInterface(self.backendDomain)
   5.363  
   5.364  
   5.365  
     6.1 --- a/tools/python/xen/xend/server/domain.py	Thu Aug 26 15:53:08 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/domain.py	Thu Aug 26 16:30:13 2004 +0000
     6.3 @@ -10,30 +10,14 @@ class DomainControllerFactory(controller
     6.4      """Factory for creating domain controllers.
     6.5      """
     6.6  
     6.7 -    def createInstance(self, dom):
     6.8 +    def createController(self, dom):
     6.9          """Create a domain controller.
    6.10  
    6.11          dom domain
    6.12  
    6.13          returns domain controller
    6.14          """
    6.15 -        d = DomainController(self, dom)
    6.16 -        self.addInstance(d)
    6.17 -        return d
    6.18 -    
    6.19 -    def getInstanceByDom(self, dom):
    6.20 -        """Get a domain controller for a domain, creating if necessary.
    6.21 -
    6.22 -        dom domain
    6.23 -
    6.24 -        returns domain controller
    6.25 -        """
    6.26 -        for inst in self.instances.values():
    6.27 -            if inst.dom == dom:
    6.28 -                return inst
    6.29 -        inst = self.createInstance(dom)
    6.30 -        return inst
    6.31 -
    6.32 +        return DomainController(self, dom)
    6.33  
    6.34  class DomainController(controller.Controller):
    6.35      """Generic controller for a domain.
     7.1 --- a/tools/python/xen/xend/server/netif.py	Thu Aug 26 15:53:08 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/netif.py	Thu Aug 26 16:30:13 2004 +0000
     7.3 @@ -19,11 +19,11 @@ import controller
     7.4  from messages import *
     7.5  
     7.6  class NetifBackendController(controller.BackendController):
     7.7 -    """Handler for the 'back-end' channel to a device driver domain.
     7.8 +    """Handler for the 'back-end' channel to a network device driver domain.
     7.9      """
    7.10      
    7.11 -    def __init__(self, ctrl, dom, handle):
    7.12 -        controller.BackendController.__init__(self, ctrl, dom, handle)
    7.13 +    def __init__(self, ctrl, dom):
    7.14 +        controller.BackendController.__init__(self, ctrl, dom)
    7.15          self.addMethod(CMSG_NETIF_BE,
    7.16                         CMSG_NETIF_BE_DRIVER_STATUS_CHANGED,
    7.17                         self.recv_be_driver_status_changed)
    7.18 @@ -33,33 +33,56 @@ class NetifBackendController(controller.
    7.19          val = unpackMsg('netif_be_driver_status_changed_t', msg)
    7.20          status = val['status']
    7.21  
    7.22 -class NetifControllerFactory(controller.ControllerFactory):
    7.23 +class NetifBackendInterface(controller.BackendInterface):
    7.24 +    """Handler for the 'back-end' channel to a network device driver domain
    7.25 +    on behalf of a front-end domain.
    7.26 +
    7.27 +    Each network device is handled separately, so we add no functionality
    7.28 +    here.
    7.29 +    """
    7.30 +
    7.31 +    pass
    7.32 +
    7.33 +class NetifControllerFactory(controller.SplitControllerFactory):
    7.34      """Factory for creating network interface controllers.
    7.35      """
    7.36  
    7.37      def __init__(self):
    7.38 -        controller.ControllerFactory.__init__(self)
    7.39 +        controller.SplitControllerFactory.__init__(self)
    7.40  
    7.41 -    def createInstance(self, dom, recreate=0):
    7.42 -        """Create or find the network interface controller for a domain.
    7.43 +    def createController(self, dom):
    7.44 +        """Create a network interface controller for a domain.
    7.45  
    7.46          @param dom:      domain
    7.47 -        @param recreate: if true this is a recreate (xend restarted)
    7.48          @return: netif controller
    7.49          """
    7.50 -        netif = self.getInstanceByDom(dom)
    7.51 -        if netif is None:
    7.52 -            netif = NetifController(self, dom)
    7.53 -            self.addInstance(netif)
    7.54 -        return netif
    7.55 +        return NetifController(self, dom)
    7.56 +
    7.57 +    def createBackendController(self, dom):
    7.58 +        """Create a network device backend controller.
    7.59 +
    7.60 +        @param dom: backend domain
    7.61 +        @return: backend controller
    7.62 +        """
    7.63 +        return NetifBackendController(self, dom)
    7.64 +    
    7.65 +    def createBackendInterface(self, ctrl, dom, handle):
    7.66 +        """Create a network device backend interface.
    7.67 +
    7.68 +        @param ctrl: controller
    7.69 +        @param dom: backend domain
    7.70 +        @param handle: interface handle
    7.71 +        @return: backend interface
    7.72 +        """
    7.73 +        return NetifBackendInterface(ctrl, dom, handle)
    7.74  
    7.75      def getDomainDevices(self, dom):
    7.76 -        """Get the network device controllers for a domain.
    7.77 +        """Get the network devices for a domain.
    7.78  
    7.79          @param dom:  domain
    7.80          @return: netif controller list
    7.81          """
    7.82 -        netif = self.getInstanceByDom(dom)
    7.83 +        netif = self.getControllerByDom(dom)
    7.84          return (netif and netif.getDevices()) or []
    7.85  
    7.86      def getDomainDevice(self, dom, vif):
    7.87 @@ -69,7 +92,7 @@ class NetifControllerFactory(controller.
    7.88          @param vif: virtual interface index
    7.89          @return: NetDev
    7.90          """
    7.91 -        netif = self.getInstanceByDom(dom)
    7.92 +        netif = self.getControllerByDom(dom)
    7.93          return (netif and netif.getDevice(vif)) or None
    7.94          
    7.95  class NetDev(controller.SplitDev):
    7.96 @@ -179,7 +202,7 @@ class NetDev(controller.SplitDev):
    7.97                        { 'domid'        : self.controller.dom,
    7.98                          'netif_handle' : self.vif,
    7.99                          'mac'          : self.mac })
   7.100 -        self.getBackend().writeRequest(msg, response=d)
   7.101 +        self.getBackendInterface().writeRequest(msg, response=d)
   7.102          return d
   7.103  
   7.104      def respond_be_create(self, msg):
   7.105 @@ -193,6 +216,7 @@ class NetDev(controller.SplitDev):
   7.106          """
   7.107          def cb_destroy(val):
   7.108              self.send_be_destroy()
   7.109 +            self.getBackendInterface().close()
   7.110          log.debug("Destroying vif domain=%d vif=%d", self.controller.dom, self.vif)
   7.111          self.vifctl('down')
   7.112          d = self.send_be_disconnect()
   7.113 @@ -203,7 +227,7 @@ class NetDev(controller.SplitDev):
   7.114          msg = packMsg('netif_be_disconnect_t',
   7.115                        { 'domid'        : self.controller.dom,
   7.116                          'netif_handle' : self.vif })
   7.117 -        self.getBackend().writeRequest(msg, response=d)
   7.118 +        self.getBackendInterface().writeRequest(msg, response=d)
   7.119          return d
   7.120  
   7.121      def send_be_destroy(self, response=None):
   7.122 @@ -211,7 +235,7 @@ class NetDev(controller.SplitDev):
   7.123                        { 'domid'        : self.controller.dom,
   7.124                          'netif_handle' : self.vif })
   7.125          self.controller.delDevice(self.vif)
   7.126 -        self.getBackend().writeRequest(msg, response=response)
   7.127 +        self.getBackendInterface().writeRequest(msg, response=response)
   7.128      
   7.129      def recv_fe_interface_connect(self, val, req):
   7.130          if not req: return
   7.131 @@ -224,7 +248,7 @@ class NetDev(controller.SplitDev):
   7.132                          'rx_shmem_frame' : val['rx_shmem_frame'] })
   7.133          d = defer.Deferred()
   7.134          d.addCallback(self.respond_be_connect)
   7.135 -        self.getBackend().writeRequest(msg, response=d)
   7.136 +        self.getBackendInterface().writeRequest(msg, response=d)
   7.137          
   7.138      def respond_be_connect(self, msg):
   7.139          val = unpackMsg('netif_be_connect_t', msg)
   7.140 @@ -262,9 +286,6 @@ class NetifController(controller.SplitCo
   7.141                         self.recv_fe_interface_connect)
   7.142          self.registerChannel()
   7.143  
   7.144 -    def createBackend(self, dom, handle):
   7.145 -        return NetifBackendController(self, dom, handle)
   7.146 -
   7.147      def sxpr(self):
   7.148          val = ['netif', ['dom', self.dom]]
   7.149          return val