xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] new commands "xl reboot" & "xl shutdown"
@ 2010-05-07 23:36 Gihan Munasinghe
  2010-05-10 15:11 ` Stefano Stabellini
  0 siblings, 1 reply; 10+ messages in thread
From: Gihan Munasinghe @ 2010-05-07 23:36 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

Guys

I patched xl to have "reboot" and "shutdown" commands.
I tested this with hvm domains with and and without pv drivers seems to 
work, of course the os level reboot and shutdown will only happen if 
there are pv drivers with the dom U.

Also the libxl_domain_shutdown was not working for hvm guests without pv 
drivers, I did a small patch to that as well. (same way xend shutdown 
works used || instead of a && ). I would appreciate if someone can test 
this more with hvm and pv domains.

Let me know what  you think


-- 
Gihan Munasinghe
R&D Team Leader
Flexiant Ltd.
www.flexiant.com


[-- Attachment #2: xen4-libxl-shutdown-reboot.patch --]
[-- Type: text/plain, Size: 6259 bytes --]

diff -Naur vanila/xen-4.0.0/tools/libxl/libxl.c xen4patch/xen-4.0.0/tools/libxl/libxl.c
--- vanila/xen-4.0.0/tools/libxl/libxl.c	2010-04-07 17:12:04.000000000 +0100
+++ xen4patch/xen-4.0.0/tools/libxl/libxl.c	2010-05-07 23:14:26.000000000 +0100
@@ -400,12 +400,12 @@
     shutdown_path = libxl_sprintf(ctx, "%s/control/shutdown", dom_path);
 
     xs_write(ctx->xsh, XBT_NULL, shutdown_path, req_table[req], strlen(req_table[req]));
-    if (/* hvm */ 0) {
+    if (/* hvm */ 1) {
         unsigned long acpi_s_state = 0;
         unsigned long pvdriver = 0;
         xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_ACPI_S_STATE, &acpi_s_state);
         xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
-        if (!pvdriver && acpi_s_state != 0)
+        if (!pvdriver || acpi_s_state != 0)
             xc_domain_shutdown(ctx->xch, domid, req);
     }
     return 0;
diff -Naur vanila/xen-4.0.0/tools/libxl/xl.c xen4patch/xen-4.0.0/tools/libxl/xl.c
--- vanila/xen-4.0.0/tools/libxl/xl.c	2010-04-07 17:12:04.000000000 +0100
+++ xen4patch/xen-4.0.0/tools/libxl/xl.c	2010-05-08 00:19:51.000000000 +0100
@@ -702,9 +702,6 @@
     if (debug)
         printf_info(&info1, &info2, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info);
 
-start:
-    domid = 0;
-
     if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
         fprintf(stderr, "cannot init xl context\n");
         return;
@@ -712,6 +709,9 @@
 
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
+start:
+    domid = 0;
+
     ret = libxl_domain_make(&ctx, &info1, &domid);
     if (ret) {
         fprintf(stderr, "cannot make domain: %d\n", ret);
@@ -830,8 +830,9 @@
                             libxl_free_waiter(w2);
                             free(w1);
                             free(w2);
-                            libxl_ctx_free(&ctx);
                             LOG("Done. Rebooting now");
+                            sleep(2);/*Fix Me: The sleep is put here to slowdown the recreation of the domain 
+                                       If this sleep it not there, hvm_domain creation failes sometimes*/
                             goto start;
                         }
                         LOG("Done. Exiting now");
@@ -864,6 +865,8 @@
         printf(" create                        create a domain from config file <filename>\n\n");
         printf(" list                          list information about all domains\n\n");
         printf(" destroy                       terminate a domain immediately\n\n");
+        printf(" shutdown                      issue a shutdown signal to a domain\n\n");
+        printf(" reboot                        issue a reboot signal to a domain\n\n");
         printf(" pci-attach                    insert a new pass-through pci device\n\n");
         printf(" pci-detach                    remove a domain's pass-through pci device\n\n");
         printf(" pci-list                      list pass-through pci devices for a domain\n\n");
@@ -917,6 +920,12 @@
     } else if(!strcmp(command, "destroy")) {
         printf("Usage: xl destroy <Domain>\n\n");
         printf("Terminate a domain immediately.\n\n");
+    } else if(!strcmp(command, "shutdown")) {
+        printf("Usage: xl shutdown <Domain>\n\n");
+        printf("Issue a shutdown signal to a domain.\n\n");
+    } else if(!strcmp(command, "reboot")) {
+        printf("Usage: xl reboot <Domain>\n\n");
+        printf("Issue a reboot signal to a domain.\n\n");
     } else if (!strcmp(command, "console")) {
         printf("Usage: xl console <Domain>\n\n");
         printf("Attach to domain's console.\n\n");
@@ -1352,6 +1361,43 @@
     libxl_domain_destroy(&ctx, domid, 0);
 }
 
+void shutdown_domain(char *p)
+{
+    struct libxl_ctx ctx;
+    uint32_t domid;
+
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+    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);
+    }
+    libxl_domain_shutdown(&ctx, domid, 0);
+}
+
+void reboot_domain(char *p)
+{
+    struct libxl_ctx ctx;
+    uint32_t domid;
+
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+    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);
+    }
+    libxl_domain_shutdown(&ctx, domid, 1);
+}
+
+
 void list_domains(void)
 {
     struct libxl_ctx ctx;
@@ -1596,6 +1642,58 @@
     exit(0);
 }
 
+int main_shutdown(int argc, char **argv)
+{
+    int opt;
+    char *p;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("shutdown");
+            exit(0);
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+    if (optind >= argc) {
+        help("shutdown");
+        exit(2);
+    }
+
+    p = argv[optind];
+
+    shutdown_domain(p);
+    exit(0);
+}
+
+int main_reboot(int argc, char **argv)
+{
+    int opt;
+    char *p;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("reboot");
+            exit(0);
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+    if (optind >= argc) {
+        help("reboot");
+        exit(2);
+    }
+
+    p = argv[optind];
+
+    reboot_domain(p);
+    exit(0);
+}
+
 int main_list(int argc, char **argv)
 {
     int opt;
@@ -1738,6 +1836,10 @@
         main_list_vm(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "destroy")) {
         main_destroy(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "shutdown")) {
+        main_shutdown(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "reboot")) {
+        main_reboot(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "pci-attach")) {
         main_pciattach(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "pci-detach")) {

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-06-01 22:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-07 23:36 [PATCH] new commands "xl reboot" & "xl shutdown" Gihan Munasinghe
2010-05-10 15:11 ` Stefano Stabellini
2010-05-11  6:51   ` Gihan Munasinghe
2010-05-12 15:57   ` Gihan Munasinghe
2010-05-12 16:34     ` Vincent Hanquez
2010-05-12 17:09       ` Gihan Munasinghe
2010-05-13  7:41         ` Keir Fraser
2010-05-31 19:03           ` Gihan Munasinghe
2010-06-01  6:09             ` Keir Fraser
2010-06-01 22:51               ` Gihan Munasinghe

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).