Refactoring: combine common code into lttng_event_enabler_ref_events
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 3 Nov 2021 19:27:37 +0000 (15:27 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 3 Nov 2021 19:27:37 +0000 (15:27 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I1b2b0f9f8bcd5f143780354d412f6a072acb32b7

src/lttng-events.c

index 8839c1e8ae6cc906d73860ad25d9cde5b0273ad1..b6375338bc822ed3ecd83da5f221bafd5aeaf30a 100644 (file)
@@ -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,
This page took 0.029143 seconds and 4 git commands to generate.