Add command header to sessiond->client response msg
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 26 Aug 2015 19:44:27 +0000 (15:44 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Feb 2016 21:45:55 +0000 (16:45 -0500)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/sessiond-comm/sessiond-comm.h
src/lib/lttng-ctl/lttng-ctl-helper.h
src/lib/lttng-ctl/lttng-ctl.c

index ec7d36ae50d07d021738d635a44267d7de84fc03..0d9f4a699479568db957669a2e9814d50a56e323 100644 (file)
@@ -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_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[];
        uint32_t data_size;
        /* Contains: trace_name + data */
        char payload[];
index b7a28268cb3b4ce83b95eb978667951527064212..8e9786bc244dd361081133c960d9bd785f0da3e8 100644 (file)
@@ -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,
  * 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.
 
 /*
  * 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)
 {
 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);
 }
 
 int lttng_check_tracing_group(void);
index afa741c05b93554c00ec5dd70d90472123176a8b..b47231e00e060ddc58a337f63d96bd5f23ea3e5b 100644 (file)
@@ -392,6 +392,54 @@ static int disconnect_sessiond(void)
        return ret;
 }
 
        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.
 /*
  * 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,
  */
 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;
 {
        int ret;
-       size_t size;
-       void *data = NULL;
+       size_t payload_len;
        struct lttcomm_lttng_msg llm;
 
        ret = connect_sessiond();
        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 */
                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;
        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;
        }
 
                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) {
        if (ret < 0) {
-               free(data);
                goto end;
        }
 
                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;
        }
 
                goto end;
        }
 
-       *buf = data;
-       ret = size;
+       ret = llm.data_size;
 
 end:
        disconnect_sessiond();
 
 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;
 
        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;
 end:
        free(buf);
        return ret;
@@ -1075,7 +1104,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
                        lsm.u.enable.bytecode_len);
        }
 
                        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);
                        (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);
        }
 
                        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);
 
                        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;
 
 
        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);
                        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;
 
 
        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);
                        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:
                        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;
 
 
        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);
                        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;
 
        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:
                        sizeof(struct lttng_uri) * size, NULL);
 
 end:
This page took 0.030263 seconds and 4 git commands to generate.