]> xenbits.xensource.com Git - xen.git/commitdiff
xl: Add "xl trigger" command, a clone of "xm trigger".
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 11 May 2010 10:23:54 +0000 (11:23 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 11 May 2010 10:23:54 +0000 (11:23 +0100)
Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdimpl.h
tools/libxl/xl_cmdtable.c

index 4ddcfe868f24d80cf97bcbc328b5ce02e1de3522..1b09294016a9c1fc7c126c1ef41e81cd0047264f 100644 (file)
@@ -2595,3 +2595,37 @@ int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid, 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;
+}
index c5186369aef93fae72a49266fedde4a4df2ab250..198d98daf29ea092128a9d024ddf4409c9cfe5a5 100644 (file)
@@ -479,5 +479,7 @@ int libxl_sched_credit_domain_get(struct libxl_ctx *ctx, uint32_t domid,
                                   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 */
 
index ae7dcf5d79df1dab40a6e22322a60848407ff214..f9e2cd647a3dfe6c92a365c40d27b6f35804f39a 100644 (file)
@@ -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);
+}
index bf1b72fa8c0c8b7f94cbe34e901670b68082dcad..c53ba4e4b8f5c60526fdbfb952fcd8d80eaa223d 100644 (file)
@@ -38,5 +38,6 @@ int main_sched_credit(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);
index 96062e6f6250e07ec6dc95bc5ddb5b677c3ea9a3..ef44a2336ce4e509dc293f5c46e4812c40f9e8f3 100644 (file)
@@ -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);