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-changelog

[Xen-changelog] [xen-unstable] libxl, hvm: Add support to trigger power

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl, hvm: Add support to trigger power or sleep button events
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Jan 2010 12:40:15 -0800
Delivery-date: Wed, 20 Jan 2010 12:40:12 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1264019779 0
# Node ID f300b53520d0b13696f6ca6669fff8ad54289817
# Parent  0edb75cd8126b9a463c829a763aafd1a5af1bb40
libxl, hvm: Add support to trigger power or sleep button events

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 tools/libxl/libxl.c |   18 +++++++++++++++
 tools/libxl/libxl.h |   10 +++++++-
 tools/libxl/xl.c    |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 1 deletion(-)

diff -r 0edb75cd8126 -r f300b53520d0 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Jan 20 20:34:19 2010 +0000
+++ b/tools/libxl/libxl.c       Wed Jan 20 20:36:19 2010 +0000
@@ -2198,3 +2198,21 @@ int libxl_set_memory_target(struct libxl
     rc = xc_domain_memory_set_pod_target(ctx->xch, domid, (target_memkb - 
videoram) / 4, NULL, NULL, NULL);
     return rc;
 }
+
+int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button 
button)
+{
+    int rc = -1;
+
+    switch (button) {
+    case POWER_BUTTON:
+        rc = xc_domain_send_trigger(ctx->xch, domid, 
XEN_DOMCTL_SENDTRIGGER_POWER, 0);
+        break;
+    case SLEEP_BUTTON:
+        rc = xc_domain_send_trigger(ctx->xch, domid, 
XEN_DOMCTL_SENDTRIGGER_SLEEP, 0);
+        break;
+    default:
+        break;
+    }
+
+    return rc;
+}
diff -r 0edb75cd8126 -r f300b53520d0 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Jan 20 20:34:19 2010 +0000
+++ b/tools/libxl/libxl.h       Wed Jan 20 20:36:19 2010 +0000
@@ -353,4 +353,12 @@ int libxl_device_pci_init(libxl_device_p
                           unsigned int bus, unsigned int dev,
                           unsigned int func, unsigned int vdevfn);
 
-#endif
+typedef enum {
+    POWER_BUTTON,
+    SLEEP_BUTTON
+} libxl_button;
+
+int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button 
button);
+
+#endif /* LIBXL_H */
+
diff -r 0edb75cd8126 -r f300b53520d0 tools/libxl/xl.c
--- a/tools/libxl/xl.c  Wed Jan 20 20:34:19 2010 +0000
+++ b/tools/libxl/xl.c  Wed Jan 20 20:36:19 2010 +0000
@@ -931,6 +931,7 @@ static void help(char *command)
         printf(" cd-insert                     insert a cdrom into a guest's 
cd drive\n\n");
         printf(" cd-eject                      eject a cdrom from a guest's cd 
drive\n\n");
         printf(" mem-set                       set the current memory usage 
for a domain\n\n");
+        printf(" button-press                  indicate an ACPI button press 
to the domain\n\n");
     } else if(!strcmp(command, "create")) {
         printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
         printf("Create a domain based on <ConfigFile>.\n\n");
@@ -984,6 +985,10 @@ static void help(char *command)
     } else if (!strcmp(command, "mem-set")) {
         printf("Usage: xl mem-set <Domain> <MemKB>\n\n");
         printf("Set the current memory usage for a domain.\n\n");
+    } else if (!strcmp(command, "button-press")) {
+        printf("Usage: xl button-press <Domain> <Button>\n\n");
+        printf("Indicate <Button> press to a domain.\n");
+        printf("<Button> may be 'power' or 'sleep'.\n\n");
     }
 }
 
@@ -1715,6 +1720,60 @@ int main_create(int argc, char **argv)
 
     filename = argv[optind];
     create_domain(debug, daemonize, filename, NULL, 0);
+    exit(0);
+}
+
+void button_press(char *p, char *b)
+{
+    struct libxl_ctx ctx;
+    uint32_t domid;
+    libxl_button button;
+
+    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", p);
+        exit(2);
+    }
+
+    if (!strcmp(b, "power")) {
+        button = POWER_BUTTON;
+    } else if (!strcmp(b, "sleep")) {
+        button = SLEEP_BUTTON;
+    } else {
+        fprintf(stderr, "%s is an invalid button identifier\n", b);
+        exit(2);
+    }
+
+    libxl_button_press(&ctx, domid, button);
+}
+
+int main_button_press(int argc, char **argv)
+{
+    int opt;
+    char *p;
+    char *b;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("button-press");
+            exit(0);
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+    if (optind >= argc - 1) {
+        help("button-press");
+        exit(2);
+    }
+
+    p = argv[optind];
+    b = argv[optind + 1];
+
+    button_press(p, b);
     exit(0);
 }
 
@@ -1757,6 +1816,8 @@ int main(int argc, char **argv)
         main_cd_eject(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "mem-set")) {
         main_memset(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "button-press")) {
+        main_button_press(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "help")) {
         if (argc > 2)
             help(argv[2]);

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl, hvm: Add support to trigger power or sleep button events, Xen patchbot-unstable <=