[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] new commands "xl reboot" & "xl shutdown"



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

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")) {
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.