Skip to contentSkip to conversation

libxl: Update of QMP xen-save-devices-state

PATCH In review Anthony PERARD 2 participants 7 messages Mar 13, 2018

lore
Share & tools
lore
#0 lore raw

cover libxl: Update of QMP xen-save-devices-state

Handle a new parameter of an existing QMP command. See patch 2 (libxl_qmp: Tell QEMU about live migration or snapshot) for more information.

Anthony PERARD (2):
libxl: Add a version check of QEMU for QMP commands
libxl_qmp: Tell QEMU about live migration or snapshot

 tools/libxl/libxl_dom_save.c    |  1 +
 tools/libxl/libxl_dom_suspend.c |  2 +-
 tools/libxl/libxl_internal.h    |  4 +++-
 tools/libxl/libxl_qmp.c         | 49 +++++++++++++++++++++++++++++++++++++----
 4 files changed, 50 insertions(+), 6 deletions(-)
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/2 libxl: Add a version check of QEMU for QMP commands

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.

---
 tools/libxl/libxl_qmp.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +30 -1
index eab993aca9..b1c6598cf7 100644
@@ -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
  */
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] libxl: Add a version check of QEMU for QMP commands

Quoted 41 lines · Anthony PERARD

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.

---
 tools/libxl/libxl_qmp.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +11 -1
index eab993aca9..b1c6598cf7 100644
@@ -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(

tools/libxl/libxl_qmp.c static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp, · line 319

Quoted 10 lines
tools/libxl/libxl_qmp.c +8 -0
+            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);
+    }

Are those fields available in QMP in all the versions we care about?

If so,

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [PATCH 1/2] libxl: Add a version check of QEMU for QMP commands

Quoted 46 lines · Wei Liu
Quoted 45 lines · Anthony PERARD

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.

---
 tools/libxl/libxl_qmp.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +15 -1
index eab993aca9..b1c6598cf7 100644
@@ -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(
Quoted 8 lines

tools/libxl/libxl_qmp.c static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp, · line 319

Quoted 6 lines
tools/libxl/libxl_qmp.c +4 -0
+            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);
+    }

Are those fields available in QMP in all the versions we care about?

I don't care if the field is available or not, the result would be a QEMU version -1.-1.-1 This is why I did not do any check here to find out if a particular value exist. But the version field is part of the QMP protocol, so it should be there.

Also yes, the field is available in all QEMU version we care about, e.i. QEMU 2.11 and later. That information is not usefull for older version of QEMU.

Quoted 3 lines

If so,

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Re: [PATCH 1/2] libxl: Add a version check of QEMU for QMP commands

Quoted 56 lines · Anthony PERARD
Quoted 46 lines · Wei Liu
Quoted 45 lines · Anthony PERARD

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.

---
 tools/libxl/libxl_qmp.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +15 -1
index eab993aca9..b1c6598cf7 100644
@@ -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(
Quoted 8 lines

tools/libxl/libxl_qmp.c static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp, · line 319

Quoted 6 lines
tools/libxl/libxl_qmp.c +4 -0
+            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);
+    }

Are those fields available in QMP in all the versions we care about?

Quoted 4 lines

I don't care if the field is available or not, the result would be a QEMU version -1.-1.-1 This is why I did not do any check here to find out if a particular value exist. But the version field is part of the QMP protocol, so it should be there.

OK that's fine.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

PATCH 2/2 libxl_qmp: Tell QEMU about live migration or snapshot

In reply to Anthony PERARD

Since version 2.10, QEMU will lock the disk images so a second QEMU instance will not try to open it. This would prevent live migration from working correctly. A new parameter as been added to the QMP command "xen-save-devices-state" in QEMU version 2.11 which allow to unlock the disk image for a live migration, but also keep it locked for a snapshot.

QEMU commit: 5d6c599fe1d69a1bf8c5c4d3c58be2b31cd625ad "migration, xen: Fix block image lock issue on live migration"

The extra "live" parameter can only be use if QEMU knows about it, so only add it if qemu is recent enough.

The struct libxl__domain_suspend_state as now knowledge if the suspend is part of a live migration.

---
 tools/libxl/libxl_dom_save.c    |  1 +
 tools/libxl/libxl_dom_suspend.c |  2 +-
 tools/libxl/libxl_internal.h    |  4 +++-
 tools/libxl/libxl_qmp.c         | 22 +++++++++++++++++-----
 4 files changed, 22 insertions(+), 7 deletions(-)
tools/libxl/libxl_dom_save.c +1 -0
index 6487672277..2e9ec4dbf2 100644
@@ -361,6 +361,7 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)
 
     dsps->ao = ao;
     dsps->domid = domid;
+    dsps->live = !!live;
     rc = libxl__domain_suspend_init(egc, dsps, type);
     if (rc) goto out;
 
tools/libxl/libxl_dom_suspend.c +1 -1
index ca41107412..1e904bae8a 100644
@@ -86,7 +86,7 @@ int libxl__domain_suspend_device_model(libxl__gc *gc,
         if (libxl__qmp_stop(gc, domid))
             return ERROR_FAIL;
         /* Save DM state into filename */
-        ret = libxl__qmp_save(gc, domid, filename);
+        ret = libxl__qmp_save(gc, domid, filename, dsps->live);
         if (ret)
             unlink(filename);
         break;
tools/libxl/libxl_internal.h +3 -1
index 506687fbe9..8dd63319fc 100644
@@ -1822,7 +1822,8 @@ _hidden int libxl__qmp_stop(libxl__gc *gc, int domid);
 /* Resume QEMU. */
 _hidden int libxl__qmp_resume(libxl__gc *gc, int domid);
 /* Save current QEMU state into fd. */
-_hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename);
+_hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename,
+                            bool live);
 /* Load current QEMU state from file. */
 _hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename);
 /* Set dirty bitmap logging status */
@@ -3264,6 +3265,7 @@ struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend_init */
     libxl__ao *ao;
     uint32_t domid;
+    bool live;
 
     /* private */
     libxl_domain_type type;
tools/libxl/libxl_qmp.c +17 -5
index b1c6598cf7..d03cb51668 100644
@@ -350,7 +350,6 @@ 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)
 {
@@ -359,7 +358,6 @@ static bool qmp_qemu_check_version(libxl__qmp_handler *qmp, int major,
             (qmp->version.minor > minor ||
              (qmp->version.minor == minor && qmp->version.micro >= micro)));
 }
-#endif
 
 /*
  * Handler functions
@@ -942,13 +940,27 @@ int libxl__qmp_system_wakeup(libxl__gc *gc, int domid)
     return qmp_run_command(gc, domid, "system_wakeup", NULL, NULL, NULL);
 }
 
-int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename)
+int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename, bool live)
 {
     libxl__json_object *args = NULL;
+    libxl__qmp_handler *qmp = NULL;
+    int rc;
+
+    qmp = libxl__qmp_initialize(gc, domid);
+    if (!qmp)
+        return ERROR_FAIL;
 
     qmp_parameters_add_string(gc, &args, "filename", (char *)filename);
-    return qmp_run_command(gc, domid, "xen-save-devices-state", args,
-                           NULL, NULL);
+
+    /* 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))
+        qmp_parameters_add_bool(gc, &args, "live", live);
+
+    rc = qmp_synchronous_send(qmp, "xen-save-devices-state", args,
+                              NULL, NULL, qmp->timeout);
+    libxl__qmp_close(qmp);
+    return rc;
 }
 
 int libxl__qmp_restore(libxl__gc *gc, int domid, const char *state_file)
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] libxl_qmp: Tell QEMU about live migration or snapshot

Quoted 9 lines · Anthony PERARD

Since version 2.10, QEMU will lock the disk images so a second QEMU instance will not try to open it. This would prevent live migration from working correctly. A new parameter as been added to the QMP command "xen-save-devices-state" in QEMU version 2.11 which allow to unlock the disk image for a live migration, but also keep it locked for a snapshot.

QEMU commit: 5d6c599fe1d69a1bf8c5c4d3c58be2b31cd625ad "migration, xen: Fix block image lock issue on live migration"

Quoted 7 lines

The extra "live" parameter can only be use if QEMU knows about it, so only add it if qemu is recent enough.

The struct libxl__domain_suspend_state as now knowledge if the suspend is part of a live migration.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel