Fix: sessiond: lttng_channel object is not reclaimed
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.cpp
index f12262101819d08b9c5d365ee1290de3bcac373b..62d323ee95619263864553464bb5bb4fa643def3 100644 (file)
@@ -287,6 +287,7 @@ void delete_ust_app_ctx(int sock, struct ust_app_ctx *ua_ctx,
        int ret;
 
        LTTNG_ASSERT(ua_ctx);
+       ASSERT_RCU_READ_LOCKED();
 
        if (ua_ctx->obj) {
                pthread_mutex_lock(&app->sock_lock);
@@ -321,6 +322,7 @@ void delete_ust_app_event(int sock, struct ust_app_event *ua_event,
        int ret;
 
        LTTNG_ASSERT(ua_event);
+       ASSERT_RCU_READ_LOCKED();
 
        free(ua_event->filter);
        if (ua_event->exclusion != NULL)
@@ -443,25 +445,20 @@ void delete_ust_app_stream(int sock, struct ust_app_stream *stream,
                struct ust_app *app)
 {
        LTTNG_ASSERT(stream);
+       ASSERT_RCU_READ_LOCKED();
 
        (void) release_ust_app_stream(sock, stream, app);
        free(stream);
 }
 
-/*
- * We need to execute ht_destroy outside of RCU read-side critical
- * section and outside of call_rcu thread, so we postpone its execution
- * using ht_cleanup_push. It is simpler than to change the semantic of
- * the many callers of delete_ust_app_session().
- */
 static
 void delete_ust_app_channel_rcu(struct rcu_head *head)
 {
        struct ust_app_channel *ua_chan =
                caa_container_of(head, struct ust_app_channel, rcu_head);
 
-       ht_cleanup_push(ua_chan->ctx);
-       ht_cleanup_push(ua_chan->events);
+       lttng_ht_destroy(ua_chan->ctx);
+       lttng_ht_destroy(ua_chan->events);
        free(ua_chan);
 }
 
@@ -549,6 +546,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan,
        struct ust_registry_session *registry;
 
        LTTNG_ASSERT(ua_chan);
+       ASSERT_RCU_READ_LOCKED();
 
        DBG3("UST app deleting channel %s", ua_chan->name);
 
@@ -670,6 +668,7 @@ ssize_t ust_app_push_metadata(struct ust_registry_session *registry,
 
        LTTNG_ASSERT(registry);
        LTTNG_ASSERT(socket);
+       ASSERT_RCU_READ_LOCKED();
 
        metadata_key = registry->metadata_key;
 
@@ -806,6 +805,7 @@ static int push_metadata(struct ust_registry_session *registry,
 
        LTTNG_ASSERT(registry);
        LTTNG_ASSERT(consumer);
+       ASSERT_RCU_READ_LOCKED();
 
        pthread_mutex_lock(&registry->lock);
        if (registry->metadata_closed) {
@@ -895,19 +895,13 @@ end:
        return ret;
 }
 
-/*
- * We need to execute ht_destroy outside of RCU read-side critical
- * section and outside of call_rcu thread, so we postpone its execution
- * using ht_cleanup_push. It is simpler than to change the semantic of
- * the many callers of delete_ust_app_session().
- */
 static
 void delete_ust_app_session_rcu(struct rcu_head *head)
 {
        struct ust_app_session *ua_sess =
                caa_container_of(head, struct ust_app_session, rcu_head);
 
-       ht_cleanup_push(ua_sess->channels);
+       lttng_ht_destroy(ua_sess->channels);
        free(ua_sess);
 }
 
@@ -927,6 +921,7 @@ void delete_ust_app_session(int sock, struct ust_app_session *ua_sess,
        struct ust_registry_session *registry;
 
        LTTNG_ASSERT(ua_sess);
+       ASSERT_RCU_READ_LOCKED();
 
        pthread_mutex_lock(&ua_sess->lock);
 
@@ -1004,8 +999,6 @@ void delete_ust_app_session(int sock, struct ust_app_session *ua_sess,
 /*
  * Delete a traceable application structure from the global list. Never call
  * this function outside of a call_rcu call.
- *
- * RCU read side lock should _NOT_ be held when calling this function.
  */
 static
 void delete_ust_app(struct ust_app *app)
@@ -1047,10 +1040,10 @@ void delete_ust_app(struct ust_app *app)
 
        rcu_read_unlock();
 
-       ht_cleanup_push(app->sessions);
-       ht_cleanup_push(app->ust_sessions_objd);
-       ht_cleanup_push(app->ust_objd);
-       ht_cleanup_push(app->token_to_event_notifier_rule_ht);
+       lttng_ht_destroy(app->sessions);
+       lttng_ht_destroy(app->ust_sessions_objd);
+       lttng_ht_destroy(app->ust_objd);
+       lttng_ht_destroy(app->token_to_event_notifier_rule_ht);
 
        /*
         * This could be NULL if the event notifier setup failed (e.g the app
@@ -1456,6 +1449,8 @@ struct ust_app *ust_app_find_by_sock(int sock)
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
 
+       ASSERT_RCU_READ_LOCKED();
+
        lttng_ht_lookup(ust_app_ht_by_sock, (void *)((unsigned long) sock), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node == NULL) {
@@ -1478,6 +1473,8 @@ static struct ust_app *find_app_by_notify_sock(int sock)
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
 
+       ASSERT_RCU_READ_LOCKED();
+
        lttng_ht_lookup(ust_app_ht_by_notify_sock, (void *)((unsigned long) sock),
                        &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
@@ -1546,6 +1543,7 @@ static struct ust_app_event_notifier_rule *find_ust_app_event_notifier_rule(
        struct ust_app_event_notifier_rule *event_notifier_rule = NULL;
 
        LTTNG_ASSERT(ht);
+       ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(ht, &token, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
@@ -2823,6 +2821,7 @@ struct ust_app_ctx *find_ust_app_context(struct lttng_ht *ht,
 
        LTTNG_ASSERT(uctx);
        LTTNG_ASSERT(ht);
+       ASSERT_RCU_READ_LOCKED();
 
        /* Lookup using the lttng_ust_context_type and a custom match fct. */
        cds_lfht_lookup(ht->ht, ht->hash_fct((void *) uctx->ctx, lttng_ht_seed),
@@ -2851,6 +2850,8 @@ int create_ust_app_channel_context(struct ust_app_channel *ua_chan,
        int ret = 0;
        struct ust_app_ctx *ua_ctx;
 
+       ASSERT_RCU_READ_LOCKED();
+
        DBG2("UST app adding context to channel %s", ua_chan->name);
 
        ua_ctx = find_ust_app_context(ua_chan->ctx, uctx);
@@ -2952,6 +2953,8 @@ static int enable_ust_app_channel(struct ust_app_session *ua_sess,
        struct lttng_ht_node_str *ua_chan_node;
        struct ust_app_channel *ua_chan;
 
+       ASSERT_RCU_READ_LOCKED();
+
        lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter);
        ua_chan_node = lttng_ht_iter_get_node_str(&iter);
        if (ua_chan_node == NULL) {
@@ -3381,6 +3384,7 @@ static int create_channel_per_uid(struct ust_app *app,
        LTTNG_ASSERT(usess);
        LTTNG_ASSERT(ua_sess);
        LTTNG_ASSERT(ua_chan);
+       ASSERT_RCU_READ_LOCKED();
 
        DBG("UST app creating channel %s with per UID buffers", ua_chan->name);
 
@@ -3601,6 +3605,7 @@ static int ust_app_channel_send(struct ust_app *app,
        LTTNG_ASSERT(usess->active);
        LTTNG_ASSERT(ua_sess);
        LTTNG_ASSERT(ua_chan);
+       ASSERT_RCU_READ_LOCKED();
 
        /* Handle buffer type before sending the channel to the application. */
        switch (usess->buffer_type) {
@@ -3659,6 +3664,8 @@ static int ust_app_channel_allocate(struct ust_app_session *ua_sess,
        struct lttng_ht_node_str *ua_chan_node;
        struct ust_app_channel *ua_chan;
 
+       ASSERT_RCU_READ_LOCKED();
+
        /* Lookup channel in the ust app session */
        lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter);
        ua_chan_node = lttng_ht_iter_get_node_str(&iter);
@@ -3706,6 +3713,8 @@ int create_ust_app_event(struct ust_app_session *ua_sess,
        int ret = 0;
        struct ust_app_event *ua_event;
 
+       ASSERT_RCU_READ_LOCKED();
+
        ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr);
        if (ua_event == NULL) {
                /* Only failure mode of alloc_ust_app_event(). */
@@ -3760,6 +3769,8 @@ int create_ust_app_event_notifier_rule(struct lttng_trigger *trigger,
        int ret = 0;
        struct ust_app_event_notifier_rule *ua_event_notifier_rule;
 
+       ASSERT_RCU_READ_LOCKED();
+
        ua_event_notifier_rule = alloc_ust_app_event_notifier_rule(trigger);
        if (ua_event_notifier_rule == NULL) {
                ret = -ENOMEM;
@@ -3817,6 +3828,7 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess,
        LTTNG_ASSERT(ua_sess);
        LTTNG_ASSERT(app);
        LTTNG_ASSERT(consumer);
+       ASSERT_RCU_READ_LOCKED();
 
        registry = get_session_registry(ua_sess);
        /* The UST app session is held registry shall not be null. */
@@ -4618,8 +4630,6 @@ error:
 
 /*
  * Free and clean all traceable apps of the global list.
- *
- * Should _NOT_ be called with RCU read-side lock held.
  */
 void ust_app_clean_list(void)
 {
@@ -4666,13 +4676,13 @@ void ust_app_clean_list(void)
 
        /* Destroy is done only when the ht is empty */
        if (ust_app_ht) {
-               ht_cleanup_push(ust_app_ht);
+               lttng_ht_destroy(ust_app_ht);
        }
        if (ust_app_ht_by_sock) {
-               ht_cleanup_push(ust_app_ht_by_sock);
+               lttng_ht_destroy(ust_app_ht_by_sock);
        }
        if (ust_app_ht_by_notify_sock) {
-               ht_cleanup_push(ust_app_ht_by_notify_sock);
+               lttng_ht_destroy(ust_app_ht_by_notify_sock);
        }
 }
 
@@ -5806,6 +5816,8 @@ void ust_app_synchronize_event_notifier_rules(struct ust_app *app)
        struct ust_app_event_notifier_rule *event_notifier_rule;
        unsigned int count, i;
 
+       ASSERT_RCU_READ_LOCKED();
+
        if (!ust_app_supports_notifiers(app)) {
                goto end;
        }
@@ -5957,6 +5969,7 @@ void ust_app_synchronize_all_channels(struct ltt_ust_session *usess,
        LTTNG_ASSERT(usess);
        LTTNG_ASSERT(ua_sess);
        LTTNG_ASSERT(app);
+       ASSERT_RCU_READ_LOCKED();
 
        cds_lfht_for_each_entry(usess->domain_global.channels->ht, &uchan_iter,
                        uchan, node.node) {
@@ -6086,6 +6099,7 @@ void ust_app_global_update(struct ltt_ust_session *usess, struct ust_app *app)
 {
        LTTNG_ASSERT(usess);
        LTTNG_ASSERT(usess->active);
+       ASSERT_RCU_READ_LOCKED();
 
        DBG2("UST app global update for app sock %d for session id %" PRIu64,
                        app->sock, usess->id);
@@ -6120,6 +6134,8 @@ void ust_app_global_update(struct ltt_ust_session *usess, struct ust_app *app)
  */
 void ust_app_global_update_event_notifier_rules(struct ust_app *app)
 {
+       ASSERT_RCU_READ_LOCKED();
+
        DBG2("UST application global event notifier rules update: app = '%s', pid = %d",
                        app->name, app->pid);
 
@@ -6282,6 +6298,7 @@ static struct ust_app_session *find_session_by_objd(struct ust_app *app,
        struct ust_app_session *ua_sess = NULL;
 
        LTTNG_ASSERT(app);
+       ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(app->ust_sessions_objd, (void *)((unsigned long) objd), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
@@ -6309,6 +6326,7 @@ static struct ust_app_channel *find_channel_by_objd(struct ust_app *app,
        struct ust_app_channel *ua_chan = NULL;
 
        LTTNG_ASSERT(app);
+       ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(app->ust_objd, (void *)((unsigned long) objd), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
This page took 0.027487 seconds and 4 git commands to generate.