From: Mathieu Desnoyers Date: Mon, 8 Nov 2021 16:56:13 +0000 (-0500) Subject: Refactoring: move duplicate check into lttng_event_notifier_create X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0effa6c84f3b8d4f18d8ba4d373bf9214638ba5a;p=lttng-ust.git Refactoring: move duplicate check into lttng_event_notifier_create Signed-off-by: Mathieu Desnoyers Change-Id: I4af04b27d8d548b1128b2c47f7e5d39a3c86cfb1 --- diff --git a/src/lib/lttng-ust/lttng-events.c b/src/lib/lttng-ust/lttng-events.c index 4124def9..628313e7 100644 --- a/src/lib/lttng-ust/lttng-events.c +++ b/src/lib/lttng-ust/lttng-events.c @@ -1035,7 +1035,9 @@ int lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_notif struct lttng_ust_event_notifier_private *event_notifier_priv; char name[LTTNG_UST_ABI_SYM_NAME_LEN]; struct cds_hlist_head *head; + struct cds_hlist_node *node; int ret = 0; + bool found = false; /* * Get the hashtable bucket the created lttng_event_notifier object @@ -1046,6 +1048,21 @@ int lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_notif event_notifier_group->event_notifiers_ht.table, LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, name); + cds_hlist_for_each_entry(event_notifier_priv, node, head, hlist) { + /* + * Check if event_notifier already exists by checking + * if the event_notifier and enabler share the same + * description and id. + */ + if (event_notifier_priv->parent.desc == desc && + event_notifier_priv->parent.user_token == event_notifier_enabler->parent.user_token) { + found = true; + break; + } + } + if (found) + return -EEXIST; + event_notifier = zmalloc(sizeof(struct lttng_ust_event_notifier)); if (!event_notifier) { ret = -ENOMEM; @@ -2058,7 +2075,6 @@ static void lttng_create_event_notifier_if_missing( struct lttng_event_notifier_enabler *event_notifier_enabler) { - struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group; struct lttng_ust_registered_probe *reg_probe; struct cds_list_head *probe_list; int i; @@ -2070,12 +2086,7 @@ void lttng_create_event_notifier_if_missing( for (i = 0; i < probe_desc->nr_events; i++) { int ret; - bool found = false; const struct lttng_ust_event_desc *desc; - char name[LTTNG_UST_ABI_SYM_NAME_LEN]; - struct lttng_ust_event_notifier_private *event_notifier_priv; - struct cds_hlist_head *head; - struct cds_hlist_node *node; desc = probe_desc->event_desc[i]; @@ -2083,38 +2094,15 @@ void lttng_create_event_notifier_if_missing( lttng_event_notifier_enabler_as_enabler(event_notifier_enabler))) continue; - /* - * Given the current event_notifier group, get the bucket that - * the target event_notifier would be if it was already - * created. - */ - lttng_ust_format_event_name(desc, name); - head = borrow_hash_table_bucket( - event_notifier_group->event_notifiers_ht.table, - LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, name); - - cds_hlist_for_each_entry(event_notifier_priv, node, head, hlist) { - /* - * Check if event_notifier already exists by checking - * if the event_notifier and enabler share the same - * description and id. - */ - if (event_notifier_priv->parent.desc == desc && - event_notifier_priv->parent.user_token == event_notifier_enabler->parent.user_token) { - found = true; - break; - } - } - - if (found) - continue; - /* * We need to create a event_notifier for this event probe. */ ret = lttng_ust_event_create(&event_notifier_enabler->parent, desc); + /* Skip if already found. */ + if (ret == -EEXIST) + continue; if (ret) { - DBG("Unable to create event_notifier \"%s:%s\", error %d\n", + DBG("Unable to create event \"%s:%s\", error %d\n", probe_desc->provider_name, probe_desc->event_desc[i]->event_name, ret); }