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 9 of 9] xl: implement "rename-restart" action for shu

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 9 of 9] xl: implement "rename-restart" action for shutdown
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 27 Jul 2010 11:13:51 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Tue, 27 Jul 2010 03:24:52 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1280225622@xxxxxxxxxxxxxxxxxxxxx>
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 1280225498 -3600
# Node ID 519187e3e2b1bbeb244d64d79153e350ca3ba0bf
# Parent  d9b5f51a54caa8430b8ea80938ee87eccaed2e37
xl: implement "rename-restart" action for shutdown

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

diff -r d9b5f51a54ca -r 519187e3e2b1 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue Jul 27 11:11:38 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Tue Jul 27 11:11:38 2010 +0100
@@ -104,6 +104,7 @@ enum action_on_shutdown {
     ACTION_DESTROY,
 
     ACTION_RESTART,
+    ACTION_RESTART_RENAME,
 
     ACTION_PRESERVE,
 
@@ -115,6 +116,7 @@ static char *action_on_shutdown_names[] 
     [ACTION_DESTROY] = "destroy",
 
     [ACTION_RESTART] = "restart",
+    [ACTION_RESTART_RENAME] = "rename-restart",
 
     [ACTION_PRESERVE] = "preserve",
 
@@ -1064,7 +1066,7 @@ int autoconnect_console(int hvm)
     _exit(1);
 }
 
-/* Returns 1 if domain should be restarted */
+/* Returns 1 if domain should be restarted, 2 if domain should be renamed then 
restarted  */
 static int handle_domain_death(struct libxl_ctx *ctx, uint32_t domid, 
libxl_event *event,
                                libxl_domain_create_info *c_info,
                                struct domain_config *d_config, struct 
libxl_dominfo *info)
@@ -1112,6 +1114,10 @@ static int handle_domain_death(struct li
 
     switch (action) {
     case ACTION_PRESERVE:
+        break;
+
+    case ACTION_RESTART_RENAME:
+        restart = 2;
         break;
 
     case ACTION_RESTART:
@@ -1129,6 +1135,43 @@ static int handle_domain_death(struct li
     }
 
     return restart;
+}
+
+static int preserve_domain(struct libxl_ctx *ctx, uint32_t domid, libxl_event 
*event,
+                           libxl_domain_create_info *c_info,
+                           struct domain_config *d_config, struct 
libxl_dominfo *info)
+{
+    time_t now;
+    struct tm tm;
+    char stime[24];
+
+    uint8_t new_uuid[16];
+
+    int rc;
+
+    now = time(NULL);
+    if (now == ((time_t) -1)) {
+        LOG("Failed to get current time for domain rename");
+        return 0;
+    }
+
+    tzset();
+    if (gmtime_r(&now, &tm) == NULL) {
+        LOG("Failed to convert time to UTC");
+        return 0;
+    }
+
+    if (!strftime(&stime[0], sizeof(stime), "-%Y%m%dT%H%MZ", &tm)) {
+        LOG("Failed to format time as a string");
+        return 0;
+    }
+
+    random_uuid(&new_uuid[0]);
+
+    LOG("Preserving domain %d %s with suffix%s", domid, c_info->name, stime);
+    rc = libxl_domain_preserve(ctx, domid, c_info, stime, new_uuid);
+
+    return rc == 0 ? 1 : 0;
 }
 
 struct domain_create {
@@ -1502,7 +1545,15 @@ start:
                 LOG("Domain %d is dead", domid);
 
                 if (ret) {
-                    if (handle_domain_death(&ctx, domid, &event, &c_info, 
&d_config, &info)) {
+                    switch (handle_domain_death(&ctx, domid, &event, &c_info, 
&d_config, &info)) {
+                    case 2:
+                        if (!preserve_domain(&ctx, domid, &event, &c_info, 
&d_config, &info))
+                            /* If we fail then exit leaving the old domain in 
place. */
+                            exit(-1);
+
+                        /* Otherwise fall through and restart. */
+                    case 1:
+
                         libxl_free_waiter(w1);
                         libxl_free_waiter(w2);
                         free(w1);
@@ -1514,9 +1565,10 @@ start:
                         LOG("Done. Rebooting now");
                         sleep(2);
                         goto start;
+                    case 0:
+                        LOG("Done. Exiting now");
+                        exit(0);
                     }
-                    LOG("Done. Exiting now");
-                    exit(0);
                 }
                 break;
             case LIBXL_EVENT_DISK_EJECT:

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