[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Remove the bizarre arrangement whereby EventChannel inherits from dict. Move



# HG changeset patch
# User emellor@ewan
# Node ID 345e517bab57e122111378783540645e1b0a5dfb
# Parent  41b1f86628a043fe273fbe62203fc679a5014bdc
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@xxxxxxxxxxxxx>

diff -r 41b1f86628a0 -r 345e517bab57 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Fri Sep 30 09:50:19 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py   Fri Sep 30 10:40:59 2005
@@ -32,7 +32,7 @@
 import xen.lowlevel.xc
 from xen.util.blkif import blkdev_uname_to_file
 
-from xen.xend.server.channel import EventChannel
+from xen.xend.server import channel
 
 from xen.xend import image
 from xen.xend import scheduler
@@ -1032,7 +1032,7 @@
             except:
                 # if anything goes wrong, assume the port was not yet set
                 pass
-        ret = EventChannel.interdomain(0, self.domid, port1=port, port2=0)
+        ret = channel.eventChannel(0, self.domid, port1=port, port2=0)
         self.storeDom(path, ret.port1)
         return ret
         
diff -r 41b1f86628a0 -r 345e517bab57 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Fri Sep 30 09:50:19 2005
+++ b/tools/python/xen/xend/image.py    Fri Sep 30 10:40:59 2005
@@ -358,7 +358,8 @@
         return vncconnect
 
     def destroy(self):
-        channel.eventChannelClose(self.device_channel)
+        if self.device_channel:
+            self.device_channel.close()
         import signal
         if not self.pid:
             return
diff -r 41b1f86628a0 -r 345e517bab57 tools/python/xen/xend/server/channel.py
--- a/tools/python/xen/xend/server/channel.py   Fri Sep 30 09:50:19 2005
+++ b/tools/python/xen/xend/server/channel.py   Fri Sep 30 10:40:59 2005
@@ -13,58 +13,41 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
+# Copyright (C) 2005 XenSource Ltd
 #============================================================================
 
-import threading
-import select
-
-import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
+import xen.lowlevel.xc
 
 from xen.xend.XendLogging import log
 
-DEBUG = 0
 
-RESPONSE_TIMEOUT = 20.0
+xc = xen.lowlevel.xc.new()
 
-class EventChannel(dict):
+
+class EventChannel:
     """An event channel between domains.
     """
 
-    def interdomain(cls, dom1, dom2, port1=0, port2=0):
-        """Create an event channel between domains.
-        
-        @return EventChannel (None on error)
-        """
-        v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
-                                       port1=port1, port2=port2)
-        if v:
-            v = cls(dom1, dom2, v)
-        return v
-
-    interdomain = classmethod(interdomain)
-
-    def __init__(self, dom1, dom2, d):
-        d['dom1'] = dom1
-        d['dom2'] = dom2
-        self.update(d)
+    def __init__(self, dom1, dom2, port1, port2):
         self.dom1 = dom1
         self.dom2 = dom2
-        self.port1 = d.get('port1')
-        self.port2 = d.get('port2')
+        self.port1 = port1
+        self.port2 = port2
+
 
     def close(self):
-        """Close the event channel.
+        """Close the event channel.  Nothrow guarantee.
         """
         def evtchn_close(dom, port):
             try:
                 xc.evtchn_close(dom=dom, port=port)
-            except Exception, ex:
-                pass
+            except Exception:
+                log.exception("Exception closing event channel %d, %d.", dom,
+                              port)
             
-        if DEBUG:
-            print 'EventChannel>close>', self
         evtchn_close(self.dom1, self.port1)
         evtchn_close(self.dom2, self.port2)
+
 
     def sxpr(self):
         return ['event-channel',
@@ -74,19 +57,20 @@
                 ['port2', self.port2 ]
                 ]
 
+
     def __repr__(self):
         return ("<EventChannel dom1:%d:%d dom2:%d:%d>"
                 % (self.dom1, self.port1, self.dom2, self.port2))
 
-def eventChannel(dom1, dom2, port1=0, port2=0):
+
+def eventChannel(dom1, dom2, port1 = 0, port2 = 0):
     """Create an event channel between domains.
         
     @return EventChannel (None on error)
     """
-    return EventChannel.interdomain(dom1, dom2, port1=port1, port2=port2)
-
-def eventChannelClose(evtchn):
-    """Close an event channel.
-    """
-    if not evtchn: return
-    evtchn.close()
+    v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
+                                   port1=port1, port2=port2)
+    if v and v.get('port1'):
+        return EventChannel(dom1, dom2, v['port1'], v['port2'])
+    else:
+        return None

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.