xen-devel.lists.xenproject.org archive mirror
 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>,
	Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 1/2] libxl: Add a version check of QEMU for QMP commands
Date: Tue, 13 Mar 2018 11:13:17 +0000	[thread overview]
Message-ID: <20180313111318.24206-2-anthony.perard@citrix.com> (raw)
In-Reply-To: <20180313111318.24206-1-anthony.perard@citrix.com>

On connection to QEMU via QMP, the version of QEMU is provided, store it
for later use.

Add a function qmp_qemu_check_version that can be used to check if QEMU
is new enough for certain fonctionnality. This will be used in a moment.

As it's a static function, it is commented out until first use, which is
in the next patch.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libxl/libxl_qmp.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index eab993aca9..b1c6598cf7 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -75,6 +75,11 @@ struct libxl__qmp_handler {
 
     int last_id_used;
     LIBXL_STAILQ_HEAD(callback_list, callback_id_pair) callback_list;
+    struct {
+        int major;
+        int minor;
+        int micro;
+    } version;
 };
 
 static int qmp_send(libxl__qmp_handler *qmp,
@@ -296,9 +301,22 @@ static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp,
     LOGD(DEBUG, qmp->domid, "message type: %s", libxl__qmp_message_type_to_string(type));
 
     switch (type) {
-    case LIBXL__QMP_MESSAGE_TYPE_QMP:
+    case LIBXL__QMP_MESSAGE_TYPE_QMP: {
+        const libxl__json_object *o;
+        o = libxl__json_map_get("QMP", resp, JSON_MAP);
+        o = libxl__json_map_get("version", o, JSON_MAP);
+        o = libxl__json_map_get("qemu", o, JSON_MAP);
+        qmp->version.major = libxl__json_object_get_integer(
+            libxl__json_map_get("major", o, JSON_INTEGER));
+        qmp->version.minor = libxl__json_object_get_integer(
+            libxl__json_map_get("minor", o, JSON_INTEGER));
+        qmp->version.micro = libxl__json_object_get_integer(
+            libxl__json_map_get("micro", o, JSON_INTEGER));
+        LOGD(DEBUG, qmp->domid, "QEMU version: %d.%d.%d",
+             qmp->version.major, qmp->version.minor, qmp->version.micro);
         /* On the greeting message from the server, enable QMP capabilities */
         return enable_qmp_capabilities(qmp);
+    }
     case LIBXL__QMP_MESSAGE_TYPE_RETURN: {
         callback_id_pair *pp = qmp_get_callback_from_id(qmp, resp);
 
@@ -332,6 +350,17 @@ static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp,
     return 0;
 }
 
+#if 0
+static bool qmp_qemu_check_version(libxl__qmp_handler *qmp, 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)));
+}
+#endif
+
 /*
  * Handler functions
  */
-- 
Anthony PERARD


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

  reply	other threads:[~2018-03-13 11:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 11:13 [PATCH 0/2] libxl: Update of QMP xen-save-devices-state Anthony PERARD
2018-03-13 11:13 ` Anthony PERARD [this message]
2018-03-13 17:40   ` [PATCH 1/2] libxl: Add a version check of QEMU for QMP commands Wei Liu
2018-03-13 17:49     ` Anthony PERARD
2018-03-13 17:56       ` Wei Liu
2018-03-13 11:13 ` [PATCH 2/2] libxl_qmp: Tell QEMU about live migration or snapshot Anthony PERARD
2018-03-13 17:42   ` Wei Liu

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=20180313111318.24206-2-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).