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