]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
libxl_qmp: Change qmp_qemu_check_version to compare version
authorAnthony PERARD <anthony.perard@citrix.com>
Fri, 9 Nov 2018 17:45:54 +0000 (17:45 +0000)
committerWei Liu <wei.liu2@citrix.com>
Fri, 11 Jan 2019 14:57:35 +0000 (14:57 +0000)
This patch makes the function simpler to read. It also add the ability
for a caller to tell if QEMU is newer or have the exact version.

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

index 45a2cc423be6d412fdbbcc69fe434d865bf824fc..73f2202b4f6bbf13c49a80873be50ca36b14f9e6 100644 (file)
@@ -392,13 +392,27 @@ static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp,
     return 0;
 }
 
-static bool qmp_qemu_check_version(libxl__qmp_handler *qmp, int major,
-                                   int minor, int micro)
+/*
+ * return values:
+ *   < 0  if qemu's version <  asked version
+ *   = 0  if qemu's version == asked version
+ *   > 0  if qemu's version >  asked version
+ */
+static int qmp_qemu_compare_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)));
+#define CHECK_VERSION(level) do { \
+    if (qmp->version.level > (level)) return +1; \
+    if (qmp->version.level < (level)) return -1; \
+} while (0)
+
+    CHECK_VERSION(major);
+    CHECK_VERSION(minor);
+    CHECK_VERSION(micro);
+
+#undef CHECK_VERSION
+
+    return 0;
 }
 
 /*
@@ -1012,7 +1026,7 @@ int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename, bool live)
 
     /* live parameter was added to QEMU 2.11. It signal QEMU that the save
      * operation is for a live migration rather that for taking a snapshot. */
-    if (qmp_qemu_check_version(qmp, 2, 11, 0))
+    if (qmp_qemu_compare_version(qmp, 2, 11, 0) >= 0)
         qmp_parameters_add_bool(gc, &args, "live", live);
 
     rc = qmp_synchronous_send(qmp, "xen-save-devices-state", args,