xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 1/3] libxc: add a callback to xc_domain_restore
Date: Thu, 19 Jan 2012 12:12:59 +0000	[thread overview]
Message-ID: <1326975184-458-1-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1201191204370.3150@kaball-desktop>

Introduce a callback argument to xc_domain_restore, so that the caller
can restore the Qemu state file by itself.
If the callback is NULL, libxc will take care of dumping the qemu
state file as usual.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/libxc/xc_domain_restore.c |   19 ++++++++++++++-----
 tools/libxc/xenguest.h          |   17 ++++++++++++++---
 tools/libxl/libxl_dom.c         |    2 +-
 tools/xcutils/xc_restore.c      |    3 ++-
 4 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c
index 14451d1..fdc3483 100644
--- a/tools/libxc/xc_domain_restore.c
+++ b/tools/libxc/xc_domain_restore.c
@@ -1248,7 +1248,8 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
 int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
                       unsigned int store_evtchn, unsigned long *store_mfn,
                       unsigned int console_evtchn, unsigned long *console_mfn,
-                      unsigned int hvm, unsigned int pae, int superpages)
+                      unsigned int hvm, unsigned int pae, int superpages,
+                      struct restore_callbacks* callbacks)
 {
     DECLARE_DOMCTL;
     int rc = 1, frc, i, j, n, m, pae_extended_cr3 = 0, ext_vcpucontext = 0;
@@ -1976,10 +1977,18 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
     goto out;
 
   finish_hvm:
-    /* Dump the QEMU state to a state file for QEMU to load */
-    if ( dump_qemu(xch, dom, &tailbuf.u.hvm) ) {
-        PERROR("Error dumping QEMU state to file");
-        goto out;
+    if (callbacks == NULL || callbacks->extract_qemu_savestate == NULL) {
+        /* Dump the QEMU state to a state file for QEMU to load */
+        if ( dump_qemu(xch, dom, &tailbuf.u.hvm) ) {
+            PERROR("Error dumping QEMU state to file");
+            goto out;
+        }
+    } else {
+        if ( callbacks->extract_qemu_savestate(tailbuf.u.hvm.qemubuf,
+                    tailbuf.u.hvm.qemubufsize, callbacks->data) ) {
+            PERROR("Error calling extract_qemu_savestate");
+            goto out;
+        }
     }
 
     /* These comms pages need to be zeroed at the start of day */
diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h
index 4475ee9..9447412 100644
--- a/tools/libxc/xenguest.h
+++ b/tools/libxc/xenguest.h
@@ -61,6 +61,15 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
                    struct save_callbacks* callbacks, int hvm);
 
 
+/* callbacks provided by xc_domain_restore */
+struct restore_callbacks {
+    /* callback to extract the qemu save state */
+    int (*extract_qemu_savestate)(uint8_t *buf, uint32_t size, void* data);
+
+    /* to be provided as the last argument to each callback function */
+    void* data;
+};
+
 /**
  * This function will restore a saved domain.
  *
@@ -72,15 +81,17 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
  * @parm hvm non-zero if this is a HVM restore
  * @parm pae non-zero if this HVM domain has PAE support enabled
  * @parm superpages non-zero to allocate guest memory with superpages
+ * @parm callbacks non-NULL to receive a callback to extract the qemu state
  * @return 0 on success, -1 on failure
  */
 int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
                       unsigned int store_evtchn, unsigned long *store_mfn,
                       unsigned int console_evtchn, unsigned long *console_mfn,
-                      unsigned int hvm, unsigned int pae, int superpages);
+                      unsigned int hvm, unsigned int pae, int superpages,
+                      struct restore_callbacks *callbacks);
 /**
- * xc_domain_restore writes a file to disk that contains the device
- * model saved state.
+ * If callbacks is NULL, xc_domain_restore writes a file to disk that
+ * contains the device model saved state.
  * The pathname of this file is XC_DEVICE_MODEL_RESTORE_FILE; The domid
  * of the new domain is automatically appended to the filename,
  * separated by a ".".
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index c898d89..fd2b051 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -373,7 +373,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);
+                           hvm, pae, superpages, NULL);
     if ( rc ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "restoring domain");
         return ERROR_FAIL;
diff --git a/tools/xcutils/xc_restore.c b/tools/xcutils/xc_restore.c
index 985cbec..eb1d31c 100644
--- a/tools/xcutils/xc_restore.c
+++ b/tools/xcutils/xc_restore.c
@@ -46,7 +46,8 @@ main(int argc, char **argv)
 	    superpages = !!hvm;
 
     ret = xc_domain_restore(xch, io_fd, domid, store_evtchn, &store_mfn,
-                            console_evtchn, &console_mfn, hvm, pae, superpages);
+                            console_evtchn, &console_mfn, hvm, pae, superpages,
+                            NULL);
 
     if ( ret == 0 )
     {
-- 
1.7.2.5

  reply	other threads:[~2012-01-19 12:12 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 ` Stefano Stabellini [this message]
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: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-1-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).