X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=liblttng-ust%2Flttng-events.c;h=b61a2293f4a8a83039f3a645da09e9fb60cab479;hb=88292c3396cfb2095bd9921d84cc2baa003bea32;hp=e489357421c92e3a4c3a0500451ca2daab746194;hpb=3b5babf8592ca27acaf01fca24406922fc5cc89c;p=lttng-ust.git diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index e4893574..b61a2293 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -54,9 +54,11 @@ #include "wait.h" #include "../libringbuffer/shm.h" #include "../libringbuffer/frontend_types.h" +#include "../libringbuffer/frontend.h" #include "../libcounter/counter.h" #include "jhash.h" #include +#include "context-provider-internal.h" /* * All operations within this file are called by the communication @@ -84,6 +86,22 @@ void lttng_event_notifier_group_sync_enablers( static void lttng_enabler_destroy(struct lttng_enabler *enabler); +bool lttng_ust_validate_event_name(const struct lttng_ust_event_desc *desc) +{ + if (strlen(desc->probe_desc->provider_name) + 1 + + strlen(desc->event_name) >= LTTNG_UST_ABI_SYM_NAME_LEN) + return false; + return true; +} + +void lttng_ust_format_event_name(const struct lttng_ust_event_desc *desc, + char *name) +{ + strcpy(name, desc->probe_desc->provider_name); + strcat(name, ":"); + strcat(name, desc->event_name); +} + /* * Called with ust lock held. */ @@ -238,7 +256,7 @@ void _lttng_channel_unmap(struct lttng_ust_channel_buffer *lttng_chan) cds_list_del(<tng_chan->priv->node); lttng_destroy_context(lttng_chan->priv->ctx); - chan = lttng_chan->chan; + chan = lttng_chan->priv->rb_chan; handle = chan->handle; channel_destroy(chan, handle, 0); free(lttng_chan->parent); @@ -250,11 +268,13 @@ static void register_event(struct lttng_ust_event_common *event) { int ret; - struct lttng_ust_event_desc *desc; + const struct lttng_ust_event_desc *desc; + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; assert(event->priv->registered == 0); desc = event->priv->desc; - ret = lttng_ust_tp_probe_register_queue_release(desc->name, + lttng_ust_format_event_name(desc, name); + ret = lttng_ust_tp_probe_register_queue_release(name, desc->probe_callback, event, desc->signature); WARN_ON_ONCE(ret); @@ -266,11 +286,13 @@ static void unregister_event(struct lttng_ust_event_common *event) { int ret; - struct lttng_ust_event_desc *desc; + const struct lttng_ust_event_desc *desc; + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; assert(event->priv->registered == 1); desc = event->priv->desc; - ret = lttng_ust_tp_probe_unregister_queue_release(desc->name, + lttng_ust_format_event_name(desc, name); + ret = lttng_ust_tp_probe_unregister_queue_release(name, desc->probe_callback, event); WARN_ON_ONCE(ret); @@ -398,7 +420,7 @@ void lttng_enabler_destroy(struct lttng_enabler *enabler) } static -int lttng_enum_create(struct lttng_ust_enum_desc *desc, +int lttng_enum_create(const struct lttng_ust_enum_desc *desc, struct lttng_ust_session *session) { const char *enum_name = desc->name; @@ -456,13 +478,13 @@ exist: } static -int lttng_create_enum_check(struct lttng_ust_type_common *type, +int lttng_create_enum_check(const struct lttng_ust_type_common *type, struct lttng_ust_session *session) { switch (type->type) { case lttng_ust_type_enum: { - struct lttng_ust_enum_desc *enum_desc; + const struct lttng_ust_enum_desc *enum_desc; int ret; enum_desc = lttng_ust_get_type_enum(type)->desc; @@ -475,8 +497,8 @@ int lttng_create_enum_check(struct lttng_ust_type_common *type, } case lttng_ust_type_dynamic: { - struct lttng_ust_event_field *tag_field_generic; - struct lttng_ust_enum_desc *enum_desc; + const struct lttng_ust_event_field *tag_field_generic; + const struct lttng_ust_enum_desc *enum_desc; int ret; tag_field_generic = lttng_ust_dynamic_type_tag_field(); @@ -497,7 +519,7 @@ int lttng_create_enum_check(struct lttng_ust_type_common *type, static int lttng_create_all_event_enums(size_t nr_fields, - struct lttng_ust_event_field **event_fields, + const struct lttng_ust_event_field **event_fields, struct lttng_ust_session *session) { size_t i; @@ -505,7 +527,7 @@ int lttng_create_all_event_enums(size_t nr_fields, /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - struct lttng_ust_type_common *type = event_fields[i]->type; + const struct lttng_ust_type_common *type = event_fields[i]->type; ret = lttng_create_enum_check(type, session); if (ret) @@ -516,7 +538,7 @@ int lttng_create_all_event_enums(size_t nr_fields, static int lttng_create_all_ctx_enums(size_t nr_fields, - struct lttng_ust_ctx_field **ctx_fields, + struct lttng_ust_ctx_field *ctx_fields, struct lttng_ust_session *session) { size_t i; @@ -524,7 +546,7 @@ int lttng_create_all_ctx_enums(size_t nr_fields, /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - struct lttng_ust_type_common *type = ctx_fields[i]->event_field->type; + const struct lttng_ust_type_common *type = ctx_fields[i].event_field->type; ret = lttng_create_enum_check(type, session); if (ret) @@ -571,7 +593,7 @@ int lttng_session_enable(struct lttng_ust_session *session) */ cds_list_for_each_entry(chan, &session->priv->chan_head, node) { struct lttng_ust_ctx *ctx; - struct lttng_ust_ctx_field **fields = NULL; + struct lttng_ust_ctx_field *fields = NULL; size_t nr_fields = 0; uint32_t chan_id; @@ -675,16 +697,16 @@ static inline struct cds_hlist_head *borrow_hash_table_bucket( struct cds_hlist_head *hash_table, unsigned int hash_table_size, - struct lttng_ust_event_desc *desc) + const struct lttng_ust_event_desc *desc) { - const char *event_name; + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; size_t name_len; uint32_t hash; - event_name = desc->name; - name_len = strlen(event_name); + lttng_ust_format_event_name(desc, name); + name_len = strlen(name); - hash = jhash(event_name, name_len, 0); + hash = jhash(name, name_len, 0); return &hash_table[hash & (hash_table_size - 1)]; } @@ -692,9 +714,10 @@ struct cds_hlist_head *borrow_hash_table_bucket( * Supports event creation while tracing session is active. */ static -int lttng_event_recorder_create(struct lttng_ust_event_desc *desc, +int lttng_event_recorder_create(const struct lttng_ust_event_desc *desc, struct lttng_ust_channel_buffer *chan) { + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; struct lttng_ust_event_recorder *event_recorder; struct lttng_ust_event_recorder_private *event_recorder_priv; struct lttng_ust_session *session = chan->parent->session; @@ -767,18 +790,20 @@ int lttng_event_recorder_create(struct lttng_ust_event_desc *desc, else uri = NULL; + lttng_ust_format_event_name(desc, name); + /* Fetch event ID from sessiond */ ret = ustcomm_register_event(notify_socket, session, session->priv->objd, chan->priv->parent.objd, - desc->name, + name, loglevel, desc->signature, desc->nr_fields, desc->fields, uri, - &event_recorder->id); + &event_recorder->priv->id); if (ret < 0) { DBG("Error (%d) registering event to sessiond", ret); goto sessiond_register_error; @@ -801,7 +826,7 @@ socket_error: } static -int lttng_event_notifier_create(struct lttng_ust_event_desc *desc, +int lttng_event_notifier_create(const struct lttng_ust_event_desc *desc, uint64_t token, uint64_t error_counter_index, struct lttng_event_notifier_group *event_notifier_group) { @@ -874,15 +899,17 @@ error: } static -int lttng_desc_match_star_glob_enabler(struct lttng_ust_event_desc *desc, +int lttng_desc_match_star_glob_enabler(const struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; int loglevel = 0; unsigned int has_loglevel = 0; + lttng_ust_format_event_name(desc, name); assert(enabler->format_type == LTTNG_ENABLER_FORMAT_STAR_GLOB); if (!strutils_star_glob_match(enabler->event_param.name, SIZE_MAX, - desc->name, SIZE_MAX)) + name, SIZE_MAX)) return 0; if (desc->loglevel) { loglevel = *(*desc->loglevel); @@ -897,14 +924,16 @@ int lttng_desc_match_star_glob_enabler(struct lttng_ust_event_desc *desc, } static -int lttng_desc_match_event_enabler(struct lttng_ust_event_desc *desc, +int lttng_desc_match_event_enabler(const struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; int loglevel = 0; unsigned int has_loglevel = 0; + lttng_ust_format_event_name(desc, name); assert(enabler->format_type == LTTNG_ENABLER_FORMAT_EVENT); - if (strcmp(desc->name, enabler->event_param.name)) + if (strcmp(name, enabler->event_param.name)) return 0; if (desc->loglevel) { loglevel = *(*desc->loglevel); @@ -919,7 +948,7 @@ int lttng_desc_match_event_enabler(struct lttng_ust_event_desc *desc, } static -int lttng_desc_match_enabler(struct lttng_ust_event_desc *desc, +int lttng_desc_match_enabler(const struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { switch (enabler->format_type) { @@ -945,8 +974,14 @@ int lttng_desc_match_enabler(struct lttng_ust_event_desc *desc, excluder_name = (char *) (excluder->excluder.names) + count * LTTNG_UST_ABI_SYM_NAME_LEN; len = strnlen(excluder_name, LTTNG_UST_ABI_SYM_NAME_LEN); - if (len > 0 && strutils_star_glob_match(excluder_name, len, desc->name, SIZE_MAX)) - return 0; + if (len > 0) { + char name[LTTNG_UST_ABI_SYM_NAME_LEN]; + + lttng_ust_format_event_name(desc, name); + if (strutils_star_glob_match(excluder_name, len, name, SIZE_MAX)) { + return 0; + } + } } } return 1; @@ -1007,8 +1042,8 @@ static void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_enabler) { struct lttng_ust_session *session = event_enabler->chan->parent->session; - struct lttng_ust_probe_desc *probe_desc; - struct lttng_ust_event_desc *desc; + struct lttng_ust_registered_probe *reg_probe; + const struct lttng_ust_event_desc *desc; struct lttng_ust_event_recorder_private *event_recorder_priv; int i; struct cds_list_head *probe_list; @@ -1019,7 +1054,9 @@ void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_en * our enabler, create an associated lttng_event if not * already present. */ - cds_list_for_each_entry(probe_desc, probe_list, head) { + cds_list_for_each_entry(reg_probe, probe_list, head) { + const struct lttng_ust_probe_desc *probe_desc = reg_probe->desc; + for (i = 0; i < probe_desc->nr_events; i++) { int ret; bool found = false; @@ -1052,15 +1089,16 @@ void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_en ret = lttng_event_recorder_create(probe_desc->event_desc[i], event_enabler->chan); if (ret) { - DBG("Unable to create event %s, error %d\n", - probe_desc->event_desc[i]->name, ret); + DBG("Unable to create event \"%s:%s\", error %d\n", + probe_desc->provider_name, + probe_desc->event_desc[i]->event_name, ret); } } } } static -void probe_provider_event_for_each(struct lttng_ust_probe_desc *provider_desc, +void probe_provider_event_for_each(const struct lttng_ust_probe_desc *provider_desc, void (*event_func)(struct lttng_ust_event_common *event)) { struct cds_hlist_node *node, *tmp_node; @@ -1075,7 +1113,7 @@ void probe_provider_event_for_each(struct lttng_ust_probe_desc *provider_desc, * sessions to queue the unregistration of the events. */ for (i = 0; i < provider_desc->nr_events; i++) { - struct lttng_ust_event_desc *event_desc; + const struct lttng_ust_event_desc *event_desc; struct lttng_event_notifier_group *event_notifier_group; struct lttng_ust_event_recorder_private *event_recorder_priv; struct lttng_ust_event_notifier_private *event_notifier_priv; @@ -1142,8 +1180,8 @@ void _event_enum_destroy(struct lttng_ust_event_common *event) /* Destroy enums of the current event. */ for (i = 0; i < event_recorder->parent->priv->desc->nr_fields; i++) { - struct lttng_ust_enum_desc *enum_desc; - struct lttng_ust_event_field *field; + const struct lttng_ust_enum_desc *enum_desc; + const struct lttng_ust_event_field *field; struct lttng_enum *curr_enum; field = event_recorder->parent->priv->desc->fields[i]; @@ -1177,7 +1215,7 @@ void _event_enum_destroy(struct lttng_ust_event_common *event) * ust_lock held. */ void lttng_probe_provider_unregister_events( - struct lttng_ust_probe_desc *provider_desc) + const struct lttng_ust_probe_desc *provider_desc) { /* * Iterate over all events in the probe provider descriptions and sessions @@ -1618,8 +1656,9 @@ int lttng_attach_context(struct lttng_ust_abi_context *context_param, } } -int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, - struct lttng_ust_abi_context *context_param) +int lttng_event_enabler_attach_context( + struct lttng_event_enabler *enabler __attribute__((unused)), + struct lttng_ust_abi_context *context_param __attribute__((unused))) { return -ENOSYS; } @@ -1714,7 +1753,7 @@ void lttng_session_sync_event_enablers(struct lttng_ust_session *session) /* Support for event notifier is introduced by probe provider major version 2. */ static -bool lttng_ust_probe_supports_event_notifier(struct lttng_ust_probe_desc *probe_desc) +bool lttng_ust_probe_supports_event_notifier(const struct lttng_ust_probe_desc *probe_desc) { return probe_desc->major >= 2; } @@ -1724,17 +1763,19 @@ void lttng_create_event_notifier_if_missing( struct lttng_event_notifier_enabler *event_notifier_enabler) { struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group; - struct lttng_ust_probe_desc *probe_desc; + struct lttng_ust_registered_probe *reg_probe; struct cds_list_head *probe_list; int i; probe_list = lttng_get_probe_list_head(); - cds_list_for_each_entry(probe_desc, probe_list, head) { + cds_list_for_each_entry(reg_probe, probe_list, head) { + const struct lttng_ust_probe_desc *probe_desc = reg_probe->desc; + for (i = 0; i < probe_desc->nr_events; i++) { int ret; bool found = false; - struct lttng_ust_event_desc *desc; + const struct lttng_ust_event_desc *desc; struct lttng_ust_event_notifier_private *event_notifier_priv; struct cds_hlist_head *head; struct cds_hlist_node *node; @@ -1772,12 +1813,12 @@ void lttng_create_event_notifier_if_missing( /* Check that the probe supports event notifiers, else report the error. */ if (!lttng_ust_probe_supports_event_notifier(probe_desc)) { - ERR("Probe \"%s\" contains event \"%s\" which matches an enabled event notifier, " + ERR("Probe \"%s\" contains event \"%s:%s\" which matches an enabled event notifier, " "but its version (%u.%u) is too old and does not implement event notifiers. " "It needs to be recompiled against a newer version of LTTng-UST, otherwise " "this event will not generate any notification.", - probe_desc->provider, - desc->name, + probe_desc->provider_name, + probe_desc->provider_name, desc->event_name, probe_desc->major, probe_desc->minor); continue; @@ -1790,8 +1831,9 @@ void lttng_create_event_notifier_if_missing( event_notifier_enabler->error_counter_index, event_notifier_group); if (ret) { - DBG("Unable to create event_notifier %s, error %d\n", - probe_desc->event_desc[i]->name, ret); + DBG("Unable to create event_notifier \"%s:%s\", error %d\n", + probe_desc->provider_name, + probe_desc->event_desc[i]->event_name, ret); } } } @@ -1960,12 +2002,11 @@ void lttng_session_lazy_sync_event_enablers(struct lttng_ust_session *session) * context (either app context callbacks, or dummy callbacks). */ void lttng_ust_context_set_session_provider(const char *name, - size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), - void (*record)(struct lttng_ust_ctx_field *field, - struct lttng_ust_lib_ring_buffer_ctx *ctx, + size_t (*get_size)(void *priv, size_t offset), + void (*record)(void *priv, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_ust_channel_buffer *chan), - void (*get_value)(struct lttng_ust_ctx_field *field, - struct lttng_ust_ctx_value *value)) + void (*get_value)(void *priv, struct lttng_ust_ctx_value *value), + void *priv) { struct lttng_ust_session_private *session_priv; @@ -1975,18 +2016,18 @@ void lttng_ust_context_set_session_provider(const char *name, int ret; ret = lttng_ust_context_set_provider_rcu(&session_priv->ctx, - name, get_size, record, get_value); + name, get_size, record, get_value, priv); if (ret) abort(); cds_list_for_each_entry(chan, &session_priv->chan_head, node) { ret = lttng_ust_context_set_provider_rcu(&chan->ctx, - name, get_size, record, get_value); + name, get_size, record, get_value, priv); if (ret) abort(); } cds_list_for_each_entry(event_recorder_priv, &session_priv->events_head, node) { ret = lttng_ust_context_set_provider_rcu(&event_recorder_priv->ctx, - name, get_size, record, get_value); + name, get_size, record, get_value, priv); if (ret) abort(); } @@ -2001,12 +2042,11 @@ void lttng_ust_context_set_session_provider(const char *name, * context (either app context callbacks, or dummy callbacks). */ void lttng_ust_context_set_event_notifier_group_provider(const char *name, - size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), - void (*record)(struct lttng_ust_ctx_field *field, - struct lttng_ust_lib_ring_buffer_ctx *ctx, + size_t (*get_size)(void *priv, size_t offset), + void (*record)(void *priv, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_ust_channel_buffer *chan), - void (*get_value)(struct lttng_ust_ctx_field *field, - struct lttng_ust_ctx_value *value)) + void (*get_value)(void *priv, struct lttng_ust_ctx_value *value), + void *priv) { struct lttng_event_notifier_group *event_notifier_group; @@ -2015,7 +2055,7 @@ void lttng_ust_context_set_event_notifier_group_provider(const char *name, ret = lttng_ust_context_set_provider_rcu( &event_notifier_group->ctx, - name, get_size, record, get_value); + name, get_size, record, get_value, priv); if (ret) abort(); }