All of lore.kernel.org
 help / color / mirror / Atom feed
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 v8 05/17] libxl: Design of an async API to issue QMP commands to QEMU
Date: Fri, 4 Jan 2019 15:30:44 +0000	[thread overview]
Message-ID: <20190104153056.19138-6-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190104153056.19138-1-anthony.perard@citrix.com>

All the functions will be implemented in later patches.

This patch includes the API that libxl can use to send QMP commands to
QEMU.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---

Notes:
    v7:
        acked, but with:
            fd field renamed to payload_fd
            libxl__ao ao field added
            added to _send that callback isn't called synchronously.
    
    v6:
        use libxl_domid type for domid instead of plain uin32_t
        avoid the work "chained", rewrite the paragraph about sending one
            cmd after another
        Rewrite the comment about the callback, and explain that on error,
            the `ev` may be Idle or may still be Connected
        Change the carefd to a simple int (field cfd -> fd)
    
    v5:
        some changes in the comment

 tools/libxl/libxl_internal.h | 76 +++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 16e6eb6c5e..fadafa5f11 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -192,6 +192,8 @@ typedef struct libxl__ao libxl__ao;
 typedef struct libxl__aop_occurred libxl__aop_occurred;
 typedef struct libxl__osevent_hook_nexus libxl__osevent_hook_nexus;
 typedef struct libxl__osevent_hook_nexi libxl__osevent_hook_nexi;
+typedef struct libxl__json_object libxl__json_object;
+typedef struct libxl__carefd libxl__carefd;
 
 typedef struct libxl__domain_create_state libxl__domain_create_state;
 typedef void libxl__domain_create_cb(struct libxl__egc *egc,
@@ -355,6 +357,76 @@ struct libxl__ev_child {
     LIBXL_LIST_ENTRY(struct libxl__ev_child) entry;
 };
 
+/*
+ * QMP asynchronous calls
+ *
+ * This facility allows a command to be sent to QEMU, and the response
+ * to be handed to a callback function.
+ *
+ * Commands can be submited one after an other with the same
+ * connection (e.g. the result from the "add-fd" command need to be
+ * use in a follow-up command before disconnecting from QMP). A
+ * libxl__ev_qmp can be reused when the callback is been called in
+ * order to use the same connection.
+ *
+ * Only one connection at a time can be made to one QEMU, so avoid
+ * keeping a libxl__ev_qmp Connected for to long and call
+ * libxl__ev_qmp_dispose as soon as it is not needed anymore.
+ *
+ * Possible states of a libxl__ev_qmp:
+ *  Undefined
+ *    Might contain anything.
+ *  Idle
+ *    Struct contents are defined enough to pass to any
+ *    libxl__ev_qmp_* function.
+ *    The struct does not contain references to any allocated private
+ *    resources so can be thrown away.
+ *  Active
+ *    Currently waiting for the callback to be called.
+ *    _dispose must be called to reclaim resources.
+ *  Connected
+ *    Struct contain allocated ressources.
+ *    Calling _send() with this same ev will use the same QMP connection.
+ *    _dispose() must be called to reclaim resources.
+ *
+ * libxl__ev_qmp_init: Undefined/Idle -> Idle
+ *
+ * libxl__ev_qmp_send: Idle/Connected -> Active (on error: Idle)
+ *    Sends a command to QEMU.
+ *    callback will be called when a response is received or when an
+ *    error as occured.
+ *    callback isn't called synchronously.
+ *
+ * libxl__ev_qmp_dispose: Connected/Active/Idle -> Idle
+ *
+ * callback: When called: Active -> Connected (on error: Idle/Connected)
+ *    When called, ev is Connected and can be reused or disposed of.
+ *    On error, the callback is called with response == NULL and the
+ *    error code in rc. The new state of ev depending on the value of rc:
+ *    - rc == ERROR_QMP_*: This is an error associated with the cmd to
+ *      run, ev is Connected.
+ *    - otherwise: An other error happend, ev is now Idle.
+ *    The callback is only called once.
+ */
+typedef struct libxl__ev_qmp libxl__ev_qmp;
+typedef void libxl__ev_qmp_callback(libxl__egc *egc, libxl__ev_qmp *ev,
+                                    const libxl__json_object *response,
+                                    int rc);
+
+_hidden void libxl__ev_qmp_init(libxl__ev_qmp *ev);
+_hidden int libxl__ev_qmp_send(libxl__gc *gc, libxl__ev_qmp *ev,
+                               const char *cmd, libxl__json_object *args);
+_hidden void libxl__ev_qmp_dispose(libxl__gc *gc, libxl__ev_qmp *ev);
+
+struct libxl__ev_qmp {
+    /* caller should include this in their own struct */
+    /* caller must fill these in, and they must all remain valid */
+    libxl__ao *ao;
+    libxl_domid domid;
+    libxl__ev_qmp_callback *callback;
+    int payload_fd; /* set to send a fd with the command, -1 otherwise */
+};
+
 
 /*
  * evgen structures, which are the state we use for generating
@@ -1909,7 +1981,7 @@ typedef enum {
     JSON_ANY     = 255 /* this is a mask of all values above, adjust as needed */
 } libxl__json_node_type;
 
-typedef struct libxl__json_object {
+struct libxl__json_object {
     libxl__json_node_type type;
     union {
         bool b;
@@ -1922,7 +1994,7 @@ typedef struct libxl__json_object {
         flexarray_t *map;
     } u;
     struct libxl__json_object *parent;
-} libxl__json_object;
+};
 
 typedef int (*libxl__json_parse_callback)(libxl__gc *gc,
                                           libxl__json_object *o,
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-01-04 15:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-04 15:30 [PATCH v8 00/17] libxl: Enable save/restore/migration of a restricted QEMU + libxl__ev_qmp_* Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 01/17] libxl: Enhance libxl__sendmsg_fds to deal with EINTR and EWOULDBLOCK Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 02/17] libxl_qmp: Separate QMP message generation from qmp_send_prepare Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 03/17] libxl_qmp: Change qmp_qemu_check_version to compare version Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 04/17] libxl: Add wrapper around libxl__json_object_to_json JSON Anthony PERARD
2019-01-04 15:30 ` Anthony PERARD [this message]
2019-01-04 15:30 ` [PATCH v8 06/17] libxl_qmp: Implementation of libxl__ev_qmp_* Anthony PERARD
2019-01-11 12:06   ` Ian Jackson
2019-01-11 12:16     ` Anthony PERARD
2019-01-11 12:21       ` Ian Jackson
2019-01-04 15:30 ` [PATCH v8 07/17] libxl_exec: Add libxl__spawn_initiate_failure Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 08/17] libxl: Add init/dispose of for libxl__domain_build_state Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 09/17] libxl_dm: Pre-open QMP socket for QEMU Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 10/17] libxl: Add dmss_init/dispose for libxl__dm_spawn_state Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 11/17] libxl: QEMU startup sync based on QMP Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 12/17] libxl_qmp: Store advertised QEMU version in libxl__ev_qmp Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 13/17] libxl: Change libxl__domain_suspend_device_model() to be async Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 14/17] libxl: Re-implement domain_suspend_device_model using libxl__ev_qmp Anthony PERARD
2019-01-04 15:30 ` [PATCH v8 15/17] libxl: Remove unused arg from libxl__sendmsg_fds Anthony PERARD
2019-01-04 16:04   ` Ian Jackson
2019-01-04 15:30 ` [PATCH v8 16/17] libxl_json: Remove libxl__json_object_append_to from header Anthony PERARD
2019-01-04 16:03   ` Ian Jackson
2019-01-04 15:30 ` [PATCH v8 17/17] libxl: Add comments to libxl__json_*get* functions Anthony PERARD
2019-01-11 11:55   ` Ian Jackson

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=20190104153056.19138-6-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.