* xl: Add "xl trigger" command
@ 2010-05-11 8:40 Yang Hongyang
0 siblings, 0 replies; only message in thread
From: Yang Hongyang @ 2010-05-11 8:40 UTC (permalink / raw)
To: xen-devel@lists.xensource.com
Add "xl trigger" command, a clone of "xm trigger".
Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
diff -r bbf009817ffb -r 2496a1a0e64d tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Fri May 07 19:22:28 2010 +0100
+++ b/tools/libxl/libxl.c Wed May 12 00:30:30 2010 +0800
@@ -2594,3 +2594,37 @@
return 0;
}
+static int trigger_type_from_string(char *trigger_name)
+{
+ if (!strcmp(trigger_name, "nmi"))
+ return XEN_DOMCTL_SENDTRIGGER_NMI;
+ else if (!strcmp(trigger_name, "reset"))
+ return XEN_DOMCTL_SENDTRIGGER_RESET;
+ else if (!strcmp(trigger_name, "init"))
+ return XEN_DOMCTL_SENDTRIGGER_INIT;
+ else if (!strcmp(trigger_name, "power"))
+ return XEN_DOMCTL_SENDTRIGGER_POWER;
+ else if (!strcmp(trigger_name, "sleep"))
+ return XEN_DOMCTL_SENDTRIGGER_SLEEP;
+ else
+ return -1;
+}
+
+int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid, char *trigger_name, uint32_t vcpuid)
+{
+ int rc = -1;
+ int trigger_type = trigger_type_from_string(trigger_name);
+
+ if (trigger_type == -1) {
+ XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1,
+ "Invalid trigger, valid triggers are <nmi|reset|init|power|sleep>");
+ return -1;
+ }
+
+ rc = xc_domain_send_trigger(ctx->xch, domid, trigger_type, vcpuid);
+ if (rc != 0)
+ XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc,
+ "Send trigger '%s' failed", trigger_name);
+
+ return rc;
+}
diff -r bbf009817ffb -r 2496a1a0e64d tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Fri May 07 19:22:28 2010 +0100
+++ b/tools/libxl/libxl.h Wed May 12 00:30:30 2010 +0800
@@ -479,5 +479,7 @@
struct libxl_sched_credit *scinfo);
int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid,
struct libxl_sched_credit *scinfo);
+int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid,
+ char *trigger_name, uint32_t vcpuid);
#endif /* LIBXL_H */
diff -r bbf009817ffb -r 2496a1a0e64d tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri May 07 19:22:28 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Wed May 12 00:30:30 2010 +0800
@@ -1269,6 +1269,9 @@
} else if (!strcmp(command, "rename")) {
printf("Usage: xl rename <Domain> <NewDomainName>\n\n");
printf("Rename a domain.\n");
+ } else if (!strcmp(command, "trigger")) {
+ printf("Usage: xm trigger <Domain> <nmi|reset|init|power|sleep> [<VCPU>]\n\n");
+ printf("Send a trigger to a domain.\n");
}
}
@@ -3108,3 +3111,45 @@
exit(0);
}
+
+int main_trigger(int argc, char **argv)
+{
+ int opt;
+ char *trigger_name = NULL;
+ char *endptr = NULL;
+ char *dom = NULL;
+ int vcpuid = 0;
+
+ while ((opt = getopt(argc, argv, "h")) != -1) {
+ switch (opt) {
+ case 'h':
+ help("trigger");
+ exit(0);
+ default:
+ fprintf(stderr, "option `%c' not supported.\n", opt);
+ break;
+ }
+ }
+
+ dom = argv[optind++];
+ if (!dom || !argv[optind]) {
+ fprintf(stderr, "'xl trigger' requires between 2 and 3 arguments.\n\n");
+ help("trigger");
+ exit(1);
+ }
+
+ find_domain(dom);
+
+ trigger_name = argv[optind++];
+
+ if (argv[optind]) {
+ vcpuid = strtol(argv[optind], &endptr, 10);
+ if (vcpuid == 0 && !strcmp(endptr, argv[optind])) {
+ fprintf(stderr, "Invalid vcpuid, using default vcpuid=0.\n\n");
+ }
+ }
+
+ libxl_send_trigger(&ctx, domid, trigger_name, vcpuid);
+
+ exit(0);
+}
diff -r bbf009817ffb -r 2496a1a0e64d tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h Fri May 07 19:22:28 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h Wed May 12 00:30:30 2010 +0800
@@ -38,5 +38,6 @@
int main_domid(int argc, char **argv);
int main_domname(int argc, char **argv);
int main_rename(int argc, char **argv);
+int main_trigger(int argc, char **argv);
void help(char *command);
diff -r bbf009817ffb -r 2496a1a0e64d tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Fri May 07 19:22:28 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Wed May 12 00:30:30 2010 +0800
@@ -39,6 +39,7 @@
{ "domid", &main_domid, "convert a domain name to domain id"},
{ "domname", &main_domname, "convert a domain id to domain name"},
{ "rename", &main_rename, "rename a domain"},
+ { "trigger", &main_trigger, "send a trigger to a domain"},
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
--
Regards
Yang Hongyang
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-05-11 8:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-11 8:40 xl: Add "xl trigger" command Yang Hongyang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.