Commit | Line | Data |
---|---|---|
54d01ffb DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
71a559f8 | 3 | * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com> |
54d01ffb | 4 | * |
d14d33bf AM |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License, version 2 only, | |
7 | * as published by the Free Software Foundation. | |
54d01ffb | 8 | * |
d14d33bf AM |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
54d01ffb | 13 | * |
d14d33bf AM |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
54d01ffb DG |
17 | */ |
18 | ||
6c1c0768 | 19 | #define _LGPL_SOURCE |
d87bfb32 | 20 | #include <errno.h> |
54d01ffb | 21 | #include <urcu/list.h> |
2bdd86d4 | 22 | #include <string.h> |
54d01ffb DG |
23 | |
24 | #include <lttng/lttng.h> | |
db758600 | 25 | #include <common/error.h> |
10a8a223 | 26 | #include <common/sessiond-comm/sessiond-comm.h> |
71a559f8 JG |
27 | #include <common/filter.h> |
28 | #include <common/context.h> | |
54d01ffb DG |
29 | |
30 | #include "channel.h" | |
31 | #include "event.h" | |
4771f025 | 32 | #include "kernel.h" |
be6a6276 | 33 | #include "lttng-sessiond.h" |
9df8df5e | 34 | #include "ust-ctl.h" |
edb67388 DG |
35 | #include "ust-app.h" |
36 | #include "trace-kernel.h" | |
37 | #include "trace-ust.h" | |
7c1d2758 | 38 | #include "agent.h" |
54d01ffb | 39 | |
025faf73 DG |
40 | /* |
41 | * Add unique UST event based on the event name, filter bytecode and loglevel. | |
42 | */ | |
18eace3b DG |
43 | static void add_unique_ust_event(struct lttng_ht *ht, |
44 | struct ltt_ust_event *event) | |
45 | { | |
46 | struct cds_lfht_node *node_ptr; | |
47 | struct ltt_ust_ht_key key; | |
48 | ||
49 | assert(ht); | |
50 | assert(ht->ht); | |
51 | assert(event); | |
52 | ||
53 | key.name = event->attr.name; | |
54 | key.filter = (struct lttng_filter_bytecode *) event->filter; | |
b953b8cd PP |
55 | key.loglevel_type = event->attr.loglevel_type; |
56 | key.loglevel_value = event->attr.loglevel; | |
4031e53e | 57 | key.exclusion = event->exclusion; |
18eace3b DG |
58 | |
59 | node_ptr = cds_lfht_add_unique(ht->ht, | |
60 | ht->hash_fct(event->node.key, lttng_ht_seed), | |
61 | trace_ust_ht_match_event, &key, &event->node.node); | |
62 | assert(node_ptr == &event->node.node); | |
63 | } | |
64 | ||
54d01ffb | 65 | /* |
9550ee81 JR |
66 | * Disable kernel tracepoint events for a channel from the kernel session of |
67 | * a specified event_name and event type. | |
68 | * On type LTTNG_EVENT_ALL all events with event_name are disabled. | |
69 | * If event_name is NULL all events of the specified type are disabled. | |
54d01ffb | 70 | */ |
d0ae4ea8 | 71 | int event_kernel_disable_event(struct ltt_kernel_channel *kchan, |
9550ee81 | 72 | char *event_name, enum lttng_event_type type) |
54d01ffb | 73 | { |
9550ee81 | 74 | int ret, error = 0, found = 0; |
54d01ffb DG |
75 | struct ltt_kernel_event *kevent; |
76 | ||
0525e9ae DG |
77 | assert(kchan); |
78 | ||
54d01ffb DG |
79 | /* For each event in the kernel session */ |
80 | cds_list_for_each_entry(kevent, &kchan->events_list.head, list) { | |
d0ae4ea8 MD |
81 | if (type != LTTNG_EVENT_ALL && kevent->type != type) |
82 | continue; | |
9550ee81 JR |
83 | if (event_name != NULL && strcmp(event_name, kevent->event->name)) { |
84 | continue; | |
85 | } | |
86 | found++; | |
54d01ffb DG |
87 | ret = kernel_disable_event(kevent); |
88 | if (ret < 0) { | |
9550ee81 | 89 | error = 1; |
54d01ffb DG |
90 | continue; |
91 | } | |
92 | } | |
9550ee81 JR |
93 | DBG("Disable kernel event: found %d events with name: %s and type: %d", |
94 | found, event_name ? event_name : "NULL", type); | |
7a3d1328 | 95 | |
9550ee81 JR |
96 | if (event_name != NULL && !found) { |
97 | ret = LTTNG_ERR_NO_EVENT; | |
98 | } else { | |
99 | ret = error ? LTTNG_ERR_KERN_DISABLE_FAIL : LTTNG_OK; | |
100 | } | |
101 | ||
102 | return ret; | |
54d01ffb DG |
103 | } |
104 | ||
105 | /* | |
7a3d1328 | 106 | * Enable kernel tracepoint event for a channel from the kernel session. |
49d21f93 | 107 | * We own filter_expression and filter. |
54d01ffb | 108 | */ |
d0ae4ea8 | 109 | int event_kernel_enable_event(struct ltt_kernel_channel *kchan, |
00a62084 MD |
110 | struct lttng_event *event, char *filter_expression, |
111 | struct lttng_filter_bytecode *filter) | |
54d01ffb DG |
112 | { |
113 | int ret; | |
114 | struct ltt_kernel_event *kevent; | |
115 | ||
0525e9ae DG |
116 | assert(kchan); |
117 | assert(event); | |
118 | ||
00a62084 MD |
119 | kevent = trace_kernel_find_event(event->name, kchan, |
120 | event->type, filter); | |
54d01ffb | 121 | if (kevent == NULL) { |
71a3bb01 | 122 | ret = kernel_create_event(event, kchan, filter_expression, filter); |
a969e101 MD |
123 | /* We have passed ownership */ |
124 | filter_expression = NULL; | |
125 | filter = NULL; | |
71a3bb01 | 126 | if (ret) { |
7a3d1328 | 127 | goto end; |
54d01ffb DG |
128 | } |
129 | } else if (kevent->enabled == 0) { | |
130 | ret = kernel_enable_event(kevent); | |
131 | if (ret < 0) { | |
f73fabfd | 132 | ret = LTTNG_ERR_KERN_ENABLE_FAIL; |
7a3d1328 | 133 | goto end; |
54d01ffb | 134 | } |
42224349 DG |
135 | } else { |
136 | /* At this point, the event is considered enabled */ | |
f73fabfd | 137 | ret = LTTNG_ERR_KERN_EVENT_EXIST; |
42224349 | 138 | goto end; |
54d01ffb | 139 | } |
42224349 | 140 | |
f73fabfd | 141 | ret = LTTNG_OK; |
7a3d1328 | 142 | end: |
a969e101 MD |
143 | free(filter_expression); |
144 | free(filter); | |
54d01ffb DG |
145 | return ret; |
146 | } | |
147 | ||
7f79d3a1 DG |
148 | /* |
149 | * ============================ | |
150 | * UST : The Ultimate Frontier! | |
151 | * ============================ | |
152 | */ | |
153 | ||
2bdd86d4 MD |
154 | /* |
155 | * Enable UST tracepoint event for a channel from a UST session. | |
49d21f93 | 156 | * We own filter_expression, filter, and exclusion. |
2bdd86d4 | 157 | */ |
7972aab2 | 158 | int event_ust_enable_tracepoint(struct ltt_ust_session *usess, |
025faf73 | 159 | struct ltt_ust_channel *uchan, struct lttng_event *event, |
6b453b5e | 160 | char *filter_expression, |
f1613f52 | 161 | struct lttng_filter_bytecode *filter, |
88f06f15 JG |
162 | struct lttng_event_exclusion *exclusion, |
163 | bool internal_event) | |
2bdd86d4 | 164 | { |
88e3c2f5 | 165 | int ret = LTTNG_OK, to_create = 0; |
edb67388 DG |
166 | struct ltt_ust_event *uevent; |
167 | ||
0525e9ae DG |
168 | assert(usess); |
169 | assert(uchan); | |
170 | assert(event); | |
171 | ||
18eace3b DG |
172 | rcu_read_lock(); |
173 | ||
025faf73 | 174 | uevent = trace_ust_find_event(uchan->events, event->name, filter, |
b953b8cd | 175 | event->loglevel_type, event->loglevel, exclusion); |
87c6e328 | 176 | if (!uevent) { |
39687410 FD |
177 | ret = trace_ust_create_event(event, filter_expression, |
178 | filter, exclusion, internal_event, &uevent); | |
49d21f93 MD |
179 | /* We have passed ownership */ |
180 | filter_expression = NULL; | |
181 | filter = NULL; | |
182 | exclusion = NULL; | |
39687410 | 183 | if (ret != LTTNG_OK) { |
edb67388 DG |
184 | goto error; |
185 | } | |
025faf73 | 186 | |
fc34caaa | 187 | /* Valid to set it after the goto error since uevent is still NULL */ |
edb67388 DG |
188 | to_create = 1; |
189 | } | |
2bdd86d4 | 190 | |
7f79d3a1 DG |
191 | if (uevent->enabled) { |
192 | /* It's already enabled so everything is OK */ | |
5bcdda4f | 193 | ret = LTTNG_ERR_UST_EVENT_ENABLED; |
7f79d3a1 DG |
194 | goto end; |
195 | } | |
196 | ||
fc34caaa | 197 | uevent->enabled = 1; |
88e3c2f5 JG |
198 | if (to_create) { |
199 | /* Add ltt ust event to channel */ | |
200 | add_unique_ust_event(uchan->events, uevent); | |
201 | } | |
202 | ||
203 | if (!usess->active) { | |
204 | goto end; | |
205 | } | |
fc34caaa | 206 | |
7972aab2 DG |
207 | if (to_create) { |
208 | /* Create event on all UST registered apps for session */ | |
209 | ret = ust_app_create_event_glb(usess, uchan, uevent); | |
210 | } else { | |
211 | /* Enable event on all UST registered apps for session */ | |
212 | ret = ust_app_enable_event_glb(usess, uchan, uevent); | |
213 | } | |
48842b30 | 214 | |
7972aab2 DG |
215 | if (ret < 0) { |
216 | if (ret == -LTTNG_UST_ERR_EXIST) { | |
217 | ret = LTTNG_ERR_UST_EVENT_EXIST; | |
218 | goto end; | |
219 | } else { | |
220 | ret = LTTNG_ERR_UST_ENABLE_FAIL; | |
221 | goto error; | |
edb67388 | 222 | } |
2bdd86d4 | 223 | } |
48842b30 | 224 | |
7f79d3a1 DG |
225 | DBG("Event UST %s %s in channel %s", uevent->attr.name, |
226 | to_create ? "created" : "enabled", uchan->name); | |
227 | ||
f73fabfd | 228 | ret = LTTNG_OK; |
fc34caaa | 229 | |
fb89d070 | 230 | end: |
18eace3b | 231 | rcu_read_unlock(); |
49d21f93 MD |
232 | free(filter_expression); |
233 | free(filter); | |
234 | free(exclusion); | |
fc34caaa | 235 | return ret; |
edb67388 DG |
236 | |
237 | error: | |
fc34caaa DG |
238 | /* |
239 | * Only destroy event on creation time (not enabling time) because if the | |
240 | * event is found in the channel (to_create == 0), it means that at some | |
241 | * point the enable_event worked and it's thus valid to keep it alive. | |
242 | * Destroying it also implies that we also destroy it's shadow copy to sync | |
243 | * everyone up. | |
244 | */ | |
245 | if (to_create) { | |
246 | /* In this code path, the uevent was not added to the hash table */ | |
247 | trace_ust_destroy_event(uevent); | |
248 | } | |
18eace3b | 249 | rcu_read_unlock(); |
49d21f93 MD |
250 | free(filter_expression); |
251 | free(filter); | |
252 | free(exclusion); | |
2bdd86d4 MD |
253 | return ret; |
254 | } | |
255 | ||
7f79d3a1 DG |
256 | /* |
257 | * Disable UST tracepoint of a channel from a UST session. | |
258 | */ | |
7972aab2 | 259 | int event_ust_disable_tracepoint(struct ltt_ust_session *usess, |
7f79d3a1 | 260 | struct ltt_ust_channel *uchan, char *event_name) |
2bdd86d4 MD |
261 | { |
262 | int ret; | |
7f79d3a1 | 263 | struct ltt_ust_event *uevent; |
18eace3b DG |
264 | struct lttng_ht_node_str *node; |
265 | struct lttng_ht_iter iter; | |
18eace3b | 266 | struct lttng_ht *ht; |
2bdd86d4 | 267 | |
0525e9ae DG |
268 | assert(usess); |
269 | assert(uchan); | |
270 | assert(event_name); | |
271 | ||
18eace3b DG |
272 | ht = uchan->events; |
273 | ||
18eace3b | 274 | rcu_read_lock(); |
025faf73 DG |
275 | |
276 | /* | |
277 | * We use a custom lookup since we need the iterator for the next_duplicate | |
278 | * call in the do while loop below. | |
279 | */ | |
280 | cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed), | |
281 | trace_ust_ht_match_event_by_name, event_name, &iter.iter); | |
18eace3b DG |
282 | node = lttng_ht_iter_get_node_str(&iter); |
283 | if (node == NULL) { | |
284 | DBG2("Trace UST event NOT found by name %s", event_name); | |
f73fabfd | 285 | ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; |
7f79d3a1 | 286 | goto error; |
2bdd86d4 | 287 | } |
7f79d3a1 | 288 | |
18eace3b DG |
289 | do { |
290 | uevent = caa_container_of(node, struct ltt_ust_event, node); | |
025faf73 DG |
291 | assert(uevent); |
292 | ||
18eace3b DG |
293 | if (uevent->enabled == 0) { |
294 | /* It's already disabled so everything is OK */ | |
a1dcaf0f | 295 | goto next; |
7f79d3a1 | 296 | } |
88e3c2f5 JG |
297 | uevent->enabled = 0; |
298 | DBG2("Event UST %s disabled in channel %s", uevent->attr.name, | |
299 | uchan->name); | |
18eace3b | 300 | |
88e3c2f5 JG |
301 | if (!usess->active) { |
302 | goto next; | |
303 | } | |
7972aab2 DG |
304 | ret = ust_app_disable_event_glb(usess, uchan, uevent); |
305 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { | |
306 | ret = LTTNG_ERR_UST_DISABLE_FAIL; | |
18eace3b DG |
307 | goto error; |
308 | } | |
a1dcaf0f | 309 | next: |
18eace3b DG |
310 | /* Get next duplicate event by name. */ |
311 | cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name, | |
312 | event_name, &iter.iter); | |
313 | node = lttng_ht_iter_get_node_str(&iter); | |
314 | } while (node); | |
7f79d3a1 | 315 | |
f73fabfd | 316 | ret = LTTNG_OK; |
7f79d3a1 | 317 | |
7f79d3a1 | 318 | error: |
18eace3b | 319 | rcu_read_unlock(); |
7f79d3a1 DG |
320 | return ret; |
321 | } | |
322 | ||
b1e7fe2d JR |
323 | /* |
324 | * Disable all UST tracepoints for a channel from a UST session. | |
325 | */ | |
326 | int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, | |
327 | struct ltt_ust_channel *uchan) | |
328 | { | |
3e81c0f2 | 329 | int ret, i, size, error = 0; |
b1e7fe2d JR |
330 | struct lttng_ht_iter iter; |
331 | struct ltt_ust_event *uevent = NULL; | |
332 | struct lttng_event *events = NULL; | |
333 | ||
334 | assert(usess); | |
335 | assert(uchan); | |
336 | ||
337 | rcu_read_lock(); | |
338 | ||
339 | /* Disabling existing events */ | |
340 | cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, | |
341 | node.node) { | |
342 | if (uevent->enabled == 1) { | |
343 | ret = event_ust_disable_tracepoint(usess, uchan, | |
344 | uevent->attr.name); | |
345 | if (ret < 0) { | |
3e81c0f2 | 346 | error = LTTNG_ERR_UST_DISABLE_FAIL; |
b1e7fe2d JR |
347 | continue; |
348 | } | |
349 | } | |
350 | } | |
351 | ||
352 | /* Get all UST available events */ | |
353 | size = ust_app_list_events(&events); | |
354 | if (size < 0) { | |
355 | ret = LTTNG_ERR_UST_LIST_FAIL; | |
356 | goto error; | |
357 | } | |
358 | ||
359 | for (i = 0; i < size; i++) { | |
360 | ret = event_ust_disable_tracepoint(usess, uchan, | |
361 | events[i].name); | |
3e81c0f2 | 362 | if (ret < 0) { |
b1e7fe2d | 363 | /* Continue to disable the rest... */ |
3e81c0f2 | 364 | error = LTTNG_ERR_UST_DISABLE_FAIL; |
b1e7fe2d JR |
365 | continue; |
366 | } | |
367 | } | |
368 | ||
3e81c0f2 | 369 | ret = error ? error : LTTNG_OK; |
b1e7fe2d JR |
370 | error: |
371 | rcu_read_unlock(); | |
372 | free(events); | |
373 | return ret; | |
374 | } | |
375 | ||
f20baf8e | 376 | /* |
022d91ba | 377 | * Enable all agent event for a given UST session. |
f20baf8e DG |
378 | * |
379 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
380 | */ | |
022d91ba | 381 | int event_agent_enable_all(struct ltt_ust_session *usess, |
fefd409b | 382 | struct agent *agt, struct lttng_event *event, |
51755dc8 | 383 | struct lttng_filter_bytecode *filter ,char *filter_expression) |
f20baf8e DG |
384 | { |
385 | int ret; | |
fefd409b | 386 | struct agent_event *aevent; |
f20baf8e DG |
387 | struct lttng_ht_iter iter; |
388 | ||
389 | assert(usess); | |
390 | ||
022d91ba | 391 | DBG("Event agent enabling ALL events for session %" PRIu64, usess->id); |
f20baf8e | 392 | |
022d91ba | 393 | /* Enable event on agent application through TCP socket. */ |
8404118c | 394 | ret = event_agent_enable(usess, agt, event, filter, filter_expression); |
f20baf8e DG |
395 | if (ret != LTTNG_OK) { |
396 | goto error; | |
397 | } | |
398 | ||
399 | /* Flag every event that they are now enabled. */ | |
400 | rcu_read_lock(); | |
fefd409b | 401 | cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent, |
f20baf8e | 402 | node.node) { |
fefd409b | 403 | aevent->enabled = 1; |
f20baf8e DG |
404 | } |
405 | rcu_read_unlock(); | |
406 | ||
407 | ret = LTTNG_OK; | |
408 | ||
409 | error: | |
410 | return ret; | |
411 | } | |
412 | ||
71a559f8 JG |
413 | /* |
414 | * Check if this event's filter requires the activation of application contexts | |
415 | * and enable them in the agent. | |
b4bc01f7 MD |
416 | * TODO: bytecode iterator does not support non-legacy application |
417 | * contexts yet. Not an issue for now, since they are not generated by | |
418 | * the lttng-ctl library. | |
71a559f8 JG |
419 | */ |
420 | static int add_filter_app_ctx(struct lttng_filter_bytecode *bytecode, | |
421 | const char *filter_expression, struct agent *agt) | |
422 | { | |
423 | int ret = LTTNG_OK; | |
424 | char *provider_name = NULL, *ctx_name = NULL; | |
425 | struct bytecode_symbol_iterator *it = | |
426 | bytecode_symbol_iterator_create(bytecode); | |
427 | ||
428 | if (!it) { | |
429 | ret = LTTNG_ERR_NOMEM; | |
430 | goto end; | |
431 | } | |
432 | ||
433 | do { | |
434 | struct lttng_event_context ctx; | |
435 | const char *symbol_name = | |
436 | bytecode_symbol_iterator_get_name(it); | |
437 | ||
438 | if (parse_application_context(symbol_name, &provider_name, | |
439 | &ctx_name)) { | |
440 | /* Not an application context. */ | |
441 | continue; | |
442 | } | |
443 | ||
444 | ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT; | |
445 | ctx.u.app_ctx.provider_name = provider_name; | |
446 | ctx.u.app_ctx.ctx_name = ctx_name; | |
447 | ||
448 | /* Recognized an application context. */ | |
449 | DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.", | |
450 | filter_expression, provider_name, ctx_name); | |
451 | ||
452 | ret = agent_add_context(&ctx, agt); | |
453 | if (ret != LTTNG_OK) { | |
454 | ERR("Failed to add application context %s:%s.", | |
455 | provider_name, ctx_name); | |
456 | goto end; | |
457 | } | |
458 | ||
459 | ret = agent_enable_context(&ctx, agt->domain); | |
460 | if (ret != LTTNG_OK) { | |
461 | ERR("Failed to enable application context %s:%s.", | |
462 | provider_name, ctx_name); | |
463 | goto end; | |
464 | } | |
465 | ||
466 | free(provider_name); | |
467 | free(ctx_name); | |
468 | provider_name = ctx_name = NULL; | |
469 | } while (bytecode_symbol_iterator_next(it) == 0); | |
470 | end: | |
471 | free(provider_name); | |
472 | free(ctx_name); | |
473 | bytecode_symbol_iterator_destroy(it); | |
474 | return ret; | |
475 | } | |
476 | ||
f20baf8e | 477 | /* |
022d91ba | 478 | * Enable a single agent event for a given UST session. |
f20baf8e DG |
479 | * |
480 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
481 | */ | |
fefd409b DG |
482 | int event_agent_enable(struct ltt_ust_session *usess, |
483 | struct agent *agt, struct lttng_event *event, | |
8404118c JG |
484 | struct lttng_filter_bytecode *filter, |
485 | char *filter_expression) | |
f20baf8e DG |
486 | { |
487 | int ret, created = 0; | |
fefd409b | 488 | struct agent_event *aevent; |
f20baf8e DG |
489 | |
490 | assert(usess); | |
491 | assert(event); | |
fefd409b | 492 | assert(agt); |
f20baf8e | 493 | |
022d91ba | 494 | DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d " |
51755dc8 JG |
495 | ", loglevel %d and filter \"%s\"", event->name, |
496 | usess->id, event->loglevel_type, event->loglevel, | |
497 | filter_expression ? filter_expression : "NULL"); | |
f20baf8e | 498 | |
a9319624 | 499 | aevent = agent_find_event(event->name, event->loglevel_type, |
71a559f8 | 500 | event->loglevel, filter_expression, agt); |
fefd409b | 501 | if (!aevent) { |
a9319624 PP |
502 | aevent = agent_create_event(event->name, event->loglevel_type, |
503 | event->loglevel, filter, | |
51755dc8 | 504 | filter_expression); |
fefd409b | 505 | if (!aevent) { |
f20baf8e DG |
506 | ret = LTTNG_ERR_NOMEM; |
507 | goto error; | |
508 | } | |
b0a23296 JG |
509 | filter = NULL; |
510 | filter_expression = NULL; | |
f20baf8e DG |
511 | created = 1; |
512 | } | |
513 | ||
71a559f8 JG |
514 | if (created && filter) { |
515 | ret = add_filter_app_ctx(filter, filter_expression, agt); | |
516 | if (ret != LTTNG_OK) { | |
517 | goto error; | |
518 | } | |
519 | } | |
520 | ||
88e3c2f5 JG |
521 | /* Already enabled? */ |
522 | if (aevent->enabled) { | |
523 | ret = LTTNG_OK; | |
524 | goto end; | |
525 | } | |
526 | ||
fefd409b | 527 | ret = agent_enable_event(aevent, agt->domain); |
f20baf8e DG |
528 | if (ret != LTTNG_OK) { |
529 | goto error; | |
530 | } | |
531 | ||
532 | /* If the event was created prior to the enable, add it to the domain. */ | |
533 | if (created) { | |
fefd409b | 534 | agent_add_event(aevent, agt); |
f20baf8e DG |
535 | } |
536 | ||
b0a23296 JG |
537 | ret = LTTNG_OK; |
538 | goto end; | |
f20baf8e DG |
539 | |
540 | error: | |
541 | if (created) { | |
fefd409b | 542 | agent_destroy_event(aevent); |
f20baf8e | 543 | } |
b0a23296 JG |
544 | end: |
545 | free(filter); | |
546 | free(filter_expression); | |
f20baf8e DG |
547 | return ret; |
548 | } | |
549 | ||
da6c3a50 | 550 | /* |
d1ec8e20 JG |
551 | * Return the default event name associated with the provided UST domain. Return |
552 | * NULL on error. | |
da6c3a50 DG |
553 | */ |
554 | const char *event_get_default_agent_ust_name(enum lttng_domain_type domain) | |
555 | { | |
556 | const char *default_event_name = NULL; | |
557 | ||
0e115563 DG |
558 | switch (domain) { |
559 | case LTTNG_DOMAIN_LOG4J: | |
d1ec8e20 | 560 | default_event_name = DEFAULT_LOG4J_EVENT_NAME; |
0e115563 DG |
561 | break; |
562 | case LTTNG_DOMAIN_JUL: | |
d1ec8e20 | 563 | default_event_name = DEFAULT_JUL_EVENT_NAME; |
0e115563 DG |
564 | break; |
565 | case LTTNG_DOMAIN_PYTHON: | |
e7c82272 | 566 | default_event_name = DEFAULT_PYTHON_EVENT_NAME; |
0e115563 DG |
567 | break; |
568 | default: | |
da6c3a50 DG |
569 | assert(0); |
570 | } | |
571 | ||
572 | return default_event_name; | |
573 | } | |
574 | ||
f20baf8e | 575 | /* |
e261a6cc | 576 | * Disable a given agent event for a given UST session. |
f20baf8e | 577 | * |
e261a6cc | 578 | * Must be called with the RCU read lock held. |
f20baf8e DG |
579 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. |
580 | */ | |
e261a6cc PP |
581 | static int event_agent_disable_one(struct ltt_ust_session *usess, |
582 | struct agent *agt, struct agent_event *aevent) | |
f20baf8e DG |
583 | { |
584 | int ret; | |
be6a6276 DG |
585 | struct ltt_ust_event *uevent = NULL; |
586 | struct ltt_ust_channel *uchan = NULL; | |
71aecbf8 | 587 | const char *ust_event_name, *ust_channel_name; |
f20baf8e | 588 | |
fefd409b | 589 | assert(agt); |
f20baf8e | 590 | assert(usess); |
e261a6cc | 591 | assert(aevent); |
f20baf8e | 592 | |
e261a6cc PP |
593 | DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64, |
594 | aevent->name, aevent->loglevel_type, aevent->loglevel_value, | |
595 | usess->id); | |
f20baf8e DG |
596 | |
597 | /* Already disabled? */ | |
fefd409b | 598 | if (!aevent->enabled) { |
f20baf8e DG |
599 | goto end; |
600 | } | |
601 | ||
71aecbf8 DG |
602 | if (agt->domain == LTTNG_DOMAIN_JUL) { |
603 | ust_channel_name = DEFAULT_JUL_CHANNEL_NAME; | |
604 | } else if (agt->domain == LTTNG_DOMAIN_LOG4J) { | |
605 | ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME; | |
0e115563 DG |
606 | } else if (agt->domain == LTTNG_DOMAIN_PYTHON) { |
607 | ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME; | |
71aecbf8 DG |
608 | } else { |
609 | ret = LTTNG_ERR_INVALID; | |
610 | goto error; | |
611 | } | |
612 | ||
be6a6276 DG |
613 | /* |
614 | * Disable it on the UST side. First get the channel reference then find | |
615 | * the event and finally disable it. | |
616 | */ | |
617 | uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, | |
71aecbf8 | 618 | (char *) ust_channel_name); |
be6a6276 DG |
619 | if (!uchan) { |
620 | ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; | |
621 | goto error; | |
622 | } | |
623 | ||
da6c3a50 DG |
624 | ust_event_name = event_get_default_agent_ust_name(agt->domain); |
625 | if (!ust_event_name) { | |
626 | ret = LTTNG_ERR_FATAL; | |
627 | goto error; | |
be6a6276 DG |
628 | } |
629 | ||
630 | /* | |
b953b8cd PP |
631 | * Agent UST event has its loglevel type forced to |
632 | * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering | |
633 | * happens thanks to an UST filter. The following -1 is actually | |
634 | * ignored since the type is LTTNG_UST_LOGLEVEL_ALL. | |
be6a6276 | 635 | */ |
da6c3a50 | 636 | uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name, |
b953b8cd | 637 | aevent->filter, LTTNG_UST_LOGLEVEL_ALL, -1, NULL); |
022d91ba | 638 | /* If the agent event exists, it must be available on the UST side. */ |
be6a6276 DG |
639 | assert(uevent); |
640 | ||
88e3c2f5 JG |
641 | if (usess->active) { |
642 | ret = ust_app_disable_event_glb(usess, uchan, uevent); | |
643 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { | |
644 | ret = LTTNG_ERR_UST_DISABLE_FAIL; | |
645 | goto error; | |
646 | } | |
be6a6276 DG |
647 | } |
648 | ||
0dcfcf94 DG |
649 | /* |
650 | * Flag event that it's disabled so the shadow copy on the ust app side | |
651 | * will disable it if an application shows up. | |
652 | */ | |
653 | uevent->enabled = 0; | |
654 | ||
fefd409b | 655 | ret = agent_disable_event(aevent, agt->domain); |
f20baf8e DG |
656 | if (ret != LTTNG_OK) { |
657 | goto error; | |
658 | } | |
659 | ||
660 | end: | |
661 | return LTTNG_OK; | |
662 | ||
663 | error: | |
664 | return ret; | |
665 | } | |
e261a6cc PP |
666 | |
667 | /* | |
668 | * Disable all agent events matching a given name for a given UST session. | |
669 | * | |
670 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
671 | */ | |
672 | int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, | |
673 | char *event_name) | |
674 | { | |
675 | int ret = LTTNG_OK; | |
676 | struct agent_event *aevent; | |
677 | struct lttng_ht_iter iter; | |
678 | struct lttng_ht_node_str *node; | |
679 | ||
680 | assert(agt); | |
681 | assert(usess); | |
682 | assert(event_name); | |
683 | ||
684 | DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id); | |
685 | ||
686 | rcu_read_lock(); | |
687 | agent_find_events_by_name(event_name, agt, &iter); | |
688 | node = lttng_ht_iter_get_node_str(&iter); | |
689 | ||
690 | if (node == NULL) { | |
691 | DBG2("Event agent NOT found by name %s", event_name); | |
692 | ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; | |
693 | goto end; | |
694 | } | |
695 | ||
696 | do { | |
697 | aevent = caa_container_of(node, struct agent_event, node); | |
698 | ret = event_agent_disable_one(usess, agt, aevent); | |
699 | ||
700 | if (ret != LTTNG_OK) { | |
701 | goto end; | |
702 | } | |
703 | ||
704 | /* Get next duplicate agent event by name. */ | |
705 | agent_event_next_duplicate(event_name, agt, &iter); | |
706 | node = lttng_ht_iter_get_node_str(&iter); | |
707 | } while (node); | |
708 | end: | |
709 | rcu_read_unlock(); | |
710 | return ret; | |
711 | } | |
f20baf8e | 712 | /* |
022d91ba | 713 | * Disable all agent event for a given UST session. |
f20baf8e DG |
714 | * |
715 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
716 | */ | |
fefd409b DG |
717 | int event_agent_disable_all(struct ltt_ust_session *usess, |
718 | struct agent *agt) | |
f20baf8e | 719 | { |
0dcfcf94 | 720 | int ret; |
fefd409b | 721 | struct agent_event *aevent; |
f20baf8e DG |
722 | struct lttng_ht_iter iter; |
723 | ||
fefd409b | 724 | assert(agt); |
f20baf8e DG |
725 | assert(usess); |
726 | ||
0dcfcf94 DG |
727 | /* |
728 | * Disable event on agent application. Continue to disable all other events | |
729 | * if the * event is not found. | |
730 | */ | |
fefd409b | 731 | ret = event_agent_disable(usess, agt, "*"); |
0dcfcf94 DG |
732 | if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) { |
733 | goto error; | |
f20baf8e DG |
734 | } |
735 | ||
b9866e08 | 736 | /* Disable every event. */ |
f20baf8e | 737 | rcu_read_lock(); |
fefd409b | 738 | cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent, |
f20baf8e | 739 | node.node) { |
0dcfcf94 DG |
740 | if (!aevent->enabled) { |
741 | continue; | |
742 | } | |
743 | ||
744 | ret = event_agent_disable(usess, agt, aevent->name); | |
745 | if (ret != LTTNG_OK) { | |
b9866e08 | 746 | goto error_unlock; |
f20baf8e | 747 | } |
f20baf8e | 748 | } |
f20baf8e DG |
749 | ret = LTTNG_OK; |
750 | ||
b9866e08 JG |
751 | error_unlock: |
752 | rcu_read_unlock(); | |
f20baf8e DG |
753 | error: |
754 | return ret; | |
755 | } |