WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] xl: Add "xl trigger" command

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] xl: Add "xl trigger" command
From: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
Date: Tue, 11 May 2010 16:40:50 +0800
Delivery-date: Tue, 11 May 2010 01:40:44 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100415 Thunderbird/3.0.4
Add "xl trigger" command, a clone of "xm trigger".

Signed-off-by: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>

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

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] xl: Add "xl trigger" command, Yang Hongyang <=