ia64/xen-unstable

changeset 17495:65802c51edb5

xm: Add a new command: xm reset

If a hang-up of a guest OS occurs, we will restart the guest OS by
using
the following commands.
1. xm destroy
2. xm create or xm start

To reduce the number of xm commands to use, this patch adds a new
command. The command is "xm reset". The command executes destruction
of a domain, and then creation of the domain.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 22 10:18:13 2008 +0100 (2008-04-22)
parents b3e53e17d87a
children da261c25f160
files 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/XendDomain.py	Mon Apr 21 20:21:39 2008 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Apr 22 10:18:13 2008 +0100
     1.3 @@ -1622,7 +1622,31 @@ class XendDomain:
     1.4                                            vcpu)
     1.5          except Exception, ex:
     1.6              raise XendError(str(ex))
     1.7 - 
     1.8 +
     1.9 +    def domain_reset(self, domid):
    1.10 +        """Terminate domain immediately, and then create domain.
    1.11 +
    1.12 +        @param domid: Domain ID or Name
    1.13 +        @type domid: int or string.
    1.14 +        @rtype: None
    1.15 +        @raise XendError: Failed to destroy or create
    1.16 +        @raise XendInvalidDomain: Domain is not valid
    1.17 +        """
    1.18 +
    1.19 +        dominfo = self.domain_lookup_nr(domid)
    1.20 +        if not dominfo:
    1.21 +            raise XendInvalidDomain(str(domid))
    1.22 +        if dominfo and dominfo.getDomid() == DOM0_ID:
    1.23 +            raise XendError("Cannot reset privileged domain %s" % domid)
    1.24 +        if dominfo._stateGet() not in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
    1.25 +            raise VMBadState("Domain '%s' is not started" % domid,
    1.26 +                             POWER_STATE_NAMES[DOM_STATE_RUNNING],
    1.27 +                             POWER_STATE_NAMES[dominfo._stateGet()])
    1.28 +        try:
    1.29 +            dominfo.resetDomain()
    1.30 +        except Exception, ex:
    1.31 +            raise XendError(str(ex))
    1.32 +
    1.33  
    1.34  def instance():
    1.35      """Singleton constructor. Use this instead of the class constructor.
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Apr 21 20:21:39 2008 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Apr 22 10:18:13 2008 +0100
     2.3 @@ -2323,6 +2323,34 @@ class XendDomainInfo:
     2.4          self._cleanup_phantom_devs(paths)
     2.5  
     2.6  
     2.7 +    def resetDomain(self):
     2.8 +        log.debug("XendDomainInfo.resetDomain(%s)", str(self.domid))
     2.9 +
    2.10 +        old_domid = self.domid
    2.11 +        prev_vm_xend = self._listRecursiveVm('xend')
    2.12 +        new_dom_info = self.info
    2.13 +        try:
    2.14 +            self._unwatchVm()
    2.15 +            self.destroy()
    2.16 +
    2.17 +            new_dom = None
    2.18 +            try:
    2.19 +                from xen.xend import XendDomain
    2.20 +                new_dom_info['domid'] = None
    2.21 +                new_dom = XendDomain.instance().domain_create_from_dict(
    2.22 +                    new_dom_info)
    2.23 +                for x in prev_vm_xend[0][1]:
    2.24 +                    new_dom._writeVm('xend/%s' % x[0], x[1])
    2.25 +                new_dom.waitForDevices()
    2.26 +                new_dom.unpause()
    2.27 +            except:
    2.28 +                if new_dom:
    2.29 +                    new_dom.destroy()
    2.30 +                raise
    2.31 +        except:
    2.32 +            log.exception('Failed to reset domain %s.', str(old_domid))
    2.33 +
    2.34 +
    2.35      def resumeDomain(self):
    2.36          log.debug("XendDomainInfo.resumeDomain(%s)", str(self.domid))
    2.37  
     3.1 --- a/tools/python/xen/xm/main.py	Mon Apr 21 20:21:39 2008 +0100
     3.2 +++ b/tools/python/xen/xm/main.py	Tue Apr 22 10:18:13 2008 +0100
     3.3 @@ -107,6 +107,7 @@ SUBCOMMAND_HELP = {
     3.4                       'Migrate a domain to another machine.'),
     3.5      'pause'       : ('<Domain>', 'Pause execution of a domain.'),
     3.6      'reboot'      : ('<Domain> [-wa]', 'Reboot a domain.'),
     3.7 +    'reset'       : ('<Domain>', 'Reset a domain.'),
     3.8      'restore'     : ('<CheckpointFile> [-p]',
     3.9                       'Restore a domain from a saved state.'),
    3.10      'save'        : ('[-c] <Domain> <CheckpointFile>',
    3.11 @@ -274,6 +275,7 @@ common_commands = [
    3.12      "migrate",
    3.13      "pause",
    3.14      "reboot",
    3.15 +    "reset",
    3.16      "restore",
    3.17      "resume",
    3.18      "save",
    3.19 @@ -303,6 +305,7 @@ domain_commands = [
    3.20      "pause",
    3.21      "reboot",
    3.22      "rename",
    3.23 +    "reset",
    3.24      "restore",
    3.25      "resume",
    3.26      "save",
    3.27 @@ -1248,6 +1251,13 @@ def xm_shutdown(args):
    3.28      from xen.xm import shutdown
    3.29      shutdown.main(["shutdown"] + args)
    3.30  
    3.31 +def xm_reset(args):
    3.32 +    arg_check(args, "reset", 1)
    3.33 +    dom = args[0]
    3.34 +
    3.35 +    # TODO: XenAPI
    3.36 +    server.xend.domain.reset(dom)
    3.37 +
    3.38  def xm_pause(args):
    3.39      arg_check(args, "pause", 1)
    3.40      dom = args[0]
    3.41 @@ -2474,6 +2484,7 @@ commands = {
    3.42      "dump-core": xm_dump_core,
    3.43      "reboot": xm_reboot,
    3.44      "rename": xm_rename,
    3.45 +    "reset": xm_reset,
    3.46      "restore": xm_restore,
    3.47      "resume": xm_resume,
    3.48      "save": xm_save,