ia64/xen-unstable

changeset 5009:8ec7db262b48

bitkeeper revision 1.1466 (428cafb3mGJpJHeRanaDw7Xj7mWFIw)

Merge firebug.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-unstable.bk
into firebug.cl.cam.ac.uk:/local/scratch/cl349/xen-unstable.bk
author cl349@firebug.cl.cam.ac.uk
date Thu May 19 15:24:35 2005 +0000 (2005-05-19)
parents 0c3e919d87f4 db2dafdbcc68
children 8e1eb9f69187 9263f821935a
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Thu May 19 14:04:05 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu May 19 15:24:35 2005 +0000
     1.3 @@ -28,47 +28,6 @@ from xen.xend.server import channel
     1.4  
     1.5  SHUTDOWN_TIMEOUT = 30
     1.6  
     1.7 -class DomainShutdown:
     1.8 -    """A pending domain shutdown. The domain is asked to shut down,
     1.9 -    if it has not terminated or rebooted when the timeout expires it
    1.10 -    is destroyed.
    1.11 -    """
    1.12 -
    1.13 -    def __init__(self, dominfo, reason, key, timeout=None):
    1.14 -        if timeout is None:
    1.15 -            timeout = SHUTDOWN_TIMEOUT
    1.16 -        self.start = time.time()
    1.17 -        self.timeout = timeout
    1.18 -        self.dominfo = dominfo
    1.19 -        self.last_restart_time = dominfo.restart_time
    1.20 -        self.last_restart_count = dominfo.restart_count
    1.21 -        self.reason = reason
    1.22 -        self.key = key
    1.23 -
    1.24 -    def getDomain(self):
    1.25 -        return self.dominfo.id
    1.26 -
    1.27 -    def getDomainName(self):
    1.28 -        return self.dominfo.name
    1.29 -
    1.30 -    def getReason(self):
    1.31 -        return self.reason
    1.32 -
    1.33 -    def getTimeout(self):
    1.34 -        return self.timeout
    1.35 -
    1.36 -    def isTerminated(self):
    1.37 -        return self.dominfo.is_terminated()
    1.38 -
    1.39 -    def isRestarted(self):
    1.40 -        return (self.dominfo.restart_count > self.last_restart_count)
    1.41 -
    1.42 -    def isShutdown(self):
    1.43 -        return self.isTerminated() or self.isRestarted()
    1.44 -
    1.45 -    def isExpired(self):
    1.46 -        return (time.time() - self.start) > self.timeout
    1.47 -        
    1.48  class XendDomain:
    1.49      """Index of all domains. Singleton.
    1.50      """
    1.51 @@ -80,9 +39,6 @@ class XendDomain:
    1.52      domain_by_id = {}
    1.53      domain_by_name = {}
    1.54      
    1.55 -    """Table of pending domain shutdowns, indexed by domain id."""
    1.56 -    shutdowns_by_id = {}
    1.57 -
    1.58      def __init__(self):
    1.59          # Hack alert. Python does not support mutual imports, but XendDomainInfo
    1.60          # needs access to the XendDomain instance to look up domains. Attempting
    1.61 @@ -465,43 +421,34 @@ class XendDomain:
    1.62              reason = 'poweroff'
    1.63          val = dominfo.shutdown(reason, key=key)
    1.64          if reason != 'sysrq':
    1.65 -            self.add_shutdown(dominfo, reason, key)
    1.66 +            self.domain_shutdowns()
    1.67          return val
    1.68  
    1.69 -    def add_shutdown(self, dominfo, reason, key):
    1.70 -        """Add a pending shutdown for a domain.
    1.71 -        This will destroy the domain if the shutdown times out.
    1.72 -        """
    1.73 -        if dominfo.id in self.shutdowns_by_id:
    1.74 -            return
    1.75 -        self.shutdowns_by_id[dominfo.id] = DomainShutdown(dominfo, reason, key)
    1.76 -        self.domain_shutdowns()
    1.77 -
    1.78      def domain_shutdowns(self):
    1.79          """Process pending domain shutdowns.
    1.80          Destroys domains whose shutdowns have timed out.
    1.81          """
    1.82 -        timeout = SHUTDOWN_TIMEOUT
    1.83 -        for shutdown in self.shutdowns_by_id.values():
    1.84 -            id = shutdown.getDomain()
    1.85 -            if shutdown.isShutdown():
    1.86 -                # Shutdown done - remove.
    1.87 -                print 'domain_shutdowns> done: ', id
    1.88 -                del self.shutdowns_by_id[id]
    1.89 -            elif shutdown.isExpired():
    1.90 -                # Shutdown expired - remove and destroy domain.
    1.91 -                del self.shutdowns_by_id[id]
    1.92 +        timeout = SHUTDOWN_TIMEOUT + 1
    1.93 +        for dominfo in self.domain_by_id.values():
    1.94 +            if not dominfo.shutdown_pending:
    1.95 +                # domain doesn't need shutdown
    1.96 +                continue
    1.97 +            id = dominfo.id
    1.98 +            left = dominfo.shutdown_time_left(SHUTDOWN_TIMEOUT)
    1.99 +            if left <= 0:
   1.100 +                # Shutdown expired - destroy domain.
   1.101                  try:
   1.102                      log.info("Domain shutdown timeout expired: name=%s id=%s",
   1.103 -                             shutdown.getDomainName(), id)
   1.104 -                    self.domain_destroy(id, reason=shutdown.getReason())
   1.105 +                             dominfo.name, id)
   1.106 +                    self.domain_destroy(id, reason=
   1.107 +                                        dominfo.shutdown_pending['reason'])
   1.108                  except Exception:
   1.109                      pass
   1.110              else:
   1.111                  # Shutdown still pending.
   1.112                  print 'domain_shutdowns> pending: ', id
   1.113 -                timeout = min(timeout, shutdown.getTimeout())
   1.114 -        if self.shutdowns_by_id:
   1.115 +                timeout = min(timeout, left)
   1.116 +        if timeout <= SHUTDOWN_TIMEOUT:
   1.117              # Pending shutdowns remain - reschedule.
   1.118              scheduler.later(timeout, self.domain_shutdowns)
   1.119  
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu May 19 14:04:05 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu May 19 15:24:35 2005 +0000
     2.3 @@ -281,6 +281,8 @@ class XendDomainInfo:
     2.4          self.netif_backend = False
     2.5          #todo: state: running, suspended
     2.6          self.state = STATE_VM_OK
     2.7 +        self.shutdown_pending = None
     2.8 +
     2.9          #todo: set to migrate info if migrating
    2.10          self.migrate = None
    2.11          
    2.12 @@ -950,6 +952,7 @@ class XendDomainInfo:
    2.13          """
    2.14          try:
    2.15              self.state = STATE_VM_OK
    2.16 +            self.shutdown_pending = None
    2.17              self.restart_check()
    2.18              self.restart_state = STATE_RESTART_BOOTING
    2.19              if self.bootloader:
    2.20 @@ -1090,7 +1093,14 @@ class XendDomainInfo:
    2.21          if self.channel:
    2.22              msg = messages.packMsg(msgtype, extra)
    2.23              self.channel.writeRequest(msg)
    2.24 +        if reason != 'sysrq':
    2.25 +            self.shutdown_pending = {'start':time.time(), 'reason':reason,
    2.26 +                                     'key':key}
    2.27  
    2.28 +    def shutdown_time_left(self, timeout):
    2.29 +        if not self.shutdown_pending:
    2.30 +            return 0
    2.31 +        return timeout - (time.time() - self.shutdown_pending['start'])
    2.32  
    2.33  def vm_image_linux(vm, image):
    2.34      """Create a VM for a linux image.