Replace libuuid with internal implementation
[lttng-tools.git] / src / bin / lttng-relayd / sessiond-trace-chunks.c
index 31fbb31891dffc03c611bca7489fbb332bcbe281..db9f558012a515d580da0af018be39e24f8c22c1 100644 (file)
@@ -112,7 +112,6 @@ void trace_chunk_registry_ht_element_free(struct rcu_head *node)
        struct trace_chunk_registry_ht_element *element =
                        container_of(node, typeof(*element), rcu_node);
 
-       lttng_trace_chunk_registry_destroy(element->trace_chunk_registry);
        free(element);
 }
 
@@ -121,7 +120,7 @@ void trace_chunk_registry_ht_element_release(struct urcu_ref *ref)
 {
        struct trace_chunk_registry_ht_element *element =
                        container_of(ref, typeof(*element), ref);
-       char uuid_str[UUID_STR_LEN];
+       char uuid_str[LTTNG_UUID_STR_LEN];
 
        lttng_uuid_to_str(element->key.sessiond_uuid, uuid_str);
 
@@ -136,6 +135,7 @@ void trace_chunk_registry_ht_element_release(struct urcu_ref *ref)
                element->sessiond_trace_chunk_registry = NULL;
        }
 
+       lttng_trace_chunk_registry_destroy(element->trace_chunk_registry);
        /* Defered reclaim of the object */
        call_rcu(&element->rcu_node, trace_chunk_registry_ht_element_free);
 }
@@ -151,6 +151,10 @@ static
 void trace_chunk_registry_ht_element_put(
                struct trace_chunk_registry_ht_element *element)
 {
+       if (!element) {
+               return;
+       }
+
        urcu_ref_put(&element->ref, trace_chunk_registry_ht_element_release);
 }
 
@@ -193,7 +197,7 @@ int trace_chunk_registry_ht_element_create(
        int ret = 0;
        struct trace_chunk_registry_ht_element *new_element;
        struct lttng_trace_chunk_registry *trace_chunk_registry;
-       char uuid_str[UUID_STR_LEN];
+       char uuid_str[LTTNG_UUID_STR_LEN];
 
        lttng_uuid_to_str(key->sessiond_uuid, uuid_str);
 
@@ -213,6 +217,7 @@ int trace_chunk_registry_ht_element_create(
        urcu_ref_init(&new_element->ref);
        cds_lfht_node_init(&new_element->ht_node);
        new_element->trace_chunk_registry = trace_chunk_registry;
+       trace_chunk_registry = NULL;
 
        /* Attempt to publish the new element. */
        rcu_read_lock();
@@ -261,6 +266,7 @@ end:
                ERR("Failed to create trace chunk registry for session daemon {%s}",
                                uuid_str);
        }
+       lttng_trace_chunk_registry_destroy(trace_chunk_registry);
        return ret;
 }
 
@@ -307,7 +313,7 @@ int sessiond_trace_chunk_registry_session_created(
 
        element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
        if (element) {
-               char uuid_str[UUID_STR_LEN];
+               char uuid_str[LTTNG_UUID_STR_LEN];
 
                lttng_uuid_to_str(sessiond_uuid, uuid_str);
                DBG("Acquired reference to trace chunk registry of sessiond {%s}",
@@ -328,7 +334,7 @@ int sessiond_trace_chunk_registry_session_destroyed(
        int ret = 0;
        struct trace_chunk_registry_ht_key key;
        struct trace_chunk_registry_ht_element *element;
-       char uuid_str[UUID_STR_LEN];
+       char uuid_str[LTTNG_UUID_STR_LEN];
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
        lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
@@ -361,7 +367,7 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
        bool is_anonymous_chunk;
        struct trace_chunk_registry_ht_key key;
        struct trace_chunk_registry_ht_element *element = NULL;
-       char uuid_str[UUID_STR_LEN];
+       char uuid_str[LTTNG_UUID_STR_LEN];
        char chunk_id_str[MAX_INT_DEC_LEN(typeof(chunk_id))] = "-1";
        struct lttng_trace_chunk *published_chunk = NULL;
 
@@ -399,6 +405,19 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
 
         published_chunk = lttng_trace_chunk_registry_publish_chunk(
                        element->trace_chunk_registry, session_id, new_chunk);
+       /*
+        * At this point, two references to the published chunks exist. One
+        * is taken by the registry while the other is being returned to the
+        * caller. In the use case of the relay daemon, the reference held
+        * by the registry itself is undesirable.
+        *
+        * We want the trace chunk to be removed from the registry as soon
+        * as it is not being used by the relay daemon (through a session
+        * or a stream). This differs from the behaviour of the consumer
+        * daemon which relies on an explicit command from the session
+        * daemon to release the registry's reference.
+        */
+       lttng_trace_chunk_put(published_chunk);
 end:
        trace_chunk_registry_ht_element_put(element);
        return published_chunk;
@@ -413,7 +432,7 @@ sessiond_trace_chunk_registry_get_anonymous_chunk(
        struct lttng_trace_chunk *chunk = NULL;
        struct trace_chunk_registry_ht_element *element;
        struct trace_chunk_registry_ht_key key;
-       char uuid_str[UUID_STR_LEN];
+       char uuid_str[LTTNG_UUID_STR_LEN];
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
 
@@ -442,7 +461,7 @@ sessiond_trace_chunk_registry_get_chunk(
        struct lttng_trace_chunk *chunk = NULL;
        struct trace_chunk_registry_ht_element *element;
        struct trace_chunk_registry_ht_key key;
-       char uuid_str[UUID_STR_LEN];
+       char uuid_str[LTTNG_UUID_STR_LEN];
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
 
@@ -461,3 +480,39 @@ sessiond_trace_chunk_registry_get_chunk(
 end:
        return chunk;
 }
+
+int sessiond_trace_chunk_registry_chunk_exists(
+               struct sessiond_trace_chunk_registry *sessiond_registry,
+               const lttng_uuid sessiond_uuid,
+               uint64_t session_id, uint64_t chunk_id, bool *chunk_exists)
+{
+       int ret;
+       struct trace_chunk_registry_ht_element *element;
+       struct trace_chunk_registry_ht_key key;
+
+       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
+       if (!element) {
+               char uuid_str[LTTNG_UUID_STR_LEN];
+
+               lttng_uuid_to_str(sessiond_uuid, uuid_str);
+               /*
+                * While this certainly means that the chunk does not exist,
+                * it is unexpected for a chunk existence query to target a
+                * session daemon that does not have an active
+                * connection/registry. This would indicate a protocol
+                * (or internal) error.
+                */
+               ERR("Failed to find trace chunk registry of sessiond {%s}",
+                               uuid_str);
+               ret = -1;
+               goto end;
+       }
+
+       ret = lttng_trace_chunk_registry_chunk_exists(
+                       element->trace_chunk_registry,
+                       session_id, chunk_id, chunk_exists);
+       trace_chunk_registry_ht_element_put(element);
+end:
+       return ret;
+}
This page took 0.025539 seconds and 5 git commands to generate.