Clean-up: sessiond: move ust_registry_session under lttng::sessiond::ust
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.cpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <inttypes.h>
15
16 #include <common/common.hpp>
17 #include <common/defaults.hpp>
18 #include <common/trace-chunk.hpp>
19 #include <common/utils.hpp>
20
21 #include "buffer-registry.hpp"
22 #include "trace-ust.hpp"
23 #include "utils.hpp"
24 #include "ust-app.hpp"
25 #include "agent.hpp"
26
27 namespace lsu = lttng::sessiond::ust;
28
29 /*
30 * Match function for the events hash table lookup.
31 *
32 * Matches by name only. Used by the disable command.
33 */
34 int 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 LTTNG_ASSERT(node);
41 LTTNG_ASSERT(_key);
42
43 event = caa_container_of(node, struct ltt_ust_event, node.node);
44 name = (const char *) _key;
45
46 /* Event name */
47 if (strncmp(event->attr.name, name, sizeof(event->attr.name)) != 0) {
48 goto no_match;
49 }
50
51 /* Match */
52 return 1;
53
54 no_match:
55 return 0;
56 }
57
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 */
64 int 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 int ev_loglevel_value;
69 int ll_match;
70
71 LTTNG_ASSERT(node);
72 LTTNG_ASSERT(_key);
73
74 event = caa_container_of(node, struct ltt_ust_event, node.node);
75 key = (ltt_ust_ht_key *) _key;
76 ev_loglevel_value = event->attr.loglevel;
77
78 /* Match the 4 elements of the key: name, filter, loglevel, exclusions. */
79
80 /* Event name */
81 if (strncmp(event->attr.name, key->name, sizeof(event->attr.name)) != 0) {
82 goto no_match;
83 }
84
85 /* Event loglevel value and type. */
86 ll_match = loglevels_match(event->attr.loglevel_type,
87 ev_loglevel_value, key->loglevel_type,
88 key->loglevel_value, LTTNG_UST_ABI_LOGLEVEL_ALL);
89
90 if (!ll_match) {
91 goto no_match;
92 }
93
94 /* Only one of the filters is NULL, fail. */
95 if ((key->filter && !event->filter) || (!key->filter && event->filter)) {
96 goto no_match;
97 }
98
99 if (key->filter && event->filter) {
100 /* Both filters exists, check length followed by the bytecode. */
101 if (event->filter->len != key->filter->len ||
102 memcmp(event->filter->data, key->filter->data,
103 event->filter->len) != 0) {
104 goto no_match;
105 }
106 }
107
108 /* If only one of the exclusions is NULL, fail. */
109 if ((key->exclusion && !event->exclusion) || (!key->exclusion && event->exclusion)) {
110 goto no_match;
111 }
112
113 if (key->exclusion && event->exclusion) {
114 size_t i;
115
116 /* Check exclusion counts first. */
117 if (event->exclusion->count != key->exclusion->count) {
118 goto no_match;
119 }
120
121 /* Compare names individually. */
122 for (i = 0; i < event->exclusion->count; ++i) {
123 size_t j;
124 bool found = false;
125 const char *name_ev =
126 LTTNG_EVENT_EXCLUSION_NAME_AT(
127 event->exclusion, i);
128
129 /*
130 * Compare this exclusion name to all the key's
131 * exclusion names.
132 */
133 for (j = 0; j < key->exclusion->count; ++j) {
134 const char *name_key =
135 LTTNG_EVENT_EXCLUSION_NAME_AT(
136 key->exclusion, j);
137
138 if (!strncmp(name_ev, name_key,
139 LTTNG_SYMBOL_NAME_LEN)) {
140 /* Names match! */
141 found = true;
142 break;
143 }
144 }
145
146 /*
147 * If the current exclusion name was not found amongst
148 * the key's exclusion names, then there's no match.
149 */
150 if (!found) {
151 goto no_match;
152 }
153 }
154 }
155 /* Match. */
156 return 1;
157
158 no_match:
159 return 0;
160 }
161
162 /*
163 * Find the channel in the hashtable and return channel pointer. RCU read side
164 * lock MUST be acquired before calling this.
165 */
166 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
167 const char *name)
168 {
169 struct lttng_ht_node_str *node;
170 struct lttng_ht_iter iter;
171
172 ASSERT_RCU_READ_LOCKED();
173 /*
174 * If we receive an empty string for channel name, it means the
175 * default channel name is requested.
176 */
177 if (name[0] == '\0')
178 name = DEFAULT_CHANNEL_NAME;
179
180 lttng_ht_lookup(ht, (void *)name, &iter);
181 node = lttng_ht_iter_get_node_str(&iter);
182 if (node == NULL) {
183 goto error;
184 }
185
186 DBG2("Trace UST channel %s found by name", name);
187
188 return caa_container_of(node, struct ltt_ust_channel, node);
189
190 error:
191 DBG2("Trace UST channel %s not found by name", name);
192 return NULL;
193 }
194
195 /*
196 * Find the event in the hashtable and return event pointer. RCU read side lock
197 * MUST be acquired before calling this.
198 */
199 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
200 char *name, struct lttng_bytecode *filter,
201 enum lttng_ust_abi_loglevel_type loglevel_type, int loglevel_value,
202 struct lttng_event_exclusion *exclusion)
203 {
204 struct lttng_ht_node_str *node;
205 struct lttng_ht_iter iter;
206 struct ltt_ust_ht_key key;
207
208 LTTNG_ASSERT(name);
209 LTTNG_ASSERT(ht);
210 ASSERT_RCU_READ_LOCKED();
211
212 key.name = name;
213 key.filter = filter;
214 key.loglevel_type = loglevel_type;
215 key.loglevel_value = loglevel_value;
216 key.exclusion = exclusion;
217
218 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed),
219 trace_ust_ht_match_event, &key, &iter.iter);
220 node = lttng_ht_iter_get_node_str(&iter);
221 if (node == NULL) {
222 goto error;
223 }
224
225 DBG2("Trace UST event %s found", key.name);
226
227 return caa_container_of(node, struct ltt_ust_event, node);
228
229 error:
230 DBG2("Trace UST event %s NOT found", key.name);
231 return NULL;
232 }
233
234 /*
235 * Lookup an agent in the session agents hash table by domain type and return
236 * the object if found else NULL.
237 *
238 * RCU read side lock must be acquired before calling and only released
239 * once the agent is no longer in scope or being used.
240 */
241 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
242 enum lttng_domain_type domain_type)
243 {
244 struct agent *agt = NULL;
245 struct lttng_ht_node_u64 *node;
246 struct lttng_ht_iter iter;
247 uint64_t key;
248
249 LTTNG_ASSERT(session);
250
251 DBG3("Trace ust agent lookup for domain %d", domain_type);
252
253 key = domain_type;
254
255 lttng_ht_lookup(session->agents, &key, &iter);
256 node = lttng_ht_iter_get_node_u64(&iter);
257 if (!node) {
258 goto end;
259 }
260 agt = caa_container_of(node, struct agent, node);
261
262 end:
263 return agt;
264 }
265
266 /*
267 * Allocate and initialize a ust session data structure.
268 *
269 * Return pointer to structure or NULL.
270 */
271 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id)
272 {
273 struct ltt_ust_session *lus;
274
275 /* Allocate a new ltt ust session */
276 lus = zmalloc<ltt_ust_session>();
277 if (lus == NULL) {
278 PERROR("create ust session zmalloc");
279 goto error_alloc;
280 }
281
282 /* Init data structure */
283 lus->id = session_id;
284 lus->active = 0;
285
286 /* Set default metadata channel attribute. */
287 lus->metadata_attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
288 lus->metadata_attr.subbuf_size = default_get_metadata_subbuf_size();
289 lus->metadata_attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM;
290 lus->metadata_attr.switch_timer_interval = DEFAULT_METADATA_SWITCH_TIMER;
291 lus->metadata_attr.read_timer_interval = DEFAULT_METADATA_READ_TIMER;
292 lus->metadata_attr.output = LTTNG_UST_ABI_MMAP;
293
294 /*
295 * Default buffer type. This can be changed through an enable channel
296 * requesting a different type. Note that this can only be changed once
297 * during the session lifetime which is at the first enable channel and
298 * only before start. The flag buffer_type_changed indicates the status.
299 */
300 lus->buffer_type = LTTNG_BUFFER_PER_UID;
301 /* Once set to 1, the buffer_type is immutable for the session. */
302 lus->buffer_type_changed = 0;
303 /* Init it in case it get used after allocation. */
304 CDS_INIT_LIST_HEAD(&lus->buffer_reg_uid_list);
305
306 /* Alloc UST global domain channels' HT */
307 lus->domain_global.channels = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
308 /* Alloc agent hash table. */
309 lus->agents = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
310
311 lus->tracker_vpid = process_attr_tracker_create();
312 if (!lus->tracker_vpid) {
313 goto error;
314 }
315 lus->tracker_vuid = process_attr_tracker_create();
316 if (!lus->tracker_vuid) {
317 goto error;
318 }
319 lus->tracker_vgid = process_attr_tracker_create();
320 if (!lus->tracker_vgid) {
321 goto error;
322 }
323 lus->consumer = consumer_create_output(CONSUMER_DST_LOCAL);
324 if (lus->consumer == NULL) {
325 goto error;
326 }
327
328 DBG2("UST trace session create successful");
329
330 return lus;
331
332 error:
333 process_attr_tracker_destroy(lus->tracker_vpid);
334 process_attr_tracker_destroy(lus->tracker_vuid);
335 process_attr_tracker_destroy(lus->tracker_vgid);
336 lttng_ht_destroy(lus->domain_global.channels);
337 lttng_ht_destroy(lus->agents);
338 free(lus);
339 error_alloc:
340 return NULL;
341 }
342
343 /*
344 * Allocate and initialize a ust channel data structure.
345 *
346 * Return pointer to structure or NULL.
347 */
348 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
349 enum lttng_domain_type domain)
350 {
351 struct ltt_ust_channel *luc;
352
353 LTTNG_ASSERT(chan);
354
355 luc = zmalloc<ltt_ust_channel>();
356 if (luc == NULL) {
357 PERROR("ltt_ust_channel zmalloc");
358 goto error;
359 }
360
361 luc->domain = domain;
362
363 /* Copy UST channel attributes */
364 luc->attr.overwrite = chan->attr.overwrite;
365 luc->attr.subbuf_size = chan->attr.subbuf_size;
366 luc->attr.num_subbuf = chan->attr.num_subbuf;
367 luc->attr.switch_timer_interval = chan->attr.switch_timer_interval;
368 luc->attr.read_timer_interval = chan->attr.read_timer_interval;
369 luc->attr.output = (enum lttng_ust_abi_output) chan->attr.output;
370 luc->monitor_timer_interval = ((struct lttng_channel_extended *)
371 chan->attr.extended.ptr)->monitor_timer_interval;
372 luc->attr.u.s.blocking_timeout = ((struct lttng_channel_extended *)
373 chan->attr.extended.ptr)->blocking_timeout;
374
375 /* Translate to UST output enum */
376 switch (luc->attr.output) {
377 default:
378 luc->attr.output = LTTNG_UST_ABI_MMAP;
379 break;
380 }
381
382 /*
383 * If we receive an empty string for channel name, it means the
384 * default channel name is requested.
385 */
386 if (chan->name[0] == '\0') {
387 strncpy(luc->name, DEFAULT_CHANNEL_NAME, sizeof(luc->name));
388 } else {
389 /* Copy channel name */
390 strncpy(luc->name, chan->name, sizeof(luc->name));
391 }
392 luc->name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
393
394 /* Init node */
395 lttng_ht_node_init_str(&luc->node, luc->name);
396 CDS_INIT_LIST_HEAD(&luc->ctx_list);
397
398 /* Alloc hash tables */
399 luc->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
400 luc->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
401
402 /* On-disk circular buffer parameters */
403 luc->tracefile_size = chan->attr.tracefile_size;
404 luc->tracefile_count = chan->attr.tracefile_count;
405
406 DBG2("Trace UST channel %s created", luc->name);
407
408 error:
409 return luc;
410 }
411
412 /*
413 * Validates an exclusion list.
414 *
415 * Returns 0 if valid, negative value if invalid.
416 */
417 static int validate_exclusion(struct lttng_event_exclusion *exclusion)
418 {
419 size_t i;
420 int ret = 0;
421
422 LTTNG_ASSERT(exclusion);
423
424 for (i = 0; i < exclusion->count; ++i) {
425 size_t j;
426 const char *name_a =
427 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, i);
428
429 for (j = 0; j < i; ++j) {
430 const char *name_b =
431 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, j);
432
433 if (!strncmp(name_a, name_b, LTTNG_SYMBOL_NAME_LEN)) {
434 /* Match! */
435 ret = -1;
436 goto end;
437 }
438 }
439 }
440
441 end:
442 return ret;
443 }
444
445 /*
446 * Allocate and initialize a ust event. Set name and event type.
447 * We own filter_expression, filter, and exclusion.
448 *
449 * Return an lttng_error_code
450 */
451 enum lttng_error_code trace_ust_create_event(struct lttng_event *ev,
452 char *filter_expression,
453 struct lttng_bytecode *filter,
454 struct lttng_event_exclusion *exclusion,
455 bool internal_event,
456 struct ltt_ust_event **ust_event)
457 {
458 struct ltt_ust_event *local_ust_event;
459 enum lttng_error_code ret = LTTNG_OK;
460
461 LTTNG_ASSERT(ev);
462
463 if (exclusion && validate_exclusion(exclusion)) {
464 ret = LTTNG_ERR_INVALID;
465 goto error;
466 }
467
468 local_ust_event = zmalloc<ltt_ust_event>();
469 if (local_ust_event == NULL) {
470 PERROR("ust event zmalloc");
471 ret = LTTNG_ERR_NOMEM;
472 goto error;
473 }
474
475 local_ust_event->internal = internal_event;
476
477 switch (ev->type) {
478 case LTTNG_EVENT_PROBE:
479 local_ust_event->attr.instrumentation = LTTNG_UST_ABI_PROBE;
480 break;
481 case LTTNG_EVENT_FUNCTION:
482 local_ust_event->attr.instrumentation = LTTNG_UST_ABI_FUNCTION;
483 break;
484 case LTTNG_EVENT_FUNCTION_ENTRY:
485 local_ust_event->attr.instrumentation = LTTNG_UST_ABI_FUNCTION;
486 break;
487 case LTTNG_EVENT_TRACEPOINT:
488 local_ust_event->attr.instrumentation = LTTNG_UST_ABI_TRACEPOINT;
489 break;
490 default:
491 ERR("Unknown ust instrumentation type (%d)", ev->type);
492 ret = LTTNG_ERR_INVALID;
493 goto error_free_event;
494 }
495
496 /* Copy event name */
497 strncpy(local_ust_event->attr.name, ev->name, LTTNG_UST_ABI_SYM_NAME_LEN);
498 local_ust_event->attr.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
499
500 switch (ev->loglevel_type) {
501 case LTTNG_EVENT_LOGLEVEL_ALL:
502 local_ust_event->attr.loglevel_type = LTTNG_UST_ABI_LOGLEVEL_ALL;
503 local_ust_event->attr.loglevel = -1; /* Force to -1 */
504 break;
505 case LTTNG_EVENT_LOGLEVEL_RANGE:
506 local_ust_event->attr.loglevel_type = LTTNG_UST_ABI_LOGLEVEL_RANGE;
507 local_ust_event->attr.loglevel = ev->loglevel;
508 break;
509 case LTTNG_EVENT_LOGLEVEL_SINGLE:
510 local_ust_event->attr.loglevel_type = LTTNG_UST_ABI_LOGLEVEL_SINGLE;
511 local_ust_event->attr.loglevel = ev->loglevel;
512 break;
513 default:
514 ERR("Unknown ust loglevel type (%d)", ev->loglevel_type);
515 ret = LTTNG_ERR_INVALID;
516 goto error_free_event;
517 }
518
519 /* Same layout. */
520 local_ust_event->filter_expression = filter_expression;
521 local_ust_event->filter = filter;
522 local_ust_event->exclusion = exclusion;
523
524 /* Init node */
525 lttng_ht_node_init_str(&local_ust_event->node, local_ust_event->attr.name);
526
527 DBG2("Trace UST event %s, loglevel (%d,%d) created",
528 local_ust_event->attr.name, local_ust_event->attr.loglevel_type,
529 local_ust_event->attr.loglevel);
530
531 *ust_event = local_ust_event;
532
533 return ret;
534
535 error_free_event:
536 free(local_ust_event);
537 error:
538 free(filter_expression);
539 free(filter);
540 free(exclusion);
541 return ret;
542 }
543
544 static
545 int trace_ust_context_type_event_to_ust(
546 enum lttng_event_context_type type)
547 {
548 int utype;
549
550 switch (type) {
551 case LTTNG_EVENT_CONTEXT_VTID:
552 utype = LTTNG_UST_ABI_CONTEXT_VTID;
553 break;
554 case LTTNG_EVENT_CONTEXT_VPID:
555 utype = LTTNG_UST_ABI_CONTEXT_VPID;
556 break;
557 case LTTNG_EVENT_CONTEXT_PTHREAD_ID:
558 utype = LTTNG_UST_ABI_CONTEXT_PTHREAD_ID;
559 break;
560 case LTTNG_EVENT_CONTEXT_PROCNAME:
561 utype = LTTNG_UST_ABI_CONTEXT_PROCNAME;
562 break;
563 case LTTNG_EVENT_CONTEXT_IP:
564 utype = LTTNG_UST_ABI_CONTEXT_IP;
565 break;
566 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
567 if (!lttng_ust_ctl_has_perf_counters()) {
568 utype = -1;
569 WARN("Perf counters not implemented in UST");
570 } else {
571 utype = LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER;
572 }
573 break;
574 case LTTNG_EVENT_CONTEXT_APP_CONTEXT:
575 utype = LTTNG_UST_ABI_CONTEXT_APP_CONTEXT;
576 break;
577 case LTTNG_EVENT_CONTEXT_CGROUP_NS:
578 utype = LTTNG_UST_ABI_CONTEXT_CGROUP_NS;
579 break;
580 case LTTNG_EVENT_CONTEXT_IPC_NS:
581 utype = LTTNG_UST_ABI_CONTEXT_IPC_NS;
582 break;
583 case LTTNG_EVENT_CONTEXT_MNT_NS:
584 utype = LTTNG_UST_ABI_CONTEXT_MNT_NS;
585 break;
586 case LTTNG_EVENT_CONTEXT_NET_NS:
587 utype = LTTNG_UST_ABI_CONTEXT_NET_NS;
588 break;
589 case LTTNG_EVENT_CONTEXT_PID_NS:
590 utype = LTTNG_UST_ABI_CONTEXT_PID_NS;
591 break;
592 case LTTNG_EVENT_CONTEXT_TIME_NS:
593 utype = LTTNG_UST_ABI_CONTEXT_TIME_NS;
594 break;
595 case LTTNG_EVENT_CONTEXT_USER_NS:
596 utype = LTTNG_UST_ABI_CONTEXT_USER_NS;
597 break;
598 case LTTNG_EVENT_CONTEXT_UTS_NS:
599 utype = LTTNG_UST_ABI_CONTEXT_UTS_NS;
600 break;
601 case LTTNG_EVENT_CONTEXT_VUID:
602 utype = LTTNG_UST_ABI_CONTEXT_VUID;
603 break;
604 case LTTNG_EVENT_CONTEXT_VEUID:
605 utype = LTTNG_UST_ABI_CONTEXT_VEUID;
606 break;
607 case LTTNG_EVENT_CONTEXT_VSUID:
608 utype = LTTNG_UST_ABI_CONTEXT_VSUID;
609 break;
610 case LTTNG_EVENT_CONTEXT_VGID:
611 utype = LTTNG_UST_ABI_CONTEXT_VGID;
612 break;
613 case LTTNG_EVENT_CONTEXT_VEGID:
614 utype = LTTNG_UST_ABI_CONTEXT_VEGID;
615 break;
616 case LTTNG_EVENT_CONTEXT_VSGID:
617 utype = LTTNG_UST_ABI_CONTEXT_VSGID;
618 break;
619 default:
620 utype = -1;
621 break;
622 }
623 return utype;
624 }
625
626 /*
627 * Return 1 if contexts match, 0 otherwise.
628 */
629 int trace_ust_match_context(const struct ltt_ust_context *uctx,
630 const struct lttng_event_context *ctx)
631 {
632 int utype;
633
634 utype = trace_ust_context_type_event_to_ust(ctx->ctx);
635 if (utype < 0) {
636 return 0;
637 }
638 if (uctx->ctx.ctx != utype) {
639 return 0;
640 }
641 switch (utype) {
642 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER:
643 if (uctx->ctx.u.perf_counter.type
644 != ctx->u.perf_counter.type) {
645 return 0;
646 }
647 if (uctx->ctx.u.perf_counter.config
648 != ctx->u.perf_counter.config) {
649 return 0;
650 }
651 if (strncmp(uctx->ctx.u.perf_counter.name,
652 ctx->u.perf_counter.name,
653 LTTNG_UST_ABI_SYM_NAME_LEN)) {
654 return 0;
655 }
656 break;
657 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT:
658 LTTNG_ASSERT(uctx->ctx.u.app_ctx.provider_name);
659 LTTNG_ASSERT(uctx->ctx.u.app_ctx.ctx_name);
660 if (strcmp(uctx->ctx.u.app_ctx.provider_name,
661 ctx->u.app_ctx.provider_name) ||
662 strcmp(uctx->ctx.u.app_ctx.ctx_name,
663 ctx->u.app_ctx.ctx_name)) {
664 return 0;
665 }
666 default:
667 break;
668
669 }
670 return 1;
671 }
672
673 /*
674 * Allocate and initialize an UST context.
675 *
676 * Return pointer to structure or NULL.
677 */
678 struct ltt_ust_context *trace_ust_create_context(
679 const struct lttng_event_context *ctx)
680 {
681 struct ltt_ust_context *uctx = NULL;
682 int utype;
683
684 LTTNG_ASSERT(ctx);
685
686 utype = trace_ust_context_type_event_to_ust(ctx->ctx);
687 if (utype < 0) {
688 ERR("Invalid UST context");
689 goto end;
690 }
691
692 uctx = zmalloc<ltt_ust_context>();
693 if (!uctx) {
694 PERROR("zmalloc ltt_ust_context");
695 goto end;
696 }
697
698 uctx->ctx.ctx = (enum lttng_ust_abi_context_type) utype;
699 switch (utype) {
700 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER:
701 uctx->ctx.u.perf_counter.type = ctx->u.perf_counter.type;
702 uctx->ctx.u.perf_counter.config = ctx->u.perf_counter.config;
703 strncpy(uctx->ctx.u.perf_counter.name, ctx->u.perf_counter.name,
704 LTTNG_UST_ABI_SYM_NAME_LEN);
705 uctx->ctx.u.perf_counter.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
706 break;
707 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT:
708 {
709 char *provider_name = NULL, *ctx_name = NULL;
710
711 provider_name = strdup(ctx->u.app_ctx.provider_name);
712 if (!provider_name) {
713 goto error;
714 }
715 uctx->ctx.u.app_ctx.provider_name = provider_name;
716
717 ctx_name = strdup(ctx->u.app_ctx.ctx_name);
718 if (!ctx_name) {
719 goto error;
720 }
721 uctx->ctx.u.app_ctx.ctx_name = ctx_name;
722 break;
723 }
724 default:
725 break;
726 }
727 lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx);
728 end:
729 return uctx;
730 error:
731 trace_ust_destroy_context(uctx);
732 return NULL;
733 }
734
735 static void destroy_id_tracker_node_rcu(struct rcu_head *head)
736 {
737 struct ust_id_tracker_node *tracker_node = caa_container_of(
738 head, struct ust_id_tracker_node, node.head);
739 free(tracker_node);
740 }
741
742 static void destroy_id_tracker_node(struct ust_id_tracker_node *tracker_node)
743 {
744 call_rcu(&tracker_node->node.head, destroy_id_tracker_node_rcu);
745 }
746
747 static int init_id_tracker(struct ust_id_tracker *id_tracker)
748 {
749 int ret = LTTNG_OK;
750
751 id_tracker->ht = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
752 if (!id_tracker->ht) {
753 ret = LTTNG_ERR_NOMEM;
754 goto end;
755 }
756
757 end:
758 return ret;
759 }
760
761 /*
762 * Teardown id tracker content, but don't free id_tracker object.
763 */
764 static void fini_id_tracker(struct ust_id_tracker *id_tracker)
765 {
766 struct ust_id_tracker_node *tracker_node;
767 struct lttng_ht_iter iter;
768
769 if (!id_tracker->ht) {
770 return;
771 }
772 rcu_read_lock();
773 cds_lfht_for_each_entry (id_tracker->ht->ht, &iter.iter, tracker_node,
774 node.node) {
775 int ret = lttng_ht_del(id_tracker->ht, &iter);
776
777 LTTNG_ASSERT(!ret);
778 destroy_id_tracker_node(tracker_node);
779 }
780 rcu_read_unlock();
781 lttng_ht_destroy(id_tracker->ht);
782 id_tracker->ht = NULL;
783 }
784
785 static struct ust_id_tracker_node *id_tracker_lookup(
786 struct ust_id_tracker *id_tracker,
787 int id,
788 struct lttng_ht_iter *iter)
789 {
790 unsigned long _id = (unsigned long) id;
791 struct lttng_ht_node_ulong *node;
792
793 lttng_ht_lookup(id_tracker->ht, (void *) _id, iter);
794 node = lttng_ht_iter_get_node_ulong(iter);
795 if (node) {
796 return caa_container_of(node, struct ust_id_tracker_node, node);
797 } else {
798 return NULL;
799 }
800 }
801
802 static int id_tracker_add_id(struct ust_id_tracker *id_tracker, int id)
803 {
804 int retval = LTTNG_OK;
805 struct ust_id_tracker_node *tracker_node;
806 struct lttng_ht_iter iter;
807
808 if (id < 0) {
809 retval = LTTNG_ERR_INVALID;
810 goto end;
811 }
812 tracker_node = id_tracker_lookup(id_tracker, id, &iter);
813 if (tracker_node) {
814 /* Already exists. */
815 retval = LTTNG_ERR_PROCESS_ATTR_EXISTS;
816 goto end;
817 }
818 tracker_node = zmalloc<ust_id_tracker_node>();
819 if (!tracker_node) {
820 retval = LTTNG_ERR_NOMEM;
821 goto end;
822 }
823 lttng_ht_node_init_ulong(&tracker_node->node, (unsigned long) id);
824 lttng_ht_add_unique_ulong(id_tracker->ht, &tracker_node->node);
825 end:
826 return retval;
827 }
828
829 static int id_tracker_del_id(struct ust_id_tracker *id_tracker, int id)
830 {
831 int retval = LTTNG_OK, ret;
832 struct ust_id_tracker_node *tracker_node;
833 struct lttng_ht_iter iter;
834
835 if (id < 0) {
836 retval = LTTNG_ERR_INVALID;
837 goto end;
838 }
839 tracker_node = id_tracker_lookup(id_tracker, id, &iter);
840 if (!tracker_node) {
841 /* Not found */
842 retval = LTTNG_ERR_PROCESS_ATTR_MISSING;
843 goto end;
844 }
845 ret = lttng_ht_del(id_tracker->ht, &iter);
846 LTTNG_ASSERT(!ret);
847
848 destroy_id_tracker_node(tracker_node);
849 end:
850 return retval;
851 }
852
853 static struct ust_id_tracker *get_id_tracker(struct ltt_ust_session *session,
854 enum lttng_process_attr process_attr)
855 {
856 switch (process_attr) {
857 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
858 return &session->vpid_tracker;
859 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
860 return &session->vuid_tracker;
861 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
862 return &session->vgid_tracker;
863 default:
864 return NULL;
865 }
866 }
867
868 static struct process_attr_tracker *_trace_ust_get_process_attr_tracker(
869 struct ltt_ust_session *session,
870 enum lttng_process_attr process_attr)
871 {
872 switch (process_attr) {
873 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
874 return session->tracker_vpid;
875 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
876 return session->tracker_vuid;
877 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
878 return session->tracker_vgid;
879 default:
880 return NULL;
881 }
882 }
883
884 const struct process_attr_tracker *trace_ust_get_process_attr_tracker(
885 struct ltt_ust_session *session,
886 enum lttng_process_attr process_attr)
887 {
888 return (const struct process_attr_tracker *)
889 _trace_ust_get_process_attr_tracker(
890 session, process_attr);
891 }
892
893 /*
894 * The session lock is held when calling this function.
895 */
896 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
897 struct ltt_ust_session *session,
898 int id)
899 {
900 struct lttng_ht_iter iter;
901 struct ust_id_tracker *id_tracker;
902
903 id_tracker = get_id_tracker(session, process_attr);
904 if (!id_tracker) {
905 abort();
906 }
907 if (!id_tracker->ht) {
908 return 1;
909 }
910 if (id_tracker_lookup(id_tracker, id, &iter)) {
911 return 1;
912 }
913 return 0;
914 }
915
916 /*
917 * Called with the session lock held.
918 */
919 enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy(
920 struct ltt_ust_session *session,
921 enum lttng_process_attr process_attr,
922 enum lttng_tracking_policy policy)
923 {
924 int ret;
925 enum lttng_error_code ret_code = LTTNG_OK;
926 struct ust_id_tracker *id_tracker =
927 get_id_tracker(session, process_attr);
928 struct process_attr_tracker *tracker =
929 _trace_ust_get_process_attr_tracker(
930 session, process_attr);
931 bool should_update_apps = false;
932 enum lttng_tracking_policy previous_policy;
933
934 if (!tracker) {
935 ret_code = LTTNG_ERR_INVALID;
936 goto end;
937 }
938
939 previous_policy = process_attr_tracker_get_tracking_policy(tracker);
940 ret = process_attr_tracker_set_tracking_policy(tracker, policy);
941 if (ret) {
942 ret_code = LTTNG_ERR_UNK;
943 goto end;
944 }
945
946 if (previous_policy == policy) {
947 goto end;
948 }
949
950 switch (policy) {
951 case LTTNG_TRACKING_POLICY_INCLUDE_ALL:
952 /* Track all values: destroy tracker if exists. */
953 if (id_tracker->ht) {
954 fini_id_tracker(id_tracker);
955 /* Ensure all apps have session. */
956 should_update_apps = true;
957 }
958 break;
959 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL:
960 case LTTNG_TRACKING_POLICY_INCLUDE_SET:
961 /* fall-through. */
962 fini_id_tracker(id_tracker);
963 ret_code = (lttng_error_code) init_id_tracker(id_tracker);
964 if (ret_code != LTTNG_OK) {
965 ERR("Error initializing ID tracker");
966 goto end;
967 }
968 /* Remove all apps from session. */
969 should_update_apps = true;
970 break;
971 default:
972 abort();
973 }
974 if (should_update_apps && session->active) {
975 ust_app_global_update_all(session);
976 }
977 end:
978 return ret_code;
979 }
980
981 /* Called with the session lock held. */
982 enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value(
983 struct ltt_ust_session *session,
984 enum lttng_process_attr process_attr,
985 const struct process_attr_value *value)
986 {
987 enum lttng_error_code ret_code = LTTNG_OK;
988 bool should_update_apps = false;
989 struct ust_id_tracker *id_tracker =
990 get_id_tracker(session, process_attr);
991 struct process_attr_tracker *tracker;
992 int integral_value;
993 enum process_attr_tracker_status status;
994 struct ust_app *app;
995
996 /*
997 * Convert process attribute tracker value to the integral
998 * representation required by the kern-ctl API.
999 */
1000 switch (process_attr) {
1001 case LTTNG_PROCESS_ATTR_PROCESS_ID:
1002 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
1003 integral_value = (int) value->value.pid;
1004 break;
1005 case LTTNG_PROCESS_ATTR_USER_ID:
1006 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
1007 if (value->type == LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME) {
1008 uid_t uid;
1009
1010 ret_code = utils_user_id_from_name(
1011 value->value.user_name, &uid);
1012 if (ret_code != LTTNG_OK) {
1013 goto end;
1014 }
1015 integral_value = (int) uid;
1016 } else {
1017 integral_value = (int) value->value.uid;
1018 }
1019 break;
1020 case LTTNG_PROCESS_ATTR_GROUP_ID:
1021 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
1022 if (value->type == LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME) {
1023 gid_t gid;
1024
1025 ret_code = utils_group_id_from_name(
1026 value->value.group_name, &gid);
1027 if (ret_code != LTTNG_OK) {
1028 goto end;
1029 }
1030 integral_value = (int) gid;
1031 } else {
1032 integral_value = (int) value->value.gid;
1033 }
1034 break;
1035 default:
1036 ret_code = LTTNG_ERR_INVALID;
1037 goto end;
1038 }
1039
1040 tracker = _trace_ust_get_process_attr_tracker(session, process_attr);
1041 if (!tracker) {
1042 ret_code = LTTNG_ERR_INVALID;
1043 goto end;
1044 }
1045
1046 status = process_attr_tracker_inclusion_set_add_value(tracker, value);
1047 if (status != PROCESS_ATTR_TRACKER_STATUS_OK) {
1048 switch (status) {
1049 case PROCESS_ATTR_TRACKER_STATUS_EXISTS:
1050 ret_code = LTTNG_ERR_PROCESS_ATTR_EXISTS;
1051 break;
1052 case PROCESS_ATTR_TRACKER_STATUS_INVALID_TRACKING_POLICY:
1053 ret_code = LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY;
1054 break;
1055 case PROCESS_ATTR_TRACKER_STATUS_ERROR:
1056 default:
1057 ret_code = LTTNG_ERR_UNK;
1058 break;
1059 }
1060 goto end;
1061 }
1062
1063 DBG("User space track %s %d for session id %" PRIu64,
1064 lttng_process_attr_to_string(process_attr),
1065 integral_value, session->id);
1066
1067 ret_code = (lttng_error_code) id_tracker_add_id(id_tracker, integral_value);
1068 if (ret_code != LTTNG_OK) {
1069 goto end;
1070 }
1071 /* Add session to application */
1072 switch (process_attr) {
1073 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
1074 app = ust_app_find_by_pid(integral_value);
1075 if (app) {
1076 should_update_apps = true;
1077 }
1078 break;
1079 default:
1080 should_update_apps = true;
1081 break;
1082 }
1083 if (should_update_apps && session->active) {
1084 ust_app_global_update_all(session);
1085 }
1086 end:
1087 return ret_code;
1088 }
1089
1090 /* Called with the session lock held. */
1091 enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value(
1092 struct ltt_ust_session *session,
1093 enum lttng_process_attr process_attr,
1094 const struct process_attr_value *value)
1095 {
1096 enum lttng_error_code ret_code = LTTNG_OK;
1097 bool should_update_apps = false;
1098 struct ust_id_tracker *id_tracker =
1099 get_id_tracker(session, process_attr);
1100 struct process_attr_tracker *tracker;
1101 int integral_value;
1102 enum process_attr_tracker_status status;
1103 struct ust_app *app;
1104
1105 /*
1106 * Convert process attribute tracker value to the integral
1107 * representation required by the kern-ctl API.
1108 */
1109 switch (process_attr) {
1110 case LTTNG_PROCESS_ATTR_PROCESS_ID:
1111 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
1112 integral_value = (int) value->value.pid;
1113 break;
1114 case LTTNG_PROCESS_ATTR_USER_ID:
1115 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
1116 if (value->type == LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME) {
1117 uid_t uid;
1118
1119 ret_code = utils_user_id_from_name(
1120 value->value.user_name, &uid);
1121 if (ret_code != LTTNG_OK) {
1122 goto end;
1123 }
1124 integral_value = (int) uid;
1125 } else {
1126 integral_value = (int) value->value.uid;
1127 }
1128 break;
1129 case LTTNG_PROCESS_ATTR_GROUP_ID:
1130 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
1131 if (value->type == LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME) {
1132 gid_t gid;
1133
1134 ret_code = utils_group_id_from_name(
1135 value->value.group_name, &gid);
1136 if (ret_code != LTTNG_OK) {
1137 goto end;
1138 }
1139 integral_value = (int) gid;
1140 } else {
1141 integral_value = (int) value->value.gid;
1142 }
1143 break;
1144 default:
1145 ret_code = LTTNG_ERR_INVALID;
1146 goto end;
1147 }
1148
1149 tracker = _trace_ust_get_process_attr_tracker(session, process_attr);
1150 if (!tracker) {
1151 ret_code = LTTNG_ERR_INVALID;
1152 goto end;
1153 }
1154
1155 status = process_attr_tracker_inclusion_set_remove_value(
1156 tracker, value);
1157 if (status != PROCESS_ATTR_TRACKER_STATUS_OK) {
1158 switch (status) {
1159 case PROCESS_ATTR_TRACKER_STATUS_MISSING:
1160 ret_code = LTTNG_ERR_PROCESS_ATTR_MISSING;
1161 break;
1162 case PROCESS_ATTR_TRACKER_STATUS_INVALID_TRACKING_POLICY:
1163 ret_code = LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY;
1164 break;
1165 case PROCESS_ATTR_TRACKER_STATUS_ERROR:
1166 default:
1167 ret_code = LTTNG_ERR_UNK;
1168 break;
1169 }
1170 goto end;
1171 }
1172
1173 DBG("User space untrack %s %d for session id %" PRIu64,
1174 lttng_process_attr_to_string(process_attr),
1175 integral_value, session->id);
1176
1177 ret_code = (lttng_error_code) id_tracker_del_id(id_tracker, integral_value);
1178 if (ret_code != LTTNG_OK) {
1179 goto end;
1180 }
1181 /* Add session to application */
1182 switch (process_attr) {
1183 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
1184 app = ust_app_find_by_pid(integral_value);
1185 if (app) {
1186 should_update_apps = true;
1187 }
1188 break;
1189 default:
1190 should_update_apps = true;
1191 break;
1192 }
1193 if (should_update_apps && session->active) {
1194 ust_app_global_update_all(session);
1195 }
1196 end:
1197 return ret_code;
1198 }
1199
1200 /*
1201 * RCU safe free context structure.
1202 */
1203 static void destroy_context_rcu(struct rcu_head *head)
1204 {
1205 struct lttng_ht_node_ulong *node =
1206 caa_container_of(head, struct lttng_ht_node_ulong, head);
1207 struct ltt_ust_context *ctx =
1208 caa_container_of(node, struct ltt_ust_context, node);
1209
1210 trace_ust_destroy_context(ctx);
1211 }
1212
1213 /*
1214 * Cleanup UST context hash table.
1215 */
1216 static void destroy_contexts(struct lttng_ht *ht)
1217 {
1218 int ret;
1219 struct lttng_ht_node_ulong *node;
1220 struct lttng_ht_iter iter;
1221 struct ltt_ust_context *ctx;
1222
1223 LTTNG_ASSERT(ht);
1224
1225 rcu_read_lock();
1226 cds_lfht_for_each_entry(ht->ht, &iter.iter, node, node) {
1227 /* Remove from ordered list. */
1228 ctx = caa_container_of(node, struct ltt_ust_context, node);
1229 cds_list_del(&ctx->list);
1230 /* Remove from channel's hash table. */
1231 ret = lttng_ht_del(ht, &iter);
1232 if (!ret) {
1233 call_rcu(&node->head, destroy_context_rcu);
1234 }
1235 }
1236 rcu_read_unlock();
1237
1238 lttng_ht_destroy(ht);
1239 }
1240
1241 /*
1242 * Cleanup ust event structure.
1243 */
1244 void trace_ust_destroy_event(struct ltt_ust_event *event)
1245 {
1246 LTTNG_ASSERT(event);
1247
1248 DBG2("Trace destroy UST event %s", event->attr.name);
1249 free(event->filter_expression);
1250 free(event->filter);
1251 free(event->exclusion);
1252 free(event);
1253 }
1254
1255 /*
1256 * Cleanup ust context structure.
1257 */
1258 void trace_ust_destroy_context(struct ltt_ust_context *ctx)
1259 {
1260 LTTNG_ASSERT(ctx);
1261
1262 if (ctx->ctx.ctx == LTTNG_UST_ABI_CONTEXT_APP_CONTEXT) {
1263 free(ctx->ctx.u.app_ctx.provider_name);
1264 free(ctx->ctx.u.app_ctx.ctx_name);
1265 }
1266 free(ctx);
1267 }
1268
1269 /*
1270 * URCU intermediate call to complete destroy event.
1271 */
1272 static void destroy_event_rcu(struct rcu_head *head)
1273 {
1274 struct lttng_ht_node_str *node =
1275 caa_container_of(head, struct lttng_ht_node_str, head);
1276 struct ltt_ust_event *event =
1277 caa_container_of(node, struct ltt_ust_event, node);
1278
1279 trace_ust_destroy_event(event);
1280 }
1281
1282 /*
1283 * Cleanup UST events hashtable.
1284 */
1285 static void destroy_events(struct lttng_ht *events)
1286 {
1287 int ret;
1288 struct lttng_ht_node_str *node;
1289 struct lttng_ht_iter iter;
1290
1291 LTTNG_ASSERT(events);
1292
1293 rcu_read_lock();
1294 cds_lfht_for_each_entry(events->ht, &iter.iter, node, node) {
1295 ret = lttng_ht_del(events, &iter);
1296 LTTNG_ASSERT(!ret);
1297 call_rcu(&node->head, destroy_event_rcu);
1298 }
1299 rcu_read_unlock();
1300
1301 lttng_ht_destroy(events);
1302 }
1303
1304 /*
1305 * Cleanup ust channel structure.
1306 *
1307 * Should _NOT_ be called with RCU read lock held.
1308 */
1309 static void _trace_ust_destroy_channel(struct ltt_ust_channel *channel)
1310 {
1311 LTTNG_ASSERT(channel);
1312
1313 DBG2("Trace destroy UST channel %s", channel->name);
1314
1315 free(channel);
1316 }
1317
1318 /*
1319 * URCU intermediate call to complete destroy channel.
1320 */
1321 static void destroy_channel_rcu(struct rcu_head *head)
1322 {
1323 struct lttng_ht_node_str *node =
1324 caa_container_of(head, struct lttng_ht_node_str, head);
1325 struct ltt_ust_channel *channel =
1326 caa_container_of(node, struct ltt_ust_channel, node);
1327
1328 _trace_ust_destroy_channel(channel);
1329 }
1330
1331 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
1332 {
1333 /* Destroying all events of the channel */
1334 destroy_events(channel->events);
1335 /* Destroying all context of the channel */
1336 destroy_contexts(channel->ctx);
1337
1338 call_rcu(&channel->node.head, destroy_channel_rcu);
1339 }
1340
1341 /*
1342 * Remove an UST channel from a channel HT.
1343 */
1344 void trace_ust_delete_channel(struct lttng_ht *ht,
1345 struct ltt_ust_channel *channel)
1346 {
1347 int ret;
1348 struct lttng_ht_iter iter;
1349
1350 LTTNG_ASSERT(ht);
1351 LTTNG_ASSERT(channel);
1352
1353 iter.iter.node = &channel->node.node;
1354 ret = lttng_ht_del(ht, &iter);
1355 LTTNG_ASSERT(!ret);
1356 }
1357
1358 int trace_ust_regenerate_metadata(struct ltt_ust_session *usess)
1359 {
1360 int ret = 0;
1361 struct buffer_reg_uid *uid_reg = NULL;
1362 struct buffer_reg_session *session_reg = NULL;
1363
1364 rcu_read_lock();
1365 cds_list_for_each_entry(uid_reg, &usess->buffer_reg_uid_list, lnode) {
1366 lsu::registry_session *registry;
1367
1368 session_reg = uid_reg->registry;
1369 registry = session_reg->reg.ust;
1370
1371 try {
1372 registry->regenerate_metadata();
1373 } catch (const std::exception& ex) {
1374 ERR("Failed to regenerate user space session metadata: %s", ex.what());
1375 ret = -1;
1376 goto end;
1377 }
1378 }
1379
1380 end:
1381 rcu_read_unlock();
1382 return ret;
1383 }
1384
1385 /*
1386 * Iterate over a hash table containing channels and cleanup safely.
1387 */
1388 static void destroy_channels(struct lttng_ht *channels)
1389 {
1390 struct lttng_ht_node_str *node;
1391 struct lttng_ht_iter iter;
1392
1393 LTTNG_ASSERT(channels);
1394
1395 rcu_read_lock();
1396 cds_lfht_for_each_entry(channels->ht, &iter.iter, node, node) {
1397 struct ltt_ust_channel *chan =
1398 caa_container_of(node, struct ltt_ust_channel, node);
1399
1400 trace_ust_delete_channel(channels, chan);
1401 trace_ust_destroy_channel(chan);
1402 }
1403 rcu_read_unlock();
1404
1405 lttng_ht_destroy(channels);
1406 }
1407
1408 /*
1409 * Cleanup UST global domain.
1410 */
1411 static void destroy_domain_global(struct ltt_ust_domain_global *dom)
1412 {
1413 LTTNG_ASSERT(dom);
1414
1415 destroy_channels(dom->channels);
1416 }
1417
1418 /*
1419 * Cleanup ust session structure, keeping data required by
1420 * destroy notifier.
1421 */
1422 void trace_ust_destroy_session(struct ltt_ust_session *session)
1423 {
1424 struct agent *agt;
1425 struct buffer_reg_uid *reg, *sreg;
1426 struct lttng_ht_iter iter;
1427
1428 LTTNG_ASSERT(session);
1429
1430 DBG2("Trace UST destroy session %" PRIu64, session->id);
1431
1432 /* Cleaning up UST domain */
1433 destroy_domain_global(&session->domain_global);
1434
1435 rcu_read_lock();
1436 cds_lfht_for_each_entry(session->agents->ht, &iter.iter, agt, node.node) {
1437 int ret = lttng_ht_del(session->agents, &iter);
1438
1439 LTTNG_ASSERT(!ret);
1440 agent_destroy(agt);
1441 }
1442 rcu_read_unlock();
1443
1444 lttng_ht_destroy(session->agents);
1445
1446 /* Cleanup UID buffer registry object(s). */
1447 cds_list_for_each_entry_safe(reg, sreg, &session->buffer_reg_uid_list,
1448 lnode) {
1449 cds_list_del(&reg->lnode);
1450 buffer_reg_uid_remove(reg);
1451 buffer_reg_uid_destroy(reg, session->consumer);
1452 }
1453
1454 process_attr_tracker_destroy(session->tracker_vpid);
1455 process_attr_tracker_destroy(session->tracker_vuid);
1456 process_attr_tracker_destroy(session->tracker_vgid);
1457
1458 fini_id_tracker(&session->vpid_tracker);
1459 fini_id_tracker(&session->vuid_tracker);
1460 fini_id_tracker(&session->vgid_tracker);
1461 lttng_trace_chunk_put(session->current_trace_chunk);
1462 }
1463
1464 /* Free elements needed by destroy notifiers. */
1465 void trace_ust_free_session(struct ltt_ust_session *session)
1466 {
1467 consumer_output_put(session->consumer);
1468 free(session);
1469 }
This page took 0.098694 seconds and 4 git commands to generate.