aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-06-02 10:52:17 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-06-02 10:52:17 +0100
commitc1d7e20205d82fa76ef7a84f0af1e01c63b15eb2 (patch)
tree7db70e2de9f4fa29ae1e90ced2f7c7468bc5f899
parent9d1f137d16a9485bbf1d44a7d3ad8ee13bcbcd78 (diff)
downloadxen-c1d7e20205d82fa76ef7a84f0af1e01c63b15eb2.tar.gz
xen-c1d7e20205d82fa76ef7a84f0af1e01c63b15eb2.tar.bz2
xen-c1d7e20205d82fa76ef7a84f0af1e01c63b15eb2.zip
xl: adds shutdown and reboot commands
libxl : remote shutdown to work for pure hvm domains Signed-off-by: Gihan Munasinghe <GMunasinghe@flexiant.com>
-rw-r--r--tools/libxl/libxl.c4
-rw-r--r--tools/libxl/xl.h2
-rw-r--r--tools/libxl/xl_cmdimpl.c72
-rw-r--r--tools/libxl/xl_cmdtable.c10
4 files changed, 86 insertions, 2 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index d7563b4b31..c6580ce0a6 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -550,12 +550,12 @@ int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req)
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 --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 3144a64e0d..6ad08f6495 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -40,6 +40,8 @@ int main_migrate(int argc, char **argv);
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 --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 476ec78eed..03eafbf45e 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1160,6 +1160,11 @@ start:
free(w1);
free(w2);
LOG("Done. Rebooting now");
+ /*
+ * XXX FIXME: If this sleep is not there then
+ * domain re-creation fails sometimes.
+ */
+ sleep(2);
goto start;
}
LOG("Done. Exiting now");
@@ -1623,6 +1628,22 @@ void destroy_domain(char *p)
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;
@@ -2375,6 +2396,57 @@ int main_destroy(int argc, char **argv)
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 --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
index accc4f929b..2ea0e66a94 100644
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -35,6 +35,16 @@ struct cmd_spec cmd_table[] = {
"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",