From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Ian Campbell <Ian.Campbell@citrix.com>
Subject: [PATCH 27/29] [VERY RFC] tools/libxl: Support restoring legacy streams
Date: Wed, 10 Sep 2014 18:11:05 +0100 [thread overview]
Message-ID: <1410369067-1330-28-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1410369067-1330-1-git-send-email-andrew.cooper3@citrix.com>
This WorksForMe in the success case, but the error handling is certainly lacking.
Specifically, the conversion scripts output fd can't be closed until the v2
read loop has exited (cleanly or otherwise), without risking a close()/open()
race silently replacing the fd behind the loops back.
However, it can't be closed when the read loop exits, as the conversion script
child might still be alive, and would prefer terminating cleaning than failing
with a bad FD.
Obviously, having one error handler block for the success/failure of the other
side is a no-go, and would still involve a preselecting which was expected to
exit first.
Does anyone have any clever ideas of how to asynchronously collect the events
"the conversion script has exited", "the save helper has exited" and "the v2
read loop has finished" given the available infrastructure, to kick of a
combined cleanup of all 3?
(I also need to fix the conversion script info/error logging, but that is a
distinctly more minor problem.)
---
tools/libxl/Makefile | 1 +
tools/libxl/libxl_convert_callout.c | 127 +++++++++++++++++++++++++++++++++++
tools/libxl/libxl_create.c | 43 +++++++++---
tools/libxl/libxl_internal.h | 16 +++++
tools/libxl/libxl_types.idl | 1 +
5 files changed, 178 insertions(+), 10 deletions(-)
create mode 100644 tools/libxl/libxl_convert_callout.c
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 4bee4af..d7b5036 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -80,6 +80,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
libxl_internal.o libxl_utils.o libxl_uuid.o \
libxl_json.o libxl_aoutils.o libxl_numa.o \
libxl_save_callout.o _libxl_save_msgs_callout.o \
+ libxl_convert_callout.o \
libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
LIBXL_OBJS += libxl_genid.o
LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
diff --git a/tools/libxl/libxl_convert_callout.c b/tools/libxl/libxl_convert_callout.c
new file mode 100644
index 0000000..9d31b91
--- /dev/null
+++ b/tools/libxl/libxl_convert_callout.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2014 Citrix Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h"
+
+#include "libxl_internal.h"
+
+static void stream_convert_done(libxl__egc *egc, libxl__conversion_helper_state *chs)
+{
+ STATE_AO_GC(chs->ao);
+
+ if (chs->rc)
+ libxl__ao_complete(egc, ao, chs->rc);
+}
+
+static void helper_done(libxl__egc *egc, libxl__conversion_helper_state *chs)
+{
+ STATE_AO_GC(chs->ao);
+
+ if (chs->rc)
+ LOG(ERROR, "conversion script failed");
+ else
+ LOG(INFO, "conversion script succeeded");
+
+ chs->completion_callback(egc, chs);
+}
+
+static void helper_exited(libxl__egc *egc, libxl__ev_child *ch,
+ pid_t pid, int status)
+{
+ libxl__conversion_helper_state *chs = CONTAINER_OF(ch, *chs, child);
+ STATE_AO_GC(chs->ao);
+
+ if (status) {
+ libxl_report_child_exitstatus(CTX, XTL_INFO, "conversion", pid, status);
+ chs->rc = ERROR_FAIL;
+ }
+
+ helper_done(egc, chs);
+}
+
+/*----- entrypoints -----*/
+int libxl__convert_legacy_stream(libxl__egc *egc,
+ libxl__domain_create_state *dcs)
+{
+ STATE_AO_GC(dcs->ao);
+ libxl__conversion_helper_state *chs = &dcs->chs;
+ int rc = 0;
+
+ chs->ao = ao;
+ chs->completion_callback = stream_convert_done;
+
+ chs->rc = 0;
+ libxl__ev_child_init(&chs->child);
+
+ int legacy_fd = dcs->restore_fd;
+ libxl__carefd *child_in = NULL;
+
+ libxl__carefd_begin();
+ int fds[2];
+ if (libxl_pipe(CTX, fds)) {
+ rc = ERROR_FAIL;
+ libxl__carefd_unlock();
+ goto err;
+
+ }
+ chs->child_out = libxl__carefd_record(CTX, fds[0]);
+ child_in = libxl__carefd_record(CTX, fds[1]);
+ libxl__carefd_unlock();
+
+ pid_t pid = libxl__ev_child_fork(gc, &chs->child, helper_exited);
+ if (!pid) {
+ LOG(INFO, "In child!");
+
+ char * const args[] =
+ {
+ getenv("LIBXL_CONVERT_HELPER") ?: PRIVATE_BINDIR "/convert-legacy-stream",
+ "--in", GCSPRINTF("%d", legacy_fd),
+ "--out", GCSPRINTF("%d", fds[1]),
+ "--width",
+#ifdef __i386__
+ "32",
+#else
+ "64",
+#endif
+ "--guest", "pv",
+ "--format", "libxl",
+ /* "--verbose", */
+ NULL,
+ };
+
+ libxl_fd_set_cloexec(CTX, legacy_fd, 0);
+ libxl_fd_set_cloexec(CTX, libxl__carefd_fd(child_in), 0);
+
+ libxl__exec(gc,
+ -1, -1, -1,
+ args[0], args, NULL);
+ }
+
+ LOG(INFO, "In parent!");
+
+ libxl__carefd_close(child_in);
+
+ LOG(INFO, "Updating restore_fd %d -> %d",
+ dcs->restore_fd, libxl__carefd_fd(chs->child_out));
+ dcs->restore_fd = libxl__carefd_fd(chs->child_out);
+
+ /* TODO - how to libxl__carefd_close(chs->child_out) ? */
+
+ assert(!rc);
+ return rc;
+
+ err:
+ assert(rc);
+ return rc;
+}
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 9661f78..a1935ec 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1514,16 +1514,6 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
ao_how, aop_console_how);
}
-int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
- uint32_t *domid, int restore_fd,
- const libxl_domain_restore_params *params,
- const libxl_asyncop_how *ao_how,
- const libxl_asyncprogress_how *aop_console_how)
-{
- return do_domain_create(ctx, d_config, domid, restore_fd,
- params->checkpointed_stream, ao_how, aop_console_how);
-}
-
static void read_restore_rec_hdr(libxl__app_domain_create_state *cdcs);
static void read_padding_cb(libxl__egc *egc, libxl__datacopier_state *dc,
@@ -1810,6 +1800,39 @@ static void libxl__domain_restore(libxl__egc *egc,
libxl__datacopier_start(dc);
}
+int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
+ uint32_t *domid, int restore_fd,
+ const libxl_domain_restore_params *params,
+ const libxl_asyncop_how *ao_how,
+ const libxl_asyncprogress_how *aop_console_how)
+{
+ AO_CREATE(ctx, 0, ao_how);
+ libxl__app_domain_create_state *cdcs;
+ int ret = 0;
+
+ GCNEW(cdcs);
+ cdcs->dcs.ao = ao;
+ cdcs->dcs.guest_config = d_config;
+ cdcs->dcs.restore_fd = restore_fd;
+ cdcs->dcs.callback = domain_create_cb;
+ cdcs->dcs.checkpointed_stream = 0;
+ cdcs->dcs.rebuild_callback = restore_rebuild_complete;
+ libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
+ cdcs->domid_out = domid;
+
+ if (params->stream_version == 1) {
+ LOG(DEBUG, "Converting legacy stream");
+ ret = libxl__convert_legacy_stream(egc, &cdcs->dcs);
+ }
+
+ if (!ret)
+ libxl__domain_restore(egc, cdcs);
+
+ if (ret)
+ return AO_ABORT(ret);
+ else
+ return AO_INPROGRESS;
+}
/*
* Local variables:
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 3964009..c56a167 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2497,6 +2497,19 @@ typedef struct libxl__save_helper_state {
* marshalling and xc callback functions */
} libxl__save_helper_state;
+/*----- Legacy conversion helper -----*/
+typedef struct libxl__conversion_helper_state libxl__conversion_helper_state;
+
+struct libxl__conversion_helper_state {
+ /* public */
+ libxl__ao *ao;
+ void (*completion_callback)(libxl__egc *egc,
+ libxl__conversion_helper_state *chs);
+ /* private */
+ int rc;
+ libxl__ev_child child;
+ libxl__carefd *child_out;
+};
/*----- Domain suspend (save) state structure -----*/
@@ -2806,6 +2819,7 @@ struct libxl__domain_create_state {
/* If we're not doing stubdom, we use only dmss.dm,
* for the non-stubdom device model. */
libxl__save_helper_state shs;
+ libxl__conversion_helper_state chs;
/* necessary if the domain creation failed and we have to destroy it */
libxl__domain_destroy_state dds;
libxl__multidev multidev;
@@ -3283,6 +3297,8 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
libxl_uuid_copy(CTX, &dst->uuid, &src->uuid);
}
+int libxl__convert_legacy_stream(libxl__egc *egc,
+ libxl__domain_create_state *dcs);
#endif
/*
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index f1fcbc3..fdd3781 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -308,6 +308,7 @@ libxl_domain_create_info = Struct("domain_create_info",[
libxl_domain_restore_params = Struct("domain_restore_params", [
("checkpointed_stream", integer),
+ ("stream_version", uint32, {'init_val': '1'}),
])
libxl_domain_sched_params = Struct("domain_sched_params",[
--
1.7.10.4
next prev parent reply other threads:[~2014-09-10 17:11 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-10 17:10 [PATCH v7 0/29] Migration Stream v2 Andrew Cooper
2014-09-10 17:10 ` [PATCH 01/29] tools/libxl: Fix stray blank line from debug logging Andrew Cooper
2014-09-11 10:18 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 02/29] tools/[lib]xl: Correct use of init/dispose for libxl_domain_restore_params Andrew Cooper
2014-09-11 10:19 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 03/29] tools/libxc: Implement writev_exact() in the same style as write_exact() Andrew Cooper
2014-09-11 10:19 ` Ian Campbell
2014-09-11 10:57 ` Ian Campbell
2014-09-11 10:59 ` Andrew Cooper
2014-09-10 17:10 ` [PATCH 04/29] libxc/bitops: Add or() to the available bitmap operations Andrew Cooper
2014-09-11 10:21 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 05/29] libxc/progress: Repurpose the current progress reporting infrastructure Andrew Cooper
2014-09-11 10:32 ` Ian Campbell
2014-09-11 14:03 ` Andrew Cooper
2014-09-11 14:06 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 06/29] docs: libxc migration stream specification Andrew Cooper
2014-09-10 17:10 ` [PATCH 07/29] docs: libxl " Andrew Cooper
2014-09-11 10:45 ` Ian Campbell
2014-09-11 10:56 ` Andrew Cooper
2014-09-11 11:03 ` Ian Campbell
2014-09-11 11:10 ` Andrew Cooper
2014-09-10 17:10 ` [PATCH 08/29] tools/python: Infrastructure relating to migration v2 streams Andrew Cooper
2014-09-10 17:10 ` [PATCH 09/29] [HACK] tools/libxc: save/restore v2 framework Andrew Cooper
2014-09-11 10:34 ` Ian Campbell
2014-09-11 10:37 ` Andrew Cooper
2014-09-11 11:01 ` Ian Campbell
2014-09-11 11:04 ` Andrew Cooper
2014-09-11 11:10 ` Ian Campbell
2014-09-14 10:23 ` Shriram Rajagopalan
2014-09-15 15:09 ` Andrew Cooper
2014-09-15 18:58 ` Konrad Rzeszutek Wilk
2014-09-16 11:44 ` Andrew Cooper
2014-09-16 19:54 ` Konrad Rzeszutek Wilk
2014-09-10 17:10 ` [PATCH 10/29] tools/libxc: C implementation of stream format Andrew Cooper
2014-09-11 10:48 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 11/29] tools/libxc: noarch common code Andrew Cooper
2014-09-11 10:52 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 12/29] tools/libxc: x86 " Andrew Cooper
2014-09-10 17:10 ` [PATCH 13/29] tools/libxc: x86 PV " Andrew Cooper
2014-09-10 17:10 ` [PATCH 14/29] tools/libxc: x86 PV save code Andrew Cooper
2014-09-10 17:10 ` [PATCH 15/29] tools/libxc: x86 PV restore code Andrew Cooper
2014-09-10 17:10 ` [PATCH 16/29] tools/libxc: x86 HVM save code Andrew Cooper
2014-09-10 17:10 ` [PATCH 17/29] tools/libxc: x86 HVM restore code Andrew Cooper
2014-09-10 17:10 ` [PATCH 18/29] tools/libxc: noarch save code Andrew Cooper
2014-09-10 17:10 ` [PATCH 19/29] tools/libxc: noarch restore code Andrew Cooper
2014-09-10 17:10 ` [PATCH 20/29] tools/libxl: Update datacopier to support sending data only Andrew Cooper
2014-09-11 11:56 ` Ian Campbell
2014-09-11 12:00 ` Andrew Cooper
2014-09-11 12:39 ` Ian Campbell
2014-09-11 13:03 ` Andrew Cooper
2014-09-11 13:04 ` Ian Campbell
2014-09-10 17:10 ` [PATCH 21/29] tools/libxl: Allow adding larger amounts of prefixdata to datacopier Andrew Cooper
2014-09-11 12:01 ` Ian Campbell
2014-09-11 12:17 ` Ross Lagerwall
2014-09-11 12:39 ` Ian Campbell
2014-09-10 17:11 ` [PATCH 22/29] tools/libxl: Allow limiting amount copied by datacopier Andrew Cooper
2014-09-11 12:02 ` Ian Campbell
2014-09-11 12:23 ` Ross Lagerwall
2014-09-11 12:40 ` Ian Campbell
2014-09-12 8:36 ` Wen Congyang
2014-09-19 7:45 ` Ross Lagerwall
2014-09-10 17:11 ` [PATCH 23/29] tools/libxl: Extend datacopier to support reading into a buffer Andrew Cooper
2014-09-11 12:03 ` Ian Campbell
2014-09-11 12:26 ` Ross Lagerwall
2014-09-11 12:41 ` Ian Campbell
2014-09-12 8:49 ` Wen Congyang
2014-09-19 7:48 ` Ross Lagerwall
2014-09-10 17:11 ` [PATCH 24/29] tools/libxl: Allow suppression of POLLHUP for datacopiers Andrew Cooper
2014-09-11 12:05 ` Ian Campbell
2014-09-10 17:11 ` [PATCH 25/29] tools/libxl: Stream v2 format Andrew Cooper
2014-09-11 12:06 ` Ian Campbell
2014-09-10 17:11 ` [PATCH 26/29] tools/libxl: Implement libxl__domain_restore() for v2 streams Andrew Cooper
2014-09-11 12:35 ` Ian Campbell
2014-09-11 13:01 ` Andrew Cooper
2014-09-10 17:11 ` Andrew Cooper [this message]
2014-09-11 12:36 ` [PATCH 27/29] [VERY RFC] tools/libxl: Support restoring legacy streams Ian Campbell
2014-09-10 17:11 ` [PATCH 28/29] tools/xl: Restore v2 streams using new interface Andrew Cooper
2014-09-10 17:11 ` [PATCH 29/29] tools/[lib]xl: Alter libxl_domain_suspend() to write a v2 stream Andrew Cooper
2014-09-11 11:50 ` [PATCH v7 0/29] Migration Stream v2 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=1410369067-1330-28-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=xen-devel@lists.xen.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).