From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 5 of 9] libxl: add libxl_domain_preserve
Date: Mon, 26 Jul 2010 11:56:49 +0100 [thread overview]
Message-ID: <85b50d34d7cc8a70c083.1280141809@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1280141804@localhost.localdomain>
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1280140563 -3600
# Node ID 85b50d34d7cc8a70c083c0acdc4c2e7ead675029
# Parent 982bf44850029802b7395a03659bf440d191be2f
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@citrix.com>
diff -r 982bf4485002 -r 85b50d34d7cc tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Mon Jul 26 11:36:03 2010 +0100
+++ b/tools/libxl/libxl.c Mon Jul 26 11:36:03 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 982bf4485002 -r 85b50d34d7cc tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Mon Jul 26 11:36:03 2010 +0100
+++ b/tools/libxl/libxl.h Mon Jul 26 11:36:03 2010 +0100
@@ -340,6 +340,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);
next prev parent reply other threads:[~2010-07-26 10:56 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-26 10:56 [PATCH 0 of 9] xl: handle domain shutdown/reboot/crash in a user configurable way Ian Campbell
2010-07-26 10:56 ` [PATCH 1 of 9] libxl: Add LIBXL_EVENT namespace to enum libxl_event_type Ian Campbell
2010-07-26 10:56 ` [PATCH 2 of 9] libxl: return libxl_dominfo from libxl_event_get_domain_death_info Ian Campbell
2010-07-26 14:32 ` Stefano Stabellini
2010-07-26 14:38 ` Ian Campbell
2010-07-26 14:59 ` Stefano Stabellini
2010-07-26 15:26 ` Ian Jackson
2010-07-26 15:31 ` Ian Campbell
2010-07-26 15:36 ` Ian Jackson
2010-07-26 15:34 ` Stefano Stabellini
2010-07-26 15:41 ` Ian Jackson
2010-07-26 16:23 ` Stefano Stabellini
2010-07-26 16:38 ` Ian Jackson
2010-07-27 9:22 ` Ian Campbell
2010-07-27 9:53 ` Stefano Stabellini
2010-07-26 10:56 ` [PATCH 3 of 9] libxl: signal caller if domain already destroyed on domain death event Ian Campbell
2010-07-26 14:32 ` Stefano Stabellini
2010-07-26 14:41 ` Ian Campbell
2010-07-26 14:58 ` Stefano Stabellini
2010-07-26 15:02 ` Ian Campbell
2010-07-26 15:08 ` Stefano Stabellini
2010-07-26 10:56 ` [PATCH 4 of 9] libxl: should consider shutdown_reason for dying as well as shutdown domains Ian Campbell
2010-07-26 10:56 ` Ian Campbell [this message]
2010-07-26 15:30 ` [PATCH 5 of 9] libxl: add libxl_domain_preserve Ian Jackson
2010-07-26 15:56 ` Ian Campbell
2010-07-26 10:56 ` [PATCH 6 of 9] xl: do not try and auto re-connect console on reboot Ian Campbell
2010-07-26 10:56 ` [PATCH 7 of 9] xl: Add function to generate random uuid and use it Ian Campbell
2010-07-26 10:56 ` [PATCH 8 of 9] xl: Factor out domain death handling into a separate function Ian Campbell
2010-07-26 10:56 ` [PATCH 9 of 9] xl: support on_{poweroff, reboot, crash} domain configuration options Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=85b50d34d7cc8a70c083.1280141809@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).