[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC v3 RESEND 01/12] Migration with Local Disks Mirroring: Added support in libxl to handle QMP events



Migration with Local Disk Mirroring uses the QEMU embedded NBD server. To
migrate the disk, a 'disk mirror job' is started from the source so that the
block devices emulated by QEMU are mirrored to the destination node. Once the
mirroring job is ready, QEMU sends an asynchronous QMP event. This code adds
support to register handlers when QMP events are received.

Signed-off-by: Bruno Alvisio <bruno.alvisio@xxxxxxxxx>
---
 tools/libxl/libxl_qmp.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index eab993a..0e993af 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -59,6 +59,13 @@ typedef struct callback_id_pair {
     LIBXL_STAILQ_ENTRY(struct callback_id_pair) next;
 } callback_id_pair;
 
+typedef struct event_handler_pair {
+    const char* event_type;
+    void *opaque;
+    qmp_request_context *context;
+    qmp_callback_t event_handler;
+} event_handler_pair;
+
 struct libxl__qmp_handler {
     struct sockaddr_un addr;
     int qmp_fd;
@@ -66,6 +73,9 @@ struct libxl__qmp_handler {
     time_t timeout;
     /* wait_for_id will be used by the synchronous send function */
     int wait_for_id;
+    /* wait_for_event_type is used to wait on QMP events */
+    const char* wait_for_event_type;
+    event_handler_pair *ehp;
 
     char buffer[QMP_RECEIVE_BUFFER_SIZE + 1];
     libxl__yajl_ctx *yajl_ctx;
@@ -287,6 +297,27 @@ static void qmp_handle_error_response(libxl__gc *gc, 
libxl__qmp_handler *qmp,
          libxl__json_object_get_string(resp));
 }
 
+static void qmp_handle_event(libxl__gc *gc, libxl__qmp_handler *qmp,
+                             const libxl__json_object *event)
+{
+    const char* event_type = NULL;
+    const libxl__json_object *event_o = NULL;
+    event_o = libxl__json_map_get("event", event, JSON_ANY);
+    event_type = libxl__json_object_get_string(event_o);
+    int rc;
+
+    if(qmp->wait_for_event_type &&
+        !strcmp(event_type, qmp->wait_for_event_type)) {
+        if(qmp->ehp->event_handler) {
+            rc = qmp->ehp->event_handler(qmp,
+                           libxl__json_map_get("data", event, JSON_ANY),
+                           qmp->ehp->opaque);
+        }
+        qmp->ehp->context->rc = rc;
+        qmp->wait_for_event_type = NULL;
+    }
+}
+
 static int qmp_handle_response(libxl__gc *gc, libxl__qmp_handler *qmp,
                                const libxl__json_object *resp)
 {
@@ -325,6 +356,7 @@ static int qmp_handle_response(libxl__gc *gc, 
libxl__qmp_handler *qmp,
         qmp_handle_error_response(gc, qmp, resp);
         return -1;
     case LIBXL__QMP_MESSAGE_TYPE_EVENT:
+        qmp_handle_event(gc, qmp, resp);
         return 0;
     case LIBXL__QMP_MESSAGE_TYPE_INVALID:
         return -1;
@@ -624,6 +656,32 @@ static void qmp_free_handler(libxl__qmp_handler *qmp)
     free(qmp);
 }
 
+static int __attribute__((unused)) wait_for_event(libxl__qmp_handler *qmp,
+                                                  event_handler_pair *ehp,
+                                                  int timeout)
+{
+    int ret = 0;
+    GC_INIT(qmp->ctx);
+    qmp->timeout = timeout;
+    qmp_request_context context = { .rc = 0 };
+    qmp->ehp = ehp;
+    qmp->wait_for_event_type = ehp->event_type;
+    ehp->context = &context;
+
+    while (qmp->wait_for_event_type) {
+        if ((ret = qmp_next(gc, qmp)) < 0) {
+            break;
+        }
+    }
+
+    if (!qmp->wait_for_event_type && ret == 0)
+        ret = context.rc;
+
+    GC_FREE;
+
+    return ret;
+}
+
 /*
  * QMP Parameters Helpers
  */
-- 
2.3.2 (Apple Git-55)


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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.