[lttng-dev] [Patch LTTng-ust 5/7] Send and receive serialized metadata for CTF named enumerations
Mathieu Desnoyers
mathieu.desnoyers at efficios.com
Thu Jan 30 20:31:22 EST 2014
----- Original Message -----
> From: "Geneviève Bastien" <gbastien+lttng at versatic.net>
> To: lttng-dev at lists.lttng.org
> Sent: Friday, January 24, 2014 3:04:43 PM
> Subject: [lttng-dev] [Patch LTTng-ust 5/7] Send and receive serialized metadata for CTF named enumerations
>
> Updates the functions used for the communication between UST and the session
> daemon so that named metadata can be sent and received. The description of
> the
> metadata follows the event that use them.
Looks good!
Thanks!
Acked-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> The extra fields for each metadata
> follow the descriptions of all metadata.
>
> Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
> ---
> include/lttng/ust-ctl.h | 4 +-
> include/ust-comm.h | 8 ++-
> liblttng-ust-comm/lttng-ust-comm.c | 110
> ++++++++++++++++++++++++++++++++-----
> liblttng-ust-ctl/ustctl.c | 74 ++++++++++++++++++++++++-
> liblttng-ust/lttng-events.c | 4 +-
> 5 files changed, 181 insertions(+), 19 deletions(-)
>
> diff --git a/include/lttng/ust-ctl.h b/include/lttng/ust-ctl.h
> index 29c89fe..1c82111 100644
> --- a/include/lttng/ust-ctl.h
> +++ b/include/lttng/ust-ctl.h
> @@ -421,7 +421,9 @@ int ustctl_recv_register_event(int sock,
> */
> size_t *nr_fields,
> struct ustctl_field **fields,
> - char **model_emf_uri);
> + char **model_emf_uri,
> + size_t *nr_metadata,
> + struct ustctl_named_metadata **named_metadata);
>
> /*
> * Returns 0 on success, negative error value on error.
> diff --git a/include/ust-comm.h b/include/ust-comm.h
> index b9bbb39..40ba09b 100644
> --- a/include/ust-comm.h
> +++ b/include/ust-comm.h
> @@ -49,6 +49,7 @@
> #define LTTNG_UST_COMM_REG_MSG_PADDING 64
>
> struct lttng_event_field;
> +struct lttng_named_metadata;
> struct lttng_ctx_field;
>
> struct ustctl_reg_msg {
> @@ -127,7 +128,7 @@ struct ustcomm_notify_hdr {
> uint32_t notify_cmd;
> } LTTNG_PACKED;
>
> -#define USTCOMM_NOTIFY_EVENT_MSG_PADDING 32
> +#define USTCOMM_NOTIFY_EVENT_MSG_PADDING 28
> struct ustcomm_notify_event_msg {
> uint32_t session_objd;
> uint32_t channel_objd;
> @@ -136,6 +137,7 @@ struct ustcomm_notify_event_msg {
> uint32_t signature_len;
> uint32_t fields_len;
> uint32_t model_emf_uri_len;
> + uint32_t metadata_len;
> char padding[USTCOMM_NOTIFY_EVENT_MSG_PADDING];
> /* followed by signature, fields, and model_emf_uri */
> } LTTNG_PACKED;
> @@ -221,7 +223,9 @@ int ustcomm_register_event(int sock,
> size_t nr_fields, /* fields */
> const struct lttng_event_field *fields,
> const char *model_emf_uri,
> - uint32_t *id); /* event id (output) */
> + uint32_t *id, /* event id (output) */
> + size_t nr_metadata,
> + const struct lttng_named_metadata *lttng_metadata); /* named metadata */
>
> /*
> * Returns 0 on success, negative error value on error.
> diff --git a/liblttng-ust-comm/lttng-ust-comm.c
> b/liblttng-ust-comm/lttng-ust-comm.c
> index 1744b9f..33620fc 100644
> --- a/liblttng-ust-comm/lttng-ust-comm.c
> +++ b/liblttng-ust-comm/lttng-ust-comm.c
> @@ -1012,7 +1012,9 @@ int ustcomm_register_event(int sock,
> size_t nr_fields, /* fields */
> const struct lttng_event_field *lttng_fields,
> const char *model_emf_uri,
> - uint32_t *id) /* event id (output) */
> + uint32_t *id, /* event id (output) */
> + size_t nr_metadata,
> + const struct lttng_named_metadata *lttng_metadata) /* named metadata */
> {
> ssize_t len;
> struct {
> @@ -1023,10 +1025,12 @@ int ustcomm_register_event(int sock,
> struct ustcomm_notify_hdr header;
> struct ustcomm_notify_event_reply r;
> } reply;
> - size_t signature_len, fields_len, model_emf_uri_len;
> + size_t signature_len, fields_len, model_emf_uri_len, metadata_len;
> struct ustctl_field *fields = NULL;
> + struct ustctl_named_metadata *metadata = NULL;
> size_t nr_write_fields = 0;
> - int ret;
> + size_t nr_write_metadata = 0;
> + int ret, i;
>
> memset(&msg, 0, sizeof(msg));
> msg.header.notify_cmd = USTCTL_NOTIFY_CMD_EVENT;
> @@ -1054,14 +1058,26 @@ int ustcomm_register_event(int sock,
> model_emf_uri_len = 0;
> }
> msg.m.model_emf_uri_len = model_emf_uri_len;
> + /* Calculate metadata len, serialize metadata. */
> + if (nr_metadata > 0) {
> + ret = serialize_metadata(&nr_write_metadata, &metadata,
> + nr_metadata, lttng_metadata);
> + if (ret) {
> + free(fields);
> + return ret;
> + }
> + }
> + metadata_len = sizeof(*metadata) * nr_write_metadata;
> + msg.m.metadata_len = metadata_len;
> +
> len = ustcomm_send_unix_sock(sock, &msg, sizeof(msg));
> if (len > 0 && len != sizeof(msg)) {
> - free(fields);
> - return -EIO;
> + ret = -EIO;
> + goto error_fields;
> }
> if (len < 0) {
> - free(fields);
> - return len;
> + ret = len;
> + goto error_fields;
> }
>
> /* send signature */
> @@ -1080,10 +1096,12 @@ int ustcomm_register_event(int sock,
> len = ustcomm_send_unix_sock(sock, fields, fields_len);
> free(fields);
> if (len > 0 && len != fields_len) {
> - return -EIO;
> + ret = -EIO;
> + goto error_metadata;
> }
> if (len < 0) {
> - return len;
> + ret = len;
> + goto error_metadata;
> }
> } else {
> free(fields);
> @@ -1093,10 +1111,57 @@ int ustcomm_register_event(int sock,
> /* send model_emf_uri */
> len = ustcomm_send_unix_sock(sock, model_emf_uri,
> model_emf_uri_len);
> - if (len > 0 && len != model_emf_uri_len)
> - return -EIO;
> - if (len < 0)
> - return len;
> + if (len > 0 && len != model_emf_uri_len) {
> + ret = -EIO;
> + goto error_metadata;
> + }
> + if (len < 0) {
> + ret = len;
> + goto error_metadata;
> + }
> + }
> +
> + /* Send metadata */
> + if (metadata_len > 0) {
> + len = ustcomm_send_unix_sock(sock, metadata, metadata_len);
> + DBG("Sending named metadata for event %s.\n", event_name);
> + if (len > 0 && len != metadata_len) {
> + goto error_metadata;
> + }
> + if (len < 0) {
> + goto error_metadata;
> + }
> + /* Send extra metadata information */
> + for (i = 0; i < nr_write_metadata; i++) {
> + struct ustctl_named_metadata *one_metadata;
> + one_metadata = &metadata[i];
> +
> + switch (one_metadata->mtype) {
> + case ustctl_mtype_enum:
> + {
> + int entry_len = one_metadata->u.ctf_enum.len *
> sizeof(*one_metadata->u.ctf_enum.entries);
> + DBG("Sending entries for enum metadata %s.\n",
> + one_metadata->u.ctf_enum.name);
> + /* Send the entries */
> + len = ustcomm_send_unix_sock(sock, one_metadata->u.ctf_enum.entries,
> entry_len);
> + free(one_metadata->u.ctf_enum.entries);
> + one_metadata->u.ctf_enum.entries = NULL;
> + if (len > 0 && len != entry_len) {
> + goto error_metadata;
> + }
> + if (len < 0) {
> + goto error_metadata;
> + }
> + break;
> + }
> + default:
> + break;
> + }
> + }
> + free(metadata);
> +
> + } else {
> + free(metadata);
> }
>
> /* receive reply */
> @@ -1130,6 +1195,25 @@ int ustcomm_register_event(int sock,
> return len;
> }
> }
> +
> +error_fields:
> + free(fields);
> +error_metadata:
> + /* First free dynamically allocated content in metadata */
> + for (i = 0; i < nr_write_metadata; i++) {
> + struct ustctl_named_metadata *one_metadata;
> + one_metadata = &metadata[i];
> +
> + switch (one_metadata->mtype) {
> + case ustctl_mtype_enum:
> + free(one_metadata->u.ctf_enum.entries);
> + break;
> + default:
> + break;
> + }
> + }
> + free(metadata);
> + return ret;
> }
>
> /*
> diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
> index 00d9802..9f8ca87 100644
> --- a/liblttng-ust-ctl/ustctl.c
> +++ b/liblttng-ust-ctl/ustctl.c
> @@ -1724,13 +1724,17 @@ int ustctl_recv_register_event(int sock,
> char **signature,
> size_t *nr_fields,
> struct ustctl_field **fields,
> - char **model_emf_uri)
> + char **model_emf_uri,
> + size_t *nr_metadata,
> + struct ustctl_named_metadata **named_metadata)
> {
> ssize_t len;
> struct ustcomm_notify_event_msg msg;
> - size_t signature_len, fields_len, model_emf_uri_len;
> + size_t signature_len, fields_len, model_emf_uri_len, metadata_len;
> char *a_sign = NULL, *a_model_emf_uri = NULL;
> struct ustctl_field *a_fields = NULL;
> + struct ustctl_named_metadata *a_metadata = NULL;
> + int i;
>
> len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg));
> if (len > 0 && len != sizeof(msg))
> @@ -1754,6 +1758,12 @@ int ustctl_recv_register_event(int sock,
>
> model_emf_uri_len = msg.model_emf_uri_len;
>
> + metadata_len = msg.metadata_len;
> +
> + if (metadata_len % sizeof(*a_metadata) != 0) {
> + return -EINVAL;
> + }
> +
> /* recv signature. contains at least \0. */
> a_sign = zmalloc(signature_len);
> if (!a_sign)
> @@ -1818,13 +1828,73 @@ int ustctl_recv_register_event(int sock,
> a_model_emf_uri[model_emf_uri_len - 1] = '\0';
> }
>
> + /* recv metadata */
> + if (metadata_len) {
> + a_metadata = zmalloc(metadata_len);
> + if (!a_metadata) {
> + len = -ENOMEM;
> + goto signature_error;
> + }
> + len = ustcomm_recv_unix_sock(sock, a_metadata, metadata_len);
> + DBG("Received named metadata for event %s.\n", event_name);
> + if (len > 0 && len != metadata_len) {
> + len = -EIO;
> + goto metadata_error;
> + }
> + if (len == 0) {
> + len = -EPIPE;
> + goto metadata_error;
> + }
> + if (len < 0) {
> + goto metadata_error;
> + }
> + /* Receive extra metadata information */
> + for (i = 0; i < metadata_len / sizeof(*a_metadata); i++) {
> + struct ustctl_named_metadata *one_metadata;
> + one_metadata = &a_metadata[i];
> +
> + switch (one_metadata->mtype) {
> + case ustctl_mtype_enum:
> + {
> + int entry_len = one_metadata->u.ctf_enum.len *
> sizeof(*one_metadata->u.ctf_enum.entries);
> + /* Send the entries */
> + one_metadata->u.ctf_enum.entries = zmalloc(entry_len);
> + if (!one_metadata->u.ctf_enum.entries) {
> + len = -ENOMEM;
> + goto metadata_error;
> + }
> + len = ustcomm_recv_unix_sock(sock, one_metadata->u.ctf_enum.entries,
> entry_len);
> + DBG("Received entries for enum %s.\n", one_metadata->u.ctf_enum.name);
> + if (len > 0 && len != entry_len) {
> + len = -EIO;
> + goto metadata_error;
> + }
> + if (len == 0) {
> + len = -EPIPE;
> + goto metadata_error;
> + }
> + if (len < 0) {
> + goto metadata_error;
> + }
> + break;
> + }
> + default:
> + break;
> + }
> + }
> + }
> +
> *signature = a_sign;
> *nr_fields = fields_len / sizeof(*a_fields);
> *fields = a_fields;
> *model_emf_uri = a_model_emf_uri;
> + *nr_metadata = metadata_len / sizeof(*a_metadata);
> + *named_metadata = a_metadata;
>
> return 0;
>
> +metadata_error:
> + free(a_metadata);
> model_error:
> free(a_model_emf_uri);
> fields_error:
> diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c
> index 6e16cf2..26a4427 100644
> --- a/liblttng-ust/lttng-events.c
> +++ b/liblttng-ust/lttng-events.c
> @@ -430,7 +430,9 @@ int lttng_event_create(const struct lttng_event_desc
> *desc,
> desc->nr_fields,
> desc->fields,
> uri,
> - &event->id);
> + &event->id,
> + desc->u.ext.nr_metadata,
> + desc->u.ext.named_metadata);
> if (ret < 0) {
> DBG("Error (%d) registering event to sessiond", ret);
> goto sessiond_register_error;
> --
> 1.8.5.3
>
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list