#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.
*/
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;
}
*/
struct lttng_ht *jul_apps_ht_by_sock;
+struct jul_ht_key {
+ const char *name;
+ enum lttng_loglevel_jul loglevel;
+};
+
/*
* Registration message payload from a JUL application. The PID is used to find
* back the corresponding UST app object so both socket can be linked.
/* JUL event API. */
struct jul_event *jul_create_event(const char *name);
void jul_add_event(struct jul_event *event, struct jul_domain *dom);
-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 jul_event *jul_find_event_by_name(const char *name,
+ struct jul_domain *dom);
void jul_delete_event(struct jul_event *event, struct jul_domain *dom);
void jul_destroy_event(struct jul_event *event);