xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: xl: Add "xl trigger" command
Date: Tue, 11 May 2010 16:40:50 +0800	[thread overview]
Message-ID: <4BE91812.1040905@cn.fujitsu.com> (raw)

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

                 reply	other threads:[~2010-05-11  8:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BE91812.1040905@cn.fujitsu.com \
    --to=yanghy@cn.fujitsu.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).