[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 19/32] libxl_qmp: Prepare the command to be sent
The actual sent will be done in a separate patch. Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx> --- tools/libxl/libxl_internal.h | 4 ++++ tools/libxl/libxl_qmp.c | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 7f200e7a46..110b951bbe 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -438,6 +438,7 @@ struct libxl__ev_qmp { libxl__carefd *qmp_cfd; libxl__ev_fd qmp_efd; libxl__qmp_state qmp_state; + unsigned int last_id_used; /* receive buffer, with: * buf_size: current allocated size, @@ -447,6 +448,9 @@ struct libxl__ev_qmp { size_t buf_size; size_t buf_used; size_t buf_consumed; + + char *tx_buf; + size_t tx_buf_len; }; diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 38a4395266..2792f35912 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -1310,6 +1310,25 @@ int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, /* ------------ Implementation of libxl__ev_qmp ---------------- */ +static int qmp_ev_prepare_cmd(libxl__gc *gc, + libxl__ev_qmp *ev, + const char *cmd, + const libxl__json_object *args) +{ + char *buf = NULL; + size_t len; + + buf = qmp_prepare_qmp_cmd(gc, cmd, args, ++ev->last_id_used, &len); + if (!buf) + return ERROR_FAIL; + + ev->id = ev->last_id_used; + ev->tx_buf = buf; + ev->tx_buf_len = len; + + return 0; +} + /* * QMP FD callbacks */ @@ -1424,6 +1443,9 @@ static void qmp_ev_callback_error(libxl__egc *egc, libxl__ev_qmp *ev) /* On error, deallocate all private ressources */ libxl__ev_qmp_dispose(gc, ev); + + ev->id = -1; + ev->callback(egc, ev, NULL, ERROR_FAIL); } static void qmp_ev_fd_callback(libxl__egc *egc, libxl__ev_fd *ev_fd, @@ -1522,8 +1544,10 @@ void libxl__ev_qmp_init(libxl__ev_qmp *ev) ev->qmp_cfd = NULL; libxl__ev_fd_init(&ev->qmp_efd); ev->qmp_state = qmp_state_disconnected; + ev->last_id_used = 0; ev->rx_buf = NULL; + ev->tx_buf = NULL; } int libxl__ev_qmp_send(libxl__gc *gc, libxl__ev_qmp *ev, @@ -1535,7 +1559,17 @@ int libxl__ev_qmp_send(libxl__gc *gc, libxl__ev_qmp *ev, /* Connect to QEMU if not already connected */ rc = qmp_ev_connect(gc, ev); + if (rc) + goto out; + + rc = qmp_ev_prepare_cmd(gc, ev, cmd, args); + if (rc) + goto out; + +out: + if (rc) + libxl__ev_qmp_dispose(gc, ev); return rc; } @@ -1546,6 +1580,9 @@ void libxl__ev_qmp_dispose(libxl__gc *gc, libxl__ev_qmp *ev) free(ev->rx_buf); ev->rx_buf = NULL; + free(ev->tx_buf); + ev->tx_buf = NULL; + libxl__ev_fd_deregister(gc, &ev->qmp_efd); libxl__carefd_close(ev->qmp_cfd); ev->qmp_cfd = NULL; -- Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |