|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen staging] libxl: QEMU startup sync based on QMP
commit f459c3ae3397c6e448b03473dc1c803c048bb980
Author: Anthony PERARD <anthony.perard@xxxxxxxxxx>
AuthorDate: Thu May 31 14:45:12 2018 +0100
Commit: Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Fri Jan 11 14:57:52 2019 +0000
libxl: QEMU startup sync based on QMP
This is only activated when dm_restrict=1, as explained in a previous
patch "libxl_dm: Pre-open QMP socket for QEMU"
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
tools/libxl/libxl_dm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl_internal.h | 1 +
tools/libxl/libxl_types.idl | 1 +
3 files changed, 55 insertions(+)
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 4000f47545..20d811be03 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -2063,10 +2063,12 @@ retry_transaction:
static void dmss_init(libxl__dm_spawn_state *dmss)
{
+ libxl__ev_qmp_init(&dmss->qmp);
}
static void dmss_dispose(libxl__gc *gc, libxl__dm_spawn_state *dmss)
{
+ libxl__ev_qmp_dispose(gc, &dmss->qmp);
}
static void spawn_stubdom_pvqemu_cb(libxl__egc *egc,
@@ -2451,6 +2453,9 @@ 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,
@@ -2605,6 +2610,17 @@ retry_transaction:
spawn->failure_cb = device_model_startup_failed;
spawn->detached_cb = device_model_detached;
+ if (state->dm_monitor_fd >= 0) {
+ /* There is a valid QMP socket available now,
+ * use it to find out when QEMU is ready */
+ dmss->qmp.ao = ao;
+ dmss->qmp.callback = device_model_qmp_cb;
+ dmss->qmp.domid = domid;
+ dmss->qmp.payload_fd = -1;
+ 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;
@@ -2678,6 +2694,43 @@ 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(ERROR, ev->domid,
+ "Missing 'status' in response to 'query-status'");
+ LOGD(DEBUG, ev->domid, ".. instead, got: %s", JSON(response));
+ rc = ERROR_QEMU_API;
+ goto failed;
+ }
+ status = libxl__json_object_get_string(o);
+ if (strcmp(status, "running")) {
+ LOGD(ERROR, ev->domid, "Unexpected QEMU status: %s", status);
+ rc = ERROR_NOT_READY;
+ 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(egc, &dmss->spawn, rc);
+}
+
static void device_model_spawn_outcome(libxl__egc *egc,
libxl__dm_spawn_state *dmss,
int rc)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index b50234482c..f30c106fbb 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3933,6 +3933,7 @@ typedef void libxl__dm_spawn_cb(libxl__egc *egc,
libxl__dm_spawn_state*,
struct libxl__dm_spawn_state {
/* mixed - spawn.ao must be initialised by user; rest is private: */
libxl__spawn_state spawn;
+ libxl__ev_qmp qmp;
/* filled in by user, must remain valid: */
uint32_t guest_domid; /* domain being served */
libxl_domain_config *guest_config;
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 212b00a677..b685ac47ac 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -75,6 +75,7 @@ libxl_error = Enumeration("error", [
(-29, "QMP_COMMAND_NOT_FOUND"), # the requested command has not been found
(-30, "QMP_DEVICE_NOT_ACTIVE"), # a device has failed to be become active
(-31, "QMP_DEVICE_NOT_FOUND"), # the requested device has not been found
+ (-32, "QEMU_API"), # QEMU's replies don't contains expected members
], value_namespace = "")
libxl_domain_type = Enumeration("domain_type", [
--
generated by git-patchbot for /home/xen/git/xen.git#staging
_______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |