From: Mathieu Desnoyers Date: Wed, 3 Nov 2021 19:27:37 +0000 (-0400) Subject: Refactoring: combine common code into lttng_event_enabler_ref_events X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3622cd4764b4d108ffc4c2074a359bf1b3edf86e;p=lttng-modules.git Refactoring: combine common code into lttng_event_enabler_ref_events Signed-off-by: Mathieu Desnoyers Change-Id: I1b2b0f9f8bcd5f143780354d412f6a072acb32b7 --- diff --git a/src/lttng-events.c b/src/lttng-events.c index 8839c1e8..b6375338 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -2263,69 +2263,25 @@ void lttng_event_enabler_init_event_capture(struct lttng_event_enabler_common *e * Should be called with sessions mutex held. */ static -int lttng_event_enabler_ref_events(struct lttng_event_recorder_enabler *event_enabler) +int lttng_event_enabler_ref_events(struct lttng_event_enabler_common *event_enabler) { - struct lttng_event_enabler_common *base_enabler = lttng_event_recorder_enabler_as_enabler(event_enabler); - struct lttng_kernel_event_recorder_private *event_recorder_priv; - struct list_head *event_list_head = lttng_get_event_list_head_from_enabler(&event_enabler->parent); + struct list_head *event_list_head = lttng_get_event_list_head_from_enabler(event_enabler); + struct lttng_kernel_event_common_private *event_priv; - lttng_syscall_table_set_wildcard_all(base_enabler); + lttng_syscall_table_set_wildcard_all(event_enabler); /* First ensure that probe events are created for this enabler. */ - lttng_create_event_if_missing(&event_enabler->parent); - - /* For each event matching event_enabler in session event list. */ - list_for_each_entry(event_recorder_priv, event_list_head, parent.node) { - struct lttng_kernel_event_recorder *event_recorder = event_recorder_priv->pub; - struct lttng_enabler_ref *enabler_ref; - - if (!lttng_event_enabler_match_event(&event_enabler->parent, &event_recorder->parent)) - continue; - enabler_ref = lttng_enabler_ref(&event_recorder_priv->parent.enablers_ref_head, - lttng_event_recorder_enabler_as_enabler(event_enabler)); - if (!enabler_ref) { - /* - * If no backward ref, create it. - * Add backward ref from event to event_enabler. - */ - enabler_ref = kzalloc(sizeof(*enabler_ref), GFP_KERNEL); - if (!enabler_ref) - return -ENOMEM; - enabler_ref->ref = lttng_event_recorder_enabler_as_enabler(event_enabler); - list_add(&enabler_ref->node, - &event_recorder_priv->parent.enablers_ref_head); - } + lttng_create_event_if_missing(event_enabler); - lttng_event_enabler_init_event_filter(&event_enabler->parent, &event_recorder->parent); - } - return 0; -} - -/* - * Create event_notifiers associated with a event_notifier enabler (if not already present). - */ -static -int lttng_event_notifier_enabler_ref_event_notifiers( - struct lttng_event_notifier_enabler *event_notifier_enabler) -{ - struct lttng_kernel_event_notifier_private *event_notifier_priv; - struct list_head *event_list_head = lttng_get_event_list_head_from_enabler(&event_notifier_enabler->parent); - - lttng_syscall_table_set_wildcard_all(&event_notifier_enabler->parent); - - /* First ensure that probe event_notifiers are created for this enabler. */ - lttng_create_event_if_missing(&event_notifier_enabler->parent); - - /* Link the created event_notifier with its associated enabler. */ - list_for_each_entry(event_notifier_priv, event_list_head, parent.node) { - struct lttng_kernel_event_notifier *event_notifier = event_notifier_priv->pub; + /* Link the created event with its associated enabler. */ + list_for_each_entry(event_priv, event_list_head, node) { + struct lttng_kernel_event_common *event = event_priv->pub; struct lttng_enabler_ref *enabler_ref; - if (!lttng_event_enabler_match_event(&event_notifier_enabler->parent, &event_notifier->parent)) + if (!lttng_event_enabler_match_event(event_enabler, event)) continue; - enabler_ref = lttng_enabler_ref(&event_notifier_priv->parent.enablers_ref_head, - lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)); + enabler_ref = lttng_enabler_ref(&event_priv->enablers_ref_head, event_enabler); if (!enabler_ref) { /* * If no backward ref, create it. @@ -2335,14 +2291,12 @@ int lttng_event_notifier_enabler_ref_event_notifiers( if (!enabler_ref) return -ENOMEM; - enabler_ref->ref = lttng_event_notifier_enabler_as_enabler( - event_notifier_enabler); - list_add(&enabler_ref->node, - &event_notifier_priv->parent.enablers_ref_head); + enabler_ref->ref = event_enabler; + list_add(&enabler_ref->node, &event_priv->enablers_ref_head); } - lttng_event_enabler_init_event_filter(&event_notifier_enabler->parent, &event_notifier->parent); - lttng_event_enabler_init_event_capture(&event_notifier_enabler->parent, &event_notifier->parent); + lttng_event_enabler_init_event_filter(event_enabler, event); + lttng_event_enabler_init_event_capture(event_enabler, event); } return 0; } @@ -2656,7 +2610,7 @@ void lttng_session_sync_event_enablers(struct lttng_kernel_session *session) struct lttng_kernel_event_recorder_private *event_recorder_priv; list_for_each_entry(event_enabler, &session->priv->enablers_head, node) - lttng_event_enabler_ref_events(event_enabler); + lttng_event_enabler_ref_events(&event_enabler->parent); /* * For each event, if at least one of its enablers is enabled, * and its channel and session transient states are enabled, we @@ -2751,7 +2705,7 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group struct lttng_kernel_event_notifier_private *event_notifier_priv; list_for_each_entry(event_notifier_enabler, &event_notifier_group->enablers_head, node) - lttng_event_notifier_enabler_ref_event_notifiers(event_notifier_enabler); + lttng_event_enabler_ref_events(&event_notifier_enabler->parent); /* * For each event_notifier, if at least one of its enablers is enabled,