Add a new command: xm reset
PATCH 1/1 Add a new command: xm reset
Hi,
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 <[email protected]>
Best regards,
Kan
tools/python/xen/xend/XendDomain.py +25 -1
@@ -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.
tools/python/xen/xend/XendDomainInfo.py +28 -0
@@ -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))
tools/python/xen/xm/main.py +11 -0
@@ -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",
@@ -1247,6 +1250,13 @@ def xm_shutdown(args): arg_check(args, "shutdown", 1, 4) 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)
@@ -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,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel