Skip to contentSkip to conversation

xl: Add "xl sysrq" command

PATCH In review Yang Hongyang 1 participant 1 message May 12, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xl: Add "xl sysrq" command

Add "xl sysrq" command, a clone of "xm sysrq".

tools/libxl/libxl.c +10 -0
diff -r d77a88f938c6 -r feb1b75800d6 tools/libxl/libxl.c
@@ -2629,3 +2629,13 @@
 
     return rc;
 }
+
+int libxl_send_sysrq(struct libxl_ctx *ctx, uint32_t domid, char sysrq)
+{
+    char *dompath = libxl_xs_get_dompath(ctx, domid);
+
+    libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/control/sysrq", dompath), "%c", sysrq);
+
+    return 0;
+}
+
tools/libxl/libxl.h +1 -0
diff -r d77a88f938c6 -r feb1b75800d6 tools/libxl/libxl.h
@@ -481,5 +481,6 @@
                                   struct libxl_sched_credit *scinfo);
 int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid,
                        char *trigger_name, uint32_t vcpuid);
+int libxl_send_sysrq(struct libxl_ctx *ctx, uint32_t domid, char sysrq);
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +40 -0
diff -r d77a88f938c6 -r feb1b75800d6 tools/libxl/xl_cmdimpl.c
@@ -3058,3 +3058,43 @@
 
     exit(0);
 }
+
+
+int main_sysrq(int argc, char **argv)
+{
+    int opt;
+    char *sysrq = NULL;
+    char *dom = NULL;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("sysrq");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    dom = argv[optind++];
+    if (!dom || !argv[optind]) {
+        fprintf(stderr, "'xl sysrq' requires 2 arguments.\n\n");
+        help("sysrq");
+        exit(1);
+    }
+
+    find_domain(dom);
+
+    sysrq = argv[optind];
+
+    if (sysrq[1] != '\0') {
+        fprintf(stderr, "Invalid sysrq.\n\n");
+        help("sysrq");
+        exit(1);
+    }
+
+    libxl_send_sysrq(&ctx, domid, sysrq[0]);
+
+    exit(0);
+}
tools/libxl/xl_cmdimpl.h +1 -0
diff -r d77a88f938c6 -r feb1b75800d6 tools/libxl/xl_cmdimpl.h
@@ -39,5 +39,6 @@
 int main_domname(int argc, char **argv);
 int main_rename(int argc, char **argv);
 int main_trigger(int argc, char **argv);
+int main_sysrq(int argc, char **argv);
 
 void help(char *command);
tools/libxl/xl_cmdtable.c +5 -0
diff -r d77a88f938c6 -r feb1b75800d6 tools/libxl/xl_cmdtable.c
@@ -172,6 +172,11 @@
       "Send a trigger to a domain",
       "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
     },
+    { "sysrq",
+      &main_sysrq,
+      "Send a sysrq to a domain",
+      "<Domain> <letter>",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang