Fix: index JUL event by name *and* loglevel
[lttng-tools.git] / src / bin / lttng-sessiond / jul.c
index 40730bb4fdf188cbc97f8daabd5c6b5025f2dfd4..7bb0d75bce80afe3265c4306033b4ea0cff3e47c 100644 (file)
 #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.
  */
@@ -668,38 +753,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_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);
+
+       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 event found %s by name.", name);
+       return caa_container_of(node, struct jul_event, node);
+
+error:
+       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_by_name(const char *name, struct jul_domain *dom)
+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);
 
-       lttng_ht_lookup(dom->events, (void *)name, &iter);
+       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 found by name %s in domain.", name);
+       DBG3("JUL event found %s.", 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 %s.", name);
        return NULL;
 }
 
This page took 0.027334 seconds and 5 git commands to generate.