ia64/xen-unstable

changeset 5351:6ffbb7f12940

bitkeeper revision 1.1662.1.13 (42a4af81MIF4vpJsgsYgQT--FGFI5w)

channel.py, XendDomainInfo.py:
Cleanup event channel code.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Mon Jun 06 20:18:09 2005 +0000 (2005-06-06)
parents 59e72b0399ac
children 3917e69c7587
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/channel.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Jun 06 19:46:33 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Jun 06 20:18:09 2005 +0000
     1.3 @@ -17,10 +17,10 @@ import xen.lowlevel.xc; xc = xen.lowleve
     1.4  from xen.util.ip import check_subnet, get_current_ipgw
     1.5  from xen.util.blkif import blkdev_uname_to_file
     1.6  
     1.7 -from xen.xend.server import channel, controller
     1.8 +from xen.xend.server import controller
     1.9  from xen.xend.server import SrvDaemon; xend = SrvDaemon.instance()
    1.10  from xen.xend.server import messages
    1.11 -from xen.xend.server.channel import channelFactory
    1.12 +from xen.xend.server.channel import EventChannel, channelFactory
    1.13  
    1.14  from xen.xend import sxp
    1.15  from xen.xend.PrettyPrint import prettyprintstring
    1.16 @@ -242,7 +242,7 @@ class XendDomainInfo:
    1.17  
    1.18          self.channel = None
    1.19          self.store_channel = None
    1.20 -        self.store_mfs = None
    1.21 +        self.store_mfn = None
    1.22          self.controllers = {}
    1.23          
    1.24          self.info = None
    1.25 @@ -286,6 +286,9 @@ class XendDomainInfo:
    1.26      def getChannel(self):
    1.27          return self.channel
    1.28  
    1.29 +    def getStoreChannel(self):
    1.30 +        return self.store_channel
    1.31 +
    1.32      def update(self, info):
    1.33          """Update with  info from xc.domain_getinfo().
    1.34          """
    1.35 @@ -401,6 +404,8 @@ class XendDomainInfo:
    1.36  
    1.37          if self.channel:
    1.38              sxpr.append(self.channel.sxpr())
    1.39 +        if self.store_channel:
    1.40 +            sxpr.append(self.store_channel.sxpr())
    1.41          console = self.getConsole()
    1.42          if console:
    1.43              sxpr.append(console.sxpr())
    1.44 @@ -550,8 +555,16 @@ class XendDomainInfo:
    1.45      def destroy(self):
    1.46          """Completely destroy the vm.
    1.47          """
    1.48 -        self.cleanup()
    1.49 -        self.destroy_domain()
    1.50 +        try:
    1.51 +            self.cleanup()
    1.52 +        except Exception, ex:
    1.53 +            log.warning("error in domain cleanup: %s", ex)
    1.54 +            pass
    1.55 +        try:
    1.56 +            self.destroy_domain()
    1.57 +        except Exception, ex:
    1.58 +            log.warning("error in domain destroy: %s", ex)
    1.59 +            pass
    1.60  
    1.61      def destroy_domain(self):
    1.62          """Destroy the vm's domain.
    1.63 @@ -559,8 +572,11 @@ class XendDomainInfo:
    1.64          devices have been released.
    1.65          """
    1.66          if self.channel:
    1.67 -            self.channel.close()
    1.68 -            self.channel = None
    1.69 +            try:
    1.70 +                self.channel.close()
    1.71 +                self.channel = None
    1.72 +            except:
    1.73 +                pass
    1.74          if self.image:
    1.75              try:
    1.76                  self.image.destroy()
    1.77 @@ -617,20 +633,32 @@ class XendDomainInfo:
    1.78          if not self.restore:
    1.79              self.setdom(dom)
    1.80  
    1.81 -    def create_channel(self):
    1.82 -        """Create the control channel to the domain.
    1.83 -        If saved info is available recreate the channel using the saved ports.
    1.84 +    def openChannel(self, name, local, remote):
    1.85 +        """Create a channel to the domain.
    1.86 +        If saved info is available recreate the channel.
    1.87 +        
    1.88 +        @param local default local port
    1.89 +        @param remote default remote port
    1.90          """
    1.91          local = 0
    1.92          remote = 1
    1.93          if self.savedinfo:
    1.94 -            info = sxp.child(self.savedinfo, "channel")
    1.95 +            info = sxp.child(self.savedinfo, name)
    1.96              if info:
    1.97                  local = int(sxp.child_value(info, "local_port", 0))
    1.98                  remote = int(sxp.child_value(info, "remote_port", 1))
    1.99 -        self.channel = channelFactory().openChannel(str(self.id),
   1.100 -                                                    local_port=local,
   1.101 -                                                    remote_port=remote)
   1.102 +        chan = channelFactory().openChannel(self.id, local_port=local,
   1.103 +                                            remote_port=remote)
   1.104 +        return chan
   1.105 +
   1.106 +    def eventChannel(self, name):
   1.107 +        return EventChannel.interdomain(0, self.id)
   1.108 +
   1.109 +    def create_channel(self):
   1.110 +        """Create the channels to the domain.
   1.111 +        """
   1.112 +        self.channel = self.openChannel("channel", 0, 1)
   1.113 +        self.store_channel = self.eventChannel("store_channel")
   1.114  
   1.115      def create_configured_devices(self):
   1.116          devices = sxp.children(self.config, 'device')
     2.1 --- a/tools/python/xen/xend/server/channel.py	Mon Jun 06 19:46:33 2005 +0000
     2.2 +++ b/tools/python/xen/xend/server/channel.py	Mon Jun 06 20:18:09 2005 +0000
     2.3 @@ -14,52 +14,90 @@ DEBUG = 0
     2.4  
     2.5  RESPONSE_TIMEOUT = 20.0
     2.6  
     2.7 -def eventChannel(dom1, dom2):
     2.8 -    """Create an event channel between domains.
     2.9 -    The returned dict contains dom1, dom2, port1 and port2 on success.
    2.10 -
    2.11 -    @return dict (empty on error)
    2.12 +class EventChannel(dict):
    2.13 +    """An event channel between domains.
    2.14      """
    2.15 -    evtchn = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2)
    2.16 -    if evtchn:
    2.17 -        evtchn['dom1'] = dom1
    2.18 -        evtchn['dom2'] = dom2
    2.19 -    return evtchn
    2.20 +
    2.21 +    def interdomain(cls, dom1, dom2, port1=0, port2=0):
    2.22 +        """Create an event channel between domains.
    2.23 +        
    2.24 +        @return EventChannel (None on error)
    2.25 +        """
    2.26 +        v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
    2.27 +                                       port1=port1, port2=port2)
    2.28 +        if v:
    2.29 +            v = cls(dom1, dom2, v)
    2.30 +        return v
    2.31 +
    2.32 +    interdomain = classmethod(interdomain)
    2.33 +
    2.34 +    def __init__(self, dom1, dom2, d):
    2.35 +        d['dom1'] = dom1
    2.36 +        d['dom2'] = dom2
    2.37 +        self.update(d)
    2.38 +        self.dom1 = dom1
    2.39 +        self.dom2 = dom2
    2.40 +        self.port1 = d.get('port1')
    2.41 +        self.port2 = d.get('port2')
    2.42 +
    2.43 +    def close(self):
    2.44 +        """Close the event channel.
    2.45 +        """
    2.46 +        def evtchn_close(dom, port):
    2.47 +            try:
    2.48 +                xc.evtchn_close(dom=dom, port=port)
    2.49 +            except Exception, ex:
    2.50 +                pass
    2.51 +            
    2.52 +        if DEBUG:
    2.53 +            print 'EventChannel>close>', self
    2.54 +        evtchn_close(self.dom1, self.port1)
    2.55 +        evtchn_close(self.dom2, self.port2)
    2.56 +
    2.57 +    def sxpr(self):
    2.58 +        return ['event-channel',
    2.59 +                ['dom1',  self.dom1  ],
    2.60 +                ['port1', self.port1 ],
    2.61 +                ['dom2',  self.dom2  ],
    2.62 +                ['port2', self.port2 ]
    2.63 +                ]
    2.64 +
    2.65 +    def __repr__(self):
    2.66 +        return ("<EventChannel dom1:%s:%s dom2:%s:%s>"
    2.67 +                % (self.dom1, self.port1, self.dom2, self.port2))
    2.68 +
    2.69 +def eventChannel(dom1, dom2, port1=0, port2=0):
    2.70 +    """Create an event channel between domains.
    2.71 +        
    2.72 +    @return EventChannel (None on error)
    2.73 +    """
    2.74 +    return EventChannel.interdomain(dom1, dom2, port1=port1, port2=port2)
    2.75  
    2.76  def eventChannelClose(evtchn):
    2.77 -    """Close an event channel that was opened by eventChannel().
    2.78 +    """Close an event channel.
    2.79      """
    2.80 -    def evtchn_close(dom, port):
    2.81 -        if (dom is None) or (port is None): return
    2.82 -        try:
    2.83 -            xc.evtchn_close(dom=dom, port=port)
    2.84 -        except Exception, ex:
    2.85 -            pass
    2.86 -        
    2.87      if not evtchn: return
    2.88 -    if DEBUG:
    2.89 -        print 'eventChannelClose>', evtchn
    2.90 -    evtchn_close(evtchn.get('dom1'), evtchn.get('port1'))
    2.91 -    evtchn_close(evtchn.get('dom2'), evtchn.get('port2'))
    2.92 -    
    2.93 +    evtchn.close()
    2.94  
    2.95  class ChannelFactory:
    2.96 -    """Factory for creating channels.
    2.97 +    """Factory for creating control channels.
    2.98      Maintains a table of channels.
    2.99      """
   2.100  
   2.101      """ Channels indexed by index. """
   2.102 -    channels = {}
   2.103 +    channels = None
   2.104  
   2.105      thread = None
   2.106  
   2.107      notifier = None
   2.108  
   2.109      """Map of ports to the virq they signal."""
   2.110 -    virqPorts = {}
   2.111 +    virqPorts = None
   2.112  
   2.113      def __init__(self):
   2.114          """Constructor - do not use. Use the channelFactory function."""
   2.115 +        self.channels = {}
   2.116 +        self.virqPorts = {}
   2.117          self.notifier = xu.notifier()
   2.118          # Register interest in virqs.
   2.119          self.bind_virq(xen.lowlevel.xc.VIRQ_DOM_EXC)
   2.120 @@ -70,10 +108,6 @@ class ChannelFactory:
   2.121          self.virqPorts[port] = virq
   2.122          log.info("Virq %s on port %s", virq, port)
   2.123  
   2.124 -    def virq(self):
   2.125 -        log.error("virq")
   2.126 -        self.notifier.virq_send(self.virqPort)
   2.127 -
   2.128      def start(self):
   2.129          """Fork a thread to read messages.
   2.130          """
   2.131 @@ -182,9 +216,13 @@ class ChannelFactory:
   2.132          return None
   2.133  
   2.134      def openChannel(self, dom, local_port=0, remote_port=0):
   2.135 -        return (self.findChannel(dom, local_port=local_port, remote_port=remote_port)
   2.136 -                or
   2.137 -                self.newChannel(dom, local_port, remote_port))
   2.138 +        chan = self.findChannel(dom, local_port=local_port,
   2.139 +                                remote_port=remote_port)
   2.140 +        if chan:
   2.141 +            return chan
   2.142 +        chan = self.newChannel(dom, local_port, remote_port)
   2.143 +        return chan
   2.144 +        
   2.145  
   2.146      def createPort(self, dom, local_port=0, remote_port=0):
   2.147          """Create a port for a channel to the given domain.
   2.148 @@ -218,7 +256,7 @@ def channelFactory():
   2.149      return inst
   2.150  
   2.151  class Channel:
   2.152 -    """Chanel to a domain.
   2.153 +    """Control channel to a domain.
   2.154      Maintains a list of device handlers to dispatch requests to, based
   2.155      on the request type.
   2.156      """