Patchwork [40/40] xen: add sysrq support

login
register
mail settings
Submitter Alexander Graf
Date Nov. 2, 2010, 4:26 p.m.
Message ID <1288715188-28710-1-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/69908/
State New
Headers show

Comments

Alexander Graf - Nov. 2, 2010, 4:26 p.m.
Sending sys-requests on Xen is different from the usual keyboard based
ways. For xen, we need to add a xenstored node which the guest pulls the
sysrq information from.

This patch implements said interface by introducing a new human monitor
command to use it. It's purely optional.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hmp-commands.hx      |   24 ++++++++++++++++++++++++
 hw/xen.h             |    2 ++
 hw/xen_domainbuild.c |    8 ++++++++
 monitor.c            |    8 ++++++++
 4 files changed, 42 insertions(+), 0 deletions(-)

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 81999aa..40fdd00 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -436,6 +436,30 @@  This command is useful to send keys that your graphical user interface
 intercepts at low level, such as @code{ctrl-alt-f1} in X Window.
 ETEXI
 
+#if defined(CONFIG_XEN) || defined(CONFIG_XENNER)
+    {
+        .name       = "xen_sysrq",
+        .args_type  = "string:s",
+        .params     = "key",
+        .help       = "send sysrq to the Xen VM",
+        .mhandler.cmd = do_xen_sysrq,
+    },
+#endif
+
+STEXI
+@item xen_sysrq @var{key}
+@findex xen_sysrq
+
+Send @var{key} as sys-request to the Xen VM. This is the equivalent to
+alt-print-@var{key} in normal Linux guests. Example:
+@example
+xen_sysrq s
+@end example
+
+Please keep in mind that this is the only way of sending sys-requests to
+Xen PV machines. The usual alt-print-@var{key} way does not work.
+ETEXI
+
     {
         .name       = "system_reset",
         .args_type  = "",
diff --git a/hw/xen.h b/hw/xen.h
index 780dcf7..f2ac576 100644
--- a/hw/xen.h
+++ b/hw/xen.h
@@ -18,4 +18,6 @@  enum xen_mode {
 extern uint32_t xen_domid;
 extern enum xen_mode xen_mode;
 
+void xen_sysrq(const char *sysrq);
+
 #endif /* QEMU_HW_XEN_H */
diff --git a/hw/xen_domainbuild.c b/hw/xen_domainbuild.c
index 7f1fd66..49962db 100644
--- a/hw/xen_domainbuild.c
+++ b/hw/xen_domainbuild.c
@@ -211,6 +211,14 @@  static int xen_domain_watcher(void)
     _exit(0);
 }
 
+void xen_sysrq(const char *sysrq)
+{
+    void *dom;
+
+    dom = xs_get_domain_path(xenstore, xen_domid);
+    xenstore_write_str(dom, "control/sysrq", sysrq);
+}
+
 /* normal cleanup */
 static void xen_domain_cleanup(void)
 {
diff --git a/monitor.c b/monitor.c
index 61607c5..99aae01 100644
--- a/monitor.c
+++ b/monitor.c
@@ -30,6 +30,7 @@ 
 #include "hw/pci.h"
 #include "hw/watchdog.h"
 #include "hw/loader.h"
+#include "hw/xen.h"
 #include "gdbstub.h"
 #include "net.h"
 #include "net/slirp.h"
@@ -1639,6 +1640,13 @@  static void release_keys(void *opaque)
     }
 }
 
+#if defined(CONFIG_XEN) || defined(CONFIG_XENNER)
+static void do_xen_sysrq(Monitor *mon, const QDict *qdict)
+{
+    xen_sysrq(strdup(qdict_get_str(qdict, "string")));
+}
+#endif
+
 static void do_sendkey(Monitor *mon, const QDict *qdict)
 {
     char keyname_buf[16];