Skip to contentSkip to conversation

new commands "xl reboot" & "xl shutdown"

PATCH In review Gihan Munasinghe 4 participants 10 messages May 7, 2010 – Jun 1, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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

Signature · 4 lines
Gihan Munasinghe
R&D Team Leader
Flexiant Ltd.
www.flexiant.com
xen-4.0.0/tools/libxl/libxl.c +2 -2
diff -Naur vanila/xen-4.0.0/tools/libxl/libxl.c xen4patch/xen-4.0.0/tools/libxl/libxl.c
@@ -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;
xen-4.0.0/tools/libxl/xl.c +106 -4

159 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 7 lines · Gihan Munasinghe

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.

Quoted 7 lines

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

Thanks for the patch!
It is mostly correct, however libxenlight changed quite a bit since xen 4.0 so could you please port your changes to xen-unstable?

Quoted 8 lines

diff -Naur vanila/xen-4.0.0/tools/libxl/libxl.c xen4patch/xen-4.0.0/tools/libxl/libxl.c

xen-4.0.0/tools/libxl/libxl.c +0 -1
@@ -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) {

xen-4.0.0/tools/libxl/libxl.c line 411

Quoted 10 lines
xen-4.0.0/tools/libxl/libxl.c +2 -1
+    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;

this should be correct

Quoted 14 lines

diff -Naur vanila/xen-4.0.0/tools/libxl/xl.c xen4patch/xen-4.0.0/tools/libxl/xl.c

xen-4.0.0/tools/libxl/xl.c +0 -3
@@ -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;

xen-4.0.0/tools/libxl/xl.c line 717

Quoted 9 lines
xen-4.0.0/tools/libxl/xl.c +3 -0
@@ -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);

this is probably not needed anymore

xen-4.0.0/tools/libxl/xl.c line 838

Quoted 11 lines
xen-4.0.0/tools/libxl/xl.c +2 -1
@@ -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");

since we don't free the ctx anymore here, it might be unnecessary. The other changes look OK but we have a command table now, so they need to be adapted.

#2 lore raw
Quoted 4 lines · Stefano Stabellini
Quoted 2 lines · Gihan Munasinghe

Guys

Quoted 10 lines
Quoted 4 lines

I patched xl to have "reboot" and "shutdown" commands.

Thanks for the patch!
It is mostly correct, however libxenlight changed quite a bit since xen 4.0 so could you please port your changes to xen-unstable?

I'll do the port and resubmit the patch

Thanks
Gihan

#3 lore raw
In reply to Stefano Stabellini
Quoted 9 lines · Stefano Stabellini
Quoted 7 lines · Gihan Munasinghe

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.

Quoted 10 lines
Quoted 3 lines

Let me know what you think

Thanks for the patch!
It is mostly correct, however libxenlight changed quite a bit since xen 4.0 so could you please port your changes to xen-unstable?

The Patch is ported to xen-unstable see attached

Quoted 12 lines

Review

Quoted 8 lines
(quoted diff) +3 -0
+start:
+    domid = 0;
+
     ret = libxl_domain_make(&ctx, &info1, &domid);
     if (ret) {
         fprintf(stderr, "cannot make domain: %d\n", ret);

this is probably not needed anymore

Yes this fix is not needed anymore

Quoted 9 lines

Review

Quoted 8 lines
                             LOG("Done. Rebooting now");
(quoted diff) +2 -0
+                            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");
Quoted 5 lines

since we don't free the ctx anymore here, it might be unnecessary. The other changes look OK but we have a command table now, so they need to be adapted.

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.

Thanks

Gihan

libxl.c +2 -2
diff -Naur libxl/libxl.c libxl-patch/libxl.c
@@ -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;
         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;
xl_cmdimpl.c +77 -0

101 lines not on this page · raw message

xl_cmdimpl.h +2 -0
diff -Naur libxl/xl_cmdimpl.h libxl-patch/xl_cmdimpl.h
@@ -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);
xl_cmdtable.c +2 -0
diff -Naur libxl/xl_cmdtable.c libxl-patch/xl_cmdtable.c
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw
Quoted 3 lines · Gihan Munasinghe

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.

libxl.c +0 -0
diff -Naur libxl/libxl.c libxl-patch/libxl.c
@@ -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).

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.

Signature · 1 line
Vincent
#5 lore raw
Quoted 18 lines · Vincent Hanquez
Quoted 3 lines · Gihan Munasinghe

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.c 2010-05-12 16:24:42.000000000 +0100 renamed from libxl.c 2010-05-11 09:37:50.000000000 +0100 +1 -1
@@ -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;
 
Quoted 1 line

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  .. )
Quoted 3 lines

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

libxl.c +2 -2
diff -Naur libxl/libxl.c libxl-patch/libxl.c
@@ -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;
xl_cmdimpl.c +77 -0

101 lines not on this page · raw message

xl_cmdimpl.h +2 -0
diff -Naur libxl/xl_cmdimpl.h libxl-patch/xl_cmdimpl.h
@@ -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);
xl_cmdtable.c +2 -0
diff -Naur libxl/xl_cmdtable.c libxl-patch/xl_cmdtable.c
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw
Quoted 6 lines · Gihan Munasinghe
Quoted 4 lines

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.

Please port your patch to the tip of xen-unstable and re-post with changeset comment and signed-off-by-line.

Thanks,
Keir

#7 lore raw
Quoted 12 lines · Keir Fraser
Quoted 8 lines · Gihan Munasinghe
Quoted 5 lines

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.

Quoted 10 lines

Please port your patch to the tip of xen-unstable and re-post with changeset comment and signed-off-by-line.

Thanks,
Keir

Sorry for the very long delay see updated patch

xl: adds shutdown and reboot commands
libxl : remote shutdown to work for pure hvm domains

tools/libxl/libxl.c +2 -2
diff -Naur xen-unstable.hg/tools/libxl/libxl.c xen-unstable.hg.p/tools/libxl/libxl.c
@@ -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;
tools/libxl/xl_cmdimpl.c +77 -0

101 lines not on this page · raw message

tools/libxl/xl_cmdimpl.h +2 -0
diff -Naur xen-unstable.hg/tools/libxl/xl_cmdimpl.h xen-unstable.hg.p/tools/libxl/xl_cmdimpl.h
@@ -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);
tools/libxl/xl_cmdtable.c +2 -0
diff -Naur xen-unstable.hg/tools/libxl/xl_cmdtable.c xen-unstable.hg.p/tools/libxl/xl_cmdtable.c
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

#9 lore raw
Quoted 14 lines

This is still against a very old version of xen-unstable.

In your repo do:
hg pull -u http://xenbits.xensource.com/staging/xen-unstable.hg

Then re-base your patch to that.

-- Keir

Hi
Re did the patch for the latest unstable release see attached

xl: adds shutdown and reboot commands
libxl : remote shutdown to work for pure hvm domains

Thanks
Gihan

tools/libxl/libxl.c +2 -2
diff -Nuar a/tools/libxl/libxl.c b/tools/libxl/libxl.c
@@ -550,12 +550,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;
tools/libxl/xl_cmdimpl.c +68 -0

86 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +10 -0
diff -Nuar a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
@@ -35,6 +35,16 @@
       "Terminate a domain immediately",
       "<Domain>",
     },
+    { "shutdown",
+      &main_shutdown,
+      "Issue a shutdown signal to a domain",
+      "<Domain>",
+    },
+    { "reboot",
+      &main_reboot,
+      "Issue a reboot signal to a domain",
+      "<Domain>",
+    }, 
     { "pci-attach",
       &main_pciattach,
       "Insert a new pass-through pci device",
tools/libxl/xl.h +2 -0
diff -Nuar a/tools/libxl/xl.h b/tools/libxl/xl.h
@@ -40,6 +40,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);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel