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

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

To: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] new commands "xl reboot" & "xl shutdown"
From: Gihan Munasinghe <GMunasinghe@xxxxxxxxxxxx>
Date: Wed, 12 May 2010 18:09:04 +0100
Cc: Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Wed, 12 May 2010 10:10:27 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4BEAD888.7070402@xxxxxxxxxxxxx>
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>
References: <4BE4A40C.8050604@xxxxxxxxxxxx> <alpine.DEB.2.00.1005101607020.11380@kaball-desktop> <4BEACFD8.6080601@xxxxxxxxxxxx> <4BEAD888.7070402@xxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.24 (Macintosh/20100228)
Vincent Hanquez wrote:
On 12/05/10 16:57, Gihan Munasinghe wrote:
The sleep is still needed, if not libxl_* calls fails sometimes. I'll do
more debugging with in the calls it self and see, but for now the
sleep() seems to do the trick.

diff -Naur libxl/libxl.c libxl-patch/libxl.c
--- libxl/libxl.c    2010-05-11 09:37:50.000000000 +0100
+++ libxl-patch/libxl.c    2010-05-12 16:24:42.000000000 +0100
@@ -538,12 +538,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;

you can't just switch from 0 to 1, otherwise pv domains will just fails (although i see we're not testing xc_get_hvm_param return values either).

I though PV domain would have been captured by..
xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
       if (!pvdriver  .. )

the if (/* hvm */ 0) is because the function never properly tested if the domain is hvm or not. nowadays you have is_hvm(domid) function that can handily replace the hardcoded value.

Yes having is_hvm is much better than the hard coded values I have changed that bit of code see attached patch. I tested with hvm with and with out pv drivers. seems to work. Would be appreciate if someone can test in full pv domains.

Thanks

--
Gihan
diff -Naur libxl/libxl.c libxl-patch/libxl.c
--- libxl/libxl.c       2010-05-11 09:37:50.000000000 +0100
+++ libxl-patch/libxl.c 2010-05-12 17:43:51.000000000 +0100
@@ -538,12 +538,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 (is_hvm(ctx,domid)) {
         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 libxl/xl_cmdimpl.c libxl-patch/xl_cmdimpl.c
--- libxl/xl_cmdimpl.c  2010-05-11 09:37:50.000000000 +0100
+++ libxl-patch/xl_cmdimpl.c    2010-05-12 16:46:12.000000000 +0100
@@ -1129,6 +1129,7 @@
                             free(w1);
                             free(w2);
                             LOG("Done. Rebooting now");
+                            sleep(2);/*Fix Me: If this sleep is not there the 
domain creation failes sometimes*/
                             goto start;
                         }
                         LOG("Done. Exiting now");
@@ -1226,6 +1227,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");
@@ -1591,6 +1598,23 @@
     if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n.",rc); exit(-1); }
 }
 
+void shutdown_domain(char *p)
+{
+    int rc;
+    find_domain(p);
+    rc=libxl_domain_shutdown(&ctx, domid, 0);
+    if (rc) { fprintf(stderr,"shutdown failed (rc=%d)\n.",rc);exit(-1); }
+}
+
+void reboot_domain(char *p)
+{
+    int rc;
+    find_domain(p);
+    rc=libxl_domain_shutdown(&ctx, domid, 1);
+    if (rc) { fprintf(stderr,"reboot failed (rc=%d)\n.",rc);exit(-1); }
+}
+
+
 void list_domains(int verbose)
 {
     struct libxl_dominfo *info;
@@ -2340,6 +2364,59 @@
     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, verbose = 0;
diff -Naur libxl/xl_cmdimpl.h libxl-patch/xl_cmdimpl.h
--- libxl/xl_cmdimpl.h  2010-05-11 09:37:50.000000000 +0100
+++ libxl-patch/xl_cmdimpl.h    2010-05-11 12:51:14.000000000 +0100
@@ -27,6 +27,8 @@
 int main_pause(int argc, char **argv);
 int main_unpause(int argc, char **argv);
 int main_destroy(int argc, char **argv);
+int main_shutdown(int argc, char **argv);
+int main_reboot(int argc, char **argv);
 int main_list(int argc, char **argv);
 int main_list_vm(int argc, char **argv);
 int main_create(int argc, char **argv);
diff -Naur libxl/xl_cmdtable.c libxl-patch/xl_cmdtable.c
--- libxl/xl_cmdtable.c 2010-05-11 09:37:50.000000000 +0100
+++ libxl-patch/xl_cmdtable.c   2010-05-11 13:28:31.000000000 +0100
@@ -18,6 +18,8 @@
     { "create", &main_create, "create a domain from config file <filename>" },
     { "list", &main_list, "list information about all domains" },
     { "destroy", &main_destroy, "terminate a domain immediately" },
+    { "shutdown", &main_shutdown, "issue a shutdown signal to a domain" },
+    { "reboot", &main_reboot, "issue a reboot signal to a domain " },
     { "pci-attach", &main_pciattach, "insert a new pass-through pci device" },
     { "pci-detach", &main_pcidetach, "remove a domain's pass-through pci 
device" },
     { "pci-list", &main_pcilist, "list pass-through pci devices for a domain" 
},
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel