Fix RCU-related hangs: incorrect lttng_ht_destroy use
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.c
index 6c483e4b71c3107b614cc6201a53719d88307fd9..7250dd12d751b0edcce93ffd4b886f8bdd7c7395 100644 (file)
@@ -308,12 +308,26 @@ void ust_registry_destroy_event(struct ust_registry_channel *chan,
        return;
 }
 
+/*
+ * We need to execute ht_destroy outside of RCU read-side critical
+ * section, so we postpone its execution using call_rcu. It is simpler
+ * than to change the semantic of the many callers of
+ * destroy_channel().
+ */
+static
+void destroy_channel_rcu(struct rcu_head *head)
+{
+       struct ust_registry_channel *chan =
+               caa_container_of(head, struct ust_registry_channel, rcu_head);
+
+       lttng_ht_destroy(chan->ht);
+       free(chan);
+}
+
 /*
  * Destroy every element of the registry and free the memory. This does NOT
  * free the registry pointer since it might not have been allocated before so
  * it's the caller responsability.
- *
- * This MUST be called within a RCU read side lock section.
  */
 static void destroy_channel(struct ust_registry_channel *chan)
 {
@@ -322,14 +336,14 @@ static void destroy_channel(struct ust_registry_channel *chan)
 
        assert(chan);
 
+       rcu_read_lock();
        /* Destroy all event associated with this registry. */
        cds_lfht_for_each_entry(chan->ht->ht, &iter.iter, event, node.node) {
                /* Delete the node from the ht and free it. */
                ust_registry_destroy_event(chan, event);
        }
-       lttng_ht_destroy(chan->ht);
-
-       free(chan);
+       rcu_read_unlock();
+       call_rcu(&chan->rcu_head, destroy_channel_rcu);
 }
 
 /*
@@ -418,22 +432,24 @@ void ust_registry_channel_del_free(struct ust_registry_session *session,
 {
        struct lttng_ht_iter iter;
        struct ust_registry_channel *chan;
+       int ret;
 
        assert(session);
 
        rcu_read_lock();
        chan = ust_registry_channel_find(session, key);
        if (!chan) {
+               rcu_read_unlock();
                goto end;
        }
 
        iter.iter.node = &chan->node.node;
-       lttng_ht_del(session->channels, &iter);
-
+       ret = lttng_ht_del(session->channels, &iter);
+       assert(!ret);
+       rcu_read_unlock();
        destroy_channel(chan);
 
 end:
-       rcu_read_unlock();
        return;
 }
 
@@ -525,8 +541,8 @@ void ust_registry_session_destroy(struct ust_registry_session *reg)
                assert(!ret);
                destroy_channel(chan);
        }
-       lttng_ht_destroy(reg->channels);
        rcu_read_unlock();
 
+       lttng_ht_destroy(reg->channels);
        free(reg->metadata);
 }
This page took 0.023301 seconds and 4 git commands to generate.