X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fjul.c;h=bf4669b239053f470807fb7110d8a5a230b6efd7;hp=40730bb4fdf188cbc97f8daabd5c6b5025f2dfd4;hb=29c0fd4d0c4f04d981df9df83d109440598b7930;hpb=1b500e7ab6676535ce092106bf4f97929fc2dd54 diff --git a/src/bin/lttng-sessiond/jul.c b/src/bin/lttng-sessiond/jul.c index 40730bb4f..bf4669b23 100644 --- a/src/bin/lttng-sessiond/jul.c +++ b/src/bin/lttng-sessiond/jul.c @@ -22,10 +22,97 @@ #include #include +#include + #include "jul.h" #include "ust-app.h" #include "utils.h" +/* + * Match function for the events hash table lookup by name. + */ +static int ht_match_event_by_name(struct cds_lfht_node *node, + const void *_key) +{ + struct jul_event *event; + const struct jul_ht_key *key; + + assert(node); + assert(_key); + + event = caa_container_of(node, struct jul_event, node.node); + key = _key; + + /* Match 1 elements of the key: name. */ + + /* Event name */ + if (strncmp(event->name, key->name, sizeof(event->name)) != 0) { + goto no_match; + } + /* Match. */ + return 1; + +no_match: + return 0; +} + +/* + * Match function for the events hash table lookup by name and loglevel. + */ +static int ht_match_event(struct cds_lfht_node *node, + const void *_key) +{ + struct jul_event *event; + const struct jul_ht_key *key; + + assert(node); + assert(_key); + + event = caa_container_of(node, struct jul_event, node.node); + key = _key; + + /* Match 2 elements of the key: name and loglevel. */ + + /* Event name */ + if (strncmp(event->name, key->name, sizeof(event->name)) != 0) { + goto no_match; + } + + if (event->loglevel != key->loglevel) { + if (event->loglevel_type == LTTNG_EVENT_LOGLEVEL_ALL && + key->loglevel == 0 && event->loglevel == -1) { + goto match; + } + goto no_match; + } +match: + return 1; + +no_match: + return 0; +} + +/* + * Add unique JUL event based on the event name and loglevel. + */ +static void add_unique_jul_event(struct lttng_ht *ht, struct jul_event *event) +{ + struct cds_lfht_node *node_ptr; + struct jul_ht_key key; + + assert(ht); + assert(ht->ht); + assert(event); + + key.name = event->name; + key.loglevel = event->loglevel; + + node_ptr = cds_lfht_add_unique(ht->ht, + ht->hash_fct(event->node.key, lttng_ht_seed), + ht_match_event, &key, &event->node.node); + assert(node_ptr == &event->node.node); +} + /* * URCU delayed JUL event reclaim. */ @@ -635,7 +722,8 @@ error: * * Return a new object else NULL on error. */ -struct jul_event *jul_create_event(const char *name) +struct jul_event *jul_create_event(const char *name, + struct lttng_filter_bytecode *filter) { struct jul_event *event; @@ -652,6 +740,10 @@ struct jul_event *jul_create_event(const char *name) lttng_ht_node_init_str(&event->node, event->name); } + if (filter) { + event->filter = filter; + } + error: return event; } @@ -668,38 +760,83 @@ void jul_add_event(struct jul_event *event, struct jul_domain *dom) DBG3("JUL adding event %s to domain", event->name); rcu_read_lock(); - lttng_ht_add_unique_str(dom->events, &event->node); + add_unique_jul_event(dom->events, event); rcu_read_unlock(); dom->being_used = 1; } /* - * Find a JUL event in the given domain using name. + * Find a JUL event in the given domain using name and loglevel. * * RCU read side lock MUST be acquired. * * Return object if found else NULL. */ -struct jul_event *jul_find_by_name(const char *name, struct jul_domain *dom) +struct jul_event *jul_find_event_by_name(const char *name, + struct jul_domain *dom) { struct lttng_ht_node_str *node; struct lttng_ht_iter iter; + struct lttng_ht *ht; + struct jul_ht_key key; assert(name); assert(dom); assert(dom->events); - lttng_ht_lookup(dom->events, (void *)name, &iter); + ht = dom->events; + key.name = name; + + cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed), + ht_match_event_by_name, &key, &iter.iter); node = lttng_ht_iter_get_node_str(&iter); if (node == NULL) { goto error; } - DBG3("JUL found by name %s in domain.", name); + DBG3("JUL event found %s by name.", name); return caa_container_of(node, struct jul_event, node); error: - DBG3("JUL NOT found by name %s in domain.", name); + DBG3("JUL NOT found by name %s.", name); + return NULL; +} + +/* + * Find a JUL event in the given domain using name and loglevel. + * + * RCU read side lock MUST be acquired. + * + * Return object if found else NULL. + */ +struct jul_event *jul_find_event(const char *name, + enum lttng_loglevel_jul loglevel, struct jul_domain *dom) +{ + struct lttng_ht_node_str *node; + struct lttng_ht_iter iter; + struct lttng_ht *ht; + struct jul_ht_key key; + + assert(name); + assert(dom); + assert(dom->events); + + ht = dom->events; + key.name = name; + key.loglevel = loglevel; + + cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed), + ht_match_event, &key, &iter.iter); + node = lttng_ht_iter_get_node_str(&iter); + if (node == NULL) { + goto error; + } + + DBG3("JUL event found %s.", name); + return caa_container_of(node, struct jul_event, node); + +error: + DBG3("JUL NOT found %s.", name); return NULL; } @@ -739,6 +876,15 @@ void jul_destroy_domain(struct jul_domain *dom) rcu_read_lock(); cds_lfht_for_each_entry(dom->events->ht, &iter.iter, node, node) { int ret; + struct jul_event *event; + + /* + * When destroying an event, we have to try to disable it on the agent + * side so the event stops generating data. The return value is not + * important since we have to continue anyway destroying the object. + */ + event = caa_container_of(node, struct jul_event, node); + (void) jul_disable_event(event); ret = lttng_ht_del(dom->events, &iter); assert(!ret);