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 8 of 9] libxl: add libxl_domain_preserve

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 8 of 9] libxl: add libxl_domain_preserve
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 27 Jul 2010 11:13:50 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Tue, 27 Jul 2010 03:23:43 -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 d9b5f51a54caa8430b8ea80938ee87eccaed2e37
# Parent  1c1b0c8bb58c78dd60f8e79b00c2bf664ea41725
libxl: add libxl_domain_preserve

This method is intended to preserve an existing domain (for debugging
purposes) in such a way that the domain can also be restarted.

There is likely to be more required to achieve this aim than the
function currently does.

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

diff -r 1c1b0c8bb58c -r d9b5f51a54ca tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Jul 27 11:11:38 2010 +0100
+++ b/tools/libxl/libxl.c       Tue Jul 27 11:11:38 2010 +0100
@@ -399,6 +399,61 @@ int libxl_domain_resume(struct libxl_ctx
                         domid);
         return ERROR_FAIL;
     }
+    return 0;
+}
+
+/*
+ * Preserves a domain but rewrites xenstore etc to make it unique so
+ * that the domain can be restarted.
+ *
+ * Does not modify info so that it may be reused.
+ */
+int libxl_domain_preserve(struct libxl_ctx *ctx, uint32_t domid,
+                          libxl_domain_create_info *info, const char 
*name_suffix, uint8_t new_uuid[16])
+{
+    struct xs_permissions roperm[2];
+    xs_transaction_t t;
+    char *preserved_name;
+    char *uuid_string;
+    char *vm_path;
+    char *dom_path;
+
+    int rc;
+
+    preserved_name = libxl_sprintf(ctx, "%s%s", info->name, name_suffix);
+    if (!preserved_name) return ERROR_NOMEM;
+
+    uuid_string = libxl_uuid2string(ctx, new_uuid);
+    if (!uuid_string) return ERROR_NOMEM;
+
+    dom_path = libxl_xs_get_dompath(ctx, domid);
+    if (!dom_path) return ERROR_FAIL;
+
+    vm_path = libxl_sprintf(ctx, "/vm/%s", uuid_string);
+    if (!vm_path) return ERROR_FAIL;
+
+    roperm[0].id = 0;
+    roperm[0].perms = XS_PERM_NONE;
+    roperm[1].id = domid;
+    roperm[1].perms = XS_PERM_READ;
+
+ retry_transaction:
+    t = xs_transaction_start(ctx->xsh);
+
+    xs_rm(ctx->xsh, t, vm_path);
+    xs_mkdir(ctx->xsh, t, vm_path);
+    xs_set_permissions(ctx->xsh, t, vm_path, roperm, ARRAY_SIZE(roperm));
+
+    xs_write(ctx->xsh, t, libxl_sprintf(ctx, "%s/vm", dom_path), vm_path, 
strlen(vm_path));
+    rc = libxl_domain_rename(ctx, domid, info->name, preserved_name, t);
+    if (rc) return rc;
+
+    xs_write(ctx->xsh, t, libxl_sprintf(ctx, "%s/uuid", vm_path), uuid_string, 
strlen(uuid_string));
+
+    if (!xs_transaction_end(ctx->xsh, t, 0))
+        if (errno == EAGAIN)
+            goto retry_transaction;
+
     return 0;
 }
 
diff -r 1c1b0c8bb58c -r d9b5f51a54ca tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Tue Jul 27 11:11:38 2010 +0100
+++ b/tools/libxl/libxl.h       Tue Jul 27 11:11:38 2010 +0100
@@ -338,6 +338,7 @@ int libxl_domain_resume(struct libxl_ctx
 int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req);
 int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
+int libxl_domain_preserve(struct libxl_ctx *ctx, uint32_t domid, 
libxl_domain_create_info *info, const char *name_suffix, uint8_t new_uuid[16]);
 
 int libxl_file_reference_map(struct libxl_ctx *ctx, libxl_file_reference *f);
 int libxl_file_reference_unmap(struct libxl_ctx *ctx, libxl_file_reference *f);

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