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