[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/3] libxl: extract the qemu state file from the save image



Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 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


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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.