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 v5 12/15] libxl: QEMU startup sync based on QMP
Date: Fri, 7 Sep 2018 16:11:01 +0100 [thread overview]
Message-ID: <20180907151104.32306-13-anthony.perard@citrix.com> (raw)
In-Reply-To: <20180907151104.32306-1-anthony.perard@citrix.com>
This is only activated when dm_restrict=1, as explained in the previous
patch "libxl_dm: Pre-open QMP socket for QEMU"
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
Notes:
v5:
removed empty success branch in device_model_qmp_cb()
call libxl__ev_qmp_init() earlier in libxl__spawn_local_dm.
otherwise the error path would use an uninitialised
libxl__ev_qmp.
v4:
moved to libxl__dm_spawn_* from libxl__spawn_*
tools/libxl/libxl_dm.c | 51 ++++++++++++++++++++++++++++++++++++
tools/libxl/libxl_internal.h | 1 +
2 files changed, 52 insertions(+)
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index c6bf81b863..9e23274bd8 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -2278,6 +2278,8 @@ static void device_model_startup_failed(libxl__egc *egc,
int rc);
static void device_model_detached(libxl__egc *egc,
libxl__spawn_state *spawn);
+static void device_model_qmp_cb(libxl__egc *egc, libxl__ev_qmp *ev,
+ const libxl__json_object *response, int rc);
/* our "next step" function, called from those callbacks and elsewhere */
static void device_model_spawn_outcome(libxl__egc *egc,
@@ -2309,6 +2311,8 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
int dm_state_fd = -1;
int dm_monitor_fd = -1;
+ libxl__ev_qmp_init(&dmss->qmp);
+
if (libxl_defbool_val(b_info->device_model_stubdomain)) {
abort();
}
@@ -2409,6 +2413,16 @@ retry_transaction:
spawn->failure_cb = device_model_startup_failed;
spawn->detached_cb = device_model_detached;
+ if (dm_monitor_fd >= 0) {
+ /* There is a valid QMP socket available now,
+ * use it to find out when QEMU is ready */
+ dmss->qmp.callback = device_model_qmp_cb;
+ dmss->qmp.domid = domid;
+ dmss->qmp.cfd = NULL;
+ rc = libxl__ev_qmp_send(gc, &dmss->qmp, "query-status", NULL);
+ if (rc) goto out_close;
+ }
+
rc = libxl__spawn_spawn(egc, spawn);
if (rc < 0)
goto out_close;
@@ -2478,6 +2492,41 @@ static void device_model_detached(libxl__egc *egc,
device_model_spawn_outcome(egc, dmss, 0);
}
+static void device_model_qmp_cb(libxl__egc *egc, libxl__ev_qmp *ev,
+ const libxl__json_object *response,
+ int rc)
+{
+ EGC_GC;
+ libxl__dm_spawn_state *dmss = CONTAINER_OF(ev, *dmss, qmp);
+ const libxl__json_object *o;
+ const char *status;
+
+ libxl__ev_qmp_dispose(gc, ev);
+
+ if (rc)
+ goto failed;
+
+ o = libxl__json_map_get("status", response, JSON_STRING);
+ if (!o) {
+ LOGD(DEBUG, ev->domid, "QMP unexpected response");
+ rc = ERROR_FAIL;
+ goto failed;
+ }
+ status = libxl__json_object_get_string(o);
+ if (strcmp(status, "running")) {
+ LOGD(DEBUG, ev->domid, "Unexpected QEMU status: %s", status);
+ rc = ERROR_FAIL;
+ goto failed;
+ }
+
+ libxl__spawn_initiate_detach(gc, &dmss->spawn);
+ return;
+
+failed:
+ LOGD(ERROR, ev->domid, "QEMU did not start properly, rc=%d", rc);
+ libxl__spawn_initiate_failure(gc, &dmss->spawn, rc);
+}
+
static void device_model_spawn_outcome(libxl__egc *egc,
libxl__dm_spawn_state *dmss,
int rc)
@@ -2501,6 +2550,8 @@ static void device_model_spawn_outcome(libxl__egc *egc,
}
}
+ libxl__ev_qmp_dispose(gc, &dmss->qmp);
+
out:
dmss->callback(egc, dmss, rc);
}
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index b6c0279bb8..bde34a3ac1 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3892,6 +3892,7 @@ struct libxl__dm_spawn_state {
libxl_domain_config *guest_config;
libxl__domain_build_state *build_state; /* relates to guest_domid */
libxl__dm_spawn_cb *callback;
+ libxl__ev_qmp qmp;
};
_hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*);
--
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-09-07 15:28 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20181015151630.3887-1-ian.jackson@eu.citrix.com>
2018-09-07 15:10 ` [PATCH v5 00/15] libxl: Enable save/restore/migration of a restricted QEMU + libxl__ev_qmp_* Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 01/15] libxl: Design of an async API to issue QMP commands to QEMU Anthony PERARD
2018-10-10 15:18 ` Ian Jackson
2018-10-11 11:17 ` Anthony PERARD
2018-10-11 11:21 ` Ian Jackson
2018-10-10 23:49 ` Marek Marczykowski-Górecki
2018-10-11 14:29 ` Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 02/15] libxl_qmp: Connect to QMP socket Anthony PERARD
2018-10-10 15:29 ` Ian Jackson
2018-10-11 11:27 ` Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 03/15] libxl_qmp: Implement fd callback and read data Anthony PERARD
2018-10-10 15:47 ` Ian Jackson
2018-10-11 14:06 ` Anthony PERARD
2018-10-15 14:04 ` Ian Jackson
2018-10-15 16:35 ` [PATCH v5 03/15] libxl_qmp: Implement fd callback and read data [and 1 more messages] Ian Jackson
2018-10-29 15:52 ` Anthony PERARD
2018-10-29 17:31 ` Ian Jackson
2018-10-30 18:03 ` Anthony PERARD
2018-10-30 18:25 ` Ian Jackson
2018-09-07 15:10 ` [PATCH v5 04/15] libxl_qmp: Parse JSON input from QMP Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 05/15] libxl_qmp: Separate QMP message generation from qmp_send_prepare Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 06/15] libxl_qmp: Prepare the command to be sent Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 07/15] libxl_qmp: Handle write to QMP socket Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 08/15] libxl_qmp: Handle messages from QEMU Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 09/15] libxl_qmp: Respond to QMP greeting Anthony PERARD
2018-09-07 15:10 ` [PATCH v5 10/15] libxl_exec: Add libxl__spawn_initiate_failure Anthony PERARD
2018-10-16 14:02 ` Ian Jackson
2018-11-09 12:26 ` Anthony PERARD
2018-09-07 15:11 ` [PATCH v5 11/15] libxl_dm: Pre-open QMP socket for QEMU Anthony PERARD
2018-10-16 14:11 ` Ian Jackson
2018-11-12 14:52 ` Anthony PERARD
2018-11-12 15:14 ` Ian Jackson
2018-11-12 15:22 ` Anthony PERARD
2018-11-12 15:54 ` Ian Jackson
2018-09-07 15:11 ` Anthony PERARD [this message]
2018-10-16 14:23 ` [PATCH v5 12/15] libxl: QEMU startup sync based on QMP Ian Jackson
2018-11-12 15:00 ` Anthony PERARD
2018-11-12 15:17 ` Ian Jackson
2018-09-07 15:11 ` [PATCH v5 13/15] libxl_qmp: Store advertised QEMU version in libxl__ev_qmp Anthony PERARD
2018-10-16 14:25 ` Ian Jackson
2018-09-07 15:11 ` [PATCH v5 14/15] libxl: Change libxl__domain_suspend_device_model() to be async Anthony PERARD
2018-10-16 15:14 ` Ian Jackson
2018-09-07 15:11 ` [PATCH v5 15/15] libxl: Re-implement domain_suspend_device_model using libxl__ev_qmp Anthony PERARD
2018-10-16 15:28 ` Ian Jackson
2018-11-09 16:59 ` Anthony PERARD
2018-11-09 17:11 ` Ian Jackson
2018-11-09 17:30 ` 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=20180907151104.32306-13-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).