# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1273573434 -3600
# Node ID 60b3417b1499a3cbe28a88d286f1b3c2ac01d5fa
# Parent 7d4deb86b9661b8585fc2b5c41334f2b34b0922b
xl: Add "xl trigger" command, a clone of "xm trigger".
Signed-off-by: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
---
tools/libxl/libxl.c | 34 ++++++++++++++++++++++++++++++++++
tools/libxl/libxl.h | 2 ++
tools/libxl/xl_cmdimpl.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
tools/libxl/xl_cmdimpl.h | 1 +
tools/libxl/xl_cmdtable.c | 1 +
5 files changed, 83 insertions(+)
diff -r 7d4deb86b966 -r 60b3417b1499 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue May 11 11:21:27 2010 +0100
+++ b/tools/libxl/libxl.c Tue May 11 11:23:54 2010 +0100
@@ -2595,3 +2595,37 @@ int libxl_sched_credit_domain_set(struct
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 7d4deb86b966 -r 60b3417b1499 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Tue May 11 11:21:27 2010 +0100
+++ b/tools/libxl/libxl.h Tue May 11 11:23:54 2010 +0100
@@ -479,5 +479,7 @@ int libxl_sched_credit_domain_get(struct
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 7d4deb86b966 -r 60b3417b1499 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue May 11 11:21:27 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue May 11 11:23:54 2010 +0100
@@ -1275,6 +1275,9 @@ void help(char *command)
} 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");
}
}
@@ -3107,3 +3110,45 @@ int main_rename(int argc, char **argv)
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 7d4deb86b966 -r 60b3417b1499 tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h Tue May 11 11:21:27 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h Tue May 11 11:23:54 2010 +0100
@@ -38,5 +38,6 @@ int main_domid(int argc, char **argv);
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 7d4deb86b966 -r 60b3417b1499 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Tue May 11 11:21:27 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Tue May 11 11:23:54 2010 +0100
@@ -41,6 +41,7 @@ struct cmd_spec cmd_table[] = {
{ "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);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|