X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-events.c;h=b61a2293f4a8a83039f3a645da09e9fb60cab479;hb=6ba6fd60507f8e045bdc4f1be14e9d99c6a15f7f;hp=762395d657330b0aca25959661d8d2ebe587bb53;hpb=891d6b550bf16672b0c3a7b35362f231d6e10fc1;p=lttng-ust.git diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index 762395d6..b61a2293 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -53,9 +53,12 @@ #include "ust-events-internal.h" #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 @@ -74,15 +77,31 @@ static void _lttng_event_destroy(struct lttng_ust_event_common *event); static void _lttng_enum_destroy(struct lttng_enum *_enum); static -void lttng_session_lazy_sync_event_enablers(struct lttng_session *session); +void lttng_session_lazy_sync_event_enablers(struct lttng_ust_session *session); static -void lttng_session_sync_event_enablers(struct lttng_session *session); +void lttng_session_sync_event_enablers(struct lttng_ust_session *session); static void lttng_event_notifier_group_sync_enablers( struct lttng_event_notifier_group *event_notifier_group); 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. */ @@ -127,16 +146,16 @@ int lttng_loglevel_match(int loglevel, } } -struct lttng_session *lttng_session_create(void) +struct lttng_ust_session *lttng_session_create(void) { - struct lttng_session *session; + struct lttng_ust_session *session; struct lttng_ust_session_private *session_priv; int i; - session = zmalloc(sizeof(struct lttng_session)); + session = zmalloc(sizeof(struct lttng_ust_session)); if (!session) return NULL; - session->struct_size = sizeof(struct lttng_session); + session->struct_size = sizeof(struct lttng_ust_session); session_priv = zmalloc(sizeof(struct lttng_ust_session_private)); if (!session_priv) { free(session); @@ -230,20 +249,19 @@ struct lttng_event_notifier_group *lttng_event_notifier_group_create(void) * Only used internally at session destruction. */ static -void _lttng_channel_unmap(struct lttng_channel *lttng_chan) +void _lttng_channel_unmap(struct lttng_ust_channel_buffer *lttng_chan) { - struct channel *chan; + struct lttng_ust_lib_ring_buffer_channel *chan; struct lttng_ust_shm_handle *handle; - cds_list_del(<tng_chan->node); - lttng_destroy_context(lttng_chan->ctx); - chan = lttng_chan->chan; - handle = lttng_chan->handle; - /* - * note: lttng_chan is private data contained within handle. It - * will be freed along with the handle. - */ + cds_list_del(<tng_chan->priv->node); + lttng_destroy_context(lttng_chan->priv->ctx); + chan = lttng_chan->priv->rb_chan; + handle = chan->handle; channel_destroy(chan, handle, 0); + free(lttng_chan->parent); + free(lttng_chan->priv); + free(lttng_chan); } static @@ -251,10 +269,12 @@ void register_event(struct lttng_ust_event_common *event) { int ret; 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 = __tracepoint_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); @@ -267,10 +287,12 @@ void unregister_event(struct lttng_ust_event_common *event) { int ret; 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 = __tracepoint_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); @@ -285,9 +307,9 @@ void _lttng_event_unregister(struct lttng_ust_event_common *event) unregister_event(event); } -void lttng_session_destroy(struct lttng_session *session) +void lttng_session_destroy(struct lttng_ust_session *session) { - struct lttng_channel *chan, *tmpchan; + struct lttng_ust_channel_buffer_private *chan, *tmpchan; struct lttng_ust_event_recorder_private *event_recorder_priv, *tmpevent_recorder_priv; struct lttng_enum *_enum, *tmp_enum; struct lttng_event_enabler *event_enabler, *event_tmpenabler; @@ -297,7 +319,7 @@ void lttng_session_destroy(struct lttng_session *session) _lttng_event_unregister(event_recorder_priv->parent.pub); } lttng_ust_urcu_synchronize_rcu(); /* Wait for in-flight events to complete */ - __tracepoint_probe_prune_release_queue(); + lttng_ust_tp_probe_prune_release_queue(); cds_list_for_each_entry_safe(event_enabler, event_tmpenabler, &session->priv->enablers_head, node) lttng_event_enabler_destroy(event_enabler); @@ -308,7 +330,7 @@ void lttng_session_destroy(struct lttng_session *session) &session->priv->enums_head, node) _lttng_enum_destroy(_enum); cds_list_for_each_entry_safe(chan, tmpchan, &session->priv->chan_head, node) - _lttng_channel_unmap(chan); + _lttng_channel_unmap(chan->pub); cds_list_del(&session->priv->node); lttng_destroy_context(session->priv->ctx); free(session->priv); @@ -399,7 +421,7 @@ void lttng_enabler_destroy(struct lttng_enabler *enabler) static int lttng_enum_create(const struct lttng_ust_enum_desc *desc, - struct lttng_session *session) + struct lttng_ust_session *session) { const char *enum_name = desc->name; struct lttng_enum *_enum; @@ -456,16 +478,16 @@ exist: } static -int lttng_create_enum_check(const struct lttng_type *type, - struct lttng_session *session) +int lttng_create_enum_check(const struct lttng_ust_type_common *type, + struct lttng_ust_session *session) { - switch (type->atype) { - case atype_enum_nestable: + switch (type->type) { + case lttng_ust_type_enum: { const struct lttng_ust_enum_desc *enum_desc; int ret; - enum_desc = type->u.enum_nestable.desc; + enum_desc = lttng_ust_get_type_enum(type)->desc; ret = lttng_enum_create(enum_desc, session); if (ret && ret != -EEXIST) { DBG("Unable to create enum error: (%d)", ret); @@ -473,14 +495,14 @@ int lttng_create_enum_check(const struct lttng_type *type, } break; } - case atype_dynamic: + case lttng_ust_type_dynamic: { 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(); - enum_desc = tag_field_generic->type.u.enum_nestable.desc; + enum_desc = lttng_ust_get_type_enum(tag_field_generic->type)->desc; ret = lttng_enum_create(enum_desc, session); if (ret && ret != -EEXIST) { DBG("Unable to create enum error: (%d)", ret); @@ -498,14 +520,14 @@ int lttng_create_enum_check(const struct lttng_type *type, static int lttng_create_all_event_enums(size_t nr_fields, const struct lttng_ust_event_field **event_fields, - struct lttng_session *session) + struct lttng_ust_session *session) { size_t i; int ret; /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - const struct lttng_type *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,15 +538,15 @@ int lttng_create_all_event_enums(size_t nr_fields, static int lttng_create_all_ctx_enums(size_t nr_fields, - const struct lttng_ctx_field *ctx_fields, - struct lttng_session *session) + struct lttng_ust_ctx_field *ctx_fields, + struct lttng_ust_session *session) { size_t i; int ret; /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - const struct lttng_type *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) @@ -537,17 +559,17 @@ int lttng_create_all_ctx_enums(size_t nr_fields, * Ensure that a state-dump will be performed for this session at the end * of the current handle_message(). */ -int lttng_session_statedump(struct lttng_session *session) +int lttng_session_statedump(struct lttng_ust_session *session) { session->priv->statedump_pending = 1; lttng_ust_sockinfo_session_enabled(session->priv->owner); return 0; } -int lttng_session_enable(struct lttng_session *session) +int lttng_session_enable(struct lttng_ust_session *session) { int ret = 0; - struct lttng_channel *chan; + struct lttng_ust_channel_buffer_private *chan; int notify_socket; if (session->active) { @@ -570,8 +592,8 @@ int lttng_session_enable(struct lttng_session *session) * we need to use. */ cds_list_for_each_entry(chan, &session->priv->chan_head, node) { - const struct lttng_ctx *ctx; - const struct lttng_ctx_field *fields = NULL; + struct lttng_ust_ctx *ctx; + struct lttng_ust_ctx_field *fields = NULL; size_t nr_fields = 0; uint32_t chan_id; @@ -592,7 +614,7 @@ int lttng_session_enable(struct lttng_session *session) ret = ustcomm_register_channel(notify_socket, session, session->priv->objd, - chan->objd, + chan->parent.objd, nr_fields, fields, &chan_id, @@ -619,7 +641,7 @@ end: return ret; } -int lttng_session_disable(struct lttng_session *session) +int lttng_session_disable(struct lttng_ust_session *session) { int ret = 0; @@ -637,36 +659,36 @@ end: return ret; } -int lttng_channel_enable(struct lttng_channel *channel) +int lttng_channel_enable(struct lttng_ust_channel_common *lttng_channel) { int ret = 0; - if (channel->enabled) { + if (lttng_channel->enabled) { ret = -EBUSY; goto end; } /* Set transient enabler state to "enabled" */ - channel->tstate = 1; - lttng_session_sync_event_enablers(channel->session); + lttng_channel->priv->tstate = 1; + lttng_session_sync_event_enablers(lttng_channel->session); /* Set atomically the state to "enabled" */ - CMM_ACCESS_ONCE(channel->enabled) = 1; + CMM_ACCESS_ONCE(lttng_channel->enabled) = 1; end: return ret; } -int lttng_channel_disable(struct lttng_channel *channel) +int lttng_channel_disable(struct lttng_ust_channel_common *lttng_channel) { int ret = 0; - if (!channel->enabled) { + if (!lttng_channel->enabled) { ret = -EBUSY; goto end; } /* Set atomically the state to "disabled" */ - CMM_ACCESS_ONCE(channel->enabled) = 0; + CMM_ACCESS_ONCE(lttng_channel->enabled) = 0; /* Set transient enabler state to "enabled" */ - channel->tstate = 0; - lttng_session_sync_event_enablers(channel->session); + lttng_channel->priv->tstate = 0; + lttng_session_sync_event_enablers(lttng_channel->session); end: return ret; } @@ -677,14 +699,14 @@ struct cds_hlist_head *borrow_hash_table_bucket( unsigned int hash_table_size, 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)]; } @@ -693,17 +715,18 @@ struct cds_hlist_head *borrow_hash_table_bucket( */ static int lttng_event_recorder_create(const struct lttng_ust_event_desc *desc, - struct lttng_channel *chan) + 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_session *session = chan->session; + struct lttng_ust_session *session = chan->parent->session; struct cds_hlist_head *head; int ret = 0; int notify_socket, loglevel; const char *uri; - head = borrow_hash_table_bucket(chan->session->priv->events_ht.table, + head = borrow_hash_table_bucket(chan->parent->session->priv->events_ht.table, LTTNG_UST_EVENT_HT_SIZE, desc); notify_socket = lttng_get_notify_socket(session->priv->owner); @@ -751,9 +774,10 @@ int lttng_event_recorder_create(const struct lttng_ust_event_desc *desc, event_recorder->chan = chan; /* Event will be enabled by enabler sync. */ + event_recorder->parent->run_filter = lttng_ust_interpret_event_filter; event_recorder->parent->enabled = 0; event_recorder->parent->priv->registered = 0; - CDS_INIT_LIST_HEAD(&event_recorder->parent->filter_bytecode_runtime_head); + CDS_INIT_LIST_HEAD(&event_recorder->parent->priv->filter_bytecode_runtime_head); CDS_INIT_LIST_HEAD(&event_recorder->parent->priv->enablers_ref_head); event_recorder->parent->priv->desc = desc; @@ -766,24 +790,26 @@ int lttng_event_recorder_create(const 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->objd, - desc->name, + chan->priv->parent.objd, + 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; } - cds_list_add(&event_recorder_priv->node, &chan->session->priv->events_head); + cds_list_add(&event_recorder_priv->node, &chan->parent->session->priv->events_head); cds_hlist_add_head(&event_recorder_priv->hlist, head); return 0; @@ -848,11 +874,12 @@ int lttng_event_notifier_create(const struct lttng_ust_event_desc *desc, event_notifier_priv->error_counter_index = error_counter_index; /* Event notifier will be enabled by enabler sync. */ + event_notifier->parent->run_filter = lttng_ust_interpret_event_filter; event_notifier->parent->enabled = 0; event_notifier_priv->parent.registered = 0; - CDS_INIT_LIST_HEAD(&event_notifier->parent->filter_bytecode_runtime_head); - CDS_INIT_LIST_HEAD(&event_notifier->capture_bytecode_runtime_head); + CDS_INIT_LIST_HEAD(&event_notifier->parent->priv->filter_bytecode_runtime_head); + CDS_INIT_LIST_HEAD(&event_notifier->priv->capture_bytecode_runtime_head); CDS_INIT_LIST_HEAD(&event_notifier_priv->parent.enablers_ref_head); event_notifier_priv->parent.desc = desc; event_notifier->notification_send = lttng_event_notifier_notification_send; @@ -875,12 +902,14 @@ static 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); @@ -898,11 +927,13 @@ static 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); @@ -943,8 +974,14 @@ int lttng_desc_match_enabler(const 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; @@ -1004,8 +1041,8 @@ struct lttng_enabler_ref *lttng_enabler_ref( static void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_enabler) { - struct lttng_session *session = event_enabler->chan->session; - struct lttng_ust_probe_desc *probe_desc; + struct lttng_ust_session *session = event_enabler->chan->parent->session; + 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; @@ -1017,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; @@ -1050,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; @@ -1135,7 +1175,7 @@ void _event_enum_destroy(struct lttng_ust_event_common *event) case LTTNG_UST_EVENT_TYPE_RECORDER: { struct lttng_ust_event_recorder *event_recorder = event->child; - struct lttng_session *session = event_recorder->chan->session; + struct lttng_ust_session *session = event_recorder->chan->parent->session; unsigned int i; /* Destroy enums of the current event. */ @@ -1145,9 +1185,9 @@ void _event_enum_destroy(struct lttng_ust_event_common *event) struct lttng_enum *curr_enum; field = event_recorder->parent->priv->desc->fields[i]; - switch (field->type.atype) { - case atype_enum_nestable: - enum_desc = field->type.u.enum_nestable.desc; + switch (field->type->type) { + case lttng_ust_type_enum: + enum_desc = lttng_ust_get_type_enum(field->type)->desc; break; default: continue; @@ -1175,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 @@ -1186,7 +1226,7 @@ void lttng_probe_provider_unregister_events( /* Wait for grace period. */ lttng_ust_urcu_synchronize_rcu(); /* Prune the unregistration queue. */ - __tracepoint_probe_prune_release_queue(); + lttng_ust_tp_probe_prune_release_queue(); /* * It is now safe to destroy the events and remove them from the event list @@ -1202,7 +1242,7 @@ void lttng_probe_provider_unregister_events( static int lttng_event_enabler_ref_event_recorders(struct lttng_event_enabler *event_enabler) { - struct lttng_session *session = event_enabler->chan->session; + struct lttng_ust_session *session = event_enabler->chan->parent->session; struct lttng_ust_event_recorder_private *event_recorder_priv; if (!lttng_event_enabler_as_enabler(event_enabler)->enabled) @@ -1239,7 +1279,7 @@ int lttng_event_enabler_ref_event_recorders(struct lttng_event_enabler *event_en */ lttng_enabler_link_bytecode(event_recorder_priv->parent.desc, &session->priv->ctx, - &event_recorder_priv->pub->parent->filter_bytecode_runtime_head, + &event_recorder_priv->parent.filter_bytecode_runtime_head, <tng_event_enabler_as_enabler(event_enabler)->filter_bytecode_head); /* TODO: merge event context. */ @@ -1322,7 +1362,7 @@ void _lttng_event_destroy(struct lttng_ust_event_common *event) /* Remove from event hash table. */ cds_hlist_del(&event_recorder->priv->hlist); - lttng_destroy_context(event_recorder->ctx); + lttng_destroy_context(event_recorder->priv->ctx); free(event_recorder->parent); free(event_recorder->priv); free(event_recorder); @@ -1369,7 +1409,7 @@ void lttng_ust_abi_events_exit(void) struct lttng_event_enabler *lttng_event_enabler_create( enum lttng_enabler_format_type format_type, struct lttng_ust_abi_event *event_param, - struct lttng_channel *chan) + struct lttng_ust_channel_buffer *chan) { struct lttng_event_enabler *event_enabler; @@ -1384,8 +1424,8 @@ struct lttng_event_enabler *lttng_event_enabler_create( event_enabler->chan = chan; /* ctx left NULL */ event_enabler->base.enabled = 0; - cds_list_add(&event_enabler->node, &event_enabler->chan->session->priv->enablers_head); - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + cds_list_add(&event_enabler->node, &event_enabler->chan->parent->session->priv->enablers_head); + lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); return event_enabler; } @@ -1433,7 +1473,7 @@ struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler) { lttng_event_enabler_as_enabler(event_enabler)->enabled = 1; - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); return 0; } @@ -1441,7 +1481,7 @@ int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler) int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler) { lttng_event_enabler_as_enabler(event_enabler)->enabled = 0; - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); return 0; } @@ -1462,7 +1502,7 @@ int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event _lttng_enabler_attach_filter_bytecode( lttng_event_enabler_as_enabler(event_enabler), bytecode); - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); return 0; } @@ -1482,7 +1522,7 @@ int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabl _lttng_enabler_attach_exclusion( lttng_event_enabler_as_enabler(event_enabler), excluder); - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); return 0; } @@ -1546,7 +1586,7 @@ int lttng_event_notifier_enabler_attach_exclusion( int lttng_attach_context(struct lttng_ust_abi_context *context_param, union lttng_ust_abi_args *uargs, - struct lttng_ctx **ctx, struct lttng_session *session) + struct lttng_ust_ctx **ctx, struct lttng_ust_session *session) { /* * We cannot attach a context after trace has been started for a @@ -1616,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; } @@ -1640,7 +1681,7 @@ void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler) * session. */ static -void lttng_session_sync_event_enablers(struct lttng_session *session) +void lttng_session_sync_event_enablers(struct lttng_ust_session *session) { struct lttng_event_enabler *event_enabler; struct lttng_ust_event_recorder_private *event_recorder_priv; @@ -1654,8 +1695,9 @@ void lttng_session_sync_event_enablers(struct lttng_session *session) */ cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) { struct lttng_enabler_ref *enabler_ref; - struct lttng_bytecode_runtime *runtime; - int enabled = 0, has_enablers_without_bytecode = 0; + struct lttng_ust_bytecode_runtime *runtime; + int enabled = 0, has_enablers_without_filter_bytecode = 0; + int nr_filters = 0; /* Enable events */ cds_list_for_each_entry(enabler_ref, @@ -1670,7 +1712,7 @@ void lttng_session_sync_event_enablers(struct lttng_session *session) * intesection of session and channel transient enable * states. */ - enabled = enabled && session->priv->tstate && event_recorder_priv->pub->chan->tstate; + enabled = enabled && session->priv->tstate && event_recorder_priv->pub->chan->priv->parent.tstate; CMM_STORE_SHARED(event_recorder_priv->pub->parent->enabled, enabled); /* @@ -1690,25 +1732,28 @@ void lttng_session_sync_event_enablers(struct lttng_session *session) &event_recorder_priv->parent.enablers_ref_head, node) { if (enabler_ref->ref->enabled && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) { - has_enablers_without_bytecode = 1; + has_enablers_without_filter_bytecode = 1; break; } } - event_recorder_priv->pub->parent->has_enablers_without_bytecode = - has_enablers_without_bytecode; + event_recorder_priv->parent.has_enablers_without_filter_bytecode = + has_enablers_without_filter_bytecode; /* Enable filters */ cds_list_for_each_entry(runtime, - &event_recorder_priv->pub->parent->filter_bytecode_runtime_head, node) { - lttng_bytecode_filter_sync_state(runtime); + &event_recorder_priv->parent.filter_bytecode_runtime_head, node) { + lttng_bytecode_sync_state(runtime); + nr_filters++; } + CMM_STORE_SHARED(event_recorder_priv->parent.pub->eval_filter, + !(has_enablers_without_filter_bytecode || !nr_filters)); } - __tracepoint_probe_prune_release_queue(); + lttng_ust_tp_probe_prune_release_queue(); } /* 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; } @@ -1718,13 +1763,15 @@ 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; @@ -1766,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; @@ -1784,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); } } } @@ -1841,14 +1889,14 @@ int lttng_event_notifier_enabler_ref_event_notifiers( */ lttng_enabler_link_bytecode(event_notifier_priv->parent.desc, &event_notifier_group->ctx, - &event_notifier_priv->pub->parent->filter_bytecode_runtime_head, + &event_notifier_priv->parent.filter_bytecode_runtime_head, <tng_event_notifier_enabler_as_enabler(event_notifier_enabler)->filter_bytecode_head); /* * Link capture bytecodes if not linked yet. */ lttng_enabler_link_bytecode(event_notifier_priv->parent.desc, - &event_notifier_group->ctx, &event_notifier_priv->pub->capture_bytecode_runtime_head, + &event_notifier_group->ctx, &event_notifier_priv->capture_bytecode_runtime_head, &event_notifier_enabler->capture_bytecode_head); event_notifier_priv->num_captures = event_notifier_enabler->num_captures; @@ -1872,8 +1920,9 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group */ cds_list_for_each_entry(event_notifier_priv, &event_notifier_group->event_notifiers_head, node) { struct lttng_enabler_ref *enabler_ref; - struct lttng_bytecode_runtime *runtime; - int enabled = 0, has_enablers_without_bytecode = 0; + struct lttng_ust_bytecode_runtime *runtime; + int enabled = 0, has_enablers_without_filter_bytecode = 0; + int nr_filters = 0, nr_captures = 0; /* Enable event_notifiers */ cds_list_for_each_entry(enabler_ref, @@ -1902,26 +1951,32 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group &event_notifier_priv->parent.enablers_ref_head, node) { if (enabler_ref->ref->enabled && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) { - has_enablers_without_bytecode = 1; + has_enablers_without_filter_bytecode = 1; break; } } - event_notifier_priv->pub->parent->has_enablers_without_bytecode = - has_enablers_without_bytecode; + event_notifier_priv->parent.has_enablers_without_filter_bytecode = + has_enablers_without_filter_bytecode; /* Enable filters */ cds_list_for_each_entry(runtime, - &event_notifier_priv->pub->parent->filter_bytecode_runtime_head, node) { - lttng_bytecode_filter_sync_state(runtime); + &event_notifier_priv->parent.filter_bytecode_runtime_head, node) { + lttng_bytecode_sync_state(runtime); + nr_filters++; } + CMM_STORE_SHARED(event_notifier_priv->parent.pub->eval_filter, + !(has_enablers_without_filter_bytecode || !nr_filters)); /* Enable captures. */ cds_list_for_each_entry(runtime, - &event_notifier_priv->pub->capture_bytecode_runtime_head, node) { - lttng_bytecode_capture_sync_state(runtime); + &event_notifier_priv->capture_bytecode_runtime_head, node) { + lttng_bytecode_sync_state(runtime); + nr_captures++; } + CMM_STORE_SHARED(event_notifier_priv->pub->eval_capture, + !!nr_captures); } - __tracepoint_probe_prune_release_queue(); + lttng_ust_tp_probe_prune_release_queue(); } /* @@ -1931,7 +1986,7 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group * "lazy" sync means we only sync if required. */ static -void lttng_session_lazy_sync_event_enablers(struct lttng_session *session) +void lttng_session_lazy_sync_event_enablers(struct lttng_ust_session *session) { /* We can skip if session is not active */ if (!session->active) @@ -1947,33 +2002,32 @@ void lttng_session_lazy_sync_event_enablers(struct lttng_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_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, - struct lttng_ust_lib_ring_buffer_ctx *ctx, - struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)) + 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)(void *priv, struct lttng_ust_ctx_value *value), + void *priv) { struct lttng_ust_session_private *session_priv; cds_list_for_each_entry(session_priv, &sessions, node) { - struct lttng_channel *chan; + struct lttng_ust_channel_buffer_private *chan; struct lttng_ust_event_recorder_private *event_recorder_priv; 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->pub->ctx, - name, get_size, record, get_value); + ret = lttng_ust_context_set_provider_rcu(&event_recorder_priv->ctx, + name, get_size, record, get_value, priv); if (ret) abort(); } @@ -1988,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_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, - struct lttng_ust_lib_ring_buffer_ctx *ctx, - struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)) + 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)(void *priv, struct lttng_ust_ctx_value *value), + void *priv) { struct lttng_event_notifier_group *event_notifier_group; @@ -2002,8 +2055,26 @@ 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(); } } + +int lttng_ust_session_uuid_validate(struct lttng_ust_session *session, + unsigned char *uuid) +{ + if (!session) + return 0; + /* Compare UUID with session. */ + if (session->priv->uuid_set) { + if (memcmp(session->priv->uuid, uuid, LTTNG_UST_UUID_LEN)) { + return -1; + } + } else { + memcpy(session->priv->uuid, uuid, LTTNG_UST_UUID_LEN); + session->priv->uuid_set = true; + } + return 0; + +}