From: Mathieu Desnoyers Date: Wed, 3 Nov 2021 16:00:02 +0000 (-0400) Subject: Refactoring: combine create event common code X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=83006ee0d75381816540c339e5dda7aba72fafa3;p=lttng-modules.git Refactoring: combine create event common code Signed-off-by: Mathieu Desnoyers Change-Id: If87900e447a45de86ca0fc2a8b999c9639f84fef --- diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index 8bfe094a..2bf0eb9a 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -1031,18 +1031,10 @@ struct lttng_kernel_channel_buffer *lttng_global_channel_create(struct lttng_ker unsigned int read_timer_interval); void lttng_metadata_channel_destroy(struct lttng_kernel_channel_buffer *chan); -struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lttng_event_recorder_enabler *event_enabler, +struct lttng_kernel_event_common *_lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler, const struct lttng_kernel_event_desc *event_desc); -struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_event_recorder_enabler *event_enabler, +struct lttng_kernel_event_common *lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler, const struct lttng_kernel_event_desc *event_desc); -struct lttng_kernel_event_recorder *lttng_event_compat_old_create(struct lttng_kernel_channel_buffer *chan, - struct lttng_kernel_abi_old_event *old_event_param, - const struct lttng_kernel_event_desc *internal_desc); - -struct lttng_kernel_event_notifier *lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, - const struct lttng_kernel_event_desc *event_notifier_desc); -struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, - const struct lttng_kernel_event_desc *event_notifier_desc); int lttng_channel_enable(struct lttng_kernel_channel_common *channel); int lttng_channel_disable(struct lttng_kernel_channel_common *channel); diff --git a/src/lttng-abi.c b/src/lttng-abi.c index 1f093981..cd946656 100644 --- a/src/lttng-abi.c +++ b/src/lttng-abi.c @@ -1912,7 +1912,7 @@ int lttng_abi_create_event(struct file *channel_file, lttng_fallthrough; case LTTNG_KERNEL_ABI_UPROBE: { - struct lttng_kernel_event_recorder *event; + struct lttng_kernel_event_common *event; struct lttng_event_recorder_enabler *event_enabler; event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, @@ -1925,14 +1925,14 @@ int lttng_abi_create_event(struct file *channel_file, * We tolerate no failure path after event creation. It * will stay invariant for the rest of the session. */ - event = lttng_kernel_event_recorder_create(event_enabler, NULL); + event = lttng_kernel_event_create(&event_enabler->parent, NULL); WARN_ON_ONCE(!event); lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event)) { ret = PTR_ERR(event); goto event_error; } - priv = event; + priv = container_of(event, struct lttng_kernel_event_recorder, parent); break; } @@ -2153,7 +2153,7 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, lttng_fallthrough; case LTTNG_KERNEL_ABI_UPROBE: { - struct lttng_kernel_event_notifier *event_notifier; + struct lttng_kernel_event_common *event; struct lttng_event_notifier_enabler *event_notifier_enabler; event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, @@ -2162,14 +2162,14 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, ret = -ENOMEM; goto event_notifier_error; } - event_notifier = lttng_event_notifier_create(event_notifier_enabler, NULL); - WARN_ON_ONCE(!event_notifier); + event = lttng_kernel_event_create(&event_notifier_enabler->parent, NULL); + WARN_ON_ONCE(!event); lttng_event_enabler_destroy(&event_notifier_enabler->parent); - if (IS_ERR(event_notifier)) { - ret = PTR_ERR(event_notifier); + if (IS_ERR(event)) { + ret = PTR_ERR(event); goto event_notifier_error; } - priv = event_notifier; + priv = container_of(event, struct lttng_kernel_event_notifier, parent); break; } diff --git a/src/lttng-events.c b/src/lttng-events.c index a467fd64..6512dde8 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -872,6 +872,7 @@ void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream) * Supports event creation while tracing session is active. * Needs to be called with sessions mutex held. */ +static struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_event_recorder_enabler *event_enabler, const struct lttng_kernel_event_desc *event_desc) { @@ -1153,7 +1154,8 @@ full: return ERR_PTR(ret); } -struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, +static +struct lttng_kernel_event_notifier *_lttng_kernel_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, const struct lttng_kernel_event_desc *event_desc) { struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_enabler->parent); @@ -1390,6 +1392,50 @@ type_error: return ERR_PTR(ret); } +struct lttng_kernel_event_common *_lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler, + const struct lttng_kernel_event_desc *event_desc) +{ + switch (event_enabler->enabler_type) { + case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + { + struct lttng_event_recorder_enabler *event_recorder_enabler = + container_of(event_enabler, struct lttng_event_recorder_enabler, parent); + struct lttng_kernel_event_recorder *event_recorder; + + event_recorder = _lttng_kernel_event_recorder_create(event_recorder_enabler, event_desc); + if (!event_recorder) + return NULL; + return &event_recorder->parent; + } + case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: + { + struct lttng_event_notifier_enabler *event_notifier_enabler = + container_of(event_enabler, struct lttng_event_notifier_enabler, parent); + struct lttng_kernel_event_notifier *event_notifier; + + event_notifier = _lttng_kernel_event_notifier_create(event_notifier_enabler, event_desc); + if (!event_notifier) + return NULL; + return &event_notifier->parent; + } + default: + return NULL; + } +} + +struct lttng_kernel_event_common *lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler, + const struct lttng_kernel_event_desc *event_desc) +{ + struct lttng_kernel_event_common *event; + + mutex_lock(&sessions_mutex); + event = _lttng_kernel_event_create(event_enabler, event_desc); + mutex_unlock(&sessions_mutex); + return event; +} + + + int lttng_kernel_counter_read(struct lttng_counter *counter, const size_t *dim_indexes, int32_t cpu, int64_t *val, bool *overflow, bool *underflow) @@ -1412,28 +1458,6 @@ int lttng_kernel_counter_clear(struct lttng_counter *counter, return counter->ops->counter_clear(counter->counter, dim_indexes); } -struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lttng_event_recorder_enabler *event_enabler, - const struct lttng_kernel_event_desc *event_desc) -{ - struct lttng_kernel_event_recorder *event; - - mutex_lock(&sessions_mutex); - event = _lttng_kernel_event_recorder_create(event_enabler, event_desc); - mutex_unlock(&sessions_mutex); - return event; -} - -struct lttng_kernel_event_notifier *lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, - const struct lttng_kernel_event_desc *event_desc) -{ - struct lttng_kernel_event_notifier *event_notifier; - - mutex_lock(&sessions_mutex); - event_notifier = _lttng_event_notifier_create(event_enabler, event_desc); - mutex_unlock(&sessions_mutex); - return event_notifier; -} - /* Only used for tracepoints for now. */ static void register_event(struct lttng_kernel_event_common *event) @@ -2125,7 +2149,7 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enable for (i = 0; i < probe_desc->nr_events; i++) { int found = 0; struct hlist_head *head; - struct lttng_kernel_event_recorder *event_recorder; + struct lttng_kernel_event_common *event; struct lttng_kernel_event_common_private *event_priv; desc = probe_desc->event_desc[i]; @@ -2145,11 +2169,10 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enable continue; /* - * We need to create an event for this - * event probe. + * We need to create an event for this event probe. */ - event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); - if (!event_recorder) { + event = _lttng_kernel_event_create(&event_enabler->parent, desc); + if (!event) { printk(KERN_INFO "LTTng: Unable to create event %s\n", probe_desc->event_desc[i]->event_name); } @@ -2176,7 +2199,7 @@ void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifi for (i = 0; i < probe_desc->nr_events; i++) { int found = 0; struct hlist_head *head; - struct lttng_kernel_event_notifier *event_notifier; + struct lttng_kernel_event_common *event; struct lttng_kernel_event_common_private *event_priv; desc = probe_desc->event_desc[i]; @@ -2199,8 +2222,8 @@ void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifi /* * We need to create a event_notifier for this event probe. */ - event_notifier = _lttng_event_notifier_create(event_notifier_enabler, desc); - if (IS_ERR(event_notifier)) { + event = _lttng_kernel_event_create(&event_notifier_enabler->parent, desc); + if (IS_ERR(event)) { printk(KERN_INFO "Unable to create event_notifier %s\n", probe_desc->event_desc[i]->event_name); } diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index 82829dcb..3208cd4d 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -546,7 +546,7 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl const struct lttng_kernel_event_desc *desc = table[i].desc; struct lttng_event_recorder_enabler *event_enabler; struct lttng_kernel_abi_event ev; - struct lttng_kernel_event_recorder *event_recorder; + struct lttng_kernel_event_common *event; struct lttng_kernel_event_common_private *event_priv; struct hlist_head *head; bool found = false; @@ -597,19 +597,19 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl if (!event_enabler) { return -ENOMEM; } - event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); - WARN_ON_ONCE(!event_recorder); + event = _lttng_kernel_event_create(&event_enabler->parent, desc); + WARN_ON_ONCE(!event); lttng_event_enabler_destroy(&event_enabler->parent); - if (IS_ERR(event_recorder)) { + if (IS_ERR(event)) { /* * If something goes wrong in event registration * after the first one, we have no choice but to * leave the previous events in there, until * deleted by session teardown. */ - return PTR_ERR(event_recorder); + return PTR_ERR(event); } - hlist_add_head(&event_recorder->priv->parent.u.syscall.node, &chan_table[i]); + hlist_add_head(&event->priv->u.syscall.node, &chan_table[i]); } return 0; } @@ -631,7 +631,7 @@ int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_ev if (hlist_empty(&syscall_table->unknown_syscall_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___syscall_entry_unknown; - struct lttng_kernel_event_recorder *event_recorder; + struct lttng_kernel_event_common *event; struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); @@ -644,19 +644,19 @@ int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_ev if (!event_enabler) { return -ENOMEM; } - event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); + event = _lttng_kernel_event_create(&event_enabler->parent, desc); lttng_event_enabler_destroy(&event_enabler->parent); - WARN_ON_ONCE(!event_recorder); - if (IS_ERR(event_recorder)) { - return PTR_ERR(event_recorder); + WARN_ON_ONCE(!event); + if (IS_ERR(event)) { + return PTR_ERR(event); } - hlist_add_head(&event_recorder->priv->parent.u.syscall.node, &syscall_table->unknown_syscall_dispatch); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->unknown_syscall_dispatch); } if (hlist_empty(&syscall_table->compat_unknown_syscall_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___compat_syscall_entry_unknown; - struct lttng_kernel_event_recorder *event_recorder; + struct lttng_kernel_event_common *event; struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); @@ -669,19 +669,19 @@ int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_ev if (!event_enabler) { return -ENOMEM; } - event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); - WARN_ON_ONCE(!event_recorder); + event = _lttng_kernel_event_create(&event_enabler->parent, desc); + WARN_ON_ONCE(!event); lttng_event_enabler_destroy(&event_enabler->parent); - if (IS_ERR(event_recorder)) { - return PTR_ERR(event_recorder); + if (IS_ERR(event)) { + return PTR_ERR(event); } - hlist_add_head(&event_recorder->priv->parent.u.syscall.node, &syscall_table->compat_unknown_syscall_dispatch); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->compat_unknown_syscall_dispatch); } if (hlist_empty(&syscall_table->compat_unknown_syscall_exit_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___compat_syscall_exit_unknown; - struct lttng_kernel_event_recorder *event_recorder; + struct lttng_kernel_event_common *event; struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); @@ -694,19 +694,19 @@ int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_ev if (!event_enabler) { return -ENOMEM; } - event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); - WARN_ON_ONCE(!event_recorder); + event = _lttng_kernel_event_create(&event_enabler->parent, desc); + WARN_ON_ONCE(!event); lttng_event_enabler_destroy(&event_enabler->parent); - if (IS_ERR(event_recorder)) { - return PTR_ERR(event_recorder); + if (IS_ERR(event)) { + return PTR_ERR(event); } - hlist_add_head(&event_recorder->priv->parent.u.syscall.node, &syscall_table->compat_unknown_syscall_exit_dispatch); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->compat_unknown_syscall_exit_dispatch); } if (hlist_empty(&syscall_table->unknown_syscall_exit_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___syscall_exit_unknown; - struct lttng_kernel_event_recorder *event_recorder; + struct lttng_kernel_event_common *event; struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); @@ -719,13 +719,13 @@ int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_ev if (!event_enabler) { return -ENOMEM; } - event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); - WARN_ON_ONCE(!event_recorder); + event = _lttng_kernel_event_create(&event_enabler->parent, desc); + WARN_ON_ONCE(!event); lttng_event_enabler_destroy(&event_enabler->parent); - if (IS_ERR(event_recorder)) { - return PTR_ERR(event_recorder); + if (IS_ERR(event)) { + return PTR_ERR(event); } - hlist_add_head(&event_recorder->priv->parent.u.syscall.node, &syscall_table->unknown_syscall_exit_dispatch); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->unknown_syscall_exit_dispatch); } ret = lttng_create_syscall_event_if_missing(sc_table.table, sc_table.len, @@ -832,7 +832,7 @@ int create_unknown_event_notifier( { struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_notifier_enabler->parent); struct lttng_kernel_event_common_private *event_priv; - struct lttng_kernel_event_notifier *event_notifier; + struct lttng_kernel_event_common *event; const struct lttng_kernel_event_desc *desc; struct lttng_event_notifier_group *group = event_notifier_enabler->group; struct lttng_kernel_syscall_table *syscall_table = &group->syscall_table; @@ -904,16 +904,16 @@ int create_unknown_event_notifier( event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &event_notifier_param, group); WARN_ON_ONCE(!event_notifier_enabler); - event_notifier = _lttng_event_notifier_create(event_notifier_enabler, desc); + event = _lttng_kernel_event_create(&event_notifier_enabler->parent, desc); lttng_event_enabler_destroy(&event_notifier_enabler->parent); - if (IS_ERR(event_notifier)) { + if (IS_ERR(event)) { printk(KERN_INFO "Unable to create unknown notifier %s\n", desc->event_name); ret = -ENOMEM; goto end; } - hlist_add_head_rcu(&event_notifier->priv->parent.u.syscall.node, unknown_dispatch_list); + hlist_add_head_rcu(&event->priv->u.syscall.node, unknown_dispatch_list); end: return ret; @@ -936,7 +936,7 @@ static int create_matching_event_notifiers( for (i = 0; i < table_len; i++) { struct lttng_event_notifier_enabler *event_notifier_enabler; struct lttng_kernel_event_common_private *event_priv; - struct lttng_kernel_event_notifier *event_notifier; + struct lttng_kernel_event_common *event; struct lttng_kernel_abi_event_notifier event_notifier_param; struct hlist_head *head; int found = 0; @@ -992,16 +992,16 @@ static int create_matching_event_notifiers( event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &event_notifier_param, group); WARN_ON_ONCE(!event_notifier_enabler); - event_notifier = _lttng_event_notifier_create(event_notifier_enabler, desc); + event = _lttng_kernel_event_create(&event_notifier_enabler->parent, desc); lttng_event_enabler_destroy(&event_notifier_enabler->parent); - if (IS_ERR(event_notifier)) { + if (IS_ERR(event)) { printk(KERN_INFO "Unable to create event_notifier %s\n", desc->event_name); ret = -ENOMEM; goto end; } - event_notifier->priv->parent.u.syscall.syscall_id = i; + event->priv->u.syscall.syscall_id = i; } end: