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 26/32] libxl_dm: Pre-open QMP socket for QEMU
Date: Fri, 27 Jul 2018 15:06:08 +0100 [thread overview]
Message-ID: <20180727140614.13256-27-anthony.perard@citrix.com> (raw)
In-Reply-To: <20180727140614.13256-1-anthony.perard@citrix.com>
When starting QEMU with dm_restrict=1, pre-open the QMP socket before
exec QEMU. That socket will be usefull to findout if QEMU is ready, and
pre-opening it means that libxl can connect to it without waiting for
QEMU to create it.
The pre-openning is conditionnal, based on the use of dm_restrict
because it is using a new command line option of QEMU, and dm_restrict
support in QEMU is newer.
-chardev socket,fd=X is available with QEMU 2.12, since commit:
> char: allow passing pre-opened socket file descriptor at startup
> 0935700f8544033ebbd41e1f13cd528f8a58d24d
dm_restrict will be available in QEMU 3.0.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Notes:
v4:
separate the logic to open a socket into a function.
Use libxl__prepare_sockaddr_un() to check path size
tools/libxl/libxl_dm.c | 86 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 77 insertions(+), 9 deletions(-)
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 5c28a0ced4..9e3e501457 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -24,6 +24,8 @@
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
+#include <sys/socket.h>
+#include <sys/un.h>
static const char *libxl_tapif_script(libxl__gc *gc)
{
@@ -915,12 +917,58 @@ const char *libxl__qemu_qmp_path(libxl__gc *gc, int domid)
return GCSPRINTF("%s/qmp-libxl-%d", libxl__run_dir_path(), domid);
}
+static int libxl__pre_open_qmp_socket(libxl__gc *gc, int domid, int *fd_r)
+{
+ int rc;
+ int fd = -1;
+ struct sockaddr_un un;
+ const char *path;
+
+ path = libxl__qemu_qmp_path(gc, domid);
+
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ LOGED(ERROR, domid, "socket() failed");
+ return ERROR_FAIL;
+ }
+
+ rc = libxl__prepare_sockaddr_un(gc, &un, path, "QEMU's QMP socket");
+ if (rc)
+ goto out;
+
+ if (unlink(path) < 0 && errno != ENOENT) {
+ LOGED(ERROR, domid, "unlink('%s') failed", path);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ if (bind(fd, (struct sockaddr*) &un, sizeof(un)) < 0) {
+ LOGED(ERROR, domid, "bind('%s') failed", path);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ if (listen(fd, 1) < 0) {
+ LOGED(ERROR, domid, "listen() failed");
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ *fd_r = fd;
+ rc = 0;
+
+out:
+ if (rc && fd >= 0)
+ close(fd);
+ return rc;
+}
+
static int libxl__build_device_model_args_new(libxl__gc *gc,
const char *dm, int guest_domid,
const libxl_domain_config *guest_config,
char ***args, char ***envs,
const libxl__domain_build_state *state,
- int *dm_state_fd)
+ int *dm_state_fd, int *dm_monitor_fd)
{
const libxl_domain_create_info *c_info = &guest_config->c_info;
const libxl_domain_build_info *b_info = &guest_config->b_info;
@@ -949,10 +997,25 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
GCSPRINTF("%d", guest_domid), NULL);
flexarray_append(dm_args, "-chardev");
- flexarray_append(dm_args,
- GCSPRINTF("socket,id=libxl-cmd,"
- "path=%s,server,nowait",
- libxl__qemu_qmp_path(gc, guest_domid)));
+ /* If we have to use dm_restrict, QEMU need to be new enough and will have
+ * the new interface where we can pre-open the QMP socket. */
+ if (libxl_defbool_val(b_info->dm_restrict))
+ {
+ int rc;
+
+ rc = libxl__pre_open_qmp_socket(gc, guest_domid, dm_monitor_fd);
+ if (rc)
+ return rc;
+
+ flexarray_append(dm_args,
+ GCSPRINTF("socket,id=libxl-cmd,fd=%d,server,nowait",
+ *dm_monitor_fd));
+ } else {
+ flexarray_append(dm_args,
+ GCSPRINTF("socket,id=libxl-cmd,"
+ "path=%s,server,nowait",
+ libxl__qemu_qmp_path(gc, guest_domid)));
+ }
flexarray_append(dm_args, "-no-shutdown");
flexarray_append(dm_args, "-mon");
@@ -1731,7 +1794,8 @@ static int libxl__build_device_model_args(libxl__gc *gc,
const libxl_domain_config *guest_config,
char ***args, char ***envs,
const libxl__domain_build_state *state,
- int *dm_state_fd)
+ int *dm_state_fd,
+ int *dm_monitor_fd)
/* dm_state_fd may be NULL iff caller knows we are using old stubdom
* and therefore will be passing a filename rather than a fd. */
{
@@ -1744,10 +1808,11 @@ static int libxl__build_device_model_args(libxl__gc *gc,
case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
assert(dm_state_fd != NULL);
assert(*dm_state_fd < 0);
+ assert(dm_monitor_fd != NULL);
return libxl__build_device_model_args_new(gc, dm,
guest_domid, guest_config,
args, envs,
- state, dm_state_fd);
+ state, dm_state_fd, dm_monitor_fd);
default:
LOGED(ERROR, guest_domid, "unknown device model version %d",
guest_config->b_info.device_model_version);
@@ -1968,7 +2033,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
ret = libxl__build_device_model_args(gc, "stubdom-dm", guest_domid,
guest_config, &args, NULL,
- d_state, NULL);
+ d_state, NULL, NULL);
if (ret) {
ret = ERROR_FAIL;
goto out;
@@ -2254,6 +2319,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
char **pass_stuff;
const char *dm;
int dm_state_fd = -1;
+ int dm_monitor_fd = -1;
if (libxl_defbool_val(b_info->device_model_stubdomain)) {
abort();
@@ -2271,7 +2337,8 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
}
rc = libxl__build_device_model_args(gc, dm, domid, guest_config,
&args, &envs, state,
- &dm_state_fd);
+ &dm_state_fd,
+ &dm_monitor_fd);
if (rc)
goto out;
@@ -2369,6 +2436,7 @@ out_close:
if (logfile_w >= 0) close(logfile_w);
out:
if (dm_state_fd >= 0) close(dm_state_fd);
+ if (dm_monitor_fd >= 0) close(dm_monitor_fd);
if (rc)
device_model_spawn_outcome(egc, dmss, rc);
}
--
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 ` Anthony PERARD [this message]
2018-08-02 15:00 ` [PATCH v4 26/32] libxl_dm: Pre-open QMP socket for QEMU 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 ` [PATCH v4 30/32] libxl: Re-implement domain_suspend_device_model using libxl__ev_qmp Anthony PERARD
2018-08-02 15:38 ` 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-27-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).