xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jason Andryuk <jandryuk@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: "Wei Liu" <wl@xen.org>, "Jason Andryuk" <jandryuk@gmail.com>,
	"Ian Jackson" <ian.jackson@eu.citrix.com>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>,
	"Anthony PERARD" <anthony.perard@citrix.com>,
	"Ian Jackson" <ian.jackson@citrix.com>
Subject: [PATCH v7 10/19] libxl: add save/restore support for qemu-xen in stubdomain
Date: Mon, 18 May 2020 21:54:54 -0400	[thread overview]
Message-ID: <20200519015503.115236-11-jandryuk@gmail.com> (raw)
In-Reply-To: <20200519015503.115236-1-jandryuk@gmail.com>

From: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

Rely on a wrapper script in stubdomain to attach relevant consoles to
qemu.  The save console (1) must be attached to fdset/1.  When
performing a restore, $STUBDOM_RESTORE_INCOMING_ARG must be replaced on
the qemu command line by "fd:$FD", where $FD is an open file descriptor
number to the restore console (2).

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

Address TODO in dm_state_save_to_fdset: Only remove savefile for
non-stubdom.
Use $STUBDOM_RESTORE_INCOMING_ARG instead of fd:3 and update commit
message.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
Changes in v3:
 - adjust for qmp_ev*
 - assume specific fdset id in qemu set in stubdomain
Changes in v5:
 - Only remove savefile for non-stubdom
Changes in v6:
 - Replace hardcoded fd:3 with placeholder $STUBDOM_RESTORE_INCOMING_ARG
Changes in v7
 - Added Acked-by: Ian Jackson
---
 tools/libxl/libxl_dm.c  | 25 +++++++++++++------------
 tools/libxl/libxl_qmp.c | 27 +++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 23b13f84d2..62d0d46c98 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1745,10 +1745,19 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
     }
 
     if (state->saved_state) {
-        /* This file descriptor is meant to be used by QEMU */
-        *dm_state_fd = open(state->saved_state, O_RDONLY);
-        flexarray_append(dm_args, "-incoming");
-        flexarray_append(dm_args, GCSPRINTF("fd:%d",*dm_state_fd));
+        if (is_stubdom) {
+            /* Linux stubdomain must replace $STUBDOM_RESTORE_INCOMING_ARG
+             * with the approriate fd:$num argument for the
+             * STUBDOM_CONSOLE_RESTORE console 2.
+             */
+            flexarray_append(dm_args, "-incoming");
+            flexarray_append(dm_args, "$STUBDOM_RESTORE_INCOMING_ARG");
+        } else {
+            /* This file descriptor is meant to be used by QEMU */
+            *dm_state_fd = open(state->saved_state, O_RDONLY);
+            flexarray_append(dm_args, "-incoming");
+            flexarray_append(dm_args, GCSPRINTF("fd:%d",*dm_state_fd));
+        }
     }
     for (i = 0; b_info->extra && b_info->extra[i] != NULL; i++)
         flexarray_append(dm_args, b_info->extra[i]);
@@ -2227,14 +2236,6 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
 
     assert(libxl_defbool_val(guest_config->b_info.device_model_stubdomain));
 
-    if (libxl__stubdomain_is_linux(&guest_config->b_info)) {
-        if (d_state->saved_state) {
-            LOG(ERROR, "Save/Restore not supported yet with Linux Stubdom.");
-            ret = -1;
-            goto out;
-        }
-    }
-
     sdss->pvqemu.guest_domid = INVALID_DOMID;
 
     libxl_domain_create_info_init(&dm_config->c_info);
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index efaba91086..c394000ea9 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -962,6 +962,7 @@ static void dm_stopped(libxl__egc *egc, libxl__ev_qmp *ev,
                        const libxl__json_object *response, int rc);
 static void dm_state_fd_ready(libxl__egc *egc, libxl__ev_qmp *ev,
                               const libxl__json_object *response, int rc);
+static void dm_state_save_to_fdset(libxl__egc *egc, libxl__ev_qmp *ev, int fdset);
 static void dm_state_saved(libxl__egc *egc, libxl__ev_qmp *ev,
                            const libxl__json_object *response, int rc);
 
@@ -994,10 +995,17 @@ static void dm_stopped(libxl__egc *egc, libxl__ev_qmp *ev,
     EGC_GC;
     libxl__domain_suspend_state *dsps = CONTAINER_OF(ev, *dsps, qmp);
     const char *const filename = dsps->dm_savefile;
+    uint32_t dm_domid = libxl_get_stubdom_id(CTX, dsps->domid);
 
     if (rc)
         goto error;
 
+    if (dm_domid) {
+        /* see Linux stubdom interface in docs/stubdom.txt */
+        dm_state_save_to_fdset(egc, ev, 1);
+        return;
+    }
+
     ev->payload_fd = open(filename, O_WRONLY | O_CREAT, 0600);
     if (ev->payload_fd < 0) {
         LOGED(ERROR, ev->domid,
@@ -1028,7 +1036,6 @@ static void dm_state_fd_ready(libxl__egc *egc, libxl__ev_qmp *ev,
     EGC_GC;
     int fdset;
     const libxl__json_object *o;
-    libxl__json_object *args = NULL;
     libxl__domain_suspend_state *dsps = CONTAINER_OF(ev, *dsps, qmp);
 
     close(ev->payload_fd);
@@ -1043,6 +1050,21 @@ static void dm_state_fd_ready(libxl__egc *egc, libxl__ev_qmp *ev,
         goto error;
     }
     fdset = libxl__json_object_get_integer(o);
+    dm_state_save_to_fdset(egc, ev, fdset);
+    return;
+
+error:
+    assert(rc);
+    libxl__remove_file(gc, dsps->dm_savefile);
+    dsps->callback_device_model_done(egc, dsps, rc);
+}
+
+static void dm_state_save_to_fdset(libxl__egc *egc, libxl__ev_qmp *ev, int fdset)
+{
+    EGC_GC;
+    int rc;
+    libxl__json_object *args = NULL;
+    libxl__domain_suspend_state *dsps = CONTAINER_OF(ev, *dsps, qmp);
 
     ev->callback = dm_state_saved;
 
@@ -1060,7 +1082,8 @@ static void dm_state_fd_ready(libxl__egc *egc, libxl__ev_qmp *ev,
 
 error:
     assert(rc);
-    libxl__remove_file(gc, dsps->dm_savefile);
+    if (!libxl_get_stubdom_id(CTX, dsps->domid))
+        libxl__remove_file(gc, dsps->dm_savefile);
     dsps->callback_device_model_done(egc, dsps, rc);
 }
 
-- 
2.25.1



  parent reply	other threads:[~2020-05-19  1:57 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19  1:54 [PATCH v7 00/19] Add support for qemu-xen runnning in a Linux-based stubdomain Jason Andryuk
2020-05-18 22:24 ` Wei Liu
2020-05-19  1:54 ` [PATCH v7 01/19] Document ioemu MiniOS stubdomain protocol Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 02/19] Document ioemu Linux " Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 03/19] libxl: fix qemu-trad cmdline for no sdl/vnc case Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 04/19] libxl: Allow running qemu-xen in stubdomain Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 05/19] libxl: Handle Linux stubdomain specific QEMU options Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 06/19] libxl: Use libxl__xs_* in libxl__write_stub_dmargs Jason Andryuk
2020-05-19 15:09   ` Ian Jackson
2020-05-19  1:54 ` [PATCH v7 07/19] libxl: write qemu arguments into separate xenstore keys Jason Andryuk
2020-05-19 15:10   ` Ian Jackson
2020-05-19 15:21     ` Wei Liu
2020-05-19 15:33       ` Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 08/19] xl: add stubdomain related options to xl config parser Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 09/19] tools/libvchan: notify server when client is connected Jason Andryuk
2020-05-19  1:54 ` Jason Andryuk [this message]
2020-05-19  1:54 ` [PATCH v7 11/19] tools: add missing libxenvchan cflags Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 12/19] tools: add simple vchan-socket-proxy Jason Andryuk
2020-05-21 11:09   ` Andrew Cooper
2020-05-21 13:12     ` Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 13/19] libxl: Refactor kill_device_model to libxl__kill_xs_path Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 14/19] libxl: use vchan for QMP access with Linux stubdomain Jason Andryuk
2020-05-19  1:54 ` [PATCH v7 15/19] libxl: require qemu in dom0 for multiple stubdomain consoles Jason Andryuk
2020-05-19  1:55 ` [PATCH v7 16/19] libxl: ignore emulated IDE disks beyond the first 4 Jason Andryuk
2020-05-19  1:55 ` [PATCH v7 17/19] libxl: consider also qemu in stubdomain in libxl__dm_active check Jason Andryuk
2020-05-19  1:55 ` [PATCH v7 18/19] docs: Add device-model-domid to xenstore-paths Jason Andryuk
2020-05-19  1:55 ` [PATCH v7 19/19] libxl: Check stubdomain kernel & ramdisk presence Jason Andryuk
2020-05-22  9:10 ` [PATCH v7 00/19] Add support for qemu-xen runnning in a Linux-based stubdomain George Dunlap
2020-05-22  9:54   ` Paul Durrant
2020-05-22 13:30     ` Jason Andryuk
2020-05-22 13:37       ` Ian Jackson

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=20200519015503.115236-11-jandryuk@gmail.com \
    --to=jandryuk@gmail.com \
    --cc=anthony.perard@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=wl@xen.org \
    --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 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).