aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>2004-12-09 17:30:15 +0000
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>2004-12-09 17:30:15 +0000
commitbc05bbc8f7013ab7465fa8b72f274ea70271d1d7 (patch)
tree445eeb5fde38df0c286f04c3b2b85a26144bf4b1
parentaee895495538183454bf8b3f85acdadd35a4ab3d (diff)
downloadxen-bc05bbc8f7013ab7465fa8b72f274ea70271d1d7.tar.gz
xen-bc05bbc8f7013ab7465fa8b72f274ea70271d1d7.tar.bz2
xen-bc05bbc8f7013ab7465fa8b72f274ea70271d1d7.zip
bitkeeper revision 1.1159.187.58 (41b88ba7ZjuJcwYxAL5HR5J_1FXMYw)
sysrq hacks from Matt Bloch
-rw-r--r--.rootkeys1
-rw-r--r--linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c19
-rw-r--r--tools/python/xen/xend/XendClient.py5
-rw-r--r--tools/python/xen/xend/XendDomain.py4
-rw-r--r--tools/python/xen/xend/server/SrvDaemon.py4
-rw-r--r--tools/python/xen/xend/server/SrvDomain.py3
-rw-r--r--tools/python/xen/xend/server/domain.py12
-rw-r--r--tools/python/xen/xend/server/messages.py5
-rw-r--r--tools/python/xen/xm/main.py15
-rw-r--r--tools/python/xen/xm/sysrq.py39
10 files changed, 93 insertions, 14 deletions
diff --git a/.rootkeys b/.rootkeys
index 44aaa3ca19..87bb718abb 100644
--- a/.rootkeys
+++ b/.rootkeys
@@ -521,6 +521,7 @@
411b2c1ehdEGO_CwG0tvn85Q-Tfh5g tools/python/xen/xm/migrate.py
40cf2937PSslwBliN1g7ofDy2H_RhA tools/python/xen/xm/opts.py
40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/python/xen/xm/shutdown.py
+41b88ba6_C4---jeA895Efg9YFZgKA tools/python/xen/xm/sysrq.py
40fcefb2K1xqVVT4D-p7nL2GzS4scg tools/sv/Main.rpy
40ffbcb66Dj5F-1kCK9BcgSqCWkt1w tools/sv/Makefile
4120b0e5L_nW-u0MWRfIdXg4ng4OjA tools/sv/images/destroy.png
diff --git a/linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c b/linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c
index 1f7303efd2..78c46675f5 100644
--- a/linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c
+++ b/linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c
@@ -8,6 +8,7 @@ static int errno;
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/reboot.h>
+#include <linux/sysrq.h>
#include <asm/irq.h>
#include <asm/mmu_context.h>
#include <asm-xen/ctrl_if.h>
@@ -49,10 +50,9 @@ EXPORT_SYMBOL(machine_power_off);
* Stop/pickle callback handling.
*/
-//#include <asm/suspend.h>
-
/* Ignore multiple shutdown requests. */
static int shutting_down = -1;
+static int pending_sysrq = -1;
static void __do_suspend(void)
{
@@ -214,9 +214,18 @@ static void __shutdown_handler(void *unused)
}
}
+static void __sysrq_handler(void *unused)
+{
+#ifdef CONFIG_MAGIC_SYSRQ
+ handle_sysrq(pending_sysrq, NULL, NULL);
+#endif
+ pending_sysrq = -1;
+}
+
static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
{
static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
+ static DECLARE_WORK(sysrq_work, __sysrq_handler, NULL);
if ( (shutting_down == -1) &&
((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
@@ -226,6 +235,12 @@ static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
shutting_down = msg->subtype;
schedule_work(&shutdown_work);
}
+ else if ( (pending_sysrq == -1) &&
+ (msg->subtype == CMSG_SHUTDOWN_SYSRQ) )
+ {
+ pending_sysrq = msg->msg[0];
+ schedule_work(&sysrq_work);
+ }
else
{
printk("Ignore spurious shutdown request\n");
diff --git a/tools/python/xen/xend/XendClient.py b/tools/python/xen/xend/XendClient.py
index 8290165412..91efd5cc8e 100644
--- a/tools/python/xen/xend/XendClient.py
+++ b/tools/python/xen/xend/XendClient.py
@@ -228,10 +228,11 @@ class Xend:
return self.xendPost(self.domainurl(id),
{'op' : 'pause' })
- def xend_domain_shutdown(self, id, reason):
+ def xend_domain_shutdown(self, id, reason, key=None):
return self.xendPost(self.domainurl(id),
{'op' : 'shutdown',
- 'reason' : reason })
+ 'reason' : reason,
+ 'key' : key })
def xend_domain_destroy(self, id, reason):
return self.xendPost(self.domainurl(id),
diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py
index fc53b4de03..4e614af54e 100644
--- a/tools/python/xen/xend/XendDomain.py
+++ b/tools/python/xen/xend/XendDomain.py
@@ -455,7 +455,7 @@ class XendDomain:
except Exception, ex:
raise XendError(str(ex))
- def domain_shutdown(self, id, reason='poweroff'):
+ def domain_shutdown(self, id, reason='poweroff', key=None):
"""Shutdown domain (nicely).
- poweroff: restart according to exit code and restart mode
- reboot: restart on exit
@@ -474,7 +474,7 @@ class XendDomain:
eserver.inject('xend.domain.shutdown', [dominfo.name, dominfo.id, reason])
if reason == 'halt':
reason = 'poweroff'
- val = xend.domain_shutdown(dominfo.id, reason)
+ val = xend.domain_shutdown(dominfo.id, reason, key)
self.refresh_schedule()
return val
diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py
index 05a0f27201..916d70a00c 100644
--- a/tools/python/xen/xend/server/SrvDaemon.py
+++ b/tools/python/xen/xend/server/SrvDaemon.py
@@ -711,14 +711,14 @@ class Daemon:
raise XendError('Invalid console id')
console.disconnect()
- def domain_shutdown(self, dom, reason):
+ def domain_shutdown(self, dom, reason, key=None):
"""Shutdown a domain.
"""
dom = int(dom)
ctrl = self.domainCF.getController(dom)
if not ctrl:
raise XendError('No domain controller: %s' % dom)
- ctrl.shutdown(reason)
+ ctrl.shutdown(reason, key)
return 0
def domain_mem_target_set(self, dom, target):
diff --git a/tools/python/xen/xend/server/SrvDomain.py b/tools/python/xen/xend/server/SrvDomain.py
index c06b260ce1..d73a39bff5 100644
--- a/tools/python/xen/xend/server/SrvDomain.py
+++ b/tools/python/xen/xend/server/SrvDomain.py
@@ -47,7 +47,8 @@ class SrvDomain(SrvDir):
def op_shutdown(self, op, req):
fn = FormFn(self.xd.domain_shutdown,
[['dom', 'str'],
- ['reason', 'str']])
+ ['reason', 'str'],
+ ['key', 'int']])
val = fn(req.args, {'dom': self.dom.id})
req.setResponseCode(http.ACCEPTED)
req.setHeader("Location", "%s/.." % req.prePathURL())
diff --git a/tools/python/xen/xend/server/domain.py b/tools/python/xen/xend/server/domain.py
index 4e1baf64de..17483dcc42 100644
--- a/tools/python/xen/xend/server/domain.py
+++ b/tools/python/xen/xend/server/domain.py
@@ -28,7 +28,8 @@ class DomainController(controller.Controller):
"""
reasons = {'poweroff' : 'shutdown_poweroff_t',
'reboot' : 'shutdown_reboot_t',
- 'suspend' : 'shutdown_suspend_t' }
+ 'suspend' : 'shutdown_suspend_t',
+ 'sysrq' : 'shutdown_sysrq_t' }
def __init__(self, factory, dom):
controller.Controller.__init__(self, factory, dom)
@@ -36,16 +37,19 @@ class DomainController(controller.Controller):
self.addMethod(CMSG_MEM_REQUEST, 0, None)
self.registerChannel()
- def shutdown(self, reason):
+ def shutdown(self, reason, key=None):
"""Shutdown a domain.
reason shutdown reason
+ key sysrq key (only if reason is 'sysrq')
"""
msgtype = self.reasons.get(reason)
if not msgtype:
raise XendError('invalid reason:' + reason)
- msg = packMsg(msgtype, {})
- self.writeRequest(msg)
+ extra = {}
+ if reason == 'sysrq': extra['key'] = key
+ print extra
+ self.writeRequest(packMsg(msgtype, extra))
def mem_target_set(self, target):
"""Set domain memory target in pages.
diff --git a/tools/python/xen/xend/server/messages.py b/tools/python/xen/xend/server/messages.py
index 081dd9ce32..35f9db986e 100644
--- a/tools/python/xen/xend/server/messages.py
+++ b/tools/python/xen/xend/server/messages.py
@@ -197,10 +197,12 @@ CMSG_SHUTDOWN = 6
CMSG_SHUTDOWN_POWEROFF = 0
CMSG_SHUTDOWN_REBOOT = 1
CMSG_SHUTDOWN_SUSPEND = 2
+CMSG_SHUTDOWN_SYSRQ = 3
STOPCODE_shutdown = 0
STOPCODE_reboot = 1
STOPCODE_suspend = 2
+STOPCODE_sysrq = 3
shutdown_formats = {
'shutdown_poweroff_t':
@@ -211,6 +213,9 @@ shutdown_formats = {
'shutdown_suspend_t':
(CMSG_SHUTDOWN, CMSG_SHUTDOWN_SUSPEND),
+
+ 'shutdown_sysrq_t':
+ (CMSG_SHUTDOWN, CMSG_SHUTDOWN_SYSRQ)
}
msg_formats.update(shutdown_formats)
diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py
index e7454e507a..411da44106 100644
--- a/tools/python/xen/xm/main.py
+++ b/tools/python/xen/xm/main.py
@@ -11,7 +11,7 @@ from xen.xend import PrettyPrint
from xen.xend import sxp
from xen.xend.XendClient import XendError, server
from xen.xend.XendClient import main as xend_client_main
-from xen.xm import create, destroy, migrate, shutdown
+from xen.xm import create, destroy, migrate, shutdown, sysrq
from xen.xm.opts import *
class Group:
@@ -401,6 +401,19 @@ class ProgShutdown(Prog):
xm.prog(ProgShutdown)
+class ProgSysrq(Prog):
+ group = 'domain'
+ name = "sysrq"
+ info = """Send a sysrq to a domain."""
+
+ def help(self, args):
+ sysrq.main([args[0], '-h'])
+
+ def main(self, args):
+ sysrq.main(args)
+
+xm.prog(ProgSysrq)
+
class ProgPause(Prog):
group = 'domain'
name = "pause"
diff --git a/tools/python/xen/xm/sysrq.py b/tools/python/xen/xm/sysrq.py
new file mode 100644
index 0000000000..44827af094
--- /dev/null
+++ b/tools/python/xen/xm/sysrq.py
@@ -0,0 +1,39 @@
+# (C) Matthew Bloch <matthew@bytemark.co.uk> 2004
+
+"""Domain shutdown.
+"""
+import string
+import sys
+import time
+
+from xen.xend.XendClient import server
+from xen.xm.opts import *
+
+DOM0_NAME = 'Domain-0'
+DOM0_ID = '0'
+
+gopts = Opts(use="""[DOM] [letter]
+
+Sends a Linux sysrq to a domain.
+""")
+
+gopts.opt('help', short='h',
+ fn=set_true, default=0,
+ use="Print this help.")
+
+def sysrq(dom, req):
+ server.xend_domain_shutdown(dom, 'sysrq', req)
+
+def main(argv):
+ opts = gopts
+ args = opts.parse(argv)
+ if opts.vals.help:
+ opts.usage()
+ return
+
+ # no options for the moment
+ if len(args) < 1: opts.err('Missing domain')
+ if len(args) < 2: opts.err('Missing sysrq character')
+ dom = args[0]
+ req = ord(args[1][0])
+ sysrq(dom, req)