From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 2/3] libxl: extract the qemu state file from the save image
Date: Thu, 19 Jan 2012 12:13:00 +0000 [thread overview]
Message-ID: <1326975184-458-2-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1201191204370.3150@kaball-desktop>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
tools/libxl/libxl_dm.c | 5 +++++
tools/libxl/libxl_dom.c | 42 +++++++++++++++++++++++++++++++++++++++++-
tools/libxl/libxl_internal.h | 1 +
3 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 97d91b4..3f19150 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -41,6 +41,11 @@ const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid)
return libxl__sprintf(gc, "/var/lib/xen/qemu-save.%d", domid);
}
+const char *libxl__device_model_restorefile(libxl__gc *gc, uint32_t domid)
+{
+ return libxl__sprintf(gc, "/var/lib/xen/qemu-resume.%d", domid);
+}
+
const char *libxl__domain_device_model(libxl__gc *gc,
libxl_device_model_info *info)
{
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index fd2b051..f33e572 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -347,6 +347,40 @@ out:
return rc;
}
+struct restore_callbacks_arg {
+ libxl__gc *gc;
+ uint32_t domid;
+};
+
+static int libxl__domain_restore_device_model(uint8_t *buf, uint32_t size,
+ void *data)
+{
+ struct restore_callbacks_arg *arg = data;
+ libxl__gc *gc = (libxl__gc *)arg->gc;
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+ uint32_t domid = arg->domid;
+ int fd2 = -1, ret = 0;
+ const char *filename;
+
+ filename = libxl__device_model_restorefile(gc, domid);
+ fd2 = open(filename, O_WRONLY|O_CREAT);
+ if (fd2 < 0) {
+ ret = fd2;
+ goto out;
+ }
+
+ ret = libxl_write_exactly(
+ ctx, fd2, buf, size, "saved-state file", "qemu state");
+ if (ret)
+ goto out;
+ ret = 0;
+
+out:
+ if (fd2 > 0)
+ close(fd2);
+ return ret;
+}
+
int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info,
libxl__domain_build_state *state,
@@ -356,11 +390,17 @@ int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid,
/* read signature */
int rc;
int hvm, pae, superpages;
+ struct restore_callbacks callbacks;
+ struct restore_callbacks_arg arg;
switch (info->type) {
case LIBXL_DOMAIN_TYPE_HVM:
hvm = 1;
superpages = 1;
pae = info->u.hvm.pae;
+ arg.domid = domid;
+ arg.gc = gc;
+ callbacks.extract_qemu_savestate = libxl__domain_restore_device_model;
+ callbacks.data = &arg;
break;
case LIBXL_DOMAIN_TYPE_PV:
hvm = 0;
@@ -373,7 +413,7 @@ int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid,
rc = xc_domain_restore(ctx->xch, fd, domid,
state->store_port, &state->store_mfn,
state->console_port, &state->console_mfn,
- hvm, pae, superpages, NULL);
+ hvm, pae, superpages, &callbacks);
if ( rc ) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "restoring domain");
return ERROR_FAIL;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index fa7fb16..7f7578a 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -247,6 +247,7 @@ _hidden int libxl__domain_suspend_common(libxl__gc *gc, uint32_t domid, int fd,
libxl_domain_type type,
int live, int debug);
_hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid);
+_hidden const char *libxl__device_model_restorefile(libxl__gc *gc, uint32_t domid);
_hidden int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd);
_hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
--
1.7.2.5
next prev parent reply other threads:[~2012-01-19 12:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-19 12:12 [PATCH 0/3] libxl: save additional info to the qemu chunk Stefano Stabellini
2012-01-19 12:12 ` [PATCH 1/3] libxc: add a callback to xc_domain_restore Stefano Stabellini
2012-01-19 12:13 ` Stefano Stabellini [this message]
2012-01-19 12:13 ` [PATCH 3/3] libxl: introduce QEMU_HEADER Stefano Stabellini
2012-01-19 12:24 ` Ian Campbell
2012-01-19 13:00 ` Stefano Stabellini
2012-01-19 12:13 ` [PATCH 1/3] libxc: add a callback to xc_domain_restore Stefano Stabellini
2012-01-19 12:13 ` [PATCH 2/3] libxl: extract the qemu state file from the save image Stefano Stabellini
2012-01-19 12:13 ` [PATCH 3/3] libxl: introduce QEMU_HEADER Stefano Stabellini
2012-01-19 12:25 ` [PATCH 0/3] libxl: save additional info to the qemu chunk Ian Campbell
2012-01-19 14:00 ` Stefano Stabellini
2012-01-19 14:01 ` Ian Campbell
2012-01-19 14:06 ` Stefano Stabellini
2012-01-19 14:09 ` 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=1326975184-458-2-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.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).