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

[Xen-changelog] [xen-unstable] libxl: libxl_qmp: Introduce qmp_request_context.



# HG changeset patch
# User Anthony PERARD <anthony.perard@xxxxxxxxxx>
# Date 1320410305 0
# Node ID 8d06378f148709fcc5d4861cbc50b40934c5b273
# Parent  0406f6783c65f246c10ee946d9646538a1e7fc31
libxl: libxl_qmp: Introduce qmp_request_context.

This structure helps to track the return code of a callback. It's only used
between qmp_synchronous_send and qmp_send.

Now, qmp_synchronous_send will return the rc of the callback if there is no
error.

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


diff -r 0406f6783c65 -r 8d06378f1487 tools/libxl/libxl_qmp.c
--- a/tools/libxl/libxl_qmp.c   Fri Nov 04 12:38:24 2011 +0000
+++ b/tools/libxl/libxl_qmp.c   Fri Nov 04 12:38:25 2011 +0000
@@ -46,10 +46,15 @@
                               const libxl__json_object *tree,
                               void *opaque);
 
+typedef struct qmp_request_context {
+    int rc;
+} qmp_request_context;
+
 typedef struct callback_id_pair {
     int id;
     qmp_callback_t callback;
     void *opaque;
+    qmp_request_context *context;
     SIMPLEQ_ENTRY(callback_id_pair) next;
 } callback_id_pair;
 
@@ -73,7 +78,8 @@
 
 static int qmp_send(libxl__qmp_handler *qmp,
                     const char *cmd, libxl_key_value_list *args,
-                    qmp_callback_t callback, void *opaque);
+                    qmp_callback_t callback, void *opaque,
+                    qmp_request_context *context);
 
 static const int QMP_SOCKET_CONNECT_TIMEOUT = 5;
 
@@ -162,7 +168,7 @@
 static int enable_qmp_capabilities(libxl__qmp_handler *qmp)
 {
     return qmp_send(qmp, "qmp_capabilities", NULL,
-                    qmp_capabilities_callback, NULL);
+                    qmp_capabilities_callback, NULL, NULL);
 }
 
 /*
@@ -214,7 +220,10 @@
 
     if (pp) {
         if (pp->callback) {
-            pp->callback(qmp, NULL, pp->opaque);
+            int rc = pp->callback(qmp, NULL, pp->opaque);
+            if (pp->context) {
+                pp->context->rc = rc;
+            }
         }
         if (pp->id == qmp->wait_for_id) {
             /* tell that the id have been processed */
@@ -241,16 +250,18 @@
     switch (type) {
     case LIBXL__QMP_MESSAGE_TYPE_QMP:
         /* On the greeting message from the server, enable QMP capabilities */
-        enable_qmp_capabilities(qmp);
-        break;
+        return enable_qmp_capabilities(qmp);
     case LIBXL__QMP_MESSAGE_TYPE_RETURN: {
         callback_id_pair *pp = qmp_get_callback_from_id(qmp, resp);
 
         if (pp) {
             if (pp->callback) {
-                pp->callback(qmp,
+                int rc = pp->callback(qmp,
                              libxl__json_map_get("return", resp, JSON_ANY),
                              pp->opaque);
+                if (pp->context) {
+                    pp->context->rc = rc;
+                }
             }
             if (pp->id == qmp->wait_for_id) {
                 /* tell that the id have been processed */
@@ -259,13 +270,13 @@
             SIMPLEQ_REMOVE(&qmp->callback_list, pp, callback_id_pair, next);
             free(pp);
         }
-        break;
+        return 0;
     }
     case LIBXL__QMP_MESSAGE_TYPE_ERROR:
         qmp_handle_error_response(qmp, resp);
-        break;
+        return -1;
     case LIBXL__QMP_MESSAGE_TYPE_EVENT:
-        break;
+        return 0;
     case LIBXL__QMP_MESSAGE_TYPE_INVALID:
         return -1;
     }
@@ -358,6 +369,7 @@
 
     char *incomplete = NULL;
     size_t incomplete_size = 0;
+    int rc = 0;
 
     do {
         fd_set rfds;
@@ -415,7 +427,7 @@
                 o = libxl__json_parse(gc, s);
 
                 if (o) {
-                    qmp_handle_response(qmp, o);
+                    rc = qmp_handle_response(qmp, o);
                     libxl__json_object_free(gc, o);
                 } else {
                     LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR,
@@ -430,12 +442,13 @@
         } while (s < s_end);
    } while (s < s_end);
 
-    return 1;
+    return rc;
 }
 
 static int qmp_send(libxl__qmp_handler *qmp,
                     const char *cmd, libxl_key_value_list *args,
-                    qmp_callback_t callback, void *opaque)
+                    qmp_callback_t callback, void *opaque,
+                    qmp_request_context *context)
 {
     yajl_gen_config conf = { 0, NULL };
     const unsigned char *buf;
@@ -477,6 +490,7 @@
     elm->id = qmp->last_id_used;
     elm->callback = callback;
     elm->opaque = opaque;
+    elm->context = context;
     SIMPLEQ_INSERT_TAIL(&qmp->callback_list, elm, next);
 
     LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG, "next qmp command: '%s'", buf);
@@ -505,8 +519,9 @@
     int id = 0;
     int ret = 0;
     libxl__gc gc = LIBXL_INIT_GC(qmp->ctx);
+    qmp_request_context context = { .rc = 0 };
 
-    id = qmp_send(qmp, cmd, args, callback, opaque);
+    id = qmp_send(qmp, cmd, args, callback, opaque, &context);
     if (id <= 0) {
         return -1;
     }
@@ -514,13 +529,17 @@
 
     while (qmp->wait_for_id == id) {
         if ((ret = qmp_next(&gc, qmp)) < 0) {
-            return ret;
+            break;
         }
     }
 
+    if (qmp->wait_for_id != id && ret == 0) {
+        ret = context.rc;
+    }
+
     libxl__free_all(&gc);
 
-    return 0;
+    return ret;
 }
 
 static void qmp_free_handler(libxl__qmp_handler *qmp)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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