]> xenbits.xensource.com Git - xen.git/commitdiff
xm: Add a new command: xm reset
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 22 Apr 2008 09:18:13 +0000 (10:18 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 22 Apr 2008 09:18:13 +0000 (10:18 +0100)
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>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/main.py

index 141942f3b9d65db0fdfc8bc71ff90a2892fab253..81dae6cd30daef6e250300628fd8269a54a78ead 100644 (file)
@@ -1622,7 +1622,31 @@ class XendDomain:
                                           vcpu)
         except Exception, ex:
             raise XendError(str(ex))
+
+    def domain_reset(self, domid):
+        """Terminate domain immediately, and then create domain.
+
+        @param domid: Domain ID or Name
+        @type domid: int or string.
+        @rtype: None
+        @raise XendError: Failed to destroy or create
+        @raise XendInvalidDomain: Domain is not valid
+        """
+
+        dominfo = self.domain_lookup_nr(domid)
+        if not dominfo:
+            raise XendInvalidDomain(str(domid))
+        if dominfo and dominfo.getDomid() == DOM0_ID:
+            raise XendError("Cannot reset privileged domain %s" % domid)
+        if dominfo._stateGet() not in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
+            raise VMBadState("Domain '%s' is not started" % domid,
+                             POWER_STATE_NAMES[DOM_STATE_RUNNING],
+                             POWER_STATE_NAMES[dominfo._stateGet()])
+        try:
+            dominfo.resetDomain()
+        except Exception, ex:
+            raise XendError(str(ex))
+
 
 def instance():
     """Singleton constructor. Use this instead of the class constructor.
index a88dfb4a3f4fbde365dc7798fffceee57af6ddf9..5fa15fd2fa32c507fd0da2ce3d9cd18375253f5c 100644 (file)
@@ -2323,6 +2323,34 @@ class XendDomainInfo:
         self._cleanup_phantom_devs(paths)
 
 
+    def resetDomain(self):
+        log.debug("XendDomainInfo.resetDomain(%s)", str(self.domid))
+
+        old_domid = self.domid
+        prev_vm_xend = self._listRecursiveVm('xend')
+        new_dom_info = self.info
+        try:
+            self._unwatchVm()
+            self.destroy()
+
+            new_dom = None
+            try:
+                from xen.xend import XendDomain
+                new_dom_info['domid'] = None
+                new_dom = XendDomain.instance().domain_create_from_dict(
+                    new_dom_info)
+                for x in prev_vm_xend[0][1]:
+                    new_dom._writeVm('xend/%s' % x[0], x[1])
+                new_dom.waitForDevices()
+                new_dom.unpause()
+            except:
+                if new_dom:
+                    new_dom.destroy()
+                raise
+        except:
+            log.exception('Failed to reset domain %s.', str(old_domid))
+
+
     def resumeDomain(self):
         log.debug("XendDomainInfo.resumeDomain(%s)", str(self.domid))
 
index f5ad85d38157f955aef06120f7805429418732ed..e27393c5057cc1e273f915957f071d9b2e119f0f 100644 (file)
@@ -107,6 +107,7 @@ SUBCOMMAND_HELP = {
                      'Migrate a domain to another machine.'),
     'pause'       : ('<Domain>', 'Pause execution of a domain.'),
     'reboot'      : ('<Domain> [-wa]', 'Reboot a domain.'),
+    'reset'       : ('<Domain>', 'Reset a domain.'),
     'restore'     : ('<CheckpointFile> [-p]',
                      'Restore a domain from a saved state.'),
     'save'        : ('[-c] <Domain> <CheckpointFile>',
@@ -274,6 +275,7 @@ common_commands = [
     "migrate",
     "pause",
     "reboot",
+    "reset",
     "restore",
     "resume",
     "save",
@@ -303,6 +305,7 @@ domain_commands = [
     "pause",
     "reboot",
     "rename",
+    "reset",
     "restore",
     "resume",
     "save",
@@ -1248,6 +1251,13 @@ def xm_shutdown(args):
     from xen.xm import shutdown
     shutdown.main(["shutdown"] + args)
 
+def xm_reset(args):
+    arg_check(args, "reset", 1)
+    dom = args[0]
+
+    # TODO: XenAPI
+    server.xend.domain.reset(dom)
+
 def xm_pause(args):
     arg_check(args, "pause", 1)
     dom = args[0]
@@ -2474,6 +2484,7 @@ commands = {
     "dump-core": xm_dump_core,
     "reboot": xm_reboot,
     "rename": xm_rename,
+    "reset": xm_reset,
     "restore": xm_restore,
     "resume": xm_resume,
     "save": xm_save,