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