ia64/xen-unstable

changeset 12642:33951d547223

Plumb the "start_paused" flag through for VM.start and VM.resume. Do not
unpause the VM on start by default. This should fix problems seen recently
whereby devices are not attached to the VM by the time they boot, as
xm create was expecting to be able to wait for the devices before unpausing.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Nov 28 17:28:43 2006 +0000 (2006-11-28)
parents 39e40ccf7df5
children bd5ebf33f222
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Tue Nov 28 17:15:22 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue Nov 28 17:28:43 2006 +0000
     1.3 @@ -248,8 +248,8 @@ def valid_sr(func):
     1.4  # Bridge to Legacy XM API calls
     1.5  # -----------------------------
     1.6  
     1.7 -def do_vm_func(fn_name, vm_ref, *args):
     1.8 -    """Helper wrapper func to abstract away from repeative code.
     1.9 +def do_vm_func(fn_name, vm_ref, *args, **kwargs):
    1.10 +    """Helper wrapper func to abstract away from repetitive code.
    1.11  
    1.12      @param fn_name: function name for XendDomain instance
    1.13      @type fn_name: string
    1.14 @@ -260,7 +260,7 @@ def do_vm_func(fn_name, vm_ref, *args):
    1.15      """
    1.16      xendom = XendDomain.instance()
    1.17      fn = getattr(xendom, fn_name)
    1.18 -    xendom.do_legacy_api_with_uuid(fn, vm_ref, *args)
    1.19 +    xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs)
    1.20      return xen_api_success_void()
    1.21  
    1.22  
    1.23 @@ -1027,9 +1027,9 @@ class XendAPI:
    1.24      def vm_pause(self, session, vm_ref):
    1.25          return do_vm_func("domain_pause", vm_ref)
    1.26      def vm_resume(self, session, vm_ref, start_paused):
    1.27 -        return do_vm_func("domain_resume", vm_ref)    
    1.28 -    def vm_start(self, session, vm_ref):
    1.29 -        return do_vm_func("domain_start", vm_ref)
    1.30 +        return do_vm_func("domain_resume", vm_ref, start_paused = start_paused)    
    1.31 +    def vm_start(self, session, vm_ref, start_paused):
    1.32 +        return do_vm_func("domain_start", vm_ref, start_paused = start_paused)
    1.33      def vm_suspend(self, session, vm_ref):
    1.34          return do_vm_func("domain_suspend", vm_ref)    
    1.35      def vm_unpause(self, session, vm_ref):
     2.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Nov 28 17:15:22 2006 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Nov 28 17:28:43 2006 +0000
     2.3 @@ -647,18 +647,18 @@ class XendDomain:
     2.4      def is_valid_dev(self, klass, dev_uuid):
     2.5          return (self.get_vm_with_dev_uuid(klass, dev_uuid) != None)
     2.6  
     2.7 -    def do_legacy_api_with_uuid(self, fn, vm_uuid, *args):
     2.8 +    def do_legacy_api_with_uuid(self, fn, vm_uuid, *args, **kwargs):
     2.9          self.domains_lock.acquire()
    2.10          try:
    2.11              for domid, dom in self.domains.items():
    2.12                  if dom.get_uuid == vm_uuid:
    2.13 -                    return fn(domid, *args)
    2.14 +                    return fn(domid, *args, **kwargs)
    2.15                      
    2.16              if vm_uuid in self.managed_domains:
    2.17                  domid = self.managed_domains[vm_uuid].getDomid()
    2.18                  if domid == None:
    2.19                      domid = self.managed_domains[vm_uuid].getName()
    2.20 -                return fn(domid, *args)
    2.21 +                return fn(domid, *args, **kwargs)
    2.22              
    2.23              raise XendInvalidDomain("Domain does not exist")
    2.24          finally:
    2.25 @@ -795,7 +795,7 @@ class XendDomain:
    2.26              raise XendError("can't write guest state file %s: %s" %
    2.27                              (path, ex[1]))
    2.28  
    2.29 -    def domain_resume(self, domname):
    2.30 +    def domain_resume(self, domname, start_paused = False):
    2.31          """Resumes a domain that is persistently managed by Xend.
    2.32  
    2.33          @param domname: Domain Name
    2.34 @@ -827,7 +827,8 @@ class XendDomain:
    2.35                      log.debug('Current DomainInfo state: %d' % dominfo.state)
    2.36                      XendCheckpoint.restore(self,
    2.37                                             os.open(chkpath, os.O_RDONLY),
    2.38 -                                           dominfo)
    2.39 +                                           dominfo,
    2.40 +                                           paused = start_paused)
    2.41                      self._add_domain(dominfo)
    2.42                      os.unlink(chkpath)
    2.43                  except OSError, ex:
    2.44 @@ -886,7 +887,7 @@ class XendDomain:
    2.45          finally:
    2.46              self.domains_lock.release()
    2.47  
    2.48 -    def domain_start(self, domid):
    2.49 +    def domain_start(self, domid, start_paused = True):
    2.50          """Start a managed domain
    2.51  
    2.52          @require: Domain must not be running.
    2.53 @@ -907,7 +908,7 @@ class XendDomain:
    2.54              if dominfo.state != DOM_STATE_HALTED:
    2.55                  raise XendError("Domain is already running")
    2.56              
    2.57 -            dominfo.start(is_managed = True)
    2.58 +            dominfo.start(is_managed = True, start_paused = start_paused)
    2.59              self._add_domain(dominfo)
    2.60          finally:
    2.61              self.domains_lock.release()
     3.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Nov 28 17:15:22 2006 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Nov 28 17:28:43 2006 +0000
     3.3 @@ -425,7 +425,7 @@ class XendDomainInfo:
     3.4      #
     3.5  
     3.6  
     3.7 -    def start(self, is_managed = False):
     3.8 +    def start(self, is_managed = False, start_paused = True):
     3.9          """Attempts to start the VM by do the appropriate
    3.10          initialisation if it not started.
    3.11          """
    3.12 @@ -439,7 +439,8 @@ class XendDomainInfo:
    3.13                  self._storeDomDetails()
    3.14                  self._registerWatches()
    3.15                  self.refreshShutdown()
    3.16 -                self.unpause()
    3.17 +                if not start_paused:
    3.18 +                    self.unpause()
    3.19  
    3.20                  # save running configuration if XendDomains believe domain is
    3.21                  # persistent
     4.1 --- a/tools/python/xen/xm/main.py	Tue Nov 28 17:15:22 2006 +0000
     4.2 +++ b/tools/python/xen/xm/main.py	Tue Nov 28 17:28:43 2006 +0000
     4.3 @@ -207,7 +207,13 @@ SUBCOMMAND_OPTIONS = {
     4.4         ('-L', '--live', 'Dump core without pausing the domain'),
     4.5         ('-C', '--crash', 'Crash domain after dumping core'),
     4.6      ),
     4.7 -    'restore': (
     4.8 +    'start': (
     4.9 +      ('-p', '--paused', 'Do not unpause domain after starting it'),
    4.10 +    ),
    4.11 +    'resume': (
    4.12 +      ('-p', '--paused', 'Do not unpause domain after resuming it'),
    4.13 +    ),
    4.14 +   'restore': (
    4.15        ('-p', '--paused', 'Do not unpause domain after restoring it'),
    4.16      ),
    4.17  }
    4.18 @@ -742,9 +748,26 @@ def xm_vcpu_list(args):
    4.19              print format % locals()
    4.20  
    4.21  def xm_start(args):
    4.22 -    arg_check(args, "start", 1)
    4.23 -    dom = args[0]
    4.24 -    server.xend.domain.start(dom)
    4.25 +    arg_check(args, "start", 1, 2)
    4.26 +
    4.27 +    try:
    4.28 +        (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
    4.29 +    except getopt.GetoptError, opterr:
    4.30 +        err(opterr)
    4.31 +        sys.exit(1)
    4.32 +
    4.33 +    paused = False
    4.34 +    for (k, v) in options:
    4.35 +        if k in ['-p', '--paused']:
    4.36 +            paused = True
    4.37 +
    4.38 +    if len(params) != 1:
    4.39 +        err("Wrong number of parameters")
    4.40 +        usage('start')
    4.41 +        sys.exit(1)
    4.42 +
    4.43 +    dom = params[0]
    4.44 +    server.xend.domain.start(dom, paused)
    4.45  
    4.46  def xm_delete(args):
    4.47      arg_check(args, "delete", 1)
    4.48 @@ -757,9 +780,26 @@ def xm_suspend(args):
    4.49      server.xend.domain.suspend(dom)
    4.50  
    4.51  def xm_resume(args):
    4.52 -    arg_check(args, "resume", 1)
    4.53 -    dom = args[0]
    4.54 -    server.xend.domain.resume(dom)
    4.55 +    arg_check(args, "resume", 1, 2)
    4.56 +
    4.57 +    try:
    4.58 +        (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
    4.59 +    except getopt.GetoptError, opterr:
    4.60 +        err(opterr)
    4.61 +        sys.exit(1)
    4.62 +
    4.63 +    paused = False
    4.64 +    for (k, v) in options:
    4.65 +        if k in ['-p', '--paused']:
    4.66 +            paused = True
    4.67 +
    4.68 +    if len(params) != 1:
    4.69 +        err("Wrong number of parameters")
    4.70 +        usage('resume')
    4.71 +        sys.exit(1)
    4.72 +
    4.73 +    dom = params[0]
    4.74 +    server.xend.domain.resume(dom, paused)
    4.75      
    4.76  def xm_reboot(args):
    4.77      arg_check(args, "reboot", 1, 3)