From d871c65bcb2e94c69e0a46e7e0dcd2dae2fce7af Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Fri, 22 Nov 2019 16:44:28 -0500 Subject: [PATCH] Abstract base `lttng_enabler` to support other types of enablers Future commits will introduce the concept of event notifier enablers which are similar to the event enablers already present with a few differences. To prepare the ground, this commit moves event dependent fields from the `struct lttng_enabler` struct to a specialized `struct lttng_event_enabler`. The `lttng_enabler_*()` functions cannot be renamed because they are currently exported. These are only used internally, so we can stop using them and add new `lttng_event_enabler_*()` functions marked as hidden which won't be exported (see liblttng-ust/ust-events-internal.h). `lttng_enabler_*()` functions are kept in the ust-events.h file but moved to the bottom of the file with other deprecated symbols. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: I6d0af091c257a9ad297d17fca8993956279eb848 --- include/lttng/ust-events.h | 35 ++--- liblttng-ust/Makefile.am | 1 + liblttng-ust/lttng-events.c | 210 ++++++++++++++++------------- liblttng-ust/lttng-filter.c | 8 +- liblttng-ust/lttng-ust-abi.c | 45 ++++--- liblttng-ust/ust-events-internal.h | 122 +++++++++++++++++ 6 files changed, 285 insertions(+), 136 deletions(-) create mode 100644 liblttng-ust/ust-events-internal.h diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 49d864d8..36534695 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -396,15 +396,8 @@ struct lttng_enabler { struct cds_list_head filter_bytecode_head; /* head list of struct lttng_ust_excluder_node */ struct cds_list_head excluder_head; - struct cds_list_head node; /* per-session list of enablers */ struct lttng_ust_event event_param; - struct lttng_channel *chan; - /* - * Unused, but kept around to make it explicit that the tracer can do - * it. - */ - struct lttng_ctx *ctx; unsigned int enabled:1; }; @@ -692,18 +685,6 @@ struct lttng_channel *lttng_channel_create(struct lttng_session *session, int lttng_channel_enable(struct lttng_channel *channel); int lttng_channel_disable(struct lttng_channel *channel); -struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_format_type type, - struct lttng_ust_event *event_param, - struct lttng_channel *chan); -int lttng_enabler_enable(struct lttng_enabler *enabler); -int lttng_enabler_disable(struct lttng_enabler *enabler); -int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, - struct lttng_ust_filter_bytecode_node *bytecode); -int lttng_enabler_attach_context(struct lttng_enabler *enabler, - struct lttng_ust_context *ctx); -int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, - struct lttng_ust_excluder_node *excluder); - int lttng_attach_context(struct lttng_ust_context *context_param, union ust_args *uargs, struct lttng_ctx **ctx, struct lttng_session *session); @@ -808,8 +789,6 @@ void lttng_probes_prune_field_list(struct lttng_ust_field_list *list); struct lttng_ust_field_iter * lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list); -void lttng_enabler_event_link_bytecode(struct lttng_event *event, - struct lttng_enabler *enabler); void lttng_free_event_filter_runtime(struct lttng_event *event); void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime); @@ -831,6 +810,20 @@ extern struct lttng_ctx *lttng_static_ctx; void lttng_context_init(void); void lttng_context_exit(void); void lttng_filter_event_link_bytecode(struct lttng_event *event); +struct lttng_enabler *lttng_enabler_create( + enum lttng_enabler_format_type format_type, + struct lttng_ust_event *event_param, + struct lttng_channel *chan); +int lttng_enabler_enable(struct lttng_enabler *enabler); +int lttng_enabler_disable(struct lttng_enabler *enabler); +int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, + struct lttng_ust_filter_bytecode_node *bytecode); +int lttng_enabler_attach_context(struct lttng_enabler *enabler, + struct lttng_ust_context *ctx); +int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, + struct lttng_ust_excluder_node *excluder); +void lttng_enabler_event_link_bytecode(struct lttng_event *event, + struct lttng_enabler *enabler); #ifdef __cplusplus } diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index 3caaa1fd..d85cf602 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -61,6 +61,7 @@ liblttng_ust_runtime_la_SOURCES = \ ust_lib.c \ ust_lib.h \ tracepoint-internal.h \ + ust-events-internal.h \ clock.h \ compat.h \ wait.h \ diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index 527aa69c..0c684df2 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -59,6 +59,7 @@ #include "lttng-tracer.h" #include "lttng-tracer-core.h" #include "lttng-ust-statedump.h" +#include "ust-events-internal.h" #include "wait.h" #include "../libringbuffer/shm.h" #include "jhash.h" @@ -79,9 +80,9 @@ static void _lttng_event_destroy(struct lttng_event *event); static void _lttng_enum_destroy(struct lttng_enum *_enum); static -void lttng_session_lazy_sync_enablers(struct lttng_session *session); +void lttng_session_lazy_sync_event_enablers(struct lttng_session *session); static -void lttng_session_sync_enablers(struct lttng_session *session); +void lttng_session_sync_event_enablers(struct lttng_session *session); static void lttng_enabler_destroy(struct lttng_enabler *enabler); @@ -225,7 +226,7 @@ void lttng_session_destroy(struct lttng_session *session) struct lttng_channel *chan, *tmpchan; struct lttng_event *event, *tmpevent; struct lttng_enum *_enum, *tmp_enum; - struct lttng_enabler *enabler, *tmpenabler; + struct lttng_event_enabler *event_enabler, *event_tmpenabler; CMM_ACCESS_ONCE(session->active) = 0; cds_list_for_each_entry(event, &session->events_head, node) { @@ -233,9 +234,9 @@ void lttng_session_destroy(struct lttng_session *session) } synchronize_trace(); /* Wait for in-flight events to complete */ __tracepoint_probe_prune_release_queue(); - cds_list_for_each_entry_safe(enabler, tmpenabler, + cds_list_for_each_entry_safe(event_enabler, event_tmpenabler, &session->enablers_head, node) - lttng_enabler_destroy(enabler); + lttng_event_enabler_destroy(event_enabler); cds_list_for_each_entry_safe(event, tmpevent, &session->events_head, node) _lttng_event_destroy(event); @@ -249,6 +250,29 @@ void lttng_session_destroy(struct lttng_session *session) free(session); } +static +void lttng_enabler_destroy(struct lttng_enabler *enabler) +{ + struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node; + struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node; + + if (!enabler) { + return; + } + + /* Destroy filter bytecode */ + cds_list_for_each_entry_safe(filter_node, tmp_filter_node, + &enabler->filter_bytecode_head, node) { + free(filter_node); + } + + /* Destroy excluders */ + cds_list_for_each_entry_safe(excluder_node, tmp_excluder_node, + &enabler->excluder_head, node) { + free(excluder_node); + } +} + static int lttng_enum_create(const struct lttng_enum_desc *desc, struct lttng_session *session) @@ -428,7 +452,7 @@ int lttng_session_enable(struct lttng_session *session) session->tstate = 1; /* We need to sync enablers with session before activation. */ - lttng_session_sync_enablers(session); + lttng_session_sync_event_enablers(session); /* * Snapshot the number of events per channel to know the type of header @@ -497,7 +521,7 @@ int lttng_session_disable(struct lttng_session *session) /* Set transient enabler state to "disabled" */ session->tstate = 0; - lttng_session_sync_enablers(session); + lttng_session_sync_event_enablers(session); end: return ret; } @@ -512,7 +536,7 @@ int lttng_channel_enable(struct lttng_channel *channel) } /* Set transient enabler state to "enabled" */ channel->tstate = 1; - lttng_session_sync_enablers(channel->session); + lttng_session_sync_event_enablers(channel->session); /* Set atomically the state to "enabled" */ CMM_ACCESS_ONCE(channel->enabled) = 1; end: @@ -531,7 +555,7 @@ int lttng_channel_disable(struct lttng_channel *channel) CMM_ACCESS_ONCE(channel->enabled) = 0; /* Set transient enabler state to "enabled" */ channel->tstate = 0; - lttng_session_sync_enablers(channel->session); + lttng_session_sync_event_enablers(channel->session); end: return ret; } @@ -710,24 +734,25 @@ int lttng_desc_match_enabler(const struct lttng_event_desc *desc, } static -int lttng_event_match_enabler(struct lttng_event *event, - struct lttng_enabler *enabler) +int lttng_event_enabler_match_event(struct lttng_event_enabler *event_enabler, + struct lttng_event *event) { - if (lttng_desc_match_enabler(event->desc, enabler) - && event->chan == enabler->chan) + if (lttng_desc_match_enabler(event->desc, + lttng_event_enabler_as_enabler(event_enabler)) + && event->chan == event_enabler->chan) return 1; else return 0; } static -struct lttng_enabler_ref * lttng_event_enabler_ref(struct lttng_event *event, +struct lttng_enabler_ref *lttng_enabler_ref( + struct cds_list_head *enabler_ref_list, struct lttng_enabler *enabler) { struct lttng_enabler_ref *enabler_ref; - cds_list_for_each_entry(enabler_ref, - &event->enablers_ref_head, node) { + cds_list_for_each_entry(enabler_ref, enabler_ref_list, node) { if (enabler_ref->ref == enabler) return enabler_ref; } @@ -739,9 +764,9 @@ struct lttng_enabler_ref * lttng_event_enabler_ref(struct lttng_event *event, * tracepoint probes. */ static -void lttng_create_event_if_missing(struct lttng_enabler *enabler) +void lttng_create_event_if_missing(struct lttng_event_enabler *event_enabler) { - struct lttng_session *session = enabler->chan->session; + struct lttng_session *session = event_enabler->chan->session; struct lttng_probe_desc *probe_desc; const struct lttng_event_desc *desc; struct lttng_event *event; @@ -765,7 +790,8 @@ void lttng_create_event_if_missing(struct lttng_enabler *enabler) uint32_t hash; desc = probe_desc->event_desc[i]; - if (!lttng_desc_match_enabler(desc, enabler)) + if (!lttng_desc_match_enabler(desc, + lttng_event_enabler_as_enabler(event_enabler))) continue; event_name = desc->name; name_len = strlen(event_name); @@ -777,7 +803,7 @@ void lttng_create_event_if_missing(struct lttng_enabler *enabler) head = &session->events_ht.table[hash & (LTTNG_UST_EVENT_HT_SIZE - 1)]; cds_hlist_for_each_entry(event, node, head, hlist) { if (event->desc == desc - && event->chan == enabler->chan) { + && event->chan == event_enabler->chan) { found = true; break; } @@ -790,7 +816,7 @@ void lttng_create_event_if_missing(struct lttng_enabler *enabler) * event probe. */ ret = lttng_event_create(probe_desc->event_desc[i], - enabler->chan); + event_enabler->chan); if (ret) { DBG("Unable to create event %s, error %d\n", probe_desc->event_desc[i]->name, ret); @@ -914,25 +940,26 @@ void lttng_probe_provider_unregister_events(struct lttng_probe_desc *provider_de * and add backward reference from the event to the enabler. */ static -int lttng_enabler_ref_events(struct lttng_enabler *enabler) +int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler) { - struct lttng_session *session = enabler->chan->session; + struct lttng_session *session = event_enabler->chan->session; struct lttng_event *event; - if (!enabler->enabled) + if (!lttng_event_enabler_as_enabler(event_enabler)->enabled) goto end; /* First ensure that probe events are created for this enabler. */ - lttng_create_event_if_missing(enabler); + lttng_create_event_if_missing(event_enabler); /* For each event matching enabler in session event list. */ cds_list_for_each_entry(event, &session->events_head, node) { struct lttng_enabler_ref *enabler_ref; - if (!lttng_event_match_enabler(event, enabler)) + if (!lttng_event_enabler_match_event(event_enabler, event)) continue; - enabler_ref = lttng_event_enabler_ref(event, enabler); + enabler_ref = lttng_enabler_ref(&event->enablers_ref_head, + lttng_event_enabler_as_enabler(event_enabler)); if (!enabler_ref) { /* * If no backward ref, create it. @@ -941,7 +968,8 @@ int lttng_enabler_ref_events(struct lttng_enabler *enabler) enabler_ref = zmalloc(sizeof(*enabler_ref)); if (!enabler_ref) return -ENOMEM; - enabler_ref->ref = enabler; + enabler_ref->ref = lttng_event_enabler_as_enabler( + event_enabler); cds_list_add(&enabler_ref->node, &event->enablers_ref_head); } @@ -949,7 +977,7 @@ int lttng_enabler_ref_events(struct lttng_enabler *enabler) /* * Link filter bytecodes if not linked yet. */ - lttng_enabler_event_link_bytecode(event, enabler); + lttng_event_enabler_link_bytecode(event, event_enabler); /* TODO: merge event context. */ } @@ -967,7 +995,7 @@ int lttng_fix_pending_events(void) struct lttng_session *session; cds_list_for_each_entry(session, &sessions, node) { - lttng_session_lazy_sync_enablers(session); + lttng_session_lazy_sync_event_enablers(session); } return 0; } @@ -1041,57 +1069,79 @@ void lttng_ust_events_exit(void) /* * Enabler management. */ -struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_format_type format_type, +struct lttng_event_enabler *lttng_event_enabler_create( + enum lttng_enabler_format_type format_type, struct lttng_ust_event *event_param, struct lttng_channel *chan) { - struct lttng_enabler *enabler; + struct lttng_event_enabler *event_enabler; - enabler = zmalloc(sizeof(*enabler)); - if (!enabler) + event_enabler = zmalloc(sizeof(*event_enabler)); + if (!event_enabler) return NULL; - enabler->format_type = format_type; - CDS_INIT_LIST_HEAD(&enabler->filter_bytecode_head); - CDS_INIT_LIST_HEAD(&enabler->excluder_head); - memcpy(&enabler->event_param, event_param, - sizeof(enabler->event_param)); - enabler->chan = chan; + event_enabler->base.format_type = format_type; + CDS_INIT_LIST_HEAD(&event_enabler->base.filter_bytecode_head); + CDS_INIT_LIST_HEAD(&event_enabler->base.excluder_head); + memcpy(&event_enabler->base.event_param, event_param, + sizeof(event_enabler->base.event_param)); + event_enabler->chan = chan; /* ctx left NULL */ - enabler->enabled = 0; - cds_list_add(&enabler->node, &enabler->chan->session->enablers_head); - lttng_session_lazy_sync_enablers(enabler->chan->session); - return enabler; + event_enabler->base.enabled = 0; + cds_list_add(&event_enabler->node, &event_enabler->chan->session->enablers_head); + lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + + return event_enabler; } -int lttng_enabler_enable(struct lttng_enabler *enabler) +int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler) { - enabler->enabled = 1; - lttng_session_lazy_sync_enablers(enabler->chan->session); + lttng_event_enabler_as_enabler(event_enabler)->enabled = 1; + lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + return 0; } -int lttng_enabler_disable(struct lttng_enabler *enabler) +int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler) { - enabler->enabled = 0; - lttng_session_lazy_sync_enablers(enabler->chan->session); + lttng_event_enabler_as_enabler(event_enabler)->enabled = 0; + lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); + return 0; } -int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, +static +void _lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, struct lttng_ust_filter_bytecode_node *bytecode) { bytecode->enabler = enabler; cds_list_add_tail(&bytecode->node, &enabler->filter_bytecode_head); - lttng_session_lazy_sync_enablers(enabler->chan->session); +} + +int lttng_event_enabler_attach_bytecode(struct lttng_event_enabler *event_enabler, + struct lttng_ust_filter_bytecode_node *bytecode) +{ + _lttng_enabler_attach_bytecode( + lttng_event_enabler_as_enabler(event_enabler), bytecode); + + lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); return 0; } -int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, +static +void _lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, struct lttng_ust_excluder_node *excluder) { excluder->enabler = enabler; cds_list_add_tail(&excluder->node, &enabler->excluder_head); - lttng_session_lazy_sync_enablers(enabler->chan->session); +} + +int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabler, + struct lttng_ust_excluder_node *excluder) +{ + _lttng_enabler_attach_exclusion( + lttng_event_enabler_as_enabler(event_enabler), excluder); + + lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); return 0; } @@ -1167,59 +1217,37 @@ int lttng_attach_context(struct lttng_ust_context *context_param, } } -int lttng_enabler_attach_context(struct lttng_enabler *enabler, +int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, struct lttng_ust_context *context_param) { -#if 0 // disabled for now. - struct lttng_session *session = enabler->chan->session; - int ret; - - ret = lttng_attach_context(context_param, &enabler->ctx, - session); - if (ret) - return ret; - lttng_session_lazy_sync_enablers(enabler->chan->session); -#endif return -ENOSYS; } -static -void lttng_enabler_destroy(struct lttng_enabler *enabler) +void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler) { - struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node; - struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node; - - /* Destroy filter bytecode */ - cds_list_for_each_entry_safe(filter_node, tmp_filter_node, - &enabler->filter_bytecode_head, node) { - free(filter_node); - } - - /* Destroy excluders */ - cds_list_for_each_entry_safe(excluder_node, tmp_excluder_node, - &enabler->excluder_head, node) { - free(excluder_node); + if (!event_enabler) { + return; } + cds_list_del(&event_enabler->node); - /* Destroy contexts */ - lttng_destroy_context(enabler->ctx); + lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler)); - cds_list_del(&enabler->node); - free(enabler); + lttng_destroy_context(event_enabler->ctx); + free(event_enabler); } /* - * lttng_session_sync_enablers should be called just before starting a + * lttng_session_sync_event_enablers should be called just before starting a * session. */ static -void lttng_session_sync_enablers(struct lttng_session *session) +void lttng_session_sync_event_enablers(struct lttng_session *session) { - struct lttng_enabler *enabler; + struct lttng_event_enabler *event_enabler; struct lttng_event *event; - cds_list_for_each_entry(enabler, &session->enablers_head, node) - lttng_enabler_ref_events(enabler); + cds_list_for_each_entry(event_enabler, &session->enablers_head, node) + lttng_event_enabler_ref_events(event_enabler); /* * For each event, if at least one of its enablers is enabled, * and its channel and session transient states are enabled, we @@ -1286,12 +1314,12 @@ void lttng_session_sync_enablers(struct lttng_session *session) * "lazy" sync means we only sync if required. */ static -void lttng_session_lazy_sync_enablers(struct lttng_session *session) +void lttng_session_lazy_sync_event_enablers(struct lttng_session *session) { /* We can skip if session is not active */ if (!session->active) return; - lttng_session_sync_enablers(session); + lttng_session_sync_event_enablers(session); } /* diff --git a/liblttng-ust/lttng-filter.c b/liblttng-ust/lttng-filter.c index 7dbe6f26..e9774b48 100644 --- a/liblttng-ust/lttng-filter.c +++ b/liblttng-ust/lttng-filter.c @@ -31,6 +31,7 @@ #include #include "lttng-filter.h" +#include "ust-events-internal.h" static const char *opnames[] = { [ FILTER_OP_UNKNOWN ] = "UNKNOWN", @@ -508,17 +509,18 @@ void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime) /* * Link bytecode for all enablers referenced by an event. */ -void lttng_enabler_event_link_bytecode(struct lttng_event *event, - struct lttng_enabler *enabler) +void lttng_event_enabler_link_bytecode(struct lttng_event *event, + struct lttng_event_enabler *event_enabler) { struct lttng_ust_filter_bytecode_node *bc; struct lttng_bytecode_runtime *runtime; + struct lttng_enabler *base_enabler = lttng_event_enabler_as_enabler(event_enabler); /* Can only be called for events with desc attached */ assert(event->desc); /* Link each bytecode. */ - cds_list_for_each_entry(bc, &enabler->filter_bytecode_head, node) { + cds_list_for_each_entry(bc, &base_enabler->filter_bytecode_head, node) { int found = 0, ret; struct cds_list_head *insert_loc; diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 126863d7..fb124c2a 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -57,6 +57,7 @@ #include "../libringbuffer/shm.h" #include "lttng-tracer.h" #include "string-utils.h" +#include "ust-events-internal.h" #define OBJ_NAME_LEN 16 @@ -281,7 +282,7 @@ void lttng_ust_objd_table_owner_cleanup(void *owner) static const struct lttng_ust_objd_ops lttng_ops; static const struct lttng_ust_objd_ops lttng_session_ops; static const struct lttng_ust_objd_ops lttng_channel_ops; -static const struct lttng_ust_objd_ops lttng_enabler_ops; +static const struct lttng_ust_objd_ops lttng_event_enabler_ops; static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops; static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops; @@ -794,17 +795,18 @@ error_add_stream: } static -int lttng_abi_create_enabler(int channel_objd, +int lttng_abi_create_event_enabler(int channel_objd, struct lttng_ust_event *event_param, void *owner, enum lttng_enabler_format_type format_type) { struct lttng_channel *channel = objd_private(channel_objd); - struct lttng_enabler *enabler; + struct lttng_event_enabler *enabler; int event_objd, ret; event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; - event_objd = objd_alloc(NULL, <tng_enabler_ops, owner, "enabler"); + event_objd = objd_alloc(NULL, <tng_event_enabler_ops, owner, + "event enabler"); if (event_objd < 0) { ret = event_objd; goto objd_error; @@ -813,7 +815,7 @@ int lttng_abi_create_enabler(int channel_objd, * We tolerate no failure path after event creation. It will stay * invariant for the rest of the session. */ - enabler = lttng_enabler_create(format_type, event_param, channel); + enabler = lttng_event_enabler_create(format_type, event_param, channel); if (!enabler) { ret = -ENOMEM; goto event_error; @@ -891,10 +893,10 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg, * If the event name is a star globbing pattern, * we create the special star globbing enabler. */ - return lttng_abi_create_enabler(objd, event_param, + return lttng_abi_create_event_enabler(objd, event_param, owner, LTTNG_ENABLER_FORMAT_STAR_GLOB); } else { - return lttng_abi_create_enabler(objd, event_param, + return lttng_abi_create_event_enabler(objd, event_param, owner, LTTNG_ENABLER_FORMAT_EVENT); } } @@ -951,24 +953,24 @@ static const struct lttng_ust_objd_ops lttng_channel_ops = { * Attach exclusions to an enabler. */ static -long lttng_enabler_cmd(int objd, unsigned int cmd, unsigned long arg, +long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg, union ust_args *uargs, void *owner) { - struct lttng_enabler *enabler = objd_private(objd); + struct lttng_event_enabler *enabler = objd_private(objd); switch (cmd) { case LTTNG_UST_CONTEXT: - return lttng_enabler_attach_context(enabler, + return lttng_event_enabler_attach_context(enabler, (struct lttng_ust_context *) arg); case LTTNG_UST_ENABLE: - return lttng_enabler_enable(enabler); + return lttng_event_enabler_enable(enabler); case LTTNG_UST_DISABLE: - return lttng_enabler_disable(enabler); + return lttng_event_enabler_disable(enabler); case LTTNG_UST_FILTER: { int ret; - ret = lttng_enabler_attach_bytecode(enabler, + ret = lttng_event_enabler_attach_bytecode(enabler, (struct lttng_ust_filter_bytecode_node *) arg); if (ret) return ret; @@ -976,7 +978,7 @@ long lttng_enabler_cmd(int objd, unsigned int cmd, unsigned long arg, } case LTTNG_UST_EXCLUSION: { - return lttng_enabler_attach_exclusion(enabler, + return lttng_event_enabler_attach_exclusion(enabler, (struct lttng_ust_excluder_node *) arg); } default: @@ -985,18 +987,19 @@ long lttng_enabler_cmd(int objd, unsigned int cmd, unsigned long arg, } static -int lttng_enabler_release(int objd) +int lttng_event_enabler_release(int objd) { - struct lttng_enabler *enabler = objd_private(objd); + struct lttng_event_enabler *event_enabler = objd_private(objd); + + if (event_enabler) + return lttng_ust_objd_unref(event_enabler->chan->objd, 0); - if (enabler) - return lttng_ust_objd_unref(enabler->chan->objd, 0); return 0; } -static const struct lttng_ust_objd_ops lttng_enabler_ops = { - .release = lttng_enabler_release, - .cmd = lttng_enabler_cmd, +static const struct lttng_ust_objd_ops lttng_event_enabler_ops = { + .release = lttng_event_enabler_release, + .cmd = lttng_event_enabler_cmd, }; void lttng_ust_abi_exit(void) diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h new file mode 100644 index 00000000..f93305ed --- /dev/null +++ b/liblttng-ust/ust-events-internal.h @@ -0,0 +1,122 @@ +#ifndef _LTTNG_UST_EVENTS_INTERNAL_H +#define _LTTNG_UST_EVENTS_INTERNAL_H + +/* + * ust-events-internal.h + * + * Copyright 2019 (c) - Francis Deslauriers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include +#include + +#include +#include + +struct lttng_event_enabler { + struct lttng_enabler base; + struct cds_list_head node; /* per-session list of enablers */ + struct lttng_channel *chan; + /* + * Unused, but kept around to make it explicit that the tracer can do + * it. + */ + struct lttng_ctx *ctx; +}; + +static inline +struct lttng_enabler *lttng_event_enabler_as_enabler( + struct lttng_event_enabler *event_enabler) +{ + return &event_enabler->base; +} + + +/* + * Allocate and initialize a `struct lttng_event_enabler` object. + * + * On success, returns a `struct lttng_event_enabler`, + * On memory error, returns NULL. + */ +LTTNG_HIDDEN +struct lttng_event_enabler *lttng_event_enabler_create( + enum lttng_enabler_format_type format_type, + struct lttng_ust_event *event_param, + struct lttng_channel *chan); + +/* + * Destroy a `struct lttng_event_enabler` object. + */ +LTTNG_HIDDEN +void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler); + +/* + * Enable a `struct lttng_event_enabler` object and all events related to this + * enabler. + */ +LTTNG_HIDDEN +int lttng_event_enabler_enable(struct lttng_event_enabler *enabler); + +/* + * Disable a `struct lttng_event_enabler` object and all events related to this + * enabler. + */ +LTTNG_HIDDEN +int lttng_event_enabler_disable(struct lttng_event_enabler *enabler); + +/* + * Attach filter bytecode program to `struct lttng_event_enabler` and all + * events related to this enabler. + */ +LTTNG_HIDDEN +int lttng_event_enabler_attach_bytecode(struct lttng_event_enabler *enabler, + struct lttng_ust_filter_bytecode_node *bytecode); + +/* + * Attach an application context to an event enabler. + * + * Not implemented. + */ +LTTNG_HIDDEN +int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, + struct lttng_ust_context *ctx); + +/* + * Attach exclusion list to `struct lttng_event_enabler` and all + * events related to this enabler. + */ +LTTNG_HIDDEN +int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, + struct lttng_ust_excluder_node *excluder); + +/* + * Synchronize bytecodes for the enabler and the event. + * + * This function goes over all bytecode programs of the event enabler to ensure + * each is linked to the provided event. + */ +LTTNG_HIDDEN +void lttng_event_enabler_link_bytecode(struct lttng_event *event, + struct lttng_event_enabler *enabler); + +#endif /* _LTTNG_UST_EVENTS_INTERNAL_H */ -- 2.34.1