+int ust_registry_channel_add(struct ust_registry_session *session,
+ uint64_t key)
+{
+ int ret = 0;
+ struct ust_registry_channel *chan;
+
+ assert(session);
+
+ chan = zmalloc(sizeof(*chan));
+ if (!chan) {
+ PERROR("zmalloc ust registry channel");
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ chan->ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
+ if (!chan->ht) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ /* Set custom match function. */
+ chan->ht->match_fct = ht_match_event;
+
+ rcu_read_lock();
+ lttng_ht_node_init_u64(&chan->node, key);
+ lttng_ht_add_unique_u64(session->channels, &chan->node);
+ rcu_read_unlock();
+
+error:
+ return ret;
+}
+
+/*
+ * Find a channel in the given registry. RCU read side lock MUST be acquired
+ * before calling this function and as long as the event reference is kept by
+ * the caller.
+ *
+ * On success, the pointer is returned else NULL.
+ */
+struct ust_registry_channel *ust_registry_channel_find(
+ struct ust_registry_session *session, uint64_t key)
+{
+ struct lttng_ht_node_u64 *node;
+ struct lttng_ht_iter iter;
+ struct ust_registry_channel *chan = NULL;
+
+ assert(session);
+ assert(session->channels);
+
+ lttng_ht_lookup(session->channels, &key, &iter);
+ node = lttng_ht_iter_get_node_u64(&iter);
+ if (!node) {
+ goto end;
+ }
+ chan = caa_container_of(node, struct ust_registry_channel, node);
+
+end:
+ return chan;
+}
+
+/*
+ * Remove channel using key from registry and free memory.
+ */
+void ust_registry_channel_del_free(struct ust_registry_session *session,
+ uint64_t key)
+{
+ struct lttng_ht_iter iter;
+ struct ust_registry_channel *chan;
+
+ assert(session);
+
+ rcu_read_lock();
+ chan = ust_registry_channel_find(session, key);
+ if (!chan) {
+ goto end;
+ }
+
+ iter.iter.node = &chan->node.node;
+ lttng_ht_del(session->channels, &iter);
+
+ destroy_channel(chan);
+
+end:
+ rcu_read_unlock();
+ return;
+}
+
+/*
+ * Initialize registry with default values and set the newly allocated session
+ * pointer to sessionp.
+ *
+ * Return 0 on success and sessionp is set or else return -1 and sessionp is
+ * kept untouched.
+ */
+int ust_registry_session_init(struct ust_registry_session **sessionp,