+ while ((ret = ustctl_tracepoint_list_get(app->key.sock, handle,
+ &uiter)) != -ENOENT) {
+ if (count >= nbmem) {
+ DBG2("Reallocating event list from %zu to %zu entries", nbmem,
+ 2 * nbmem);
+ nbmem *= 2;
+ tmp = realloc(tmp, nbmem * sizeof(struct lttng_event));
+ if (tmp == NULL) {
+ PERROR("realloc ust app events");
+ ret = -ENOMEM;
+ goto rcu_error;
+ }
+ }
+ memcpy(tmp[count].name, uiter.name, LTTNG_UST_SYM_NAME_LEN);
+ memcpy(tmp[count].loglevel, uiter.loglevel, LTTNG_UST_SYM_NAME_LEN);
+ tmp[count].loglevel_value = uiter.loglevel_value;
+ tmp[count].type = LTTNG_UST_TRACEPOINT;
+ tmp[count].pid = app->key.pid;
+ tmp[count].enabled = -1;
+ count++;
+ }
+ }
+
+ ret = count;
+ *events = tmp;
+
+ DBG2("UST app list events done (%zu events)", count);
+
+rcu_error:
+ rcu_read_unlock();
+error:
+ return ret;
+}
+
+/*
+ * Free and clean all traceable apps of the global list.
+ */
+void ust_app_clean_list(void)
+{
+ int ret;
+ struct lttng_ht_iter iter;
+ struct lttng_ht_node_ulong *node;
+
+ DBG2("UST app cleaning registered apps hash table");
+
+ rcu_read_lock();
+
+ cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, node, node) {
+ ret = lttng_ht_del(ust_app_ht, &iter);
+ assert(!ret);
+ call_rcu(&node->head, delete_ust_app_rcu);
+ }
+ /* Destroy is done only when the ht is empty */
+ lttng_ht_destroy(ust_app_ht);
+
+ cds_lfht_for_each_entry(ust_app_sock_key_map->ht, &iter.iter, node, node) {
+ ret = lttng_ht_del(ust_app_sock_key_map, &iter);
+ assert(!ret);
+ }
+ /* Destroy is done only when the ht is empty */
+ lttng_ht_destroy(ust_app_sock_key_map);
+
+ rcu_read_unlock();
+}
+
+/*
+ * Init UST app hash table.
+ */
+void ust_app_ht_alloc(void)
+{
+ ust_app_ht = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+ ust_app_sock_key_map = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+}
+
+/*
+ * For a specific UST session, disable the channel for all registered apps.
+ */
+int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan)
+{
+ int ret = 0;
+ struct lttng_ht_iter iter;
+ struct lttng_ht_node_str *ua_chan_node;
+ struct ust_app *app;
+ struct ust_app_session *ua_sess;
+ struct ust_app_channel *ua_chan;
+
+ if (usess == NULL || uchan == NULL) {
+ ERR("Disabling UST global channel with NULL values");
+ ret = -1;
+ goto error;
+ }
+
+ DBG2("UST app disabling channel %s from global domain for session id %d",
+ uchan->name, usess->id);
+
+ rcu_read_lock();
+
+ /* For every registered applications */
+ cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+ struct lttng_ht_iter uiter;
+ ua_sess = lookup_session_by_app(usess, app);
+ if (ua_sess == NULL) {
+ continue;
+ }
+
+ /* Get channel */
+ lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter);
+ ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+ /* If the session if found for the app, the channel must be there */
+ assert(ua_chan_node);
+
+ ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ /* The channel must not be already disabled */
+ assert(ua_chan->enabled == 1);
+
+ /* Disable channel onto application */
+ ret = disable_ust_app_channel(ua_sess, ua_chan, app);
+ if (ret < 0) {
+ /* XXX: We might want to report this error at some point... */
+ continue;
+ }
+ }
+
+ rcu_read_unlock();
+
+error:
+ return ret;
+}
+
+/*
+ * For a specific UST session, enable the channel for all registered apps.
+ */
+int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan)
+{
+ int ret = 0;
+ struct lttng_ht_iter iter;
+ struct ust_app *app;
+ struct ust_app_session *ua_sess;
+
+ if (usess == NULL || uchan == NULL) {
+ ERR("Adding UST global channel to NULL values");
+ ret = -1;
+ goto error;
+ }
+
+ DBG2("UST app enabling channel %s to global domain for session id %d",
+ uchan->name, usess->id);
+
+ rcu_read_lock();
+
+ /* For every registered applications */
+ cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+ ua_sess = lookup_session_by_app(usess, app);
+ if (ua_sess == NULL) {
+ continue;
+ }
+
+ /* Enable channel onto application */
+ ret = enable_ust_app_channel(ua_sess, uchan, app);
+ if (ret < 0) {
+ /* XXX: We might want to report this error at some point... */
+ continue;
+ }
+ }
+
+ rcu_read_unlock();
+
+error:
+ return ret;
+}
+
+/*
+ * Disable an event in a channel and for a specific session.
+ */
+int ust_app_disable_event_glb(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
+{
+ int ret = 0;
+ struct lttng_ht_iter iter, uiter;
+ struct lttng_ht_node_str *ua_chan_node, *ua_event_node;
+ struct ust_app *app;
+ struct ust_app_session *ua_sess;
+ struct ust_app_channel *ua_chan;
+ struct ust_app_event *ua_event;
+
+ DBG("UST app disabling event %s for all apps in channel "
+ "%s for session id %d", uevent->attr.name, uchan->name, usess->id);
+
+ rcu_read_lock();
+
+ /* For all registered applications */
+ cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+ ua_sess = lookup_session_by_app(usess, app);
+ if (ua_sess == NULL) {
+ /* Next app */
+ continue;
+ }
+
+ /* Lookup channel in the ust app session */
+ lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter);
+ ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+ if (ua_chan_node == NULL) {
+ DBG2("Channel %s not found in session id %d for app pid %d."
+ "Skipping", uchan->name, usess->id, app->key.pid);
+ continue;
+ }
+ ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+
+ lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &uiter);
+ ua_event_node = lttng_ht_iter_get_node_str(&uiter);
+ if (ua_event_node == NULL) {
+ DBG2("Event %s not found in channel %s for app pid %d."
+ "Skipping", uevent->attr.name, uchan->name, app->key.pid);
+ continue;
+ }
+ ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);