Commit | Line | Data |
---|---|---|
97ee3a89 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License, version 2 only, | |
6 | * as published by the Free Software Foundation. | |
97ee3a89 | 7 | * |
d14d33bf AM |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
97ee3a89 | 12 | * |
d14d33bf AM |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
97ee3a89 DG |
16 | */ |
17 | ||
18 | #define _GNU_SOURCE | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | #include <unistd.h> | |
23 | ||
990570ed DG |
24 | #include <common/common.h> |
25 | #include <common/defaults.h> | |
97ee3a89 DG |
26 | |
27 | #include "trace-ust.h" | |
28 | ||
18eace3b DG |
29 | int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, |
30 | const void *_key) | |
31 | { | |
32 | struct ltt_ust_event *event; | |
33 | const char *name; | |
34 | ||
35 | assert(node); | |
36 | assert(_key); | |
37 | ||
38 | event = caa_container_of(node, struct ltt_ust_event, node.node); | |
39 | name = _key; | |
40 | ||
41 | /* Event name */ | |
42 | if (strncmp(event->attr.name, name, sizeof(event->attr.name)) != 0) { | |
43 | goto no_match; | |
44 | } | |
45 | ||
46 | /* Match. */ | |
47 | return 1; | |
48 | ||
49 | no_match: | |
50 | return 0; | |
51 | } | |
52 | ||
53 | int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key) | |
54 | { | |
55 | struct ltt_ust_event *event; | |
56 | const struct ltt_ust_ht_key *key; | |
57 | ||
58 | assert(node); | |
59 | assert(_key); | |
60 | ||
61 | event = caa_container_of(node, struct ltt_ust_event, node.node); | |
62 | key = _key; | |
63 | ||
64 | /* Match the 3 elements of the key: name, filter and loglevel. */ | |
65 | ||
66 | /* Event name */ | |
67 | if (strncmp(event->attr.name, key->name, sizeof(event->attr.name)) != 0) { | |
68 | DBG3("[Match] name failed: %s and %s", | |
69 | event->attr.name, key->name); | |
70 | goto no_match; | |
71 | } | |
72 | ||
73 | /* Event loglevel. */ | |
74 | if (event->attr.loglevel != key->loglevel) { | |
75 | if (event->attr.loglevel_type == 0 && key->loglevel == 0 && | |
76 | event->attr.loglevel == -1) { | |
77 | /* | |
78 | * This is because on event creation, the loglevel is set to -1 if | |
79 | * the event loglevel type is ALL so 0 and -1 are accepted for this | |
80 | * loglevel type. | |
81 | */ | |
82 | } else { | |
83 | DBG3("[Match] loglevel failed: %d and %d", | |
84 | event->attr.loglevel, key->loglevel); | |
85 | goto no_match; | |
86 | } | |
87 | } | |
88 | ||
89 | /* Only one of the filters is NULL, fail. */ | |
90 | if ((key->filter && !event->filter) || (!key->filter && event->filter)) { | |
91 | DBG3("[Match] filters failed: k:%p and e:%p", | |
92 | key->filter, event->filter); | |
93 | goto no_match; | |
94 | } | |
95 | ||
96 | /* Both filters are NULL, success. */ | |
97 | if (!key->filter && !event->filter) { | |
98 | goto match; | |
99 | } | |
100 | ||
101 | /* Both filters exists, check length followed by the bytecode. */ | |
102 | if (event->filter->len == key->filter->len && | |
103 | memcmp(event->filter->data, key->filter->data, | |
104 | event->filter->len) == 0) { | |
105 | goto match; | |
106 | } | |
107 | ||
108 | DBG3("[Match] filters failed: k:%p and e:%p", | |
109 | key->filter, event->filter); | |
110 | ||
111 | no_match: | |
112 | return 0; | |
113 | ||
114 | match: | |
115 | DBG3("[MATCH] %s", key->name); | |
116 | return 1; | |
117 | } | |
118 | ||
0177d773 | 119 | /* |
f6a9efaa | 120 | * Find the channel in the hashtable. |
0177d773 | 121 | */ |
bec39940 | 122 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
f6a9efaa | 123 | char *name) |
0177d773 | 124 | { |
bec39940 DG |
125 | struct lttng_ht_node_str *node; |
126 | struct lttng_ht_iter iter; | |
0177d773 | 127 | |
f6a9efaa | 128 | rcu_read_lock(); |
bec39940 DG |
129 | lttng_ht_lookup(ht, (void *)name, &iter); |
130 | node = lttng_ht_iter_get_node_str(&iter); | |
f6a9efaa DG |
131 | if (node == NULL) { |
132 | rcu_read_unlock(); | |
44d3bd01 DG |
133 | goto error; |
134 | } | |
f6a9efaa | 135 | rcu_read_unlock(); |
44d3bd01 | 136 | |
f6a9efaa | 137 | DBG2("Trace UST channel %s found by name", name); |
0177d773 | 138 | |
f6a9efaa | 139 | return caa_container_of(node, struct ltt_ust_channel, node); |
97ee3a89 DG |
140 | |
141 | error: | |
f6a9efaa | 142 | DBG2("Trace UST channel %s not found by name", name); |
97ee3a89 DG |
143 | return NULL; |
144 | } | |
145 | ||
146 | /* | |
f6a9efaa | 147 | * Find the event in the hashtable. |
97ee3a89 | 148 | */ |
18eace3b DG |
149 | struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
150 | char *name, struct lttng_filter_bytecode *filter, int loglevel) | |
97ee3a89 | 151 | { |
bec39940 DG |
152 | struct lttng_ht_node_str *node; |
153 | struct lttng_ht_iter iter; | |
18eace3b DG |
154 | struct ltt_ust_ht_key key; |
155 | void *orig_match_fct; | |
97ee3a89 | 156 | |
18eace3b DG |
157 | assert(name); |
158 | assert(ht); | |
159 | ||
160 | key.name = name; | |
161 | key.filter = filter; | |
162 | key.loglevel = loglevel; | |
163 | ||
164 | /* Save match function so we can use the ust app event match. */ | |
165 | orig_match_fct = (void *) ht->match_fct; | |
166 | ht->match_fct = trace_ust_ht_match_event; | |
167 | ||
168 | cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed), | |
169 | trace_ust_ht_match_event, &key, &iter.iter); | |
bec39940 | 170 | node = lttng_ht_iter_get_node_str(&iter); |
f6a9efaa | 171 | if (node == NULL) { |
97ee3a89 DG |
172 | goto error; |
173 | } | |
174 | ||
18eace3b | 175 | DBG2("Trace UST event %s found", key.name); |
f6a9efaa DG |
176 | |
177 | return caa_container_of(node, struct ltt_ust_event, node); | |
97ee3a89 DG |
178 | |
179 | error: | |
18eace3b DG |
180 | DBG2("Trace UST event %s NOT found", key.name); |
181 | /* Put back original match function. */ | |
182 | ht->match_fct = orig_match_fct; | |
97ee3a89 DG |
183 | return NULL; |
184 | } | |
185 | ||
186 | /* | |
187 | * Allocate and initialize a ust session data structure. | |
188 | * | |
189 | * Return pointer to structure or NULL. | |
190 | */ | |
fc4705fe DG |
191 | struct ltt_ust_session *trace_ust_create_session(char *path, |
192 | unsigned int session_id, struct lttng_domain *domain) | |
97ee3a89 | 193 | { |
0177d773 | 194 | int ret; |
97ee3a89 DG |
195 | struct ltt_ust_session *lus; |
196 | ||
197 | /* Allocate a new ltt ust session */ | |
ba7f0ae5 | 198 | lus = zmalloc(sizeof(struct ltt_ust_session)); |
97ee3a89 | 199 | if (lus == NULL) { |
ba7f0ae5 | 200 | PERROR("create ust session zmalloc"); |
97ee3a89 DG |
201 | goto error; |
202 | } | |
203 | ||
204 | /* Init data structure */ | |
a991f516 | 205 | lus->id = session_id; |
36dc12cc | 206 | lus->start_trace = 0; |
97ee3a89 | 207 | |
f6a9efaa | 208 | /* Alloc UST domain hash tables */ |
bec39940 DG |
209 | lus->domain_pid = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); |
210 | lus->domain_exec = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); | |
f6a9efaa DG |
211 | |
212 | /* Alloc UST global domain channels' HT */ | |
bec39940 | 213 | lus->domain_global.channels = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); |
44d3bd01 | 214 | |
00e2e675 DG |
215 | lus->consumer = consumer_create_output(CONSUMER_DST_LOCAL); |
216 | if (lus->consumer == NULL) { | |
09a90bcd | 217 | goto error_consumer; |
00e2e675 DG |
218 | } |
219 | ||
220 | /* | |
221 | * The tmp_consumer stays NULL until a set_consumer_uri command is | |
222 | * executed. At this point, the consumer should be nullify until an | |
223 | * enable_consumer command. This assignment is symbolic since we've zmalloc | |
224 | * the struct. | |
225 | */ | |
226 | lus->tmp_consumer = NULL; | |
227 | ||
228 | /* Use the default consumer output which is the tracing session path. */ | |
a4b92340 DG |
229 | if (path && strlen(path) > 0) { |
230 | ret = snprintf(lus->consumer->dst.trace_path, PATH_MAX, | |
231 | "%s" DEFAULT_UST_TRACE_DIR, path); | |
232 | if (ret < 0) { | |
233 | PERROR("snprintf UST consumer trace path"); | |
09a90bcd | 234 | goto error_path; |
a4b92340 DG |
235 | } |
236 | ||
237 | /* Set session path */ | |
238 | ret = snprintf(lus->pathname, PATH_MAX, "%s" DEFAULT_UST_TRACE_DIR, | |
239 | path); | |
240 | if (ret < 0) { | |
241 | PERROR("snprintf kernel traces path"); | |
09a90bcd | 242 | goto error_path; |
a4b92340 | 243 | } |
0177d773 DG |
244 | } |
245 | ||
44d3bd01 DG |
246 | DBG2("UST trace session create successful"); |
247 | ||
97ee3a89 DG |
248 | return lus; |
249 | ||
09a90bcd DG |
250 | error_path: |
251 | consumer_destroy_output(lus->consumer); | |
252 | error_consumer: | |
a2c0da86 MD |
253 | lttng_ht_destroy(lus->domain_global.channels); |
254 | lttng_ht_destroy(lus->domain_exec); | |
255 | lttng_ht_destroy(lus->domain_pid); | |
44844c29 | 256 | free(lus); |
97ee3a89 DG |
257 | error: |
258 | return NULL; | |
259 | } | |
260 | ||
261 | /* | |
262 | * Allocate and initialize a ust channel data structure. | |
263 | * | |
264 | * Return pointer to structure or NULL. | |
265 | */ | |
44d3bd01 DG |
266 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan, |
267 | char *path) | |
97ee3a89 DG |
268 | { |
269 | int ret; | |
270 | struct ltt_ust_channel *luc; | |
271 | ||
37357452 | 272 | luc = zmalloc(sizeof(struct ltt_ust_channel)); |
97ee3a89 | 273 | if (luc == NULL) { |
df0f840b | 274 | PERROR("ltt_ust_channel zmalloc"); |
97ee3a89 DG |
275 | goto error; |
276 | } | |
277 | ||
44d3bd01 | 278 | /* Copy UST channel attributes */ |
48842b30 DG |
279 | luc->attr.overwrite = chan->attr.overwrite; |
280 | luc->attr.subbuf_size = chan->attr.subbuf_size; | |
281 | luc->attr.num_subbuf = chan->attr.num_subbuf; | |
282 | luc->attr.switch_timer_interval = chan->attr.switch_timer_interval; | |
283 | luc->attr.read_timer_interval = chan->attr.read_timer_interval; | |
6775595e | 284 | luc->attr.output = (enum lttng_ust_output) chan->attr.output; |
44d3bd01 DG |
285 | |
286 | /* Translate to UST output enum */ | |
287 | switch (luc->attr.output) { | |
288 | default: | |
289 | luc->attr.output = LTTNG_UST_MMAP; | |
290 | break; | |
97ee3a89 | 291 | } |
97ee3a89 | 292 | |
97ee3a89 | 293 | /* Copy channel name */ |
0a1459bb | 294 | strncpy(luc->name, chan->name, sizeof(luc->name)); |
97ee3a89 DG |
295 | luc->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; |
296 | ||
f6a9efaa | 297 | /* Init node */ |
bec39940 | 298 | lttng_ht_node_init_str(&luc->node, luc->name); |
f6a9efaa | 299 | /* Alloc hash tables */ |
bec39940 DG |
300 | luc->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); |
301 | luc->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); | |
f6a9efaa | 302 | |
97ee3a89 | 303 | /* Set trace output path */ |
48842b30 | 304 | ret = snprintf(luc->pathname, PATH_MAX, "%s", path); |
97ee3a89 | 305 | if (ret < 0) { |
df0f840b | 306 | PERROR("asprintf ust create channel"); |
44844c29 | 307 | goto error_free_channel; |
97ee3a89 DG |
308 | } |
309 | ||
f6a9efaa DG |
310 | DBG2("Trace UST channel %s created", luc->name); |
311 | ||
97ee3a89 DG |
312 | return luc; |
313 | ||
44844c29 | 314 | error_free_channel: |
a2c0da86 MD |
315 | lttng_ht_destroy(luc->ctx); |
316 | lttng_ht_destroy(luc->events); | |
44844c29 | 317 | free(luc); |
97ee3a89 DG |
318 | error: |
319 | return NULL; | |
320 | } | |
321 | ||
322 | /* | |
323 | * Allocate and initialize a ust event. Set name and event type. | |
324 | * | |
325 | * Return pointer to structure or NULL. | |
326 | */ | |
327 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev) | |
328 | { | |
329 | struct ltt_ust_event *lue; | |
97ee3a89 | 330 | |
37357452 | 331 | lue = zmalloc(sizeof(struct ltt_ust_event)); |
44d3bd01 | 332 | if (lue == NULL) { |
ba7f0ae5 | 333 | PERROR("ust event zmalloc"); |
97ee3a89 DG |
334 | goto error; |
335 | } | |
336 | ||
337 | switch (ev->type) { | |
338 | case LTTNG_EVENT_PROBE: | |
44d3bd01 | 339 | lue->attr.instrumentation = LTTNG_UST_PROBE; |
97ee3a89 DG |
340 | break; |
341 | case LTTNG_EVENT_FUNCTION: | |
44d3bd01 | 342 | lue->attr.instrumentation = LTTNG_UST_FUNCTION; |
97ee3a89 DG |
343 | break; |
344 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
44d3bd01 | 345 | lue->attr.instrumentation = LTTNG_UST_FUNCTION; |
97ee3a89 DG |
346 | break; |
347 | case LTTNG_EVENT_TRACEPOINT: | |
44d3bd01 | 348 | lue->attr.instrumentation = LTTNG_UST_TRACEPOINT; |
97ee3a89 DG |
349 | break; |
350 | default: | |
351 | ERR("Unknown ust instrumentation type (%d)", ev->type); | |
44844c29 | 352 | goto error_free_event; |
97ee3a89 DG |
353 | } |
354 | ||
355 | /* Copy event name */ | |
44d3bd01 DG |
356 | strncpy(lue->attr.name, ev->name, LTTNG_UST_SYM_NAME_LEN); |
357 | lue->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; | |
97ee3a89 | 358 | |
0cda4f28 | 359 | switch (ev->loglevel_type) { |
8005f29a MD |
360 | case LTTNG_EVENT_LOGLEVEL_ALL: |
361 | lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_ALL; | |
22e25b71 | 362 | lue->attr.loglevel = -1; /* Force to -1 */ |
0cda4f28 | 363 | break; |
8005f29a MD |
364 | case LTTNG_EVENT_LOGLEVEL_RANGE: |
365 | lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_RANGE; | |
22e25b71 | 366 | lue->attr.loglevel = ev->loglevel; |
8005f29a MD |
367 | break; |
368 | case LTTNG_EVENT_LOGLEVEL_SINGLE: | |
369 | lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_SINGLE; | |
22e25b71 | 370 | lue->attr.loglevel = ev->loglevel; |
0cda4f28 MD |
371 | break; |
372 | default: | |
4431494b | 373 | ERR("Unknown ust loglevel type (%d)", ev->loglevel_type); |
0cda4f28 MD |
374 | goto error_free_event; |
375 | } | |
376 | ||
0cda4f28 | 377 | |
f6a9efaa | 378 | /* Init node */ |
bec39940 | 379 | lttng_ht_node_init_str(&lue->node, lue->attr.name); |
97ee3a89 | 380 | |
300b8fd5 MD |
381 | DBG2("Trace UST event %s, loglevel (%d,%d) created", |
382 | lue->attr.name, lue->attr.loglevel_type, | |
383 | lue->attr.loglevel); | |
284d8f55 | 384 | |
97ee3a89 DG |
385 | return lue; |
386 | ||
44844c29 MD |
387 | error_free_event: |
388 | free(lue); | |
97ee3a89 DG |
389 | error: |
390 | return NULL; | |
391 | } | |
392 | ||
393 | /* | |
394 | * Allocate and initialize a ust metadata. | |
395 | * | |
396 | * Return pointer to structure or NULL. | |
397 | */ | |
398 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path) | |
399 | { | |
400 | int ret; | |
401 | struct ltt_ust_metadata *lum; | |
97ee3a89 | 402 | |
3a009adb | 403 | lum = zmalloc(sizeof(struct ltt_ust_metadata)); |
44d3bd01 | 404 | if (lum == NULL) { |
df0f840b | 405 | PERROR("ust metadata zmalloc"); |
97ee3a89 DG |
406 | goto error; |
407 | } | |
408 | ||
409 | /* Set default attributes */ | |
44d3bd01 | 410 | lum->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; |
3e230f92 | 411 | lum->attr.subbuf_size = default_get_metadata_subbuf_size(); |
44d3bd01 DG |
412 | lum->attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM; |
413 | lum->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; | |
414 | lum->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; | |
d41f73b7 | 415 | lum->attr.output = LTTNG_UST_MMAP; |
44d3bd01 | 416 | |
97ee3a89 DG |
417 | lum->handle = -1; |
418 | /* Set metadata trace path */ | |
f6a9efaa | 419 | ret = snprintf(lum->pathname, PATH_MAX, "%s/metadata", path); |
97ee3a89 | 420 | if (ret < 0) { |
df0f840b | 421 | PERROR("asprintf ust metadata"); |
44844c29 | 422 | goto error_free_metadata; |
97ee3a89 DG |
423 | } |
424 | ||
425 | return lum; | |
426 | ||
44844c29 MD |
427 | error_free_metadata: |
428 | free(lum); | |
97ee3a89 DG |
429 | error: |
430 | return NULL; | |
431 | } | |
432 | ||
55cc08a6 DG |
433 | /* |
434 | * Allocate and initialize an UST context. | |
435 | * | |
436 | * Return pointer to structure or NULL. | |
437 | */ | |
438 | struct ltt_ust_context *trace_ust_create_context( | |
439 | struct lttng_event_context *ctx) | |
440 | { | |
441 | struct ltt_ust_context *uctx; | |
9197c5c4 MD |
442 | enum lttng_ust_context_type utype; |
443 | ||
444 | switch (ctx->ctx) { | |
445 | case LTTNG_EVENT_CONTEXT_VTID: | |
446 | utype = LTTNG_UST_CONTEXT_VTID; | |
447 | break; | |
448 | case LTTNG_EVENT_CONTEXT_VPID: | |
449 | utype = LTTNG_UST_CONTEXT_VPID; | |
450 | break; | |
451 | case LTTNG_EVENT_CONTEXT_PTHREAD_ID: | |
452 | utype = LTTNG_UST_CONTEXT_PTHREAD_ID; | |
453 | break; | |
454 | case LTTNG_EVENT_CONTEXT_PROCNAME: | |
455 | utype = LTTNG_UST_CONTEXT_PROCNAME; | |
456 | break; | |
457 | default: | |
458 | ERR("Invalid UST context"); | |
459 | return NULL; | |
460 | } | |
55cc08a6 DG |
461 | |
462 | uctx = zmalloc(sizeof(struct ltt_ust_context)); | |
463 | if (uctx == NULL) { | |
464 | PERROR("zmalloc ltt_ust_context"); | |
465 | goto error; | |
466 | } | |
467 | ||
9197c5c4 | 468 | uctx->ctx.ctx = utype; |
bec39940 | 469 | lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx); |
55cc08a6 DG |
470 | |
471 | return uctx; | |
472 | ||
473 | error: | |
474 | return NULL; | |
475 | } | |
476 | ||
f6a9efaa DG |
477 | /* |
478 | * RCU safe free context structure. | |
479 | */ | |
480 | static void destroy_context_rcu(struct rcu_head *head) | |
481 | { | |
bec39940 DG |
482 | struct lttng_ht_node_ulong *node = |
483 | caa_container_of(head, struct lttng_ht_node_ulong, head); | |
f6a9efaa DG |
484 | struct ltt_ust_context *ctx = |
485 | caa_container_of(node, struct ltt_ust_context, node); | |
486 | ||
487 | free(ctx); | |
488 | } | |
489 | ||
490 | /* | |
491 | * Cleanup UST context hash table. | |
492 | */ | |
7bd39047 | 493 | static void destroy_contexts(struct lttng_ht *ht) |
f6a9efaa DG |
494 | { |
495 | int ret; | |
bec39940 DG |
496 | struct lttng_ht_node_ulong *node; |
497 | struct lttng_ht_iter iter; | |
f6a9efaa | 498 | |
bec39940 DG |
499 | cds_lfht_for_each_entry(ht->ht, &iter.iter, node, node) { |
500 | ret = lttng_ht_del(ht, &iter); | |
f6a9efaa DG |
501 | if (!ret) { |
502 | call_rcu(&node->head, destroy_context_rcu); | |
503 | } | |
f6a9efaa | 504 | } |
ed52805d | 505 | |
bec39940 | 506 | lttng_ht_destroy(ht); |
f6a9efaa DG |
507 | } |
508 | ||
97ee3a89 DG |
509 | /* |
510 | * Cleanup ust event structure. | |
511 | */ | |
512 | void trace_ust_destroy_event(struct ltt_ust_event *event) | |
513 | { | |
f6a9efaa | 514 | DBG2("Trace destroy UST event %s", event->attr.name); |
53a80697 | 515 | free(event->filter); |
97ee3a89 DG |
516 | free(event); |
517 | } | |
518 | ||
f6a9efaa DG |
519 | /* |
520 | * URCU intermediate call to complete destroy event. | |
521 | */ | |
522 | static void destroy_event_rcu(struct rcu_head *head) | |
523 | { | |
bec39940 DG |
524 | struct lttng_ht_node_str *node = |
525 | caa_container_of(head, struct lttng_ht_node_str, head); | |
f6a9efaa DG |
526 | struct ltt_ust_event *event = |
527 | caa_container_of(node, struct ltt_ust_event, node); | |
528 | ||
529 | trace_ust_destroy_event(event); | |
530 | } | |
531 | ||
284d8f55 DG |
532 | /* |
533 | * Cleanup UST events hashtable. | |
534 | */ | |
7bd39047 | 535 | static void destroy_events(struct lttng_ht *events) |
ed52805d DG |
536 | { |
537 | int ret; | |
bec39940 DG |
538 | struct lttng_ht_node_str *node; |
539 | struct lttng_ht_iter iter; | |
ed52805d | 540 | |
bec39940 DG |
541 | cds_lfht_for_each_entry(events->ht, &iter.iter, node, node) { |
542 | ret = lttng_ht_del(events, &iter); | |
7bd39047 DG |
543 | assert(!ret); |
544 | call_rcu(&node->head, destroy_event_rcu); | |
ed52805d DG |
545 | } |
546 | ||
bec39940 | 547 | lttng_ht_destroy(events); |
ed52805d DG |
548 | } |
549 | ||
97ee3a89 DG |
550 | /* |
551 | * Cleanup ust channel structure. | |
552 | */ | |
553 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel) | |
554 | { | |
f6a9efaa | 555 | DBG2("Trace destroy UST channel %s", channel->name); |
97ee3a89 | 556 | |
f6a9efaa DG |
557 | rcu_read_lock(); |
558 | ||
7bd39047 DG |
559 | /* Destroying all events of the channel */ |
560 | destroy_events(channel->events); | |
561 | /* Destroying all context of the channel */ | |
562 | destroy_contexts(channel->ctx); | |
97ee3a89 | 563 | |
97ee3a89 | 564 | free(channel); |
f6a9efaa DG |
565 | |
566 | rcu_read_unlock(); | |
567 | } | |
568 | ||
569 | /* | |
570 | * URCU intermediate call to complete destroy channel. | |
571 | */ | |
572 | static void destroy_channel_rcu(struct rcu_head *head) | |
573 | { | |
bec39940 DG |
574 | struct lttng_ht_node_str *node = |
575 | caa_container_of(head, struct lttng_ht_node_str, head); | |
f6a9efaa DG |
576 | struct ltt_ust_channel *channel = |
577 | caa_container_of(node, struct ltt_ust_channel, node); | |
578 | ||
579 | trace_ust_destroy_channel(channel); | |
97ee3a89 DG |
580 | } |
581 | ||
582 | /* | |
583 | * Cleanup ust metadata structure. | |
584 | */ | |
585 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata) | |
586 | { | |
abc9138a MD |
587 | if (!metadata->handle) { |
588 | return; | |
589 | } | |
f6a9efaa | 590 | DBG2("Trace UST destroy metadata %d", metadata->handle); |
97ee3a89 DG |
591 | free(metadata); |
592 | } | |
593 | ||
594 | /* | |
f6a9efaa | 595 | * Iterate over a hash table containing channels and cleanup safely. |
97ee3a89 | 596 | */ |
bec39940 | 597 | static void destroy_channels(struct lttng_ht *channels) |
f6a9efaa DG |
598 | { |
599 | int ret; | |
bec39940 DG |
600 | struct lttng_ht_node_str *node; |
601 | struct lttng_ht_iter iter; | |
f6a9efaa | 602 | |
24d1723f DG |
603 | rcu_read_lock(); |
604 | ||
bec39940 DG |
605 | cds_lfht_for_each_entry(channels->ht, &iter.iter, node, node) { |
606 | ret = lttng_ht_del(channels, &iter); | |
7bd39047 DG |
607 | assert(!ret); |
608 | call_rcu(&node->head, destroy_channel_rcu); | |
f6a9efaa | 609 | } |
ed52805d | 610 | |
bec39940 | 611 | lttng_ht_destroy(channels); |
24d1723f DG |
612 | |
613 | rcu_read_unlock(); | |
f6a9efaa DG |
614 | } |
615 | ||
616 | /* | |
617 | * Cleanup UST pid domain. | |
618 | */ | |
bec39940 | 619 | static void destroy_domain_pid(struct lttng_ht *ht) |
f6a9efaa DG |
620 | { |
621 | int ret; | |
bec39940 | 622 | struct lttng_ht_iter iter; |
ed52805d | 623 | struct ltt_ust_domain_pid *dpid; |
f6a9efaa | 624 | |
bec39940 DG |
625 | cds_lfht_for_each_entry(ht->ht, &iter.iter, dpid, node.node) { |
626 | ret = lttng_ht_del(ht , &iter); | |
7bd39047 DG |
627 | assert(!ret); |
628 | destroy_channels(dpid->channels); | |
f6a9efaa | 629 | } |
ed52805d | 630 | |
bec39940 | 631 | lttng_ht_destroy(ht); |
f6a9efaa DG |
632 | } |
633 | ||
634 | /* | |
635 | * Cleanup UST exec name domain. | |
636 | */ | |
bec39940 | 637 | static void destroy_domain_exec(struct lttng_ht *ht) |
97ee3a89 | 638 | { |
f6a9efaa | 639 | int ret; |
bec39940 | 640 | struct lttng_ht_iter iter; |
ed52805d | 641 | struct ltt_ust_domain_exec *dexec; |
f6a9efaa | 642 | |
bec39940 DG |
643 | cds_lfht_for_each_entry(ht->ht, &iter.iter, dexec, node.node) { |
644 | ret = lttng_ht_del(ht , &iter); | |
7bd39047 DG |
645 | assert(!ret); |
646 | destroy_channels(dexec->channels); | |
f6a9efaa | 647 | } |
ed52805d | 648 | |
bec39940 | 649 | lttng_ht_destroy(ht); |
f6a9efaa | 650 | } |
97ee3a89 | 651 | |
f6a9efaa DG |
652 | /* |
653 | * Cleanup UST global domain. | |
654 | */ | |
655 | static void destroy_domain_global(struct ltt_ust_domain_global *dom) | |
656 | { | |
657 | destroy_channels(dom->channels); | |
658 | } | |
97ee3a89 | 659 | |
f6a9efaa DG |
660 | /* |
661 | * Cleanup ust session structure | |
662 | */ | |
663 | void trace_ust_destroy_session(struct ltt_ust_session *session) | |
664 | { | |
ed52805d | 665 | /* Extra protection */ |
97ee3a89 DG |
666 | if (session == NULL) { |
667 | return; | |
668 | } | |
669 | ||
f6a9efaa DG |
670 | rcu_read_lock(); |
671 | ||
fc4705fe | 672 | DBG2("Trace UST destroy session %u", session->id); |
f6a9efaa | 673 | |
f6a9efaa DG |
674 | /* Cleaning up UST domain */ |
675 | destroy_domain_global(&session->domain_global); | |
676 | destroy_domain_pid(session->domain_pid); | |
677 | destroy_domain_exec(session->domain_exec); | |
44d3bd01 | 678 | |
3f8e211f DG |
679 | consumer_destroy_output(session->consumer); |
680 | consumer_destroy_output(session->tmp_consumer); | |
681 | ||
97ee3a89 | 682 | free(session); |
f6a9efaa DG |
683 | |
684 | rcu_read_unlock(); | |
97ee3a89 | 685 | } |