From: Philippe Proulx Date: Wed, 26 Aug 2015 19:44:27 +0000 (-0400) Subject: Add command header to sessiond->client response msg X-Git-Tag: v2.8.0-rc1~146 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=795a978d0fddb43019e4031932cf98840c54f504;p=lttng-tools.git Add command header to sessiond->client response msg Response messages from the session daemon have this layout for the moment: [message header] (fixed size) [payload data] (0 to n bytes) This patch makes them have this layout: [message header] (fixed size) [command header] (0 to n bytes) [payload data] (0 to n bytes) The command header allows a command to specify additional informations about its payload. The header size is set to 0 for all commands for the moment. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index ec7d36ae5..0d9f4a699 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -348,6 +348,7 @@ struct lttcomm_lttng_msg { uint32_t cmd_type; /* enum lttcomm_sessiond_command */ uint32_t ret_code; /* enum lttcomm_return_code */ uint32_t pid; /* pid_t */ + uint32_t cmd_header_size; uint32_t data_size; /* Contains: trace_name + data */ char payload[]; diff --git a/src/lib/lttng-ctl/lttng-ctl-helper.h b/src/lib/lttng-ctl/lttng-ctl-helper.h index b7a28268c..8e9786bc2 100644 --- a/src/lib/lttng-ctl/lttng-ctl-helper.h +++ b/src/lib/lttng-ctl/lttng-ctl-helper.h @@ -42,7 +42,20 @@ void lttng_ctl_copy_lttng_domain(struct lttng_domain *dst, * error code. If buf is NULL, 0 is returned on success. */ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, - const void *vardata, size_t varlen, void **buf); + const void *vardata, size_t vardata_len, + void **user_payload_buf, void **user_cmd_header_buf, + size_t *user_cmd_header_len); + +/* + * Calls lttng_ctl_ask_sessiond_varlen() with no expected command header. + */ +static inline +int lttng_ctl_ask_sessiond_varlen_no_cmd_header(struct lttcomm_session_msg *lsm, + void *vardata, size_t vardata_len, void **user_payload_buf) +{ + return lttng_ctl_ask_sessiond_varlen(lsm, vardata, + vardata_len, user_payload_buf, NULL, NULL); +} /* * Use this if no variable length data needs to be sent. @@ -50,7 +63,7 @@ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, static inline int lttng_ctl_ask_sessiond(struct lttcomm_session_msg *lsm, void **buf) { - return lttng_ctl_ask_sessiond_varlen(lsm, NULL, 0, buf); + return lttng_ctl_ask_sessiond_varlen_no_cmd_header(lsm, NULL, 0, buf); } int lttng_check_tracing_group(void); diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index afa741c05..b47231e00 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -392,6 +392,54 @@ static int disconnect_sessiond(void) return ret; } +static int recv_sessiond_optional_data(size_t len, void **user_buf, + size_t *user_len) +{ + int ret = 0; + void *buf = NULL; + + if (len) { + if (!user_len) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + buf = zmalloc(len); + if (!buf) { + ret = -ENOMEM; + goto end; + } + + ret = recv_data_sessiond(buf, len); + if (ret < 0) { + goto end; + } + + if (!user_buf) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + /* Move ownership of command header buffer to user. */ + *user_buf = buf; + buf = NULL; + *user_len = len; + } else { + /* No command header. */ + if (user_len) { + *user_len = 0; + } + + if (user_buf) { + *user_buf = NULL; + } + } + +end: + free(buf); + return ret; +} + /* * Ask the session daemon a specific command and put the data into buf. * Takes extra var. len. data as input to send to the session daemon. @@ -400,11 +448,12 @@ static int disconnect_sessiond(void) */ LTTNG_HIDDEN int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, - const void *vardata, size_t varlen, void **buf) + const void *vardata, size_t vardata_len, + void **user_payload_buf, void **user_cmd_header_buf, + size_t *user_cmd_header_len) { int ret; - size_t size; - void *data = NULL; + size_t payload_len; struct lttcomm_lttng_msg llm; ret = connect_sessiond(); @@ -420,7 +469,7 @@ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, goto end; } /* Send var len data */ - ret = send_session_varlen(vardata, varlen); + ret = send_session_varlen(vardata, vardata_len); if (ret < 0) { /* Ret value is a valid lttng error code. */ goto end; @@ -439,41 +488,21 @@ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, goto end; } - size = llm.data_size; - if (size == 0) { - /* If client free with size 0 */ - if (buf != NULL) { - *buf = NULL; - } - ret = 0; - goto end; - } - - data = zmalloc(size); - if (!data) { - ret = -ENOMEM; - goto end; - } - - /* Get payload data */ - ret = recv_data_sessiond(data, size); + /* Get command header from data transmission */ + ret = recv_sessiond_optional_data(llm.cmd_header_size, + user_cmd_header_buf, user_cmd_header_len); if (ret < 0) { - free(data); goto end; } - /* - * Extra protection not to dereference a NULL pointer. If buf is NULL at - * this point, an error is returned and data is freed. - */ - if (buf == NULL) { - ret = -LTTNG_ERR_INVALID; - free(data); + /* Get payload from data transmission */ + ret = recv_sessiond_optional_data(llm.data_size, user_payload_buf, + &payload_len); + if (ret < 0) { goto end; } - *buf = data; - ret = size; + ret = llm.data_size; end: disconnect_sessiond(); @@ -711,7 +740,7 @@ int lttng_add_context(struct lttng_handle *handle, lsm.u.context.ctx.u.app_ctx.provider_name = NULL; lsm.u.context.ctx.u.app_ctx.ctx_name = NULL; - ret = lttng_ctl_ask_sessiond_varlen(&lsm, buf, len, NULL); + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL); end: free(buf); return ret; @@ -1075,7 +1104,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, lsm.u.enable.bytecode_len); } - ret = lttng_ctl_ask_sessiond_varlen(&lsm, varlen_data, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, varlen_data, (LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count) + lsm.u.enable.bytecode_len + lsm.u.enable.expression_len, NULL); @@ -1234,7 +1263,7 @@ int lttng_disable_event_ext(struct lttng_handle *handle, lsm.u.disable.bytecode_len); } - ret = lttng_ctl_ask_sessiond_varlen(&lsm, varlen_data, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, varlen_data, lsm.u.disable.bytecode_len + lsm.u.disable.expression_len, NULL); free(varlen_data); @@ -1514,7 +1543,7 @@ int lttng_create_session(const char *name, const char *url) lsm.u.uri.size = size; - ret = lttng_ctl_ask_sessiond_varlen(&lsm, uris, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris, sizeof(struct lttng_uri) * size, NULL); free(uris); @@ -1882,7 +1911,7 @@ int lttng_set_consumer_url(struct lttng_handle *handle, lsm.u.uri.size = size; - ret = lttng_ctl_ask_sessiond_varlen(&lsm, uris, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris, sizeof(struct lttng_uri) * size, NULL); free(uris); @@ -1965,7 +1994,7 @@ int _lttng_create_session_ext(const char *name, const char *url, } } - ret = lttng_ctl_ask_sessiond_varlen(&lsm, uris, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris, sizeof(struct lttng_uri) * size, NULL); error: @@ -2037,7 +2066,7 @@ int lttng_create_session_snapshot(const char *name, const char *snapshot_url) lsm.u.uri.size = size; - ret = lttng_ctl_ask_sessiond_varlen(&lsm, uris, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris, sizeof(struct lttng_uri) * size, NULL); free(uris); @@ -2085,7 +2114,7 @@ int lttng_create_session_live(const char *name, const char *url, lsm.u.session_live.nb_uri = size; lsm.u.session_live.timer_interval = timer_interval; - ret = lttng_ctl_ask_sessiond_varlen(&lsm, uris, + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris, sizeof(struct lttng_uri) * size, NULL); end: