mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
bitkeeper revision 1.1159.187.58 (41b88ba7ZjuJcwYxAL5HR5J_1FXMYw)
sysrq hacks from Matt Bloch
This commit is contained in:
1 parent
aee8954955
commit
bc05bbc8f7
10 files changed
+93
-14
No files matched your search
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||