debuggers.hg
changeset 20875:f300b53520d0
libxl, hvm: Add support to trigger power or sleep button events
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Wed Jan 20 20:36:19 2010 +0000 (2010-01-20) |
parents | 0edb75cd8126 |
children | aa00760933df |
files | tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/xl.c |
line diff
1.1 --- a/tools/libxl/libxl.c Wed Jan 20 20:34:19 2010 +0000 1.2 +++ b/tools/libxl/libxl.c Wed Jan 20 20:36:19 2010 +0000 1.3 @@ -2198,3 +2198,21 @@ int libxl_set_memory_target(struct libxl 1.4 rc = xc_domain_memory_set_pod_target(ctx->xch, domid, (target_memkb - videoram) / 4, NULL, NULL, NULL); 1.5 return rc; 1.6 } 1.7 + 1.8 +int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button) 1.9 +{ 1.10 + int rc = -1; 1.11 + 1.12 + switch (button) { 1.13 + case POWER_BUTTON: 1.14 + rc = xc_domain_send_trigger(ctx->xch, domid, XEN_DOMCTL_SENDTRIGGER_POWER, 0); 1.15 + break; 1.16 + case SLEEP_BUTTON: 1.17 + rc = xc_domain_send_trigger(ctx->xch, domid, XEN_DOMCTL_SENDTRIGGER_SLEEP, 0); 1.18 + break; 1.19 + default: 1.20 + break; 1.21 + } 1.22 + 1.23 + return rc; 1.24 +}
2.1 --- a/tools/libxl/libxl.h Wed Jan 20 20:34:19 2010 +0000 2.2 +++ b/tools/libxl/libxl.h Wed Jan 20 20:36:19 2010 +0000 2.3 @@ -353,4 +353,12 @@ int libxl_device_pci_init(libxl_device_p 2.4 unsigned int bus, unsigned int dev, 2.5 unsigned int func, unsigned int vdevfn); 2.6 2.7 -#endif 2.8 +typedef enum { 2.9 + POWER_BUTTON, 2.10 + SLEEP_BUTTON 2.11 +} libxl_button; 2.12 + 2.13 +int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button); 2.14 + 2.15 +#endif /* LIBXL_H */ 2.16 +
3.1 --- a/tools/libxl/xl.c Wed Jan 20 20:34:19 2010 +0000 3.2 +++ b/tools/libxl/xl.c Wed Jan 20 20:36:19 2010 +0000 3.3 @@ -931,6 +931,7 @@ static void help(char *command) 3.4 printf(" cd-insert insert a cdrom into a guest's cd drive\n\n"); 3.5 printf(" cd-eject eject a cdrom from a guest's cd drive\n\n"); 3.6 printf(" mem-set set the current memory usage for a domain\n\n"); 3.7 + printf(" button-press indicate an ACPI button press to the domain\n\n"); 3.8 } else if(!strcmp(command, "create")) { 3.9 printf("Usage: xl create <ConfigFile> [options] [vars]\n\n"); 3.10 printf("Create a domain based on <ConfigFile>.\n\n"); 3.11 @@ -984,6 +985,10 @@ static void help(char *command) 3.12 } else if (!strcmp(command, "mem-set")) { 3.13 printf("Usage: xl mem-set <Domain> <MemKB>\n\n"); 3.14 printf("Set the current memory usage for a domain.\n\n"); 3.15 + } else if (!strcmp(command, "button-press")) { 3.16 + printf("Usage: xl button-press <Domain> <Button>\n\n"); 3.17 + printf("Indicate <Button> press to a domain.\n"); 3.18 + printf("<Button> may be 'power' or 'sleep'.\n\n"); 3.19 } 3.20 } 3.21 3.22 @@ -1718,6 +1723,60 @@ int main_create(int argc, char **argv) 3.23 exit(0); 3.24 } 3.25 3.26 +void button_press(char *p, char *b) 3.27 +{ 3.28 + struct libxl_ctx ctx; 3.29 + uint32_t domid; 3.30 + libxl_button button; 3.31 + 3.32 + libxl_ctx_init(&ctx, LIBXL_VERSION); 3.33 + libxl_ctx_set_log(&ctx, log_callback, NULL); 3.34 + 3.35 + if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { 3.36 + fprintf(stderr, "%s is an invalid domain identifier\n", p); 3.37 + exit(2); 3.38 + } 3.39 + 3.40 + if (!strcmp(b, "power")) { 3.41 + button = POWER_BUTTON; 3.42 + } else if (!strcmp(b, "sleep")) { 3.43 + button = SLEEP_BUTTON; 3.44 + } else { 3.45 + fprintf(stderr, "%s is an invalid button identifier\n", b); 3.46 + exit(2); 3.47 + } 3.48 + 3.49 + libxl_button_press(&ctx, domid, button); 3.50 +} 3.51 + 3.52 +int main_button_press(int argc, char **argv) 3.53 +{ 3.54 + int opt; 3.55 + char *p; 3.56 + char *b; 3.57 + 3.58 + while ((opt = getopt(argc, argv, "h")) != -1) { 3.59 + switch (opt) { 3.60 + case 'h': 3.61 + help("button-press"); 3.62 + exit(0); 3.63 + default: 3.64 + fprintf(stderr, "option not supported\n"); 3.65 + break; 3.66 + } 3.67 + } 3.68 + if (optind >= argc - 1) { 3.69 + help("button-press"); 3.70 + exit(2); 3.71 + } 3.72 + 3.73 + p = argv[optind]; 3.74 + b = argv[optind + 1]; 3.75 + 3.76 + button_press(p, b); 3.77 + exit(0); 3.78 +} 3.79 + 3.80 int main(int argc, char **argv) 3.81 { 3.82 if (argc < 2) { 3.83 @@ -1757,6 +1816,8 @@ int main(int argc, char **argv) 3.84 main_cd_eject(argc - 1, argv + 1); 3.85 } else if (!strcmp(argv[1], "mem-set")) { 3.86 main_memset(argc - 1, argv + 1); 3.87 + } else if (!strcmp(argv[1], "button-press")) { 3.88 + main_button_press(argc - 1, argv + 1); 3.89 } else if (!strcmp(argv[1], "help")) { 3.90 if (argc > 2) 3.91 help(argv[2]);