Revert "sessiond: trigger: run trigger actions through an action executor"
[lttng-tools.git] / src / bin / lttng-relayd / ctf-trace.c
index 4ca6dba1e40c489bdd92f6a0a90636d5841dd94e..5f77d676963f7fc97c519baf71df8627cb3f28ea 100644 (file)
@@ -1,20 +1,10 @@
 /*
- * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
- *                      David Goulet <dgoulet@efficios.com>
- *               2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
+ * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
@@ -44,7 +34,7 @@ static void rcu_destroy_ctf_trace(struct rcu_head *rcu_head)
  *
  * MUST be called with the RCU read side lock.
  */
-void ctf_trace_destroy(struct ctf_trace *trace)
+static void ctf_trace_destroy(struct ctf_trace *trace)
 {
        /*
         * Getting to this point, every stream referenced by that trace
@@ -54,10 +44,12 @@ void ctf_trace_destroy(struct ctf_trace *trace)
        assert(cds_list_empty(&trace->stream_list));
        session_put(trace->session);
        trace->session = NULL;
+       free(trace->path);
+       trace->path = NULL;
        call_rcu(&trace->rcu_node, rcu_destroy_ctf_trace);
 }
 
-void ctf_trace_release(struct urcu_ref *ref)
+static void ctf_trace_release(struct urcu_ref *ref)
 {
        struct ctf_trace *trace =
                caa_container_of(ref, struct ctf_trace, ref);
@@ -85,23 +77,26 @@ bool ctf_trace_get(struct ctf_trace *trace)
  * put their reference, its refcount drops to 0.
  */
 static struct ctf_trace *ctf_trace_create(struct relay_session *session,
-               char *path_name)
+               const char *subpath)
 {
        struct ctf_trace *trace;
 
        trace = zmalloc(sizeof(*trace));
        if (!trace) {
-               PERROR("ctf_trace alloc");
-               goto error;
+               PERROR("Failed to allocate ctf_trace");
+               goto end;
        }
+       urcu_ref_init(&trace->ref);
 
        if (!session_get(session)) {
-               ERR("Cannot get session");
-               free(trace);
-               trace = NULL;
+               ERR("Failed to acquire session reference");
                goto error;
        }
        trace->session = session;
+       trace->path = strdup(subpath);
+       if (!trace->path) {
+               goto error;
+       }
 
        CDS_INIT_LIST_HEAD(&trace->stream_list);
 
@@ -109,17 +104,21 @@ static struct ctf_trace *ctf_trace_create(struct relay_session *session,
        trace->id = ++last_relay_ctf_trace_id;
        pthread_mutex_unlock(&last_relay_ctf_trace_id_lock);
 
-       lttng_ht_node_init_str(&trace->node, path_name);
+       lttng_ht_node_init_str(&trace->node, trace->path);
        trace->session = session;
-       urcu_ref_init(&trace->ref);
        pthread_mutex_init(&trace->lock, NULL);
        pthread_mutex_init(&trace->stream_list_lock, NULL);
        lttng_ht_add_str(session->ctf_traces_ht, &trace->node);
 
-       DBG("Created ctf_trace %" PRIu64 " with path: %s", trace->id, path_name);
+       DBG("Created ctf_trace %" PRIu64 "of session \"%s\" from host \"%s\" with path: %s",
+                       trace->id, session->session_name, session->hostname,
+                       subpath);
 
-error:
+end:
        return trace;
+error:
+       ctf_trace_put(trace);
+       return NULL;
 }
 
 /*
@@ -128,17 +127,17 @@ error:
  * ctf_trace_put().
  */
 struct ctf_trace *ctf_trace_get_by_path_or_create(struct relay_session *session,
-               char *path_name)
+               const char *subpath)
 {
        struct lttng_ht_node_str *node;
        struct lttng_ht_iter iter;
        struct ctf_trace *trace = NULL;
 
        rcu_read_lock();
-       lttng_ht_lookup(session->ctf_traces_ht, (void *) path_name, &iter);
+       lttng_ht_lookup(session->ctf_traces_ht, subpath, &iter);
        node = lttng_ht_iter_get_node_str(&iter);
        if (!node) {
-               DBG("CTF Trace path %s not found", path_name);
+               DBG("CTF Trace path %s not found", subpath);
                goto end;
        }
        trace = caa_container_of(node, struct ctf_trace, node);
@@ -149,7 +148,7 @@ end:
        rcu_read_unlock();
        if (!trace) {
                /* Try to create */
-               trace = ctf_trace_create(session, path_name);
+               trace = ctf_trace_create(session, subpath);
        }
        return trace;
 }
This page took 0.026896 seconds and 5 git commands to generate.