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

[Xen-devel] [PATCH 3 of 5] xl: Add --wait and --all to xl reboot



# HG changeset patch
# User Ian Campbell <ijc@xxxxxxxxxxxxxx>
# Date 1350295718 -3600
# Node ID 5a24315f39c035e5e5b773ebca676d5248a41252
# Parent  2329dca4ef449979b1403c4bb002fcb70c578b35
xl: Add --wait and --all to xl reboot.

Inspired by a patch by Sander Eikelenboom.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 2329dca4ef44 -r 5a24315f39c0 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Sep 06 21:41:27 2012 +0200
+++ b/tools/libxl/xl_cmdimpl.c  Mon Oct 15 11:08:38 2012 +0100
@@ -2716,7 +2716,7 @@ static void destroy_domain(uint32_t domi
 static void wait_for_domain_deaths(libxl_evgen_domain_death **deathws, int nr)
 {
     int rc, count = 0;
-    LOG("Waiting for %d domains to shutdown", nr);
+    LOG("Waiting for %d domains", nr);
     while(1 && count < nr) {
         libxl_event *event;
         rc = libxl_event_wait(ctx, &event, LIBXL_EVENTMASK_ALL, 0,0);
@@ -2776,15 +2776,15 @@ static void shutdown_domain(uint32_t dom
             fprintf(stderr,"wait for death failed (evgen, rc=%d)\n",rc);
             exit(-1);
         }
-        printf("Waiting for domain %d death %p %"PRIx64"\n",
-               domid, *deathw, for_user);
-    }
-}
-
-static void reboot_domain(uint32_t domid, int fallback_trigger)
+    }
+}
+
+static void reboot_domain(uint32_t domid, libxl_evgen_domain_death **deathw,
+                          libxl_ev_user for_user, int fallback_trigger)
 {
     int rc;
 
+    fprintf(stderr, "Rebooting domain %d\n", domid);
     rc=libxl_domain_reboot(ctx, domid);
     if (rc == ERROR_NOPARAVIRT) {
         if (fallback_trigger) {
@@ -2800,6 +2800,14 @@ static void reboot_domain(uint32_t domid
     if (rc) {
         fprintf(stderr,"reboot failed (rc=%d)\n",rc);exit(-1);
     }
+
+    if (deathw) {
+        rc = libxl_evenable_domain_death(ctx, domid, for_user, deathw);
+        if (rc) {
+            fprintf(stderr,"wait for death failed (evgen, rc=%d)\n",rc);
+            exit(-1);
+        }
+    }
 }
 
 static void list_domains_details(const libxl_dominfo *info, int nb_domain)
@@ -3713,8 +3721,11 @@ int main_destroy(int argc, char **argv)
     return 0;
 }
 
-int main_shutdown(int argc, char **argv)
-{
+static int main_shutdown_or_reboot(int reboot, int argc, char **argv)
+{
+    void (*fn)(uint32_t domid,
+               libxl_evgen_domain_death **, libxl_ev_user, int) =
+        reboot ? &reboot_domain : &shutdown_domain;
     int opt, i, nb_domain;
     int wait_for_it = 0, all =0;
     int fallback_trigger = 0;
@@ -3730,6 +3741,7 @@ int main_shutdown(int argc, char **argv)
             return opt;
         case 'a':
             all = 1;
+            break;
         case 'w':
             wait_for_it = 1;
             break;
@@ -3758,9 +3770,8 @@ int main_shutdown(int argc, char **argv)
         for (i = 0; i<nb_domain; i++) {
             if (dominfo[i].domid == 0)
                 continue;
-            shutdown_domain(dominfo[i].domid,
-                            deathws ? &deathws[i] : NULL, i,
-                            fallback_trigger);
+            fn(dominfo[i].domid, deathws ? &deathws[i] : NULL, i,
+               fallback_trigger);
         }
 
         wait_for_domain_deaths(deathws, nb_domain - 1 /* not dom 0 */);
@@ -3769,8 +3780,7 @@ int main_shutdown(int argc, char **argv)
         libxl_evgen_domain_death *deathw = NULL;
         uint32_t domid = find_domain(argv[optind]);
 
-        shutdown_domain(domid, wait_for_it ? &deathw : NULL, 0,
-                        fallback_trigger);
+        fn(domid, wait_for_it ? &deathw : NULL, 0, fallback_trigger);
 
         if (wait_for_it)
             wait_for_domain_deaths(&deathw, 1);
@@ -3780,23 +3790,14 @@ int main_shutdown(int argc, char **argv)
     return 0;
 }
 
+int main_shutdown(int argc, char **argv)
+{
+    return main_shutdown_or_reboot(0, argc, argv);
+}
+
 int main_reboot(int argc, char **argv)
 {
-    int opt;
-    int fallback_trigger = 0;
-
-    while ((opt = def_getopt(argc, argv, "F", "reboot", 1)) != -1) {
-        switch (opt) {
-        case 0: case 2:
-            return opt;
-        case 'F':
-            fallback_trigger = 1;
-            break;
-        }
-    }
-
-    reboot_domain(find_domain(argv[optind]), fallback_trigger);
-    return 0;
+    return main_shutdown_or_reboot(1, argc, argv);
 }
 
 int main_list(int argc, char **argv)
diff -r 2329dca4ef44 -r 5a24315f39c0 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Thu Sep 06 21:41:27 2012 +0200
+++ b/tools/libxl/xl_cmdtable.c Mon Oct 15 11:08:38 2012 +0100
@@ -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, --all               Shutdown 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              Wait for guest(s) to reboot.\n"
     },
     { "pci-attach",
       &main_pciattach, 0, 1,

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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