ia64/xen-unstable

changeset 7153:fe401301929e

Change rebooting specification so that we can have domains crash and stay
around to be debugged, for example.

Fix problem in XendDomainInfo.eventChannel caused by a mis-merge.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Fri Sep 30 13:59:28 2005 +0100 (2005-09-30)
parents 034ada135379
children 71466686d026 468ad17f9970
files tools/examples/xmexample.vmx tools/examples/xmexample1 tools/examples/xmexample2 tools/examples/xmexample3 tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/examples/xmexample.vmx	Fri Sep 30 13:58:08 2005 +0100
     1.2 +++ b/tools/examples/xmexample.vmx	Fri Sep 30 13:59:28 2005 +0100
     1.3 @@ -48,12 +48,36 @@ vcpus=1
     1.4  disk = [ 'file:/var/images/min-el3-i386.img,ioemu:hda,w' ]
     1.5  
     1.6  #----------------------------------------------------------------------------
     1.7 -# Set according to whether you want the domain restarted when it exits.
     1.8 -# The default is 'onreboot', which restarts the domain when it shuts down
     1.9 -# with exit code reboot.
    1.10 -# Other values are 'always', and 'never'.
    1.11 +# Configure the behaviour when a domain exits.  There are three 'reasons'
    1.12 +# for a domain to stop: poweroff, reboot, and crash.  For each of these you
    1.13 +# may specify "destroy", meaning that the domain is cleaned up as normal,
    1.14 +# "restart", meaning that a new domain is started in place of the old one, or
    1.15 +# "preserve", meaning that no clean-up is done until the domain is manually
    1.16 +# destroyed (using xm destroy, for example).
    1.17 +#
    1.18 +# The default is
    1.19 +#
    1.20 +#   on_poweroff = 'destroy'
    1.21 +#   on_reboot   = 'restart'
    1.22 +#   on_crash    = 'restart'
    1.23 +#
    1.24 +# For backwards compatibility we also support the deprecated option restart
    1.25 +#
    1.26 +# restart = 'onreboot' means on_poweroff = 'destroy'
    1.27 +#                            on_reboot   = 'restart'
    1.28 +#                            on_crash    = 'destroy'
    1.29 +#
    1.30 +# restart = 'always'   means on_poweroff = 'restart'
    1.31 +#                            on_reboot   = 'restart'
    1.32 +#                            on_crash    = 'restart'
    1.33 +#
    1.34 +# restart = 'never'    means on_poweroff = 'destroy'
    1.35 +#                            on_reboot   = 'destroy'
    1.36 +#                            on_crash    = 'destroy'
    1.37  
    1.38 -#restart = 'onreboot'
    1.39 +#on_poweroff = 'destroy'
    1.40 +#on_reboot   = 'restart'
    1.41 +#on_crash    = 'restart'
    1.42  
    1.43  #============================================================================
    1.44  
     2.1 --- a/tools/examples/xmexample1	Fri Sep 30 13:58:08 2005 +0100
     2.2 +++ b/tools/examples/xmexample1	Fri Sep 30 13:59:28 2005 +0100
     2.3 @@ -91,11 +91,35 @@ root = "/dev/hda1 ro"
     2.4  extra = "4"
     2.5  
     2.6  #----------------------------------------------------------------------------
     2.7 -# Set according to whether you want the domain restarted when it exits.
     2.8 -# The default is 'onreboot', which restarts the domain when it shuts down
     2.9 -# with exit code reboot.
    2.10 -# Other values are 'always', and 'never'.
    2.11 +# Configure the behaviour when a domain exits.  There are three 'reasons'
    2.12 +# for a domain to stop: poweroff, reboot, and crash.  For each of these you
    2.13 +# may specify "destroy", meaning that the domain is cleaned up as normal,
    2.14 +# "restart", meaning that a new domain is started in place of the old one, or
    2.15 +# "preserve", meaning that no clean-up is done until the domain is manually
    2.16 +# destroyed (using xm destroy, for example).
    2.17 +#
    2.18 +# The default is
    2.19 +#
    2.20 +#   on_poweroff = 'destroy'
    2.21 +#   on_reboot   = 'restart'
    2.22 +#   on_crash    = 'restart'
    2.23 +#
    2.24 +# For backwards compatibility we also support the deprecated option restart
    2.25 +#
    2.26 +# restart = 'onreboot' means on_poweroff = 'destroy'
    2.27 +#                            on_reboot   = 'restart'
    2.28 +#                            on_crash    = 'destroy'
    2.29 +#
    2.30 +# restart = 'always'   means on_poweroff = 'restart'
    2.31 +#                            on_reboot   = 'restart'
    2.32 +#                            on_crash    = 'restart'
    2.33 +#
    2.34 +# restart = 'never'    means on_poweroff = 'destroy'
    2.35 +#                            on_reboot   = 'destroy'
    2.36 +#                            on_crash    = 'destroy'
    2.37  
    2.38 -#restart = 'onreboot'
    2.39 +#on_poweroff = 'destroy'
    2.40 +#on_reboot   = 'restart'
    2.41 +#on_crash    = 'restart'
    2.42  
    2.43  #============================================================================
     3.1 --- a/tools/examples/xmexample2	Fri Sep 30 13:58:08 2005 +0100
     3.2 +++ b/tools/examples/xmexample2	Fri Sep 30 13:59:28 2005 +0100
     3.3 @@ -127,11 +127,35 @@ root = "/dev/sda1 ro"
     3.4  extra = "4 VMID=%d usr=/dev/sda6" % vmid
     3.5  
     3.6  #----------------------------------------------------------------------------
     3.7 -# Set according to whether you want the domain restarted when it exits.
     3.8 -# The default is 'onreboot', which restarts the domain when it shuts down
     3.9 -# with exit code reboot.
    3.10 -# Other values are 'always', and 'never'.
    3.11 +# Configure the behaviour when a domain exits.  There are three 'reasons'
    3.12 +# for a domain to stop: poweroff, reboot, and crash.  For each of these you
    3.13 +# may specify "destroy", meaning that the domain is cleaned up as normal,
    3.14 +# "restart", meaning that a new domain is started in place of the old one, or
    3.15 +# "preserve", meaning that no clean-up is done until the domain is manually
    3.16 +# destroyed (using xm destroy, for example).
    3.17 +#
    3.18 +# The default is
    3.19 +#
    3.20 +#   on_poweroff = 'destroy'
    3.21 +#   on_reboot   = 'restart'
    3.22 +#   on_crash    = 'restart'
    3.23 +#
    3.24 +# For backwards compatibility we also support the deprecated option restart
    3.25 +#
    3.26 +# restart = 'onreboot' means on_poweroff = 'destroy'
    3.27 +#                            on_reboot   = 'restart'
    3.28 +#                            on_crash    = 'destroy'
    3.29 +#
    3.30 +# restart = 'always'   means on_poweroff = 'restart'
    3.31 +#                            on_reboot   = 'restart'
    3.32 +#                            on_crash    = 'restart'
    3.33 +#
    3.34 +# restart = 'never'    means on_poweroff = 'destroy'
    3.35 +#                            on_reboot   = 'destroy'
    3.36 +#                            on_crash    = 'destroy'
    3.37  
    3.38 -#restart = 'onreboot'
    3.39 +#on_poweroff = 'destroy'
    3.40 +#on_reboot   = 'restart'
    3.41 +#on_crash    = 'restart'
    3.42  
    3.43  #============================================================================
     4.1 --- a/tools/examples/xmexample3	Fri Sep 30 13:58:08 2005 +0100
     4.2 +++ b/tools/examples/xmexample3	Fri Sep 30 13:59:28 2005 +0100
     4.3 @@ -124,11 +124,35 @@ root = "/dev/hda1 ro"
     4.4  extra = "4 VMID=%d" % vmid
     4.5  
     4.6  #----------------------------------------------------------------------------
     4.7 -# Set according to whether you want the domain restarted when it exits.
     4.8 -# The default is 'onreboot', which restarts the domain when it shuts down
     4.9 -# with exit code reboot.
    4.10 -# Other values are 'always', and 'never'.
    4.11 +# Configure the behaviour when a domain exits.  There are three 'reasons'
    4.12 +# for a domain to stop: poweroff, reboot, and crash.  For each of these you
    4.13 +# may specify "destroy", meaning that the domain is cleaned up as normal,
    4.14 +# "restart", meaning that a new domain is started in place of the old one, or
    4.15 +# "preserve", meaning that no clean-up is done until the domain is manually
    4.16 +# destroyed (using xm destroy, for example).
    4.17 +#
    4.18 +# The default is
    4.19 +#
    4.20 +#   on_poweroff = 'destroy'
    4.21 +#   on_reboot   = 'restart'
    4.22 +#   on_crash    = 'restart'
    4.23 +#
    4.24 +# For backwards compatibility we also support the deprecated option restart
    4.25 +#
    4.26 +# restart = 'onreboot' means on_poweroff = 'destroy'
    4.27 +#                            on_reboot   = 'restart'
    4.28 +#                            on_crash    = 'destroy'
    4.29 +#
    4.30 +# restart = 'always'   means on_poweroff = 'restart'
    4.31 +#                            on_reboot   = 'restart'
    4.32 +#                            on_crash    = 'restart'
    4.33 +#
    4.34 +# restart = 'never'    means on_poweroff = 'destroy'
    4.35 +#                            on_reboot   = 'destroy'
    4.36 +#                            on_crash    = 'destroy'
    4.37  
    4.38 -#restart = 'onreboot'
    4.39 +#on_poweroff = 'destroy'
    4.40 +#on_reboot   = 'restart'
    4.41 +#on_crash    = 'restart'
    4.42  
    4.43  #============================================================================
     5.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 30 13:58:08 2005 +0100
     5.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 30 13:59:28 2005 +0100
     5.3 @@ -67,14 +67,10 @@ shutdown_reasons = {
     5.4      DOMAIN_CRASH   : "crash",
     5.5      }
     5.6  
     5.7 -RESTART_ALWAYS   = 'always'
     5.8 -RESTART_ONREBOOT = 'onreboot'
     5.9 -RESTART_NEVER    = 'never'
    5.10 -
    5.11  restart_modes = [
    5.12 -    RESTART_ALWAYS,
    5.13 -    RESTART_ONREBOOT,
    5.14 -    RESTART_NEVER,
    5.15 +    "restart",
    5.16 +    "destroy",
    5.17 +    "preserve"
    5.18      ]
    5.19  
    5.20  STATE_VM_OK         = "ok"
    5.21 @@ -112,7 +108,10 @@ ROUNDTRIPPING_CONFIG_ENTRIES = [
    5.22          ('name',         str),
    5.23          ('ssidref',      int),
    5.24          ('cpu_weight',   float),
    5.25 -        ('bootloader',   str)
    5.26 +        ('bootloader',   str),
    5.27 +        ('on_poweroff',  str),
    5.28 +        ('on_reboot',    str),
    5.29 +        ('on_crash',     str)
    5.30      ]
    5.31  
    5.32  
    5.33 @@ -135,8 +134,6 @@ def restore(config):
    5.34      vm.storeVmDetails()
    5.35      vm.configure()
    5.36      vm.create_channel()
    5.37 -#         vm.exportToDB()
    5.38 -#    vm.refreshShutdown()
    5.39      vm.storeDomDetails()
    5.40      return vm
    5.41  
    5.42 @@ -272,7 +269,6 @@ class XendDomainInfo:
    5.43          result['maxmem']       = get_cfg('maxmem',     int)
    5.44          result['maxmem_kb']    = get_cfg('maxmem_kb',  int)
    5.45          result['cpu']          = get_cfg('cpu',        int)
    5.46 -        result['restart_mode'] = get_cfg('restart')
    5.47          result['image']        = get_cfg('image')
    5.48  
    5.49          try:
    5.50 @@ -295,6 +291,30 @@ class XendDomainInfo:
    5.51              c = sxp.child0(d)
    5.52              result['device'].append((sxp.name(c), c))
    5.53  
    5.54 +        # Configuration option "restart" is deprecated.  Parse it, but
    5.55 +        # let on_xyz override it if they are present.
    5.56 +        restart = get_cfg('restart')
    5.57 +        if restart:
    5.58 +            def handle_restart(event, val):
    5.59 +                if not event in result:
    5.60 +                    result[event] = val
    5.61 +
    5.62 +            if restart == "onreboot":
    5.63 +                handle_restart('on_poweroff', 'destroy')
    5.64 +                handle_restart('on_reboot',   'restart')
    5.65 +                handle_restart('on_crash',    'destroy')
    5.66 +            elif restart == "always":
    5.67 +                handle_restart('on_poweroff', 'restart')
    5.68 +                handle_restart('on_reboot',   'restart')
    5.69 +                handle_restart('on_crash',    'restart')
    5.70 +            elif restart == "never":
    5.71 +                handle_restart('on_poweroff', 'destroy')
    5.72 +                handle_restart('on_reboot',   'destroy')
    5.73 +                handle_restart('on_crash',    'destroy')
    5.74 +            else:
    5.75 +                log.warn("Ignoring malformed and deprecated config option "
    5.76 +                         "restart = %s", restart)
    5.77 +
    5.78          log.debug("parseConfig: result is %s" % str(result))
    5.79          return result
    5.80  
    5.81 @@ -347,7 +367,9 @@ class XendDomainInfo:
    5.82                  self.info[name] = val
    5.83  
    5.84          params = (("name", str),
    5.85 -                  ("restart_mode", str),
    5.86 +                  ("on_poweroff",  str),
    5.87 +                  ("on_reboot",    str),
    5.88 +                  ("on_crash",     str),
    5.89                    ("image",        str),
    5.90                    ("start_time", float))
    5.91  
    5.92 @@ -375,7 +397,9 @@ class XendDomainInfo:
    5.93          try:
    5.94              defaultInfo('name',         lambda: "Domain-%d" % self.domid)
    5.95              defaultInfo('ssidref',      lambda: 0)
    5.96 -            defaultInfo('restart_mode', lambda: RESTART_ONREBOOT)
    5.97 +            defaultInfo('on_poweroff',  lambda: "destroy")
    5.98 +            defaultInfo('on_reboot',    lambda: "restart")
    5.99 +            defaultInfo('on_crash',     lambda: "restart")
   5.100              defaultInfo('cpu',          lambda: None)
   5.101              defaultInfo('cpu_weight',   lambda: 1.0)
   5.102              defaultInfo('bootloader',   lambda: None)
   5.103 @@ -459,9 +483,10 @@ class XendDomainInfo:
   5.104                      raise VmError('invalid device (%s, %s)' %
   5.105                                    (str(n), str(c)))
   5.106  
   5.107 -            if self.info['restart_mode'] not in restart_modes:
   5.108 -                raise VmError('invalid restart mode: ' +
   5.109 -                              str(self.info['restart_mode']))
   5.110 +            for event in ['on_poweroff', 'on_reboot', 'on_crash']:
   5.111 +                if self.info[event] not in restart_modes:
   5.112 +                    raise VmError('invalid restart event: %s = %s' %
   5.113 +                                  (event, str(self.info[event])))
   5.114  
   5.115              if 'cpumap' not in self.info:
   5.116                  if [self.info['vcpus'] == 1]:
   5.117 @@ -509,14 +534,14 @@ class XendDomainInfo:
   5.118          to_store = {
   5.119              'uuid':               self.uuid,
   5.120  
   5.121 -            # !!!
   5.122 +            # XXX
   5.123              'memory/target':      str(self.info['memory_KiB'])
   5.124              }
   5.125  
   5.126          if self.infoIsSet('image'):
   5.127              to_store['image'] = sxp.to_string(self.info['image'])
   5.128  
   5.129 -        for k in ['name', 'ssidref', 'restart_mode']:
   5.130 +        for k in ['name', 'ssidref', 'on_poweroff', 'on_reboot', 'on_crash']:
   5.131              if self.infoIsSet(k):
   5.132                  to_store[k] = str(self.info[k])
   5.133  
   5.134 @@ -625,7 +650,7 @@ class XendDomainInfo:
   5.135                  if xroot.get_enable_dump():
   5.136                      self.dumpCore()
   5.137  
   5.138 -                restart_reason = 'crashed'
   5.139 +                restart_reason = 'crash'
   5.140  
   5.141              elif xeninfo['shutdown']:
   5.142                  reason = shutdown_reason(xeninfo['shutdown_reason'])
   5.143 @@ -682,10 +707,16 @@ class XendDomainInfo:
   5.144  
   5.145  
   5.146      def maybeRestart(self, reason):
   5.147 -        if self.restart_needed(reason):
   5.148 -            self.restart()
   5.149 -        else:
   5.150 -            self.destroy()
   5.151 +        # Dispatch to the correct method based upon the configured on_{reason}
   5.152 +        # behaviour.
   5.153 +        {"destroy"  : self.destroy,
   5.154 +         "restart"  : self.restart,
   5.155 +         "preserve" : self.preserve}[self.info['on_' + reason]]()
   5.156 +
   5.157 +
   5.158 +    def preserve(self):
   5.159 +        log.info("Preserving dead domain %s (%d).", self.info['name'],
   5.160 +                 self.domid)
   5.161  
   5.162  
   5.163      def dumpCore(self):
   5.164 @@ -998,7 +1029,6 @@ class XendDomainInfo:
   5.165          """
   5.166          self.create_channel()
   5.167          self.image.createImage()
   5.168 -#        !!! self.exportToDB()
   5.169          IntroduceDomain(self.domid, self.store_mfn,
   5.170                          self.store_channel.port1, self.dompath)
   5.171          self.configure_vcpus()
   5.172 @@ -1091,7 +1121,6 @@ class XendDomainInfo:
   5.173                  # The port is not yet set, i.e. the channel has not yet been
   5.174                  # created.
   5.175                  pass
   5.176 -        ret = channel.eventChannel(0, self.domid, port1=port, port2=0)
   5.177  
   5.178          # Stale port information from above causes an Invalid Argument to be
   5.179          # thrown by the eventChannel call below.  To recover, we throw away