All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Wei Liu <wei.liu2@citrix.com>
Subject: [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor
Date: Mon, 16 Apr 2018 18:32:24 +0100	[thread overview]
Message-ID: <20180416173227.22671-7-anthony.perard@citrix.com> (raw)
In-Reply-To: <20180416173227.22671-1-anthony.perard@citrix.com>

In case QEMU have restricted access to the system, open the file for it,
and QEMU will save its state to this file descritor.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libxl/libxl_qmp.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 28bc2cabcd..3bb0f28bea 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -989,25 +989,61 @@ int libxl__qmp_system_wakeup(libxl__gc *gc, int domid)
     return qmp_run_command(gc, domid, "system_wakeup", NULL, NULL, NULL);
 }
 
+/* Find out which fdset have been allocated */
+static int qmp_fdset_add_fd_callback(libxl__qmp_handler *qmp,
+                                     const libxl__json_object *ret,
+                                     void *opaque)
+{
+    const libxl__json_object *o;
+    int fdset;
+
+    o = libxl__json_map_get("fdset-id", ret, JSON_INTEGER);
+    if (!o)
+        return 1;
+
+    fdset = libxl__json_object_get_integer(o);
+    *(int*)opaque = fdset;
+    return 0;
+}
+
 int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename, bool live)
 {
     libxl__json_object *args = NULL;
     libxl__qmp_handler *qmp = NULL;
     int rc;
+    int state_fd;
+    int new_fdset;
 
     qmp = libxl__qmp_initialize(gc, domid);
     if (!qmp)
         return ERROR_FAIL;
 
-    qmp_parameters_add_string(gc, &args, "filename", (char *)filename);
+    state_fd = open(filename, O_WRONLY | O_CREAT, 0600);
+    if (state_fd < 0) {
+        LOGED(ERROR, domid,
+              "Failed to open file %s for QEMU", filename);
+        goto out;
+    }
+
+    qmp->fd_to_send = state_fd;
+
+    rc = qmp_synchronous_send(qmp, "add-fd", NULL,
+                              qmp_fdset_add_fd_callback, &new_fdset,
+                              qmp->timeout);
+    if (rc)
+        goto out;
 
     /* live parameter was added to QEMU 2.11. It signal QEMU that the save
      * operation is for a live migration rather that for taking a snapshot. */
     if (qmp_qemu_check_version(qmp, 2, 11, 0))
         qmp_parameters_add_bool(gc, &args, "live", live);
 
+    QMP_PARAMETERS_SPRINTF(&args, "filename", "/dev/fdset/%d", new_fdset);
     rc = qmp_synchronous_send(qmp, "xen-save-devices-state", args,
                               NULL, NULL, qmp->timeout);
+out:
+    if (state_fd >= 0)
+        close(state_fd);
     libxl__qmp_close(qmp);
     return rc;
 }
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-04-16 17:32 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 17:32 [RFC v2 0/9] libxl: Enable save/restore/migration of a restricted QEMU Anthony PERARD
2018-04-16 17:32 ` [RFC v2 1/9] libxl_event: Fix DEBUG prints Anthony PERARD
2018-04-19  8:17   ` Wei Liu
2018-04-19 11:01     ` Anthony PERARD
2018-04-16 17:32 ` [RFC v2 2/9] libxl_qmp: Documentation of the logic of the QMP client Anthony PERARD
2018-04-19  8:19   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 3/9] libxl_qmp: Fix use of DEBUG_RECEIVED Anthony PERARD
2018-04-19  8:22   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 4/9] libxl_qmp: Move the buffer realloc to the same scope level as read Anthony PERARD
2018-04-23  9:03   ` Wei Liu
2018-04-23 14:50     ` Anthony PERARD
2018-04-23 15:01       ` Wei Liu
2018-04-16 17:32 ` [RFC v2 5/9] libxl: Learned to send FD through QMP to QEMU Anthony PERARD
2018-04-23  9:04   ` Wei Liu
2018-04-16 17:32 ` Anthony PERARD [this message]
2018-04-23  9:20   ` [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor Wei Liu
2018-04-23 15:45     ` Anthony PERARD
2018-04-24  9:37       ` Wei Liu
2018-04-24  9:46   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 7/9] libxl_qmp: Implement query-status command Anthony PERARD
2018-04-23  9:24   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 8/9] HACK libxl_exec: Check QEMU status via QMP instead of xenstore Anthony PERARD
2018-04-16 18:09   ` Anthony PERARD
2018-04-17  9:18   ` Anthony PERARD
2018-04-20 18:37   ` Ian Jackson
2018-04-23 16:54     ` Anthony PERARD
2018-04-23 16:56       ` Ian Jackson
2018-04-16 17:32 ` [RFC v2 9/9] libxl_qmp: Add a warning to not trust QEMU Anthony PERARD

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=20180416173227.22671-7-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.