Add a new pair "xm sleep/wake" to support light-weight
domain suspend/resume, which is required for physical
Xen S3 support. All the domain context are kept intact
except domain itself is suspended.
Signed-off-by Kevin Tian <kevin.tian@xxxxxxxxx>
diff -r 2b5715497bcc -r 4e424b06653e tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py Mon Feb 05 17:34:19 2007 +0800
+++ b/tools/python/xen/xend/XendAPI.py Mon Feb 05 17:34:38 2007 +0800
@@ -992,6 +992,8 @@ class XendAPI(object):
('start', None),
('pause', None),
('unpause', None),
+ ('sleep', None),
+ ('wake', None),
('clean_shutdown', None),
('clean_reboot', None),
('hard_shutdown', None),
@@ -1434,6 +1436,14 @@ class XendAPI(object):
"domain_resume", vm_ref,
start_paused = start_paused)
+ def VM_sleep(self, session, vm_ref):
+ return XendTask.log_progress(0, 100, do_vm_func,
+ "domain_sleep", vm_ref)
+
+ def VM_wake(self, session, vm_ref):
+ return XendTask.log_progress(0, 100, do_vm_func,
+ "domain_wake", vm_ref)
+
def VM_start(self, session, vm_ref, start_paused):
return XendTask.log_progress(0, 100, do_vm_func,
"domain_start", vm_ref,
diff -r 2b5715497bcc -r 4e424b06653e tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py Mon Feb 05 17:34:19 2007
+0800
+++ b/tools/python/xen/xend/XendDomain.py Mon Feb 05 17:34:38 2007
+0800
@@ -1086,6 +1086,56 @@ class XendDomain:
log.exception("domain_pause")
raise XendError(str(ex))
+ def domain_wake(self, domid):
+ """wake a domain from sleep state.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: None
+ @raise XendError: Failed to wake
+ @raise XendInvalidDomain: Domain is not valid
+ """
+ try:
+ dominfo = self.domain_lookup_nr(domid)
+ if not dominfo:
+ raise XendInvalidDomain(str(domid))
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot wake privileged domain %s" %
domid)
+ log.info("Domain %s (%d) waken.", dominfo.getName(),
+ int(dominfo.getDomid()))
+ dominfo.wake()
+ except XendInvalidDomain:
+ log.exception("domain_wake")
+ raise
+ except Exception, ex:
+ log.exception("domain_wake")
+ raise XendError(str(ex))
+
+ def domain_sleep(self, domid):
+ """Put a domain into sleep state.
+
+ @param domid: Domain ID or Name
+ @type domid: int or string.
+ @rtype: None
+ @raise XendError: Failed to sleep
+ @raise XendInvalidDomain: Domain is not valid
+ """
+ try:
+ dominfo = self.domain_lookup_nr(domid)
+ if not dominfo:
+ raise XendInvalidDomain(str(domid))
+ if dominfo.getDomid() == DOM0_ID:
+ raise XendError("Cannot sleep privileged domain %s" %
domid)
+ log.info("Domain %s (%d) slept.", dominfo.getName(),
+ int(dominfo.getDomid()))
+ dominfo.sleep()
+ except XendInvalidDomain:
+ log.exception("domain_sleep")
+ raise
+ except Exception, ex:
+ log.exception("domain_sleep")
+ raise XendError(str(ex))
+
def domain_dump(self, domid, filename, live, crash):
"""Dump domain core."""
diff -r 2b5715497bcc -r 4e424b06653e
tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py Mon Feb 05 17:34:19 2007
+0800
+++ b/tools/python/xen/xend/XendDomainInfo.py Mon Feb 05 17:34:38 2007
+0800
@@ -472,6 +472,34 @@ class XendDomainInfo:
log.exception(ex)
raise XendError("Domain unable to be unpaused: %s" %
str(ex))
+ def sleep(self):
+ """ Sleep domain
+
+ @raise XendError: Failed sleeping a domain
+ """
+ try:
+ log.debug("Sleeping %d ...", self.getDomid())
+ self.shutdown('suspend')
+ self.waitForShutdown()
+ log.info("Domain %d slept.", self.getDomid())
+ log.debug("done\n")
+ except Exception, ex:
+ log.exception(ex)
+ raise XendError("Domain unable to be slept: %s" % str(ex))
+
+ def wake(self):
+ """ Wake domain
+
+ @raise XendError: Failed to wake up a domain
+ """
+ try:
+ self.resumeDomain(resume=1)
+ self.vmWatch = xswatch(self.vmpath, self._storeChanged)
+ self.refreshShutdown()
+ except Exception, ex:
+ log.exception(ex)
+ raise XendError("Domain unable to be waken: %s" % str(ex))
+
def send_sysrq(self, key):
""" Send a Sysrq equivalent key via xenstored."""
asserts.isCharConvertible(key)
diff -r 2b5715497bcc -r 4e424b06653e tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py Mon Feb 05 17:34:19 2007 +0800
+++ b/tools/python/xen/xm/main.py Mon Feb 05 17:34:38 2007 +0800
@@ -108,6 +108,8 @@ SUBCOMMAND_HELP = {
'top' : ('', 'Monitor a host and the domains in real
time.'),
'unpause' : ('<Domain>', 'Unpause a paused domain.'),
'uptime' : ('[-s] <Domain>', 'Print uptime for a domain.'),
+ 'sleep' : ('<Domain>', 'Sleep a domain.'),
+ 'wake' : ('<Domain>', 'Wake up a slept domain.'),
# Life cycle xm commands
'new' : ('<ConfigFile> [options] [vars]',
@@ -253,12 +255,14 @@ common_commands = [
"save",
"shell",
"shutdown",
+ "sleep",
"start",
"suspend",
"top",
"unpause",
"uptime",
"vcpu-set",
+ "wake",
]
domain_commands = [
@@ -281,6 +285,7 @@ domain_commands = [
"resume",
"save",
"shutdown",
+ "sleep",
"start",
"suspend",
"sysrq",
@@ -290,6 +295,7 @@ domain_commands = [
"vcpu-list",
"vcpu-pin",
"vcpu-set",
+ "wake",
]
host_commands = [
@@ -951,6 +957,24 @@ def xm_shutdown(args):
from xen.xm import shutdown
shutdown.main(["shutdown"] + args)
+def xm_sleep(args):
+ arg_check(args, "sleep", 1)
+ dom = args[0]
+
+ if serverType == SERVER_XEN_API:
+ server.xenapi.VM.sleep(get_single_vm(dom))
+ else:
+ server.xend.domain.sleep(dom)
+
+def xm_wake(args):
+ arg_check(args, "wake", 1)
+ dom = args[0]
+
+ if serverType == SERVER_XEN_API:
+ server.xenapi.VM.wake(get_single_vm(dom))
+ else:
+ server.xend.domain.wake(dom)
+
def xm_pause(args):
arg_check(args, "pause", 1)
dom = args[0]
@@ -1664,6 +1688,8 @@ commands = {
"sysrq": xm_sysrq,
"uptime": xm_uptime,
"suspend": xm_suspend,
+ "sleep": xm_sleep,
+ "wake": xm_wake,
"list": xm_list,
# memory commands
"mem-max": xm_mem_max,
xm_sleep_wake.patch
Description: xm_sleep_wake.patch
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|