From: Mathieu Desnoyers Date: Mon, 1 Nov 2021 18:47:24 +0000 (-0400) Subject: Refactoring: combine event enabler destroy for notifier and recorder X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=44b1abdc77d0587d2b800584b7b6612a4fbcb96b;p=lttng-modules.git Refactoring: combine event enabler destroy for notifier and recorder Signed-off-by: Mathieu Desnoyers Change-Id: I39ed3d9046604e5ab16f3e565ba72460348f54f5 --- diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index 8ac1b01b..416e0fea 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -785,22 +785,21 @@ struct lttng_event_recorder_enabler *lttng_event_recorder_enabler_create( struct lttng_kernel_channel_buffer *chan); void lttng_event_enabler_session_add(struct lttng_kernel_session *session, struct lttng_event_recorder_enabler *event_enabler); -void lttng_event_enabler_destroy(struct lttng_event_recorder_enabler *event_enabler); - -int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler); -int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler); struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( struct lttng_event_notifier_group *event_notifier_group, enum lttng_enabler_format_type format_type, struct lttng_kernel_abi_event_notifier *event_notifier_param); - -int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler, - struct lttng_kernel_abi_filter_bytecode __user *bytecode); int lttng_event_notifier_enabler_attach_capture_bytecode( struct lttng_event_notifier_enabler *event_notifier_enabler, struct lttng_kernel_abi_capture_bytecode __user *bytecode); +int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler); +int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler); +int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler, + struct lttng_kernel_abi_filter_bytecode __user *bytecode); +void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler); + int lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc, struct lttng_event_enabler_common *enabler); diff --git a/src/lttng-abi.c b/src/lttng-abi.c index 8eeb632a..7eafe2d0 100644 --- a/src/lttng-abi.c +++ b/src/lttng-abi.c @@ -1927,7 +1927,7 @@ int lttng_abi_create_event(struct file *channel_file, */ event = lttng_kernel_event_recorder_create(event_enabler, NULL); WARN_ON_ONCE(!event); - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event)) { ret = PTR_ERR(event); goto event_error; diff --git a/src/lttng-events.c b/src/lttng-events.c index f864eaba..f5c0fa95 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -66,7 +66,6 @@ static struct kmem_cache *event_notifier_private_cache; static void lttng_session_lazy_sync_event_enablers(struct lttng_kernel_session *session); static void lttng_session_sync_event_enablers(struct lttng_kernel_session *session); -static void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler *event_notifier_enabler); static void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group *event_notifier_group); static void lttng_event_enabler_sync(struct lttng_event_enabler_common *event_enabler); @@ -355,7 +354,7 @@ void lttng_session_destroy(struct lttng_kernel_session *session) struct lttng_kernel_channel_buffer_private *chan_priv, *tmpchan_priv; struct lttng_kernel_event_recorder_private *event_recorder_priv, *tmpevent_recorder_priv; struct lttng_metadata_stream *metadata_stream; - struct lttng_event_recorder_enabler *event_enabler, *tmp_event_enabler; + struct lttng_event_recorder_enabler *event_recorder_enabler, *tmp_event_recorder_enabler; int ret; mutex_lock(&sessions_mutex); @@ -373,9 +372,9 @@ void lttng_session_destroy(struct lttng_kernel_session *session) ret = lttng_syscalls_destroy_event(chan_priv->pub); WARN_ON(ret); } - list_for_each_entry_safe(event_enabler, tmp_event_enabler, + list_for_each_entry_safe(event_recorder_enabler, tmp_event_recorder_enabler, &session->priv->enablers_head, node) - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_recorder_enabler->parent); list_for_each_entry_safe(event_recorder_priv, tmpevent_recorder_priv, &session->priv->events, node) _lttng_event_destroy(&event_recorder_priv->pub->parent); list_for_each_entry_safe(chan_priv, tmpchan_priv, &session->priv->chan, node) { @@ -429,7 +428,7 @@ void lttng_event_notifier_group_destroy( list_for_each_entry_safe(event_notifier_enabler, tmp_event_notifier_enabler, &event_notifier_group->enablers_head, node) - lttng_event_notifier_enabler_destroy(event_notifier_enabler); + lttng_event_enabler_destroy(&event_notifier_enabler->parent); list_for_each_entry_safe(event_notifier_priv, tmpevent_notifier_priv, &event_notifier_group->event_notifiers_head, node) @@ -2593,13 +2592,33 @@ void lttng_enabler_destroy(struct lttng_event_enabler_common *enabler) } } -void lttng_event_enabler_destroy(struct lttng_event_recorder_enabler *event_enabler) +void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler) { - lttng_enabler_destroy(lttng_event_recorder_enabler_as_enabler(event_enabler)); + 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); - if (event_enabler->published) - list_del(&event_enabler->node); - kfree(event_enabler); + lttng_enabler_destroy(event_enabler); + if (event_recorder_enabler->published) + list_del(&event_recorder_enabler->node); + kfree(event_recorder_enabler); + break; + } + case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: + { + struct lttng_event_notifier_enabler *event_notifier_enabler = + container_of(event_enabler, struct lttng_event_notifier_enabler, parent); + + list_del(&event_notifier_enabler->node); + lttng_enabler_destroy(event_enabler); + kfree(event_notifier_enabler); + break; + } + default: + WARN_ON_ONCE(1); + } } struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( @@ -2699,20 +2718,6 @@ end: return ret; } -static -void lttng_event_notifier_enabler_destroy( - struct lttng_event_notifier_enabler *event_notifier_enabler) -{ - if (!event_notifier_enabler) { - return; - } - - list_del(&event_notifier_enabler->node); - - lttng_enabler_destroy(lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)); - kfree(event_notifier_enabler); -} - /* * lttng_session_sync_event_enablers should be called just before starting a * session. diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index 34dc138e..c68baab7 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -598,7 +598,7 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl } event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); WARN_ON_ONCE(!event_recorder); - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event_recorder)) { /* * If something goes wrong in event registration @@ -670,7 +670,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e return -ENOMEM; } event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_enabler->parent); WARN_ON_ONCE(!event_recorder); if (IS_ERR(event_recorder)) { return PTR_ERR(event_recorder); @@ -696,7 +696,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e } event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); WARN_ON_ONCE(!event_recorder); - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event_recorder)) { return PTR_ERR(event_recorder); } @@ -721,7 +721,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e } event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); WARN_ON_ONCE(!event_recorder); - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event_recorder)) { return PTR_ERR(event_recorder); } @@ -746,7 +746,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e } event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc); WARN_ON_ONCE(!event_recorder); - lttng_event_enabler_destroy(event_enabler); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event_recorder)) { return PTR_ERR(event_recorder); }