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