From: Sander Eikelenboom <linux@eikelenboom.it>
To: xen-devel@lists.xensource.com
Cc: Ian.Campbell@citrix.com
Subject: [PATCH 2 of 3] xl: Introduce reboot xm compatibility option -a and -w
Date: Thu, 06 Sep 2012 21:41:28 +0200 [thread overview]
Message-ID: <780eae92908a911f63f7.1346960488@xentest.example.org> (raw)
In-Reply-To: <patchbomb.1346960486@xentest.example.org>
* Add missing option -a to reboot all guest domains
* Add missing option -w to wait for the domain to reboot before returning
Signed-off-by: Sander Eikelenboom <linux@eikelenboom.it>
diff -r 4c3d49787cea -r 780eae92908a docs/man/xl.pod.1
--- a/docs/man/xl.pod.1 Thu Sep 06 21:36:14 2012 +0200
+++ b/docs/man/xl.pod.1 Thu Sep 06 21:36:41 2012 +0200
@@ -432,7 +432,7 @@ Pause a domain. When in a paused state
allocated resources such as memory, but will not be eligible for
scheduling by the Xen hypervisor.
-=item B<reboot> [I<OPTIONS>] I<domain-id>
+=item B<reboot> [I<OPTIONS>] I<-a|domain-id>
Reboot a domain. This acts just as if the domain had the B<reboot>
command run from the console. The command returns as soon as it has
@@ -452,6 +452,12 @@ B<OPTIONS>
=over 4
+-a Shutdown all guest domains. Often used when doing a complete shutdown of a Xen system.
+
+=item B<-w>
+
+Wait for the domain to complete shutdown before returning.
+
=item B<-F>
If the guest does not support PV reboot control then fallback to
diff -r 4c3d49787cea -r 780eae92908a tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Thu Sep 06 21:36:14 2012 +0200
+++ b/tools/libxl/xl_cmdimpl.c Thu Sep 06 21:36:41 2012 +0200
@@ -2743,11 +2743,14 @@ static void shutdown_domain(uint32_t dom
}
}
-static void reboot_domain(const char *p, int fallback_trigger)
+static void reboot_domain(uint32_t domain_id, int wait, int fallback_trigger)
{
int rc;
- find_domain(p);
- rc=libxl_domain_reboot(ctx, domid);
+ libxl_event *event;
+
+ domid = domain_id;
+ rc = libxl_domain_reboot(ctx, domid);
+
if (rc == ERROR_NOPARAVIRT) {
if (fallback_trigger) {
fprintf(stderr, "PV control interface not available:"
@@ -2762,6 +2765,42 @@ static void reboot_domain(const char *p,
if (rc) {
fprintf(stderr,"reboot failed (rc=%d)\n",rc);exit(-1);
}
+
+ if (wait) {
+ libxl_evgen_domain_death *deathw;
+
+ rc = libxl_evenable_domain_death(ctx, domid, 0, &deathw);
+ if (rc) {
+ fprintf(stderr,"wait for death failed (evgen, rc=%d)\n",rc);
+ exit(-1);
+ }
+
+ for (;;) {
+ rc = domain_wait_event(&event);
+ if (rc) exit(-1);
+
+ switch (event->type) {
+
+ case LIBXL_EVENT_TYPE_DOMAIN_DEATH:
+ LOG("Domain %d has been destroyed", domid);
+ goto done;
+
+ case LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN:
+ LOG("Domain %d has been shut down, reason code %d %x", domid,
+ event->u.domain_shutdown.shutdown_reason,
+ event->u.domain_shutdown.shutdown_reason);
+ goto done;
+
+ default:
+ LOG("Unexpected event type %d", event->type);
+ break;
+ }
+ libxl_event_free(ctx, event);
+ }
+ done:
+ libxl_event_free(ctx, event);
+ libxl_evdisable_domain_death(ctx, deathw);
+ }
}
static void list_domains_details(const libxl_dominfo *info, int nb_domain)
@@ -3722,20 +3761,52 @@ int main_shutdown(int argc, char **argv)
int main_reboot(int argc, char **argv)
{
- int opt;
+ libxl_dominfo *dominfo;
+ int opt, i, nb_domain;
+ int all = 0;
+ int wait = 0;
int fallback_trigger = 0;
- while ((opt = def_getopt(argc, argv, "F", "reboot", 1)) != -1) {
+ while ((opt = def_getopt(argc, argv, "awF", "reboot", 0)) != -1) {
switch (opt) {
case 0: case 2:
return opt;
+ case 'a':
+ all = 1;
+ break;
+ case 'w':
+ wait = 1;
+ break;
case 'F':
fallback_trigger = 1;
break;
}
}
- reboot_domain(argv[optind], fallback_trigger);
+ if (!argv[optind] && !all) {
+ fprintf(stderr, "You must specify -a or a domain id.\n\n");
+ return opt;
+ }
+
+ if (all) {
+ if (!(dominfo = libxl_list_domain(ctx, &nb_domain))) {
+ fprintf(stderr, "libxl_list_domain failed.\n");
+ return -1;
+ }
+
+ for (i = 0; i<nb_domain; i++) {
+ if (dominfo[i].domid == 0)
+ continue;
+
+ reboot_domain(dominfo[i].domid, wait, fallback_trigger);
+ }
+
+ libxl_dominfo_list_free(dominfo, nb_domain);
+ } else {
+ find_domain(argv[optind]);
+ reboot_domain(domid, wait, fallback_trigger);
+ }
+
return 0;
}
diff -r 4c3d49787cea -r 780eae92908a tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Thu Sep 06 21:36:14 2012 +0200
+++ b/tools/libxl/xl_cmdtable.c Thu Sep 06 21:36:41 2012 +0200
@@ -70,10 +70,12 @@ struct cmd_spec cmd_table[] = {
{ "reboot",
&main_reboot, 0, 1,
"Issue a reboot signal to a domain",
- "[options] <Domain>",
+ "[options] <-a|Domain>",
+ "-a Reboot all guest domains.\n"
"-h Print this help.\n"
"-F Fallback to ACPI reset event for HVM guests with\n"
" no PV drivers.\n"
+ "-w Wait for guest to reboot.\n"
},
{ "pci-attach",
&main_pciattach, 0, 1,
next prev parent reply other threads:[~2012-09-06 19:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-06 19:41 [PATCH 0 of 3] xl and hotplug: Introduce and use shutdown and reboot xm compatibility options Sander Eikelenboom
2012-09-06 19:41 ` [PATCH 1 of 3] xl: Introduce shutdown xm compatibility option -a Sander Eikelenboom
2012-09-13 16:06 ` Ian Jackson
2012-09-06 19:41 ` Sander Eikelenboom [this message]
2012-09-07 8:57 ` [PATCH 2 of 3] xl: Introduce reboot xm compatibility option -a and -w Ian Campbell
2012-09-06 19:41 ` [PATCH 3 of 3] hotplug: Change options used for shutdown command in xendomains script to be compatible with both xm and xl Sander Eikelenboom
2012-09-13 16:07 ` Ian Jackson
2012-09-25 9:35 ` [PATCH 0 of 3] xl and hotplug: Introduce and use shutdown and reboot xm compatibility options Ian Campbell
2012-09-25 15:11 ` Sander Eikelenboom
2012-09-25 15:29 ` Ian Campbell
2012-09-25 15:47 ` Sander Eikelenboom
2012-09-25 15:49 ` Ian Jackson
2012-09-25 15:56 ` Ian Campbell
2012-09-25 15:48 ` Ian Jackson
2012-09-27 20:11 ` Sander Eikelenboom
2012-10-02 14:02 ` Ian Campbell
2012-10-03 9:03 ` Sander Eikelenboom
2012-10-04 8:35 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=780eae92908a911f63f7.1346960488@xentest.example.org \
--to=linux@eikelenboom.it \
--cc=Ian.Campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).