WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xl: support -w (wait) option in xl shutdown

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] xl: support -w (wait) option in xl shutdown
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 26 Oct 2010 13:02:17 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Tue, 26 Oct 2010 05:03:25 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1288094528 -3600
# Node ID 29aeb30b8488e2a25d38dee16d88b6d9efa72c21
# Parent  1d07e53e60e5414919f76296500bc138ab971f9b
xl: support -w (wait) option in xl shutdown

improves compatibility with xm.

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

diff -r 1d07e53e60e5 -r 29aeb30b8488 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Mon Oct 25 16:55:22 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Tue Oct 26 13:02:08 2010 +0100
@@ -2396,12 +2396,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)
-{
-    int rc;
+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)
@@ -3221,13 +3256,17 @@ int main_shutdown(int argc, char **argv)
 int main_shutdown(int argc, char **argv)
 {
     int opt;
-    char *p;
-
-    while ((opt = getopt(argc, argv, "h")) != -1) {
+    int wait = 0;
+    char *p;
+
+    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;
@@ -3240,7 +3279,7 @@ int main_shutdown(int argc, char **argv)
 
     p = argv[optind];
 
-    shutdown_domain(p);
+    shutdown_domain(p, wait);
     return 0;
 }
 

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

<Prev in Thread] Current Thread [Next in Thread>