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

[Xen-changelog] [xen-unstable] libxl: split libxl__qmp_send



# HG changeset patch
# User Anthony PERARD <anthony.perard@xxxxxxxxxx>
# Date 1322762982 0
# Node ID 92cc4631836c45a6b0945af35da2771fe42f66b9
# Parent  ad5941e51c87aba4f0e1934b1d7ec2d37763a9eb
libxl: split libxl__qmp_send

This patch prepares for the next patch, that will introduce an
alternative send function.

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


diff -r ad5941e51c87 -r 92cc4631836c tools/libxl/libxl_qmp.c
--- a/tools/libxl/libxl_qmp.c   Thu Dec 01 18:04:13 2011 +0000
+++ b/tools/libxl/libxl_qmp.c   Thu Dec 01 18:09:42 2011 +0000
@@ -446,13 +446,14 @@
     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_request_context *context)
+static char *qmp_send_prepare(libxl__gc *gc, libxl__qmp_handler *qmp,
+                              const char *cmd, libxl_key_value_list *args,
+                              qmp_callback_t callback, void *opaque,
+                              qmp_request_context *context)
 {
     yajl_gen_config conf = { 0, NULL };
-    const unsigned char *buf;
+    const unsigned char *buf = NULL;
+    char *ret = NULL;
     unsigned int len = 0;
     yajl_gen_status s;
     yajl_gen hand;
@@ -460,7 +461,7 @@
 
     hand = yajl_gen_alloc(&conf, NULL);
     if (!hand) {
-        return -1;
+        return NULL;
     }
 
     yajl_gen_map_open(hand);
@@ -479,14 +480,14 @@
     if (s) {
         LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR,
                    "Failed to generate a qmp command");
-        return -1;
+        goto out;
     }
 
     elm = malloc(sizeof (callback_id_pair));
     if (elm == NULL) {
         LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR,
                          "Failed to allocate a QMP callback");
-        goto error;
+        goto out;
     }
     elm->id = qmp->last_id_used;
     elm->callback = callback;
@@ -494,22 +495,41 @@
     elm->context = context;
     SIMPLEQ_INSERT_TAIL(&qmp->callback_list, elm, next);
 
+    ret = libxl__strndup(gc, (const char*)buf, len);
+
     LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG, "next qmp command: '%s'", buf);
 
-    if (libxl_write_exactly(qmp->ctx, qmp->qmp_fd, buf, len,
+out:
+    yajl_gen_free(hand);
+    return ret;
+}
+
+static int qmp_send(libxl__qmp_handler *qmp,
+                    const char *cmd, libxl_key_value_list *args,
+                    qmp_callback_t callback, void *opaque,
+                    qmp_request_context *context)
+{
+    char *buf = NULL;
+    int rc = -1;
+    libxl__gc gc = LIBXL_INIT_GC(qmp->ctx);
+
+    buf = qmp_send_prepare(&gc, qmp, cmd, args, callback, opaque, context);
+
+    if (buf == NULL) {
+        goto out;
+    }
+
+    if (libxl_write_exactly(qmp->ctx, qmp->qmp_fd, buf, strlen(buf),
                             "QMP command", "QMP socket"))
-        goto error;
+        goto out;
     if (libxl_write_exactly(qmp->ctx, qmp->qmp_fd, "\r\n", 2,
                             "CRLF", "QMP socket"))
-        goto error;
+        goto out;
 
-    yajl_gen_free(hand);
-
-    return qmp->last_id_used;
-
-error:
-    yajl_gen_free(hand);
-    return -1;
+    rc = qmp->last_id_used;
+out:
+    libxl__free_all(&gc);
+    return rc;
 }
 
 static int qmp_synchronous_send(libxl__qmp_handler *qmp, const char *cmd,

_______________________________________________
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®.