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

[Xen-changelog] [xen-unstable] xl: support -w (wait) option in xl shutdown



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1288264608 -3600
# Node ID 902fdaaa1fe6e081bb1d8acbc21ed81931556f4c
# Parent  951222c08589729770af022dd4f5d0ed41bea233
xl: support -w (wait) option in xl shutdown

improves compatibility with xm.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c |   45 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 42 insertions(+), 3 deletions(-)

diff -r 951222c08589 -r 902fdaaa1fe6 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Oct 28 12:15:41 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Thu Oct 28 12:16:48 2010 +0100
@@ -2395,12 +2395,47 @@ static void destroy_domain(char *p)
     if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n.",rc); exit(-1); }
 }
 
-static void shutdown_domain(char *p)
+static void shutdown_domain(char *p, int wait)
 {
     int rc;
+
     find_domain(p);
     rc=libxl_domain_shutdown(&ctx, domid, 0);
     if (rc) { fprintf(stderr,"shutdown failed (rc=%d)\n.",rc);exit(-1); }
+
+    if (wait) {
+        libxl_waiter waiter;
+        int fd;
+
+        libxl_wait_for_domain_death(&ctx, domid, &waiter);
+
+        libxl_get_wait_fd(&ctx, &fd);
+
+        while (wait) {
+            fd_set rfds;
+            libxl_event event;
+            libxl_dominfo info;
+
+            FD_ZERO(&rfds);
+            FD_SET(fd, &rfds);
+
+            if (!select(fd + 1, &rfds, NULL, NULL, NULL))
+                continue;
+
+            libxl_get_event(&ctx, &event);
+
+            if (event.type == LIBXL_EVENT_DOMAIN_DEATH) {
+                if (libxl_event_get_domain_death_info(&ctx, domid, &event, 
&info) < 0)
+                    continue;
+
+                LOG("Domain %d is dead", domid);
+                wait = 0;
+            }
+
+            libxl_free_event(&event);
+        }
+        libxl_free_waiter(&waiter);
+    }
 }
 
 static void reboot_domain(char *p)
@@ -3220,13 +3255,17 @@ int main_shutdown(int argc, char **argv)
 int main_shutdown(int argc, char **argv)
 {
     int opt;
+    int wait = 0;
     char *p;
 
-    while ((opt = getopt(argc, argv, "h")) != -1) {
+    while ((opt = getopt(argc, argv, "hw")) != -1) {
         switch (opt) {
         case 'h':
             help("shutdown");
             return 0;
+        case 'w':
+            wait = 1;
+            break;
         default:
             fprintf(stderr, "option not supported\n");
             break;
@@ -3239,7 +3278,7 @@ int main_shutdown(int argc, char **argv)
 
     p = argv[optind];
 
-    shutdown_domain(p);
+    shutdown_domain(p, wait);
     return 0;
 }
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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