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: [PATCH v4 30/32] libxl: Re-implement domain_suspend_device_model using libxl__ev_qmp
Date: Fri, 27 Jul 2018 15:06:12 +0100 [thread overview]
Message-ID: <20180727140614.13256-31-anthony.perard@citrix.com> (raw)
In-Reply-To: <20180727140614.13256-1-anthony.perard@citrix.com>
The re-implementation is done because we want to be able to send the
file description that QEMU can use to save its state. When QEMU is
restricted, it would not be able to write to a path.
This replace both libxl__qmp_stop() and libxl__qmp_save().
qmp_qemu_check_version() was only used by libxl__qmp_save(), so it is
replace by a version using libxl__ev_qmp instead.
Coding style fixed in libxl__domain_suspend_device_model() for the
return value.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Notes:
v4:
This patch replace the patch "libxl_qmp: Have QEMU save its state to a file
descriptor" from previous version of the serie.
It uses libxl__ev_qmp instead.
tools/libxl/libxl_dom_suspend.c | 16 ++--
tools/libxl/libxl_internal.h | 9 +-
tools/libxl/libxl_qmp.c | 152 +++++++++++++++++++++++++-------
3 files changed, 129 insertions(+), 48 deletions(-)
diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c
index 51c432a00a..0f4e1be115 100644
--- a/tools/libxl/libxl_dom_suspend.c
+++ b/tools/libxl/libxl_dom_suspend.c
@@ -34,6 +34,7 @@ int libxl__domain_suspend_init(libxl__egc *egc,
libxl__ev_evtchn_init(&dsps->guest_evtchn);
libxl__ev_xswatch_init(&dsps->guest_watch);
libxl__ev_time_init(&dsps->guest_timeout);
+ libxl__ev_qmp_init(&dsps->qmp);
if (type == LIBXL_DOMAIN_TYPE_INVALID) goto out;
dsps->type = type;
@@ -72,7 +73,7 @@ int libxl__domain_suspend_device_model(libxl__egc *egc,
libxl__domain_suspend_state *dsps)
{
STATE_AO_GC(dsps->ao);
- int ret = 0;
+ int rc;
uint32_t const domid = dsps->domid;
const char *const filename = dsps->dm_savefile;
@@ -81,22 +82,18 @@ int libxl__domain_suspend_device_model(libxl__egc *egc,
LOGD(DEBUG, domid, "Saving device model state to %s", filename);
libxl__qemu_traditional_cmd(gc, domid, "save");
libxl__wait_for_device_model_deprecated(gc, domid, "paused", NULL, NULL, NULL);
+ dsps->callback_device_model_done(egc, dsps, 0);
+ rc = 0;
break;
}
case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
- if (libxl__qmp_stop(gc, domid))
- return ERROR_FAIL;
- /* Save DM state into filename */
- ret = libxl__qmp_save(gc, domid, filename, dsps->live);
- if (ret)
- unlink(filename);
+ rc = libxl__qmp_suspend_save(gc, dsps);
break;
default:
return ERROR_INVAL;
}
- dsps->callback_device_model_done(egc, dsps, ret);
- return ret;
+ return rc;
}
static void domain_suspend_common_wait_guest(libxl__egc *egc,
@@ -402,6 +399,7 @@ static void domain_suspend_common_done(libxl__egc *egc,
libxl__ev_evtchn_cancel(gc, &dsps->guest_evtchn);
libxl__ev_xswatch_deregister(gc, &dsps->guest_watch);
libxl__ev_time_deregister(gc, &dsps->guest_timeout);
+ libxl__ev_qmp_dispose(gc, &dsps->qmp);
dsps->callback_common_done(egc, dsps, rc);
}
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 5b65cdbe40..cafe8b5733 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1942,13 +1942,8 @@ _hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid,
libxl_device_pci *pcidev);
/* Resume hvm domain */
_hidden int libxl__qmp_system_wakeup(libxl__gc *gc, int domid);
-/* Suspend QEMU. */
-_hidden int libxl__qmp_stop(libxl__gc *gc, int domid);
/* Resume QEMU. */
_hidden int libxl__qmp_resume(libxl__gc *gc, int domid);
-/* Save current QEMU state into fd. */
-_hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename,
- bool live);
/* Load current QEMU state from file. */
_hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename);
/* Set dirty bitmap logging status */
@@ -3406,6 +3401,7 @@ struct libxl__domain_suspend_state {
libxl__xswait_state pvcontrol;
libxl__ev_xswatch guest_watch;
libxl__ev_time guest_timeout;
+ libxl__ev_qmp qmp;
const char *dm_savefile;
void (*callback_device_model_done)(libxl__egc*,
@@ -3417,6 +3413,9 @@ int libxl__domain_suspend_init(libxl__egc *egc,
libxl__domain_suspend_state *dsps,
libxl_domain_type type);
+_hidden int libxl__qmp_suspend_save(libxl__gc *gc,
+ libxl__domain_suspend_state *dsps);
+
struct libxl__domain_save_state {
/* set by caller of libxl__domain_save */
libxl__ao *ao;
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 332dcf2069..07203a6fe6 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -398,13 +398,14 @@ static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp,
return 0;
}
-static bool qmp_qemu_check_version(libxl__qmp_handler *qmp, int major,
- int minor, int micro)
+static bool qmp_ev_qemu_check_version(libxl__ev_qmp *ev, int major,
+ int minor, int micro)
{
- return qmp->version.major > major ||
- (qmp->version.major == major &&
- (qmp->version.minor > minor ||
- (qmp->version.minor == minor && qmp->version.micro >= micro)));
+ return ev->qemu_version.major > major ||
+ (ev->qemu_version.major == major &&
+ (ev->qemu_version.minor > minor ||
+ (ev->qemu_version.minor == minor &&
+ ev->qemu_version.micro >= micro)));
}
/*
@@ -1017,29 +1018,6 @@ int libxl__qmp_system_wakeup(libxl__gc *gc, int domid)
return qmp_run_command(gc, domid, "system_wakeup", NULL, NULL, NULL);
}
-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;
-
- qmp = libxl__qmp_initialize(gc, domid);
- if (!qmp)
- return ERROR_FAIL;
-
- qmp_parameters_add_string(gc, &args, "filename", (char *)filename);
-
- /* 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);
-
- rc = qmp_synchronous_send(qmp, "xen-save-devices-state", args,
- NULL, NULL, qmp->timeout);
- libxl__qmp_close(qmp);
- return rc;
-}
-
int libxl__qmp_restore(libxl__gc *gc, int domid, const char *state_file)
{
libxl__json_object *args = NULL;
@@ -1068,11 +1046,6 @@ static int qmp_change(libxl__gc *gc, libxl__qmp_handler *qmp,
return rc;
}
-int libxl__qmp_stop(libxl__gc *gc, int domid)
-{
- return qmp_run_command(gc, domid, "stop", NULL, NULL, NULL);
-}
-
int libxl__qmp_resume(libxl__gc *gc, int domid)
{
return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL);
@@ -1312,6 +1285,117 @@ int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
return ret;
}
+
+/*
+ * Function using libxl__ev_qmp
+ */
+
+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_saved(libxl__egc *egc, libxl__ev_qmp *ev,
+ const libxl__json_object *response, int rc);
+int libxl__qmp_suspend_save(libxl__gc *gc, libxl__domain_suspend_state *dsps)
+{
+ libxl__ev_qmp *ev = &dsps->qmp;
+ uint32_t const domid = dsps->domid;
+
+ ev->domid = domid;
+ ev->callback = dm_stopped;
+ ev->cfd = NULL;
+
+ return libxl__ev_qmp_send(gc, ev, "stop", NULL);
+}
+
+static void dm_stopped(libxl__egc *egc, libxl__ev_qmp *ev,
+ const libxl__json_object *response, int rc)
+{
+ EGC_GC;
+ libxl__domain_suspend_state *dsps = CONTAINER_OF(ev, *dsps, qmp);
+ const char *const filename = dsps->dm_savefile;
+ uint32_t const domid = ev->domid;
+
+ if (rc)
+ goto out;
+
+ libxl__carefd_begin();
+ ev->cfd = libxl__carefd_opened(CTX,
+ open(filename, O_WRONLY | O_CREAT, 0600));
+ if (!ev->cfd) {
+ LOGED(ERROR, domid, "Failed to open file %s for QEMU", filename);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ ev->callback = dm_state_fd_ready;
+ rc = libxl__ev_qmp_send(gc, ev, "add-fd", NULL);
+ if (rc)
+ goto out;
+
+ return;
+out:
+ if (ev->cfd) {
+ libxl__carefd_close(ev->cfd);
+ unlink(filename);
+ ev->cfd = NULL;
+ }
+ dsps->callback_device_model_done(egc, dsps, rc);
+}
+
+static void dm_state_fd_ready(libxl__egc *egc, libxl__ev_qmp *ev,
+ const libxl__json_object *response, int rc)
+{
+ EGC_GC;
+ libxl__domain_suspend_state *dsps = CONTAINER_OF(ev, *dsps, qmp);
+ libxl__json_object *args = NULL;
+ const libxl__json_object *o;
+ int fdset;
+
+ libxl__carefd_close(ev->cfd);
+ ev->cfd = NULL;
+
+ if (rc)
+ goto out;
+
+ o = libxl__json_map_get("fdset-id", response, JSON_INTEGER);
+ if (!o) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ fdset = libxl__json_object_get_integer(o);
+
+ ev->callback = dm_state_saved;
+
+ if (qmp_ev_qemu_check_version(ev, 2, 11, 0))
+ qmp_parameters_add_bool(gc, &args, "live", dsps->live);
+ QMP_PARAMETERS_SPRINTF(&args, "filename", "/dev/fdset/%d", fdset);
+ rc = libxl__ev_qmp_send(gc, ev, "xen-save-devices-state", args);
+ if (rc)
+ goto out;
+
+ return;
+out:
+ if (rc)
+ unlink(dsps->dm_savefile);
+ dsps->callback_device_model_done(egc, dsps, rc);
+}
+
+static void dm_state_saved(libxl__egc *egc, libxl__ev_qmp *ev,
+ const libxl__json_object *response, int rc)
+{
+ EGC_GC;
+ libxl__domain_suspend_state *dsps = CONTAINER_OF(ev, *dsps, qmp);
+
+ if (rc)
+ unlink(dsps->dm_savefile);
+
+ libxl__ev_qmp_dispose(gc, ev);
+ dsps->callback_device_model_done(egc, dsps, rc);
+}
+
+
+
/* ------------ Implementation of libxl__ev_qmp ---------------- */
/* hard coded message ID used for capability negociation */
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-07-27 14:28 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-27 14:05 [PATCH v4 00/32] libxl: Enable save/restore/migration of a restricted QEMU + libxl__ev_qmp_* Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 01/32] libxl_event: Fix DEBUG prints Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 02/32] libxl_qmp: Documentation of the logic of the QMP client Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 03/32] libxl_qmp: Fix use of DEBUG_RECEIVED Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 04/32] libxl_json: fix build with DEBUG_ANSWER Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 05/32] libxl_qmp: Move the buffer realloc to the same scope level as read Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 06/32] libxl_qmp: Add a warning to not trust QEMU Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 07/32] libxl_qmp: Move struct sockaddr_un variable to qmp_open() Anthony PERARD
2018-08-02 8:26 ` Roger Pau Monné
2018-08-20 14:52 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 08/32] libxl: Add libxl__prepare_sockaddr_un() helper Anthony PERARD
2018-08-02 8:36 ` Roger Pau Monné
2018-08-20 14:56 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 09/32] libxl_qmp: Remove unused yajl_ctx from handler Anthony PERARD
2018-08-20 14:56 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 10/32] libxl_json: constify libxl__json_object_to_yajl_gen arguments Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 11/32] libxl_dm: Add libxl__qemu_qmp_path() Anthony PERARD
2018-08-02 8:41 ` Roger Pau Monné
2018-08-20 14:57 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 12/32] libxl: Design of an async API to issue QMP commands to QEMU Anthony PERARD
2018-08-02 9:01 ` [PATCH v4 12/32] libxl: Design of an async API to issue QMP commands to QEMUç Roger Pau Monné
2018-08-03 11:18 ` Anthony PERARD
2018-08-03 13:55 ` Roger Pau Monné
2018-08-03 14:45 ` Anthony PERARD
2018-08-03 15:30 ` Roger Pau Monné
2018-07-27 14:05 ` [PATCH v4 13/32] libxl_qmp: Connect to QMP socket Anthony PERARD
2018-08-02 9:35 ` Roger Pau Monné
2018-08-03 13:54 ` Anthony PERARD
2018-08-03 14:03 ` Roger Pau Monné
2018-08-21 8:22 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 14/32] libxl_qmp: Implement fd callback and read data Anthony PERARD
2018-08-02 9:56 ` Roger Pau Monné
2018-08-03 14:32 ` Anthony PERARD
2018-08-03 15:24 ` Roger Pau Monné
2018-08-06 15:01 ` Anthony PERARD
2018-07-27 14:05 ` [PATCH v4 15/32] libxl_json: Enable yajl_allow_trailing_garbage Anthony PERARD
2018-08-02 10:01 ` Roger Pau Monné
2018-08-21 8:26 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 16/32] libxl_json: libxl__json_object_to_json Anthony PERARD
2018-08-02 10:10 ` Roger Pau Monné
2018-08-21 8:26 ` Wei Liu
2018-07-27 14:05 ` [PATCH v4 17/32] libxl_qmp: Parse JSON input from QMP Anthony PERARD
2018-08-02 10:25 ` Roger Pau Monné
2018-08-03 15:33 ` Anthony PERARD
2018-08-06 11:17 ` Roger Pau Monné
2018-07-27 14:06 ` [PATCH v4 18/32] libxl_qmp: Separate QMP message generation from qmp_send_prepare Anthony PERARD
2018-08-02 10:34 ` Roger Pau Monné
2018-08-03 15:43 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 19/32] libxl_qmp: Prepare the command to be sent Anthony PERARD
2018-08-02 10:41 ` Roger Pau Monné
2018-08-03 16:35 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 20/32] libxl_qmp: Handle write to QMP socket Anthony PERARD
2018-08-02 11:02 ` Roger Pau Monné
2018-08-03 16:50 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 21/32] libxl_qmp: Simplify qmp_response_type() prototype Anthony PERARD
2018-08-02 11:03 ` Roger Pau Monné
2018-08-21 8:53 ` Wei Liu
2018-07-27 14:06 ` [PATCH v4 22/32] libxl_qmp: Handle messages from QEMU Anthony PERARD
2018-08-02 11:17 ` Roger Pau Monné
2018-08-03 17:25 ` Anthony PERARD
2018-08-06 11:25 ` Roger Pau Monné
2018-08-06 13:14 ` Anthony PERARD
2018-08-06 15:03 ` Roger Pau Monné
2018-08-21 8:58 ` Wei Liu
2018-08-21 12:50 ` Anthony PERARD
2018-08-21 14:56 ` Ian Jackson
2018-07-27 14:06 ` [PATCH v4 23/32] libxl_qmp: Respond to QMP greeting Anthony PERARD
2018-08-02 11:26 ` Roger Pau Monné
2018-08-06 17:41 ` Anthony PERARD
2018-08-21 9:00 ` Wei Liu
2018-08-21 10:51 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 24/32] libxl_qmp: Disable beautify for QMP generated cmd Anthony PERARD
2018-08-21 9:00 ` Wei Liu
2018-07-27 14:06 ` [PATCH v4 25/32] libxl_exec: Add libxl__spawn_initiate_failure Anthony PERARD
2018-08-02 11:34 ` Roger Pau Monné
2018-08-06 15:58 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 26/32] libxl_dm: Pre-open QMP socket for QEMU Anthony PERARD
2018-08-02 15:00 ` Roger Pau Monné
2018-07-27 14:06 ` [PATCH v4 27/32] libxl: QEMU startup sync based on QMP Anthony PERARD
2018-08-02 15:06 ` Roger Pau Monné
2018-07-27 14:06 ` [PATCH v4 28/32] libxl_qmp: Store advertised QEMU version in libxl__ev_qmp Anthony PERARD
2018-08-02 15:08 ` Roger Pau Monné
2018-08-06 16:52 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 29/32] libxl: Change libxl__domain_suspend_device_model() to be async Anthony PERARD
2018-08-02 15:15 ` Roger Pau Monné
2018-07-27 14:06 ` Anthony PERARD [this message]
2018-08-02 15:38 ` [PATCH v4 30/32] libxl: Re-implement domain_suspend_device_model using libxl__ev_qmp Roger Pau Monné
2018-08-06 17:07 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 31/32] libxl_disk: Cut libxl_cdrom_insert into step Anthony PERARD
2018-08-02 15:50 ` Roger Pau Monné
2018-08-06 17:20 ` Anthony PERARD
2018-08-07 14:18 ` Roger Pau Monné
2018-08-07 14:40 ` Anthony PERARD
2018-08-21 9:08 ` Wei Liu
2018-08-21 12:58 ` Anthony PERARD
2018-07-27 14:06 ` [PATCH v4 32/32] libxl_disk: Have libxl_cdrom_insert use libxl__ev_qmp 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=20180727140614.13256-31-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 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).