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, |
6938db9c | 72 | const 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 | { |
0ce9aa93 | 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, |
466fafb8 JG |
175 | (enum lttng_ust_loglevel_type) event->loglevel_type, |
176 | event->loglevel, exclusion); | |
87c6e328 | 177 | if (!uevent) { |
39687410 FD |
178 | ret = trace_ust_create_event(event, filter_expression, |
179 | filter, exclusion, internal_event, &uevent); | |
49d21f93 MD |
180 | /* We have passed ownership */ |
181 | filter_expression = NULL; | |
182 | filter = NULL; | |
183 | exclusion = NULL; | |
39687410 | 184 | if (ret != LTTNG_OK) { |
edb67388 DG |
185 | goto error; |
186 | } | |
025faf73 | 187 | |
fc34caaa | 188 | /* Valid to set it after the goto error since uevent is still NULL */ |
edb67388 DG |
189 | to_create = 1; |
190 | } | |
2bdd86d4 | 191 | |
7f79d3a1 DG |
192 | if (uevent->enabled) { |
193 | /* It's already enabled so everything is OK */ | |
39543064 | 194 | assert(!to_create); |
5bcdda4f | 195 | ret = LTTNG_ERR_UST_EVENT_ENABLED; |
7f79d3a1 DG |
196 | goto end; |
197 | } | |
198 | ||
fc34caaa | 199 | uevent->enabled = 1; |
0ce9aa93 JG |
200 | if (to_create) { |
201 | /* Add ltt ust event to channel */ | |
202 | add_unique_ust_event(uchan->events, uevent); | |
203 | } | |
204 | ||
205 | if (!usess->active) { | |
206 | goto end; | |
207 | } | |
fc34caaa | 208 | |
7972aab2 DG |
209 | if (to_create) { |
210 | /* Create event on all UST registered apps for session */ | |
211 | ret = ust_app_create_event_glb(usess, uchan, uevent); | |
212 | } else { | |
213 | /* Enable event on all UST registered apps for session */ | |
214 | ret = ust_app_enable_event_glb(usess, uchan, uevent); | |
215 | } | |
48842b30 | 216 | |
7972aab2 DG |
217 | if (ret < 0) { |
218 | if (ret == -LTTNG_UST_ERR_EXIST) { | |
219 | ret = LTTNG_ERR_UST_EVENT_EXIST; | |
220 | goto end; | |
221 | } else { | |
222 | ret = LTTNG_ERR_UST_ENABLE_FAIL; | |
223 | goto error; | |
edb67388 | 224 | } |
2bdd86d4 | 225 | } |
48842b30 | 226 | |
7f79d3a1 DG |
227 | DBG("Event UST %s %s in channel %s", uevent->attr.name, |
228 | to_create ? "created" : "enabled", uchan->name); | |
229 | ||
f73fabfd | 230 | ret = LTTNG_OK; |
fc34caaa | 231 | |
fb89d070 | 232 | end: |
18eace3b | 233 | rcu_read_unlock(); |
49d21f93 MD |
234 | free(filter_expression); |
235 | free(filter); | |
236 | free(exclusion); | |
fc34caaa | 237 | return ret; |
edb67388 DG |
238 | |
239 | error: | |
fc34caaa DG |
240 | /* |
241 | * Only destroy event on creation time (not enabling time) because if the | |
242 | * event is found in the channel (to_create == 0), it means that at some | |
243 | * point the enable_event worked and it's thus valid to keep it alive. | |
244 | * Destroying it also implies that we also destroy it's shadow copy to sync | |
245 | * everyone up. | |
246 | */ | |
247 | if (to_create) { | |
248 | /* In this code path, the uevent was not added to the hash table */ | |
249 | trace_ust_destroy_event(uevent); | |
250 | } | |
18eace3b | 251 | rcu_read_unlock(); |
49d21f93 MD |
252 | free(filter_expression); |
253 | free(filter); | |
254 | free(exclusion); | |
2bdd86d4 MD |
255 | return ret; |
256 | } | |
257 | ||
7f79d3a1 DG |
258 | /* |
259 | * Disable UST tracepoint of a channel from a UST session. | |
260 | */ | |
7972aab2 | 261 | int event_ust_disable_tracepoint(struct ltt_ust_session *usess, |
6938db9c | 262 | struct ltt_ust_channel *uchan, const char *event_name) |
2bdd86d4 MD |
263 | { |
264 | int ret; | |
7f79d3a1 | 265 | struct ltt_ust_event *uevent; |
18eace3b DG |
266 | struct lttng_ht_node_str *node; |
267 | struct lttng_ht_iter iter; | |
18eace3b | 268 | struct lttng_ht *ht; |
2bdd86d4 | 269 | |
0525e9ae DG |
270 | assert(usess); |
271 | assert(uchan); | |
272 | assert(event_name); | |
273 | ||
18eace3b DG |
274 | ht = uchan->events; |
275 | ||
18eace3b | 276 | rcu_read_lock(); |
025faf73 DG |
277 | |
278 | /* | |
279 | * We use a custom lookup since we need the iterator for the next_duplicate | |
280 | * call in the do while loop below. | |
281 | */ | |
282 | cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed), | |
283 | trace_ust_ht_match_event_by_name, event_name, &iter.iter); | |
18eace3b DG |
284 | node = lttng_ht_iter_get_node_str(&iter); |
285 | if (node == NULL) { | |
286 | DBG2("Trace UST event NOT found by name %s", event_name); | |
f73fabfd | 287 | ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; |
7f79d3a1 | 288 | goto error; |
2bdd86d4 | 289 | } |
7f79d3a1 | 290 | |
18eace3b DG |
291 | do { |
292 | uevent = caa_container_of(node, struct ltt_ust_event, node); | |
025faf73 DG |
293 | assert(uevent); |
294 | ||
18eace3b DG |
295 | if (uevent->enabled == 0) { |
296 | /* It's already disabled so everything is OK */ | |
a1dcaf0f | 297 | goto next; |
7f79d3a1 | 298 | } |
0ce9aa93 JG |
299 | uevent->enabled = 0; |
300 | DBG2("Event UST %s disabled in channel %s", uevent->attr.name, | |
301 | uchan->name); | |
18eace3b | 302 | |
0ce9aa93 JG |
303 | if (!usess->active) { |
304 | goto next; | |
305 | } | |
7972aab2 DG |
306 | ret = ust_app_disable_event_glb(usess, uchan, uevent); |
307 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { | |
308 | ret = LTTNG_ERR_UST_DISABLE_FAIL; | |
18eace3b DG |
309 | goto error; |
310 | } | |
a1dcaf0f | 311 | next: |
18eace3b DG |
312 | /* Get next duplicate event by name. */ |
313 | cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name, | |
314 | event_name, &iter.iter); | |
315 | node = lttng_ht_iter_get_node_str(&iter); | |
316 | } while (node); | |
7f79d3a1 | 317 | |
f73fabfd | 318 | ret = LTTNG_OK; |
7f79d3a1 | 319 | |
7f79d3a1 | 320 | error: |
18eace3b | 321 | rcu_read_unlock(); |
7f79d3a1 DG |
322 | return ret; |
323 | } | |
324 | ||
b1e7fe2d JR |
325 | /* |
326 | * Disable all UST tracepoints for a channel from a UST session. | |
327 | */ | |
328 | int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, | |
329 | struct ltt_ust_channel *uchan) | |
330 | { | |
3e81c0f2 | 331 | int ret, i, size, error = 0; |
b1e7fe2d JR |
332 | struct lttng_ht_iter iter; |
333 | struct ltt_ust_event *uevent = NULL; | |
334 | struct lttng_event *events = NULL; | |
335 | ||
336 | assert(usess); | |
337 | assert(uchan); | |
338 | ||
339 | rcu_read_lock(); | |
340 | ||
341 | /* Disabling existing events */ | |
342 | cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, | |
343 | node.node) { | |
344 | if (uevent->enabled == 1) { | |
345 | ret = event_ust_disable_tracepoint(usess, uchan, | |
346 | uevent->attr.name); | |
347 | if (ret < 0) { | |
3e81c0f2 | 348 | error = LTTNG_ERR_UST_DISABLE_FAIL; |
b1e7fe2d JR |
349 | continue; |
350 | } | |
351 | } | |
352 | } | |
353 | ||
354 | /* Get all UST available events */ | |
355 | size = ust_app_list_events(&events); | |
356 | if (size < 0) { | |
357 | ret = LTTNG_ERR_UST_LIST_FAIL; | |
358 | goto error; | |
359 | } | |
360 | ||
361 | for (i = 0; i < size; i++) { | |
362 | ret = event_ust_disable_tracepoint(usess, uchan, | |
363 | events[i].name); | |
3e81c0f2 | 364 | if (ret < 0) { |
b1e7fe2d | 365 | /* Continue to disable the rest... */ |
3e81c0f2 | 366 | error = LTTNG_ERR_UST_DISABLE_FAIL; |
b1e7fe2d JR |
367 | continue; |
368 | } | |
369 | } | |
370 | ||
3e81c0f2 | 371 | ret = error ? error : LTTNG_OK; |
b1e7fe2d JR |
372 | error: |
373 | rcu_read_unlock(); | |
374 | free(events); | |
375 | return ret; | |
376 | } | |
377 | ||
f20baf8e | 378 | /* |
022d91ba | 379 | * Enable all agent event for a given UST session. |
f20baf8e DG |
380 | * |
381 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
382 | */ | |
022d91ba | 383 | int event_agent_enable_all(struct ltt_ust_session *usess, |
fefd409b | 384 | struct agent *agt, struct lttng_event *event, |
51755dc8 | 385 | struct lttng_filter_bytecode *filter ,char *filter_expression) |
f20baf8e DG |
386 | { |
387 | int ret; | |
fefd409b | 388 | struct agent_event *aevent; |
f20baf8e DG |
389 | struct lttng_ht_iter iter; |
390 | ||
391 | assert(usess); | |
392 | ||
022d91ba | 393 | DBG("Event agent enabling ALL events for session %" PRIu64, usess->id); |
f20baf8e | 394 | |
022d91ba | 395 | /* Enable event on agent application through TCP socket. */ |
8404118c | 396 | ret = event_agent_enable(usess, agt, event, filter, filter_expression); |
f20baf8e DG |
397 | if (ret != LTTNG_OK) { |
398 | goto error; | |
399 | } | |
400 | ||
401 | /* Flag every event that they are now enabled. */ | |
402 | rcu_read_lock(); | |
fefd409b | 403 | cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent, |
f20baf8e | 404 | node.node) { |
fefd409b | 405 | aevent->enabled = 1; |
f20baf8e DG |
406 | } |
407 | rcu_read_unlock(); | |
408 | ||
409 | ret = LTTNG_OK; | |
410 | ||
411 | error: | |
412 | return ret; | |
413 | } | |
414 | ||
71a559f8 JG |
415 | /* |
416 | * Check if this event's filter requires the activation of application contexts | |
417 | * and enable them in the agent. | |
b4bc01f7 MD |
418 | * TODO: bytecode iterator does not support non-legacy application |
419 | * contexts yet. Not an issue for now, since they are not generated by | |
420 | * the lttng-ctl library. | |
71a559f8 JG |
421 | */ |
422 | static int add_filter_app_ctx(struct lttng_filter_bytecode *bytecode, | |
423 | const char *filter_expression, struct agent *agt) | |
424 | { | |
425 | int ret = LTTNG_OK; | |
426 | char *provider_name = NULL, *ctx_name = NULL; | |
427 | struct bytecode_symbol_iterator *it = | |
428 | bytecode_symbol_iterator_create(bytecode); | |
429 | ||
430 | if (!it) { | |
431 | ret = LTTNG_ERR_NOMEM; | |
432 | goto end; | |
433 | } | |
434 | ||
435 | do { | |
436 | struct lttng_event_context ctx; | |
437 | const char *symbol_name = | |
438 | bytecode_symbol_iterator_get_name(it); | |
439 | ||
440 | if (parse_application_context(symbol_name, &provider_name, | |
441 | &ctx_name)) { | |
442 | /* Not an application context. */ | |
443 | continue; | |
444 | } | |
445 | ||
446 | ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT; | |
447 | ctx.u.app_ctx.provider_name = provider_name; | |
448 | ctx.u.app_ctx.ctx_name = ctx_name; | |
449 | ||
450 | /* Recognized an application context. */ | |
451 | DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.", | |
452 | filter_expression, provider_name, ctx_name); | |
453 | ||
454 | ret = agent_add_context(&ctx, agt); | |
455 | if (ret != LTTNG_OK) { | |
456 | ERR("Failed to add application context %s:%s.", | |
457 | provider_name, ctx_name); | |
458 | goto end; | |
459 | } | |
460 | ||
461 | ret = agent_enable_context(&ctx, agt->domain); | |
462 | if (ret != LTTNG_OK) { | |
463 | ERR("Failed to enable application context %s:%s.", | |
464 | provider_name, ctx_name); | |
465 | goto end; | |
466 | } | |
467 | ||
468 | free(provider_name); | |
469 | free(ctx_name); | |
470 | provider_name = ctx_name = NULL; | |
471 | } while (bytecode_symbol_iterator_next(it) == 0); | |
472 | end: | |
473 | free(provider_name); | |
474 | free(ctx_name); | |
475 | bytecode_symbol_iterator_destroy(it); | |
476 | return ret; | |
477 | } | |
478 | ||
f20baf8e | 479 | /* |
022d91ba | 480 | * Enable a single agent event for a given UST session. |
f20baf8e DG |
481 | * |
482 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
483 | */ | |
fefd409b DG |
484 | int event_agent_enable(struct ltt_ust_session *usess, |
485 | struct agent *agt, struct lttng_event *event, | |
8404118c JG |
486 | struct lttng_filter_bytecode *filter, |
487 | char *filter_expression) | |
f20baf8e DG |
488 | { |
489 | int ret, created = 0; | |
fefd409b | 490 | struct agent_event *aevent; |
f20baf8e DG |
491 | |
492 | assert(usess); | |
493 | assert(event); | |
fefd409b | 494 | assert(agt); |
f20baf8e | 495 | |
022d91ba | 496 | DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d " |
51755dc8 JG |
497 | ", loglevel %d and filter \"%s\"", event->name, |
498 | usess->id, event->loglevel_type, event->loglevel, | |
499 | filter_expression ? filter_expression : "NULL"); | |
f20baf8e | 500 | |
a9319624 | 501 | aevent = agent_find_event(event->name, event->loglevel_type, |
71a559f8 | 502 | event->loglevel, filter_expression, agt); |
fefd409b | 503 | if (!aevent) { |
a9319624 PP |
504 | aevent = agent_create_event(event->name, event->loglevel_type, |
505 | event->loglevel, filter, | |
51755dc8 | 506 | filter_expression); |
fefd409b | 507 | if (!aevent) { |
f20baf8e DG |
508 | ret = LTTNG_ERR_NOMEM; |
509 | goto error; | |
510 | } | |
c3cf3d2b JG |
511 | filter = NULL; |
512 | filter_expression = NULL; | |
f20baf8e DG |
513 | created = 1; |
514 | } | |
515 | ||
71a559f8 JG |
516 | if (created && filter) { |
517 | ret = add_filter_app_ctx(filter, filter_expression, agt); | |
518 | if (ret != LTTNG_OK) { | |
519 | goto error; | |
520 | } | |
521 | } | |
522 | ||
0ce9aa93 JG |
523 | /* Already enabled? */ |
524 | if (aevent->enabled) { | |
525 | ret = LTTNG_OK; | |
526 | goto end; | |
527 | } | |
528 | ||
fefd409b | 529 | ret = agent_enable_event(aevent, agt->domain); |
f20baf8e DG |
530 | if (ret != LTTNG_OK) { |
531 | goto error; | |
532 | } | |
533 | ||
534 | /* If the event was created prior to the enable, add it to the domain. */ | |
535 | if (created) { | |
fefd409b | 536 | agent_add_event(aevent, agt); |
f20baf8e DG |
537 | } |
538 | ||
c3cf3d2b JG |
539 | ret = LTTNG_OK; |
540 | goto end; | |
f20baf8e DG |
541 | |
542 | error: | |
543 | if (created) { | |
fefd409b | 544 | agent_destroy_event(aevent); |
f20baf8e | 545 | } |
c3cf3d2b JG |
546 | end: |
547 | free(filter); | |
548 | free(filter_expression); | |
f20baf8e DG |
549 | return ret; |
550 | } | |
551 | ||
da6c3a50 | 552 | /* |
d1ec8e20 JG |
553 | * Return the default event name associated with the provided UST domain. Return |
554 | * NULL on error. | |
da6c3a50 DG |
555 | */ |
556 | const char *event_get_default_agent_ust_name(enum lttng_domain_type domain) | |
557 | { | |
558 | const char *default_event_name = NULL; | |
559 | ||
0e115563 DG |
560 | switch (domain) { |
561 | case LTTNG_DOMAIN_LOG4J: | |
d1ec8e20 | 562 | default_event_name = DEFAULT_LOG4J_EVENT_NAME; |
0e115563 DG |
563 | break; |
564 | case LTTNG_DOMAIN_JUL: | |
d1ec8e20 | 565 | default_event_name = DEFAULT_JUL_EVENT_NAME; |
0e115563 DG |
566 | break; |
567 | case LTTNG_DOMAIN_PYTHON: | |
e7c82272 | 568 | default_event_name = DEFAULT_PYTHON_EVENT_NAME; |
0e115563 DG |
569 | break; |
570 | default: | |
da6c3a50 DG |
571 | assert(0); |
572 | } | |
573 | ||
574 | return default_event_name; | |
575 | } | |
576 | ||
f20baf8e | 577 | /* |
e261a6cc | 578 | * Disable a given agent event for a given UST session. |
f20baf8e | 579 | * |
e261a6cc | 580 | * Must be called with the RCU read lock held. |
f20baf8e DG |
581 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. |
582 | */ | |
e261a6cc PP |
583 | static int event_agent_disable_one(struct ltt_ust_session *usess, |
584 | struct agent *agt, struct agent_event *aevent) | |
f20baf8e DG |
585 | { |
586 | int ret; | |
be6a6276 DG |
587 | struct ltt_ust_event *uevent = NULL; |
588 | struct ltt_ust_channel *uchan = NULL; | |
71aecbf8 | 589 | const char *ust_event_name, *ust_channel_name; |
f20baf8e | 590 | |
fefd409b | 591 | assert(agt); |
f20baf8e | 592 | assert(usess); |
e261a6cc | 593 | assert(aevent); |
f20baf8e | 594 | |
e261a6cc PP |
595 | DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64, |
596 | aevent->name, aevent->loglevel_type, aevent->loglevel_value, | |
597 | usess->id); | |
f20baf8e DG |
598 | |
599 | /* Already disabled? */ | |
fefd409b | 600 | if (!aevent->enabled) { |
f20baf8e DG |
601 | goto end; |
602 | } | |
603 | ||
71aecbf8 DG |
604 | if (agt->domain == LTTNG_DOMAIN_JUL) { |
605 | ust_channel_name = DEFAULT_JUL_CHANNEL_NAME; | |
606 | } else if (agt->domain == LTTNG_DOMAIN_LOG4J) { | |
607 | ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME; | |
0e115563 DG |
608 | } else if (agt->domain == LTTNG_DOMAIN_PYTHON) { |
609 | ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME; | |
71aecbf8 DG |
610 | } else { |
611 | ret = LTTNG_ERR_INVALID; | |
612 | goto error; | |
613 | } | |
614 | ||
be6a6276 DG |
615 | /* |
616 | * Disable it on the UST side. First get the channel reference then find | |
617 | * the event and finally disable it. | |
618 | */ | |
619 | uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, | |
71aecbf8 | 620 | (char *) ust_channel_name); |
be6a6276 DG |
621 | if (!uchan) { |
622 | ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; | |
623 | goto error; | |
624 | } | |
625 | ||
da6c3a50 DG |
626 | ust_event_name = event_get_default_agent_ust_name(agt->domain); |
627 | if (!ust_event_name) { | |
628 | ret = LTTNG_ERR_FATAL; | |
629 | goto error; | |
be6a6276 DG |
630 | } |
631 | ||
632 | /* | |
b953b8cd PP |
633 | * Agent UST event has its loglevel type forced to |
634 | * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering | |
635 | * happens thanks to an UST filter. The following -1 is actually | |
636 | * ignored since the type is LTTNG_UST_LOGLEVEL_ALL. | |
be6a6276 | 637 | */ |
da6c3a50 | 638 | uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name, |
b953b8cd | 639 | aevent->filter, LTTNG_UST_LOGLEVEL_ALL, -1, NULL); |
022d91ba | 640 | /* If the agent event exists, it must be available on the UST side. */ |
be6a6276 DG |
641 | assert(uevent); |
642 | ||
0ce9aa93 JG |
643 | if (usess->active) { |
644 | ret = ust_app_disable_event_glb(usess, uchan, uevent); | |
645 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { | |
646 | ret = LTTNG_ERR_UST_DISABLE_FAIL; | |
647 | goto error; | |
648 | } | |
be6a6276 DG |
649 | } |
650 | ||
0dcfcf94 DG |
651 | /* |
652 | * Flag event that it's disabled so the shadow copy on the ust app side | |
653 | * will disable it if an application shows up. | |
654 | */ | |
655 | uevent->enabled = 0; | |
656 | ||
fefd409b | 657 | ret = agent_disable_event(aevent, agt->domain); |
f20baf8e DG |
658 | if (ret != LTTNG_OK) { |
659 | goto error; | |
660 | } | |
661 | ||
662 | end: | |
663 | return LTTNG_OK; | |
664 | ||
665 | error: | |
666 | return ret; | |
667 | } | |
e261a6cc PP |
668 | |
669 | /* | |
670 | * Disable all agent events matching a given name for a given UST session. | |
671 | * | |
672 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
673 | */ | |
674 | int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, | |
6938db9c | 675 | const char *event_name) |
e261a6cc PP |
676 | { |
677 | int ret = LTTNG_OK; | |
678 | struct agent_event *aevent; | |
679 | struct lttng_ht_iter iter; | |
680 | struct lttng_ht_node_str *node; | |
681 | ||
682 | assert(agt); | |
683 | assert(usess); | |
684 | assert(event_name); | |
685 | ||
686 | DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id); | |
687 | ||
688 | rcu_read_lock(); | |
689 | agent_find_events_by_name(event_name, agt, &iter); | |
690 | node = lttng_ht_iter_get_node_str(&iter); | |
691 | ||
692 | if (node == NULL) { | |
693 | DBG2("Event agent NOT found by name %s", event_name); | |
694 | ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; | |
695 | goto end; | |
696 | } | |
697 | ||
698 | do { | |
699 | aevent = caa_container_of(node, struct agent_event, node); | |
700 | ret = event_agent_disable_one(usess, agt, aevent); | |
701 | ||
702 | if (ret != LTTNG_OK) { | |
703 | goto end; | |
704 | } | |
705 | ||
706 | /* Get next duplicate agent event by name. */ | |
707 | agent_event_next_duplicate(event_name, agt, &iter); | |
708 | node = lttng_ht_iter_get_node_str(&iter); | |
709 | } while (node); | |
710 | end: | |
711 | rcu_read_unlock(); | |
712 | return ret; | |
713 | } | |
f20baf8e | 714 | /* |
022d91ba | 715 | * Disable all agent event for a given UST session. |
f20baf8e DG |
716 | * |
717 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
718 | */ | |
fefd409b DG |
719 | int event_agent_disable_all(struct ltt_ust_session *usess, |
720 | struct agent *agt) | |
f20baf8e | 721 | { |
0dcfcf94 | 722 | int ret; |
fefd409b | 723 | struct agent_event *aevent; |
f20baf8e DG |
724 | struct lttng_ht_iter iter; |
725 | ||
fefd409b | 726 | assert(agt); |
f20baf8e DG |
727 | assert(usess); |
728 | ||
0dcfcf94 DG |
729 | /* |
730 | * Disable event on agent application. Continue to disable all other events | |
731 | * if the * event is not found. | |
732 | */ | |
fefd409b | 733 | ret = event_agent_disable(usess, agt, "*"); |
0dcfcf94 DG |
734 | if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) { |
735 | goto error; | |
f20baf8e DG |
736 | } |
737 | ||
b9866e08 | 738 | /* Disable every event. */ |
f20baf8e | 739 | rcu_read_lock(); |
fefd409b | 740 | cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent, |
f20baf8e | 741 | node.node) { |
0dcfcf94 DG |
742 | if (!aevent->enabled) { |
743 | continue; | |
744 | } | |
745 | ||
746 | ret = event_agent_disable(usess, agt, aevent->name); | |
747 | if (ret != LTTNG_OK) { | |
b9866e08 | 748 | goto error_unlock; |
f20baf8e | 749 | } |
f20baf8e | 750 | } |
f20baf8e DG |
751 | ret = LTTNG_OK; |
752 | ||
b9866e08 JG |
753 | error_unlock: |
754 | rcu_read_unlock(); | |
f20baf8e DG |
755 | error: |
756 | return ret; | |
757 | } |