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

[Xen-changelog] XendDomainInfo.py, XendDomain.py:



ChangeSet 1.1461.1.1, 2005/05/19 16:23:39+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        XendDomainInfo.py, XendDomain.py:
          Remove DomainShutdown class and store shutdown information in domain's
          XendDomainInfo object.
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 XendDomain.py     |   83 +++++++++---------------------------------------------
 XendDomainInfo.py |   12 +++++++
 2 files changed, 26 insertions(+), 69 deletions(-)


diff -Nru a/tools/python/xen/xend/XendDomain.py 
b/tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       2005-05-19 12:03:39 -04:00
+++ b/tools/python/xen/xend/XendDomain.py       2005-05-19 12:03:39 -04:00
@@ -28,47 +28,6 @@
 
 SHUTDOWN_TIMEOUT = 30
 
-class DomainShutdown:
-    """A pending domain shutdown. The domain is asked to shut down,
-    if it has not terminated or rebooted when the timeout expires it
-    is destroyed.
-    """
-
-    def __init__(self, dominfo, reason, key, timeout=None):
-        if timeout is None:
-            timeout = SHUTDOWN_TIMEOUT
-        self.start = time.time()
-        self.timeout = timeout
-        self.dominfo = dominfo
-        self.last_restart_time = dominfo.restart_time
-        self.last_restart_count = dominfo.restart_count
-        self.reason = reason
-        self.key = key
-
-    def getDomain(self):
-        return self.dominfo.id
-
-    def getDomainName(self):
-        return self.dominfo.name
-
-    def getReason(self):
-        return self.reason
-
-    def getTimeout(self):
-        return self.timeout
-
-    def isTerminated(self):
-        return self.dominfo.is_terminated()
-
-    def isRestarted(self):
-        return (self.dominfo.restart_count > self.last_restart_count)
-
-    def isShutdown(self):
-        return self.isTerminated() or self.isRestarted()
-
-    def isExpired(self):
-        return (time.time() - self.start) > self.timeout
-        
 class XendDomain:
     """Index of all domains. Singleton.
     """
@@ -80,9 +39,6 @@
     domain_by_id = {}
     domain_by_name = {}
     
-    """Table of pending domain shutdowns, indexed by domain id."""
-    shutdowns_by_id = {}
-
     def __init__(self):
         # Hack alert. Python does not support mutual imports, but 
XendDomainInfo
         # needs access to the XendDomain instance to look up domains. 
Attempting
@@ -465,43 +421,34 @@
             reason = 'poweroff'
         val = dominfo.shutdown(reason, key=key)
         if reason != 'sysrq':
-            self.add_shutdown(dominfo, reason, key)
+            self.domain_shutdowns()
         return val
 
-    def add_shutdown(self, dominfo, reason, key):
-        """Add a pending shutdown for a domain.
-        This will destroy the domain if the shutdown times out.
-        """
-        if dominfo.id in self.shutdowns_by_id:
-            return
-        self.shutdowns_by_id[dominfo.id] = DomainShutdown(dominfo, reason, key)
-        self.domain_shutdowns()
-
     def domain_shutdowns(self):
         """Process pending domain shutdowns.
         Destroys domains whose shutdowns have timed out.
         """
-        timeout = SHUTDOWN_TIMEOUT
-        for shutdown in self.shutdowns_by_id.values():
-            id = shutdown.getDomain()
-            if shutdown.isShutdown():
-                # Shutdown done - remove.
-                print 'domain_shutdowns> done: ', id
-                del self.shutdowns_by_id[id]
-            elif shutdown.isExpired():
-                # Shutdown expired - remove and destroy domain.
-                del self.shutdowns_by_id[id]
+        timeout = SHUTDOWN_TIMEOUT + 1
+        for dominfo in self.domain_by_id.values():
+            if not dominfo.shutdown_pending:
+                # domain doesn't need shutdown
+                continue
+            id = dominfo.id
+            left = dominfo.shutdown_time_left(SHUTDOWN_TIMEOUT)
+            if left <= 0:
+                # Shutdown expired - destroy domain.
                 try:
                     log.info("Domain shutdown timeout expired: name=%s id=%s",
-                             shutdown.getDomainName(), id)
-                    self.domain_destroy(id, reason=shutdown.getReason())
+                             dominfo.name, id)
+                    self.domain_destroy(id, reason=
+                                        dominfo.shutdown_pending['reason'])
                 except Exception:
                     pass
             else:
                 # Shutdown still pending.
                 print 'domain_shutdowns> pending: ', id
-                timeout = min(timeout, shutdown.getTimeout())
-        if self.shutdowns_by_id:
+                timeout = min(timeout, left)
+        if timeout <= SHUTDOWN_TIMEOUT:
             # Pending shutdowns remain - reschedule.
             scheduler.later(timeout, self.domain_shutdowns)
 
diff -Nru a/tools/python/xen/xend/XendDomainInfo.py 
b/tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   2005-05-19 12:03:39 -04:00
+++ b/tools/python/xen/xend/XendDomainInfo.py   2005-05-19 12:03:39 -04:00
@@ -281,6 +281,8 @@
         self.netif_backend = False
         #todo: state: running, suspended
         self.state = STATE_VM_OK
+        self.shutdown_pending = None
+
         #todo: set to migrate info if migrating
         self.migrate = None
         
@@ -950,6 +952,7 @@
         """
         try:
             self.state = STATE_VM_OK
+            self.shutdown_pending = None
             self.restart_check()
             self.restart_state = STATE_RESTART_BOOTING
             if self.bootloader:
@@ -1090,7 +1093,14 @@
         if self.channel:
             msg = messages.packMsg(msgtype, extra)
             self.channel.writeRequest(msg)
-
+        if reason != 'sysrq':
+            self.shutdown_pending = {'start':time.time(), 'reason':reason,
+                                     'key':key}
+
+    def shutdown_time_left(self, timeout):
+        if not self.shutdown_pending:
+            return 0
+        return timeout - (time.time() - self.shutdown_pending['start'])
 
 def vm_image_linux(vm, image):
     """Create a VM for a linux image.

_______________________________________________
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®.