Refactoring: introduce lttng_event_enabler_event_name_match_event
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 4 Nov 2021 20:33:39 +0000 (16:33 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 4 Nov 2021 20:33:39 +0000 (16:33 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie7960f23e06a23d0db70e3c9586ec37739d5b4da

include/lttng/events-internal.h
src/lttng-events.c

index 39446ebeda3d43ba11232123d519edd87d1c0d75..202427f2aa9482a8731b02ff3630e4eb2970821b 100644 (file)
@@ -843,6 +843,9 @@ bool lttng_event_enabler_match_event(struct lttng_event_enabler_common *event_en
 bool lttng_event_enabler_desc_match_event(struct lttng_event_enabler_common *event_enabler,
                const struct lttng_kernel_event_desc *desc,
                struct lttng_kernel_event_common *event);
+bool lttng_event_enabler_event_name_match_event(struct lttng_event_enabler_common *event_enabler,
+               const char *event_name,
+               struct lttng_kernel_event_common *event);
 
 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_desc,
                struct lttng_kernel_ctx *ctx,
index 08cb66dc49a3fcd00856a5ec3132f2b9c38c034c..ad5faa98cfc0add560fdf10eab4dc54473e9b91f 100644 (file)
@@ -984,7 +984,6 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
        enum lttng_kernel_abi_instrumentation itype = event_param->instrumentation;
        struct lttng_kernel_event_common_private *event_priv;
        struct lttng_kernel_event_common *event;
-       struct lttng_kernel_event_recorder_private *event_recorder_priv;
        struct lttng_kernel_event_recorder *event_recorder;
        const char *event_name;
        struct hlist_head *head;
@@ -1022,12 +1021,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
 
        head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, event_name);
        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
-               event_recorder_priv = container_of(event_priv, struct lttng_kernel_event_recorder_private, parent);
-
-               WARN_ON_ONCE(!event_priv->desc);
-               if (!strncmp(event_priv->desc->event_name, event_name,
-                                       LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1)
-                               && chan == event_recorder_priv->pub->chan) {
+               if (lttng_event_enabler_event_name_match_event(&event_enabler->parent, event_name, event_priv->pub)) {
                        ret = -EEXIST;
                        goto exist;
                }
@@ -1228,11 +1222,9 @@ struct lttng_kernel_event_notifier *_lttng_kernel_event_notifier_create(struct l
        struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_enabler->parent);
        struct lttng_event_notifier_group *event_notifier_group = event_enabler->group;
        struct lttng_kernel_abi_event *event_param = &event_enabler->parent.event_param;
-       uint64_t token = event_enabler->parent.user_token;
        enum lttng_kernel_abi_instrumentation itype = event_param->instrumentation;
        struct lttng_kernel_event_common_private *event_priv;
        struct lttng_kernel_event_common *event;
-       struct lttng_kernel_event_notifier_private *event_notifier_priv;
        struct lttng_kernel_event_notifier *event_notifier;
        struct lttng_counter *error_counter;
        const char *event_name;
@@ -1266,13 +1258,7 @@ struct lttng_kernel_event_notifier *_lttng_kernel_event_notifier_create(struct l
 
        head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, event_name);
        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
-               event_notifier_priv = container_of(event_priv, struct lttng_kernel_event_notifier_private, parent);
-
-               WARN_ON_ONCE(!event_priv->desc);
-               if (!strncmp(event_priv->desc->event_name, event_name,
-                                       LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1)
-                               && event_notifier_group == event_notifier_priv->group
-                               && token == event_priv->user_token) {
+               if (lttng_event_enabler_event_name_match_event(&event_enabler->parent, event_name, event_priv->pub)) {
                        ret = -EEXIST;
                        goto exist;
                }
@@ -2174,6 +2160,47 @@ bool lttng_event_enabler_desc_match_event(struct lttng_event_enabler_common *eve
        }
 }
 
+bool lttng_event_enabler_event_name_match_event(struct lttng_event_enabler_common *event_enabler,
+               const char *event_name,
+               struct lttng_kernel_event_common *event)
+{
+       if (event_enabler->event_param.instrumentation != event->priv->instrumentation)
+               return false;
+
+       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 =
+                       container_of(event, struct lttng_kernel_event_recorder, parent);
+
+               if (!strncmp(event->priv->desc->event_name, event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1)
+                               && event_recorder->chan == event_recorder_enabler->chan)
+                       return true;
+               else
+                       return false;
+       }
+       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 =
+                       container_of(event, struct lttng_kernel_event_notifier, parent);
+
+               if (!strncmp(event->priv->desc->event_name, event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1)
+                               && event_notifier->priv->group == event_notifier_enabler->group
+                               && event->priv->user_token == event_enabler->user_token)
+                       return true;
+               else
+                       return false;
+       }
+       default:
+               WARN_ON_ONCE(1);
+               return false;
+       }
+}
+
 static
 struct lttng_enabler_ref *lttng_enabler_ref(
                struct list_head *enablers_ref_list,
This page took 0.029337 seconds and 4 git commands to generate.