02a8b2bf16e6b553ccd6d4059c88634aa42bd49d
2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <common/common.h>
24 #include <common/utils.h>
26 #include "ctf-trace.h"
27 #include "lttng-relayd.h"
30 static uint64_t last_relay_ctf_trace_id
;
32 static void rcu_destroy_ctf_trace(struct rcu_head
*head
)
34 struct lttng_ht_node_str
*node
=
35 caa_container_of(head
, struct lttng_ht_node_str
, head
);
36 struct ctf_trace
*trace
=
37 caa_container_of(node
, struct ctf_trace
, node
);
42 static void rcu_destroy_stream(struct rcu_head
*head
)
44 struct relay_stream
*stream
=
45 caa_container_of(head
, struct relay_stream
, rcu_node
);
47 stream_destroy(stream
);
51 * Destroy a ctf trace and all stream contained in it.
53 * MUST be called with the RCU read side lock.
55 void ctf_trace_destroy(struct ctf_trace
*obj
)
57 struct relay_stream
*stream
, *tmp_stream
;
61 * Getting to this point, every stream referenced to that object have put
62 * back their ref since the've been closed by the control side.
64 assert(!obj
->refcount
);
66 cds_list_for_each_entry_safe(stream
, tmp_stream
, &obj
->stream_list
,
68 stream_delete(relay_streams_ht
, stream
);
69 call_rcu(&stream
->rcu_node
, rcu_destroy_stream
);
72 call_rcu(&obj
->node
.head
, rcu_destroy_ctf_trace
);
75 void ctf_trace_try_destroy(struct relay_session
*session
,
76 struct ctf_trace
*ctf_trace
)
82 * Considering no viewer attach to the session and the trace having no more
83 * stream attached, wipe the trace.
85 if (uatomic_read(&session
->viewer_refcount
) == 0 &&
86 uatomic_read(&ctf_trace
->refcount
) == 0) {
87 ctf_trace_delete(session
->ctf_traces_ht
, ctf_trace
);
88 ctf_trace_destroy(ctf_trace
);
93 * Create and return an allocated ctf_trace object. NULL on error.
95 struct ctf_trace
*ctf_trace_create(char *path_name
)
97 struct ctf_trace
*obj
;
101 obj
= zmalloc(sizeof(*obj
));
103 PERROR("ctf_trace alloc");
107 CDS_INIT_LIST_HEAD(&obj
->stream_list
);
109 obj
->id
= ++last_relay_ctf_trace_id
;
110 lttng_ht_node_init_str(&obj
->node
, path_name
);
112 DBG("Created ctf_trace %" PRIu64
" with path: %s", obj
->id
, path_name
);
119 * Return a ctf_trace object if found by id in the given hash table else NULL.
121 * Must be called with rcu_read_lock() taken.
123 struct ctf_trace
*ctf_trace_find_by_path(struct lttng_ht
*ht
,
126 struct lttng_ht_node_str
*node
;
127 struct lttng_ht_iter iter
;
128 struct ctf_trace
*trace
= NULL
;
132 lttng_ht_lookup(ht
, (void *) path_name
, &iter
);
133 node
= lttng_ht_iter_get_node_str(&iter
);
135 DBG("CTF Trace path %s not found", path_name
);
138 trace
= caa_container_of(node
, struct ctf_trace
, node
);
145 * Add stream to a given hash table.
147 void ctf_trace_add(struct lttng_ht
*ht
, struct ctf_trace
*trace
)
152 lttng_ht_add_str(ht
, &trace
->node
);
156 * Delete stream from a given hash table.
158 void ctf_trace_delete(struct lttng_ht
*ht
, struct ctf_trace
*trace
)
161 struct lttng_ht_iter iter
;
166 iter
.iter
.node
= &trace
->node
.node
;
167 ret
= lttng_ht_del(ht
, &iter
);
This page took 0.034496 seconds and 5 git commands to generate.