ia64/xen-unstable

changeset 7149:345e517bab57

Remove the bizarre arrangement whereby EventChannel inherits from dict. Move
the channel-creation logic into eventChannel, making the EventChannel class
simpler. Remove the closeEventChannel method -- it was simply doing a check
for None, and that isn't enough value to justify the extra method when there
is an EventChannel.close method there too.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Fri Sep 30 11:40:59 2005 +0100 (2005-09-30)
parents 41b1f86628a0
children a39510ad5c59
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xend/server/channel.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 30 10:50:19 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 30 11:40:59 2005 +0100
     1.3 @@ -32,7 +32,7 @@ import errno
     1.4  import xen.lowlevel.xc
     1.5  from xen.util.blkif import blkdev_uname_to_file
     1.6  
     1.7 -from xen.xend.server.channel import EventChannel
     1.8 +from xen.xend.server import channel
     1.9  
    1.10  from xen.xend import image
    1.11  from xen.xend import scheduler
    1.12 @@ -1032,7 +1032,7 @@ class XendDomainInfo:
    1.13              except:
    1.14                  # if anything goes wrong, assume the port was not yet set
    1.15                  pass
    1.16 -        ret = EventChannel.interdomain(0, self.domid, port1=port, port2=0)
    1.17 +        ret = channel.eventChannel(0, self.domid, port1=port, port2=0)
    1.18          self.storeDom(path, ret.port1)
    1.19          return ret
    1.20          
     2.1 --- a/tools/python/xen/xend/image.py	Fri Sep 30 10:50:19 2005 +0100
     2.2 +++ b/tools/python/xen/xend/image.py	Fri Sep 30 11:40:59 2005 +0100
     2.3 @@ -358,7 +358,8 @@ class VmxImageHandler(ImageHandler):
     2.4          return vncconnect
     2.5  
     2.6      def destroy(self):
     2.7 -        channel.eventChannelClose(self.device_channel)
     2.8 +        if self.device_channel:
     2.9 +            self.device_channel.close()
    2.10          import signal
    2.11          if not self.pid:
    2.12              return
     3.1 --- a/tools/python/xen/xend/server/channel.py	Fri Sep 30 10:50:19 2005 +0100
     3.2 +++ b/tools/python/xen/xend/server/channel.py	Fri Sep 30 11:40:59 2005 +0100
     3.3 @@ -13,59 +13,42 @@
     3.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     3.5  #============================================================================
     3.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     3.7 +# Copyright (C) 2005 XenSource Ltd
     3.8  #============================================================================
     3.9  
    3.10 -import threading
    3.11 -import select
    3.12 -
    3.13 -import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
    3.14 +import xen.lowlevel.xc
    3.15  
    3.16  from xen.xend.XendLogging import log
    3.17  
    3.18 -DEBUG = 0
    3.19  
    3.20 -RESPONSE_TIMEOUT = 20.0
    3.21 +xc = xen.lowlevel.xc.new()
    3.22  
    3.23 -class EventChannel(dict):
    3.24 +
    3.25 +class EventChannel:
    3.26      """An event channel between domains.
    3.27      """
    3.28  
    3.29 -    def interdomain(cls, dom1, dom2, port1=0, port2=0):
    3.30 -        """Create an event channel between domains.
    3.31 -        
    3.32 -        @return EventChannel (None on error)
    3.33 -        """
    3.34 -        v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
    3.35 -                                       port1=port1, port2=port2)
    3.36 -        if v:
    3.37 -            v = cls(dom1, dom2, v)
    3.38 -        return v
    3.39 -
    3.40 -    interdomain = classmethod(interdomain)
    3.41 -
    3.42 -    def __init__(self, dom1, dom2, d):
    3.43 -        d['dom1'] = dom1
    3.44 -        d['dom2'] = dom2
    3.45 -        self.update(d)
    3.46 +    def __init__(self, dom1, dom2, port1, port2):
    3.47          self.dom1 = dom1
    3.48          self.dom2 = dom2
    3.49 -        self.port1 = d.get('port1')
    3.50 -        self.port2 = d.get('port2')
    3.51 +        self.port1 = port1
    3.52 +        self.port2 = port2
    3.53 +
    3.54  
    3.55      def close(self):
    3.56 -        """Close the event channel.
    3.57 +        """Close the event channel.  Nothrow guarantee.
    3.58          """
    3.59          def evtchn_close(dom, port):
    3.60              try:
    3.61                  xc.evtchn_close(dom=dom, port=port)
    3.62 -            except Exception, ex:
    3.63 -                pass
    3.64 +            except Exception:
    3.65 +                log.exception("Exception closing event channel %d, %d.", dom,
    3.66 +                              port)
    3.67              
    3.68 -        if DEBUG:
    3.69 -            print 'EventChannel>close>', self
    3.70          evtchn_close(self.dom1, self.port1)
    3.71          evtchn_close(self.dom2, self.port2)
    3.72  
    3.73 +
    3.74      def sxpr(self):
    3.75          return ['event-channel',
    3.76                  ['dom1',  self.dom1  ],
    3.77 @@ -74,19 +57,20 @@ class EventChannel(dict):
    3.78                  ['port2', self.port2 ]
    3.79                  ]
    3.80  
    3.81 +
    3.82      def __repr__(self):
    3.83          return ("<EventChannel dom1:%d:%d dom2:%d:%d>"
    3.84                  % (self.dom1, self.port1, self.dom2, self.port2))
    3.85  
    3.86 -def eventChannel(dom1, dom2, port1=0, port2=0):
    3.87 +
    3.88 +def eventChannel(dom1, dom2, port1 = 0, port2 = 0):
    3.89      """Create an event channel between domains.
    3.90          
    3.91      @return EventChannel (None on error)
    3.92      """
    3.93 -    return EventChannel.interdomain(dom1, dom2, port1=port1, port2=port2)
    3.94 -
    3.95 -def eventChannelClose(evtchn):
    3.96 -    """Close an event channel.
    3.97 -    """
    3.98 -    if not evtchn: return
    3.99 -    evtchn.close()
   3.100 +    v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
   3.101 +                                   port1=port1, port2=port2)
   3.102 +    if v and v.get('port1'):
   3.103 +        return EventChannel(dom1, dom2, v['port1'], v['port2'])
   3.104 +    else:
   3.105 +        return None