ia64/xen-unstable

changeset 12598:445db3980f61

When suspending and resuming, look up the managed path using the domain's UUID.

Add a resumed domain to the self.domains list after XendCheckpoint.restore,
to ensure that it does not get recreated immediately afterwards.

Perform domain_resume under the domains_lock, given that the domain needs to
be added.

These fixes together should fix xm suspend and xm resume.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Mon Nov 27 14:52:41 2006 +0000 (2006-11-27)
parents 1c09d1d195e7
children 93e657836d07
files tools/python/xen/xend/XendDomain.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Nov 27 14:48:38 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Nov 27 14:52:41 2006 +0000
     1.3 @@ -564,8 +564,7 @@ class XendDomain:
     1.4                          log.debug('Shutting down domain: %s' % dom.getName())
     1.5                          dom.shutdown("poweroff")
     1.6                      elif shutdownAction == 'suspend':
     1.7 -                        chkfile = self._managed_check_point_path(dom.getName())
     1.8 -                        self.domain_save(dom.domid, chkfile)
     1.9 +                        self.domain_suspend(dom.getName())
    1.10          finally:
    1.11              self.domains_lock.release()
    1.12  
    1.13 @@ -751,11 +750,13 @@ class XendDomain:
    1.14              if dominfo.state != DOM_STATE_RUNNING:
    1.15                  raise XendError("Cannot suspend domain that is not running.")
    1.16  
    1.17 -            if not os.path.exists(self._managed_config_path(domname)):
    1.18 +            dom_uuid = dominfo.get_uuid()
    1.19 +
    1.20 +            if not os.path.exists(self._managed_config_path(dom_uuid)):
    1.21                  raise XendError("Domain is not managed by Xend lifecycle " +
    1.22                                  "support.")
    1.23 -            
    1.24 -            path = self._managed_check_point_path(domname)
    1.25 +
    1.26 +            path = self._managed_check_point_path(dom_uuid)
    1.27              fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
    1.28              try:
    1.29                  # For now we don't support 'live checkpoint' 
    1.30 @@ -774,36 +775,42 @@ class XendDomain:
    1.31          @rtype: None
    1.32          @raise XendError: If failed to restore.
    1.33          """
    1.34 +        self.domains_lock.acquire()
    1.35          try:
    1.36 -            dominfo = self.domain_lookup_nr(domname)
    1.37 -            
    1.38 -            if not dominfo:
    1.39 -                raise XendInvalidDomain(domname)
    1.40 -
    1.41 -            if dominfo.getDomid() == DOM0_ID:
    1.42 -                raise XendError("Cannot save privileged domain %s" % domname)
    1.43 -
    1.44 -            if dominfo.state != DOM_STATE_HALTED:
    1.45 -                raise XendError("Cannot suspend domain that is not running.")
    1.46 +            try:
    1.47 +                dominfo = self.domain_lookup_nr(domname)
    1.48  
    1.49 -            chkpath = self._managed_check_point_path(domname)
    1.50 -            if not os.path.exists(chkpath):
    1.51 -                raise XendError("Domain was not suspended by Xend")
    1.52 +                if not dominfo:
    1.53 +                    raise XendInvalidDomain(domname)
    1.54  
    1.55 -            # Restore that replaces the existing XendDomainInfo
    1.56 -            try:
    1.57 -                log.debug('Current DomainInfo state: %d' % dominfo.state)
    1.58 -                XendCheckpoint.restore(self,
    1.59 -                                       os.open(chkpath, os.O_RDONLY),
    1.60 -                                       dominfo)
    1.61 -                os.unlink(chkpath)
    1.62 -            except OSError, ex:
    1.63 -                raise XendError("Failed to read stored checkpoint file")
    1.64 -            except IOError, ex:
    1.65 -                raise XendError("Failed to delete checkpoint file")
    1.66 -        except Exception, ex:
    1.67 -            log.exception("Exception occurred when resuming")
    1.68 -            raise XendError("Error occurred when resuming: %s" % str(ex))
    1.69 +                if dominfo.getDomid() == DOM0_ID:
    1.70 +                    raise XendError("Cannot save privileged domain %s" % domname)
    1.71 +
    1.72 +                if dominfo.state != DOM_STATE_HALTED:
    1.73 +                    raise XendError("Cannot suspend domain that is not running.")
    1.74 +
    1.75 +                dom_uuid = dominfo.get_uuid()
    1.76 +                chkpath = self._managed_check_point_path(dom_uuid)
    1.77 +                if not os.path.exists(chkpath):
    1.78 +                    raise XendError("Domain was not suspended by Xend")
    1.79 +
    1.80 +                # Restore that replaces the existing XendDomainInfo
    1.81 +                try:
    1.82 +                    log.debug('Current DomainInfo state: %d' % dominfo.state)
    1.83 +                    XendCheckpoint.restore(self,
    1.84 +                                           os.open(chkpath, os.O_RDONLY),
    1.85 +                                           dominfo)
    1.86 +                    self._add_domain(dominfo)
    1.87 +                    os.unlink(chkpath)
    1.88 +                except OSError, ex:
    1.89 +                    raise XendError("Failed to read stored checkpoint file")
    1.90 +                except IOError, ex:
    1.91 +                    raise XendError("Failed to delete checkpoint file")
    1.92 +            except Exception, ex:
    1.93 +                log.exception("Exception occurred when resuming")
    1.94 +                raise XendError("Error occurred when resuming: %s" % str(ex))
    1.95 +        finally:
    1.96 +            self.domains_lock.release()
    1.97  
    1.98  
    1.99      def domain_create(self, config):