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 |
d87bfb32 | 19 | #include <errno.h> |
54d01ffb | 20 | #include <urcu/list.h> |
2bdd86d4 | 21 | #include <string.h> |
54d01ffb DG |
22 | |
23 | #include <lttng/lttng.h> | |
db758600 | 24 | #include <common/error.h> |
10a8a223 | 25 | #include <common/sessiond-comm/sessiond-comm.h> |
54d01ffb DG |
26 | |
27 | #include "channel.h" | |
28 | #include "event.h" | |
4771f025 | 29 | #include "kernel.h" |
7923a38c | 30 | #include "lttng-sessiond.h" |
9df8df5e | 31 | #include "ust-ctl.h" |
edb67388 DG |
32 | #include "ust-app.h" |
33 | #include "trace-kernel.h" | |
34 | #include "trace-ust.h" | |
54d01ffb | 35 | |
025faf73 DG |
36 | /* |
37 | * Add unique UST event based on the event name, filter bytecode and loglevel. | |
38 | */ | |
18eace3b DG |
39 | static void add_unique_ust_event(struct lttng_ht *ht, |
40 | struct ltt_ust_event *event) | |
41 | { | |
42 | struct cds_lfht_node *node_ptr; | |
43 | struct ltt_ust_ht_key key; | |
44 | ||
45 | assert(ht); | |
46 | assert(ht->ht); | |
47 | assert(event); | |
48 | ||
49 | key.name = event->attr.name; | |
50 | key.filter = (struct lttng_filter_bytecode *) event->filter; | |
51 | key.loglevel = event->attr.loglevel; | |
4031e53e | 52 | key.exclusion = event->exclusion; |
18eace3b DG |
53 | |
54 | node_ptr = cds_lfht_add_unique(ht->ht, | |
55 | ht->hash_fct(event->node.key, lttng_ht_seed), | |
56 | trace_ust_ht_match_event, &key, &event->node.node); | |
57 | assert(node_ptr == &event->node.node); | |
58 | } | |
59 | ||
8c9ae521 DG |
60 | /* |
61 | * Setup a lttng_event used to enable *all* syscall tracing. | |
62 | */ | |
63 | static void init_syscalls_kernel_event(struct lttng_event *event) | |
64 | { | |
0525e9ae DG |
65 | assert(event); |
66 | ||
8c9ae521 DG |
67 | event->name[0] = '\0'; |
68 | /* | |
69 | * We use LTTNG_EVENT* here since the trace kernel creation will make the | |
70 | * right changes for the kernel. | |
71 | */ | |
72 | event->type = LTTNG_EVENT_SYSCALL; | |
73 | } | |
74 | ||
54d01ffb | 75 | /* |
7a3d1328 | 76 | * Disable kernel tracepoint event for a channel from the kernel session. |
54d01ffb | 77 | */ |
d3a56674 DG |
78 | int event_kernel_disable_tracepoint(struct ltt_kernel_channel *kchan, |
79 | char *event_name) | |
54d01ffb DG |
80 | { |
81 | int ret; | |
82 | struct ltt_kernel_event *kevent; | |
83 | ||
0525e9ae DG |
84 | assert(kchan); |
85 | ||
54d01ffb DG |
86 | kevent = trace_kernel_get_event_by_name(event_name, kchan); |
87 | if (kevent == NULL) { | |
f73fabfd | 88 | ret = LTTNG_ERR_NO_EVENT; |
54d01ffb DG |
89 | goto error; |
90 | } | |
91 | ||
92 | ret = kernel_disable_event(kevent); | |
93 | if (ret < 0) { | |
f73fabfd | 94 | ret = LTTNG_ERR_KERN_DISABLE_FAIL; |
54d01ffb DG |
95 | goto error; |
96 | } | |
97 | ||
98 | DBG("Kernel event %s disable for channel %s.", | |
99 | kevent->event->name, kchan->channel->name); | |
100 | ||
f73fabfd | 101 | ret = LTTNG_OK; |
54d01ffb DG |
102 | |
103 | error: | |
104 | return ret; | |
105 | } | |
106 | ||
107 | /* | |
7a3d1328 | 108 | * Disable kernel tracepoint events for a channel from the kernel session. |
54d01ffb | 109 | */ |
d3a56674 | 110 | int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan) |
54d01ffb DG |
111 | { |
112 | int ret; | |
113 | struct ltt_kernel_event *kevent; | |
114 | ||
0525e9ae DG |
115 | assert(kchan); |
116 | ||
54d01ffb DG |
117 | /* For each event in the kernel session */ |
118 | cds_list_for_each_entry(kevent, &kchan->events_list.head, list) { | |
119 | ret = kernel_disable_event(kevent); | |
120 | if (ret < 0) { | |
121 | /* We continue disabling the rest */ | |
122 | continue; | |
123 | } | |
124 | } | |
f73fabfd | 125 | ret = LTTNG_OK; |
7a3d1328 MD |
126 | return ret; |
127 | } | |
128 | ||
129 | /* | |
130 | * Disable kernel syscall events for a channel from the kernel session. | |
131 | */ | |
d3a56674 | 132 | int event_kernel_disable_all_syscalls(struct ltt_kernel_channel *kchan) |
7a3d1328 MD |
133 | { |
134 | ERR("Cannot disable syscall tracing for existing session. Please destroy session instead."); | |
f73fabfd | 135 | return LTTNG_OK; /* Return OK so disable all succeeds */ |
7a3d1328 | 136 | } |
54d01ffb | 137 | |
7a3d1328 MD |
138 | /* |
139 | * Disable all kernel event for a channel from the kernel session. | |
140 | */ | |
d3a56674 | 141 | int event_kernel_disable_all(struct ltt_kernel_channel *kchan) |
7a3d1328 MD |
142 | { |
143 | int ret; | |
144 | ||
0525e9ae DG |
145 | assert(kchan); |
146 | ||
d3a56674 | 147 | ret = event_kernel_disable_all_tracepoints(kchan); |
f73fabfd | 148 | if (ret != LTTNG_OK) |
7a3d1328 | 149 | return ret; |
d3a56674 | 150 | ret = event_kernel_disable_all_syscalls(kchan); |
54d01ffb DG |
151 | return ret; |
152 | } | |
153 | ||
154 | /* | |
7a3d1328 | 155 | * Enable kernel tracepoint event for a channel from the kernel session. |
54d01ffb | 156 | */ |
d3a56674 DG |
157 | int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan, |
158 | struct lttng_event *event) | |
54d01ffb DG |
159 | { |
160 | int ret; | |
161 | struct ltt_kernel_event *kevent; | |
162 | ||
0525e9ae DG |
163 | assert(kchan); |
164 | assert(event); | |
165 | ||
54d01ffb DG |
166 | kevent = trace_kernel_get_event_by_name(event->name, kchan); |
167 | if (kevent == NULL) { | |
168 | ret = kernel_create_event(event, kchan); | |
169 | if (ret < 0) { | |
bd29c13d DG |
170 | switch (-ret) { |
171 | case EEXIST: | |
f73fabfd | 172 | ret = LTTNG_ERR_KERN_EVENT_EXIST; |
bd29c13d DG |
173 | break; |
174 | case ENOSYS: | |
f73fabfd | 175 | ret = LTTNG_ERR_KERN_EVENT_ENOSYS; |
bd29c13d DG |
176 | break; |
177 | default: | |
f73fabfd | 178 | ret = LTTNG_ERR_KERN_ENABLE_FAIL; |
bd29c13d | 179 | break; |
d87bfb32 | 180 | } |
7a3d1328 | 181 | goto end; |
54d01ffb DG |
182 | } |
183 | } else if (kevent->enabled == 0) { | |
184 | ret = kernel_enable_event(kevent); | |
185 | if (ret < 0) { | |
f73fabfd | 186 | ret = LTTNG_ERR_KERN_ENABLE_FAIL; |
7a3d1328 | 187 | goto end; |
54d01ffb | 188 | } |
42224349 DG |
189 | } else { |
190 | /* At this point, the event is considered enabled */ | |
f73fabfd | 191 | ret = LTTNG_ERR_KERN_EVENT_EXIST; |
42224349 | 192 | goto end; |
54d01ffb | 193 | } |
42224349 | 194 | |
f73fabfd | 195 | ret = LTTNG_OK; |
7a3d1328 | 196 | end: |
54d01ffb DG |
197 | return ret; |
198 | } | |
199 | ||
200 | /* | |
7a3d1328 | 201 | * Enable all kernel tracepoint events of a channel of the kernel session. |
54d01ffb | 202 | */ |
d3a56674 DG |
203 | int event_kernel_enable_all_tracepoints(struct ltt_kernel_channel *kchan, |
204 | int kernel_tracer_fd) | |
54d01ffb DG |
205 | { |
206 | int size, i, ret; | |
207 | struct ltt_kernel_event *kevent; | |
8f69e5eb | 208 | struct lttng_event *event_list = NULL; |
54d01ffb | 209 | |
0525e9ae DG |
210 | assert(kchan); |
211 | ||
54d01ffb DG |
212 | /* For each event in the kernel session */ |
213 | cds_list_for_each_entry(kevent, &kchan->events_list.head, list) { | |
8f69e5eb DG |
214 | if (kevent->enabled == 0) { |
215 | ret = kernel_enable_event(kevent); | |
216 | if (ret < 0) { | |
217 | /* Enable failed but still continue */ | |
218 | continue; | |
219 | } | |
54d01ffb DG |
220 | } |
221 | } | |
222 | ||
223 | size = kernel_list_events(kernel_tracer_fd, &event_list); | |
224 | if (size < 0) { | |
f73fabfd | 225 | ret = LTTNG_ERR_KERN_LIST_FAIL; |
7a3d1328 | 226 | goto end; |
54d01ffb DG |
227 | } |
228 | ||
229 | for (i = 0; i < size; i++) { | |
230 | kevent = trace_kernel_get_event_by_name(event_list[i].name, kchan); | |
231 | if (kevent == NULL) { | |
232 | /* Default event type for enable all */ | |
233 | event_list[i].type = LTTNG_EVENT_TRACEPOINT; | |
234 | /* Enable each single tracepoint event */ | |
235 | ret = kernel_create_event(&event_list[i], kchan); | |
236 | if (ret < 0) { | |
237 | /* Ignore error here and continue */ | |
238 | } | |
239 | } | |
240 | } | |
54d01ffb | 241 | free(event_list); |
8f69e5eb | 242 | |
f73fabfd | 243 | ret = LTTNG_OK; |
7a3d1328 | 244 | end: |
54d01ffb DG |
245 | return ret; |
246 | } | |
8c9ae521 DG |
247 | |
248 | /* | |
8b037137 | 249 | * Enable all kernel sycalls events of a channel of the kernel session. |
8c9ae521 | 250 | */ |
d3a56674 DG |
251 | int event_kernel_enable_all_syscalls(struct ltt_kernel_channel *kchan, |
252 | int kernel_tracer_fd) | |
8c9ae521 DG |
253 | { |
254 | int ret; | |
255 | struct lttng_event event; | |
256 | ||
0525e9ae DG |
257 | assert(kchan); |
258 | ||
8c9ae521 DG |
259 | init_syscalls_kernel_event(&event); |
260 | ||
261 | DBG("Enabling all syscall tracing"); | |
262 | ||
263 | ret = kernel_create_event(&event, kchan); | |
264 | if (ret < 0) { | |
8f69e5eb | 265 | if (ret == -EEXIST) { |
f73fabfd | 266 | ret = LTTNG_ERR_KERN_EVENT_EXIST; |
8f69e5eb | 267 | } else { |
f73fabfd | 268 | ret = LTTNG_ERR_KERN_ENABLE_FAIL; |
8f69e5eb | 269 | } |
7a3d1328 | 270 | goto end; |
8c9ae521 | 271 | } |
8f69e5eb | 272 | |
f73fabfd | 273 | ret = LTTNG_OK; |
7a3d1328 MD |
274 | end: |
275 | return ret; | |
276 | } | |
8c9ae521 | 277 | |
7a3d1328 MD |
278 | /* |
279 | * Enable all kernel events of a channel of the kernel session. | |
280 | */ | |
d3a56674 DG |
281 | int event_kernel_enable_all(struct ltt_kernel_channel *kchan, |
282 | int kernel_tracer_fd) | |
7a3d1328 | 283 | { |
6bd8707a | 284 | int tp_ret; |
7a3d1328 | 285 | |
0525e9ae DG |
286 | assert(kchan); |
287 | ||
d3a56674 | 288 | tp_ret = event_kernel_enable_all_tracepoints(kchan, kernel_tracer_fd); |
f73fabfd | 289 | if (tp_ret != LTTNG_OK) { |
7a3d1328 MD |
290 | goto end; |
291 | } | |
bd29c13d DG |
292 | |
293 | /* | |
294 | * Reaching this code path means that all tracepoints were enabled without | |
295 | * errors so we ignore the error value of syscalls. | |
296 | * | |
297 | * At the moment, failing to enable syscalls on "lttng enable-event -a -k" | |
298 | * is not considered an error that need to be returned to the client since | |
299 | * tracepoints did not fail. Future work will allow us to send back | |
300 | * multiple errors to the client in one API call. | |
301 | */ | |
d3a56674 | 302 | (void) event_kernel_enable_all_syscalls(kchan, kernel_tracer_fd); |
bd29c13d | 303 | |
7a3d1328 | 304 | end: |
bd29c13d | 305 | return tp_ret; |
8c9ae521 | 306 | } |
2bdd86d4 | 307 | |
7f79d3a1 DG |
308 | /* |
309 | * ============================ | |
310 | * UST : The Ultimate Frontier! | |
311 | * ============================ | |
312 | */ | |
313 | ||
76d45b40 DG |
314 | /* |
315 | * Enable all UST tracepoints for a channel from a UST session. | |
316 | */ | |
7972aab2 | 317 | int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess, |
6b453b5e JG |
318 | struct ltt_ust_channel *uchan, |
319 | char *filter_expression, | |
320 | struct lttng_filter_bytecode *filter) | |
76d45b40 | 321 | { |
6775595e | 322 | int ret, i, size; |
bec39940 | 323 | struct lttng_ht_iter iter; |
76d45b40 | 324 | struct ltt_ust_event *uevent = NULL; |
7f79d3a1 | 325 | struct lttng_event *events = NULL; |
76d45b40 | 326 | |
0525e9ae DG |
327 | assert(usess); |
328 | assert(uchan); | |
329 | ||
025faf73 DG |
330 | rcu_read_lock(); |
331 | ||
7972aab2 DG |
332 | /* Enable existing events */ |
333 | cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, | |
334 | node.node) { | |
335 | if (uevent->enabled == 0) { | |
336 | ret = ust_app_enable_event_glb(usess, uchan, uevent); | |
337 | if (ret < 0) { | |
76d45b40 DG |
338 | continue; |
339 | } | |
7972aab2 DG |
340 | uevent->enabled = 1; |
341 | } | |
342 | } | |
76d45b40 | 343 | |
7972aab2 DG |
344 | /* Get all UST available events */ |
345 | size = ust_app_list_events(&events); | |
346 | if (size < 0) { | |
347 | ret = LTTNG_ERR_UST_LIST_FAIL; | |
348 | goto error; | |
349 | } | |
76d45b40 | 350 | |
7972aab2 DG |
351 | for (i = 0; i < size; i++) { |
352 | /* | |
353 | * Check if event exist and if so, continue since it was enable | |
354 | * previously. | |
355 | */ | |
356 | uevent = trace_ust_find_event(uchan->events, events[i].name, filter, | |
10646003 | 357 | events[i].loglevel, NULL); |
7972aab2 | 358 | if (uevent != NULL) { |
76d45b40 DG |
359 | ret = ust_app_enable_event_pid(usess, uchan, uevent, |
360 | events[i].pid); | |
361 | if (ret < 0) { | |
7972aab2 | 362 | if (ret != -LTTNG_UST_ERR_EXIST) { |
f73fabfd | 363 | ret = LTTNG_ERR_UST_ENABLE_FAIL; |
7972aab2 | 364 | goto error; |
76d45b40 | 365 | } |
76d45b40 | 366 | } |
7972aab2 DG |
367 | continue; |
368 | } | |
76d45b40 | 369 | |
7972aab2 | 370 | /* Create ust event */ |
6b453b5e JG |
371 | uevent = trace_ust_create_event(&events[i], filter_expression, |
372 | filter, NULL); | |
7972aab2 DG |
373 | if (uevent == NULL) { |
374 | ret = LTTNG_ERR_FATAL; | |
375 | goto error_destroy; | |
76d45b40 DG |
376 | } |
377 | ||
7972aab2 DG |
378 | /* Create event for the specific PID */ |
379 | ret = ust_app_enable_event_pid(usess, uchan, uevent, | |
380 | events[i].pid); | |
381 | if (ret < 0) { | |
382 | if (ret == -LTTNG_UST_ERR_EXIST) { | |
383 | ret = LTTNG_ERR_UST_EVENT_EXIST; | |
384 | goto error; | |
385 | } else { | |
386 | ret = LTTNG_ERR_UST_ENABLE_FAIL; | |
387 | goto error_destroy; | |
388 | } | |
389 | } | |
390 | ||
391 | uevent->enabled = 1; | |
392 | /* Add ltt ust event to channel */ | |
393 | rcu_read_lock(); | |
394 | add_unique_ust_event(uchan->events, uevent); | |
395 | rcu_read_unlock(); | |
76d45b40 | 396 | } |
7972aab2 | 397 | free(events); |
76d45b40 | 398 | |
025faf73 | 399 | rcu_read_unlock(); |
f73fabfd | 400 | return LTTNG_OK; |
76d45b40 | 401 | |
7f79d3a1 | 402 | error_destroy: |
76d45b40 | 403 | trace_ust_destroy_event(uevent); |
7f79d3a1 DG |
404 | |
405 | error: | |
406 | free(events); | |
025faf73 | 407 | rcu_read_unlock(); |
76d45b40 DG |
408 | return ret; |
409 | } | |
410 | ||
2bdd86d4 MD |
411 | /* |
412 | * Enable UST tracepoint event for a channel from a UST session. | |
413 | */ | |
7972aab2 | 414 | int event_ust_enable_tracepoint(struct ltt_ust_session *usess, |
025faf73 | 415 | struct ltt_ust_channel *uchan, struct lttng_event *event, |
6b453b5e | 416 | char *filter_expression, |
f1613f52 JI |
417 | struct lttng_filter_bytecode *filter, |
418 | struct lttng_event_exclusion *exclusion) | |
2bdd86d4 | 419 | { |
f73fabfd | 420 | int ret = LTTNG_OK, to_create = 0; |
edb67388 DG |
421 | struct ltt_ust_event *uevent; |
422 | ||
0525e9ae DG |
423 | assert(usess); |
424 | assert(uchan); | |
425 | assert(event); | |
426 | ||
18eace3b DG |
427 | rcu_read_lock(); |
428 | ||
025faf73 | 429 | uevent = trace_ust_find_event(uchan->events, event->name, filter, |
10646003 | 430 | event->loglevel, exclusion); |
edb67388 | 431 | if (uevent == NULL) { |
6b453b5e JG |
432 | uevent = trace_ust_create_event(event, filter_expression, |
433 | filter, exclusion); | |
edb67388 | 434 | if (uevent == NULL) { |
95a82664 | 435 | ret = LTTNG_ERR_UST_ENABLE_FAIL; |
edb67388 DG |
436 | goto error; |
437 | } | |
025faf73 | 438 | |
fc34caaa | 439 | /* Valid to set it after the goto error since uevent is still NULL */ |
edb67388 DG |
440 | to_create = 1; |
441 | } | |
2bdd86d4 | 442 | |
7f79d3a1 DG |
443 | if (uevent->enabled) { |
444 | /* It's already enabled so everything is OK */ | |
5bcdda4f | 445 | ret = LTTNG_ERR_UST_EVENT_ENABLED; |
7f79d3a1 DG |
446 | goto end; |
447 | } | |
448 | ||
fc34caaa DG |
449 | uevent->enabled = 1; |
450 | ||
7972aab2 DG |
451 | if (to_create) { |
452 | /* Create event on all UST registered apps for session */ | |
453 | ret = ust_app_create_event_glb(usess, uchan, uevent); | |
454 | } else { | |
455 | /* Enable event on all UST registered apps for session */ | |
456 | ret = ust_app_enable_event_glb(usess, uchan, uevent); | |
457 | } | |
48842b30 | 458 | |
7972aab2 DG |
459 | if (ret < 0) { |
460 | if (ret == -LTTNG_UST_ERR_EXIST) { | |
461 | ret = LTTNG_ERR_UST_EVENT_EXIST; | |
462 | goto end; | |
463 | } else { | |
464 | ret = LTTNG_ERR_UST_ENABLE_FAIL; | |
465 | goto error; | |
edb67388 | 466 | } |
2bdd86d4 | 467 | } |
48842b30 | 468 | |
7f79d3a1 | 469 | if (to_create) { |
fc34caaa | 470 | /* Add ltt ust event to channel */ |
18eace3b | 471 | add_unique_ust_event(uchan->events, uevent); |
7f79d3a1 | 472 | } |
edb67388 | 473 | |
7f79d3a1 DG |
474 | DBG("Event UST %s %s in channel %s", uevent->attr.name, |
475 | to_create ? "created" : "enabled", uchan->name); | |
476 | ||
f73fabfd | 477 | ret = LTTNG_OK; |
fc34caaa | 478 | |
fb89d070 | 479 | end: |
18eace3b | 480 | rcu_read_unlock(); |
fc34caaa | 481 | return ret; |
edb67388 DG |
482 | |
483 | error: | |
fc34caaa DG |
484 | /* |
485 | * Only destroy event on creation time (not enabling time) because if the | |
486 | * event is found in the channel (to_create == 0), it means that at some | |
487 | * point the enable_event worked and it's thus valid to keep it alive. | |
488 | * Destroying it also implies that we also destroy it's shadow copy to sync | |
489 | * everyone up. | |
490 | */ | |
491 | if (to_create) { | |
492 | /* In this code path, the uevent was not added to the hash table */ | |
493 | trace_ust_destroy_event(uevent); | |
494 | } | |
18eace3b | 495 | rcu_read_unlock(); |
2bdd86d4 MD |
496 | return ret; |
497 | } | |
498 | ||
7f79d3a1 DG |
499 | /* |
500 | * Disable UST tracepoint of a channel from a UST session. | |
501 | */ | |
7972aab2 | 502 | int event_ust_disable_tracepoint(struct ltt_ust_session *usess, |
7f79d3a1 | 503 | struct ltt_ust_channel *uchan, char *event_name) |
2bdd86d4 MD |
504 | { |
505 | int ret; | |
7f79d3a1 | 506 | struct ltt_ust_event *uevent; |
18eace3b DG |
507 | struct lttng_ht_node_str *node; |
508 | struct lttng_ht_iter iter; | |
18eace3b | 509 | struct lttng_ht *ht; |
2bdd86d4 | 510 | |
0525e9ae DG |
511 | assert(usess); |
512 | assert(uchan); | |
513 | assert(event_name); | |
514 | ||
18eace3b DG |
515 | ht = uchan->events; |
516 | ||
18eace3b | 517 | rcu_read_lock(); |
025faf73 DG |
518 | |
519 | /* | |
520 | * We use a custom lookup since we need the iterator for the next_duplicate | |
521 | * call in the do while loop below. | |
522 | */ | |
523 | cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed), | |
524 | trace_ust_ht_match_event_by_name, event_name, &iter.iter); | |
18eace3b DG |
525 | node = lttng_ht_iter_get_node_str(&iter); |
526 | if (node == NULL) { | |
527 | DBG2("Trace UST event NOT found by name %s", event_name); | |
f73fabfd | 528 | ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; |
7f79d3a1 | 529 | goto error; |
2bdd86d4 | 530 | } |
7f79d3a1 | 531 | |
18eace3b DG |
532 | do { |
533 | uevent = caa_container_of(node, struct ltt_ust_event, node); | |
025faf73 DG |
534 | assert(uevent); |
535 | ||
18eace3b DG |
536 | if (uevent->enabled == 0) { |
537 | /* It's already disabled so everything is OK */ | |
a1dcaf0f | 538 | goto next; |
7f79d3a1 | 539 | } |
18eace3b | 540 | |
7972aab2 DG |
541 | ret = ust_app_disable_event_glb(usess, uchan, uevent); |
542 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { | |
543 | ret = LTTNG_ERR_UST_DISABLE_FAIL; | |
18eace3b DG |
544 | goto error; |
545 | } | |
18eace3b DG |
546 | uevent->enabled = 0; |
547 | ||
025faf73 DG |
548 | DBG2("Event UST %s disabled in channel %s", uevent->attr.name, |
549 | uchan->name); | |
550 | ||
a1dcaf0f | 551 | next: |
18eace3b DG |
552 | /* Get next duplicate event by name. */ |
553 | cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name, | |
554 | event_name, &iter.iter); | |
555 | node = lttng_ht_iter_get_node_str(&iter); | |
556 | } while (node); | |
7f79d3a1 | 557 | |
f73fabfd | 558 | ret = LTTNG_OK; |
7f79d3a1 | 559 | |
7f79d3a1 | 560 | error: |
18eace3b | 561 | rcu_read_unlock(); |
7f79d3a1 DG |
562 | return ret; |
563 | } | |
564 | ||
565 | /* | |
566 | * Disable all UST tracepoints for a channel from a UST session. | |
567 | */ | |
7972aab2 | 568 | int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, |
7f79d3a1 DG |
569 | struct ltt_ust_channel *uchan) |
570 | { | |
6775595e | 571 | int ret, i, size; |
bec39940 | 572 | struct lttng_ht_iter iter; |
7f79d3a1 DG |
573 | struct ltt_ust_event *uevent = NULL; |
574 | struct lttng_event *events = NULL; | |
575 | ||
0525e9ae DG |
576 | assert(usess); |
577 | assert(uchan); | |
578 | ||
025faf73 DG |
579 | rcu_read_lock(); |
580 | ||
7972aab2 DG |
581 | /* Disabling existing events */ |
582 | cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, | |
583 | node.node) { | |
584 | if (uevent->enabled == 1) { | |
585 | ret = event_ust_disable_tracepoint(usess, uchan, | |
586 | uevent->attr.name); | |
587 | if (ret < 0) { | |
7f79d3a1 DG |
588 | continue; |
589 | } | |
590 | } | |
7f79d3a1 | 591 | } |
7972aab2 DG |
592 | |
593 | /* Get all UST available events */ | |
594 | size = ust_app_list_events(&events); | |
595 | if (size < 0) { | |
596 | ret = LTTNG_ERR_UST_LIST_FAIL; | |
7f79d3a1 DG |
597 | goto error; |
598 | } | |
599 | ||
7972aab2 DG |
600 | for (i = 0; i < size; i++) { |
601 | ret = event_ust_disable_tracepoint(usess, uchan, | |
602 | events[i].name); | |
603 | if (ret != LTTNG_OK) { | |
604 | /* Continue to disable the rest... */ | |
605 | continue; | |
606 | } | |
607 | } | |
608 | free(events); | |
609 | ||
025faf73 | 610 | rcu_read_unlock(); |
f73fabfd | 611 | return LTTNG_OK; |
7f79d3a1 DG |
612 | |
613 | error: | |
614 | free(events); | |
025faf73 | 615 | rcu_read_unlock(); |
2bdd86d4 MD |
616 | return ret; |
617 | } | |
f20baf8e DG |
618 | |
619 | /* | |
620 | * Enable all JUL event for a given UST session. | |
621 | * | |
622 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
623 | */ | |
b2064f54 | 624 | int event_jul_enable_all(struct ltt_ust_session *usess, |
7923a38c | 625 | struct lttng_event *event, struct lttng_filter_bytecode *filter) |
f20baf8e DG |
626 | { |
627 | int ret; | |
628 | struct jul_event *jevent; | |
f20baf8e DG |
629 | struct lttng_ht_iter iter; |
630 | ||
631 | assert(usess); | |
632 | ||
633 | DBG("Event JUL enabling ALL events for session %" PRIu64, usess->id); | |
634 | ||
f20baf8e | 635 | /* Enable event on JUL application through TCP socket. */ |
7923a38c | 636 | ret = event_jul_enable(usess, event, filter); |
f20baf8e DG |
637 | if (ret != LTTNG_OK) { |
638 | goto error; | |
639 | } | |
640 | ||
641 | /* Flag every event that they are now enabled. */ | |
642 | rcu_read_lock(); | |
643 | cds_lfht_for_each_entry(usess->domain_jul.events->ht, &iter.iter, jevent, | |
644 | node.node) { | |
645 | jevent->enabled = 1; | |
646 | } | |
647 | rcu_read_unlock(); | |
648 | ||
649 | ret = LTTNG_OK; | |
650 | ||
651 | error: | |
652 | return ret; | |
653 | } | |
654 | ||
655 | /* | |
656 | * Enable a single JUL event for a given UST session. | |
657 | * | |
658 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
659 | */ | |
7923a38c DG |
660 | int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event, |
661 | struct lttng_filter_bytecode *filter) | |
f20baf8e DG |
662 | { |
663 | int ret, created = 0; | |
664 | struct jul_event *jevent; | |
665 | ||
666 | assert(usess); | |
667 | assert(event); | |
668 | ||
b2064f54 DG |
669 | DBG("Event JUL enabling %s for session %" PRIu64 " with loglevel type %d " |
670 | "and loglevel %d", event->name, usess->id, event->loglevel_type, | |
671 | event->loglevel); | |
f20baf8e | 672 | |
4a4ab2c3 | 673 | jevent = jul_find_event(event->name, event->loglevel, &usess->domain_jul); |
f20baf8e | 674 | if (!jevent) { |
7923a38c | 675 | jevent = jul_create_event(event->name, filter); |
f20baf8e DG |
676 | if (!jevent) { |
677 | ret = LTTNG_ERR_NOMEM; | |
678 | goto error; | |
679 | } | |
b2064f54 DG |
680 | jevent->loglevel = event->loglevel; |
681 | jevent->loglevel_type = event->loglevel_type; | |
f20baf8e DG |
682 | created = 1; |
683 | } | |
684 | ||
685 | /* Already enabled? */ | |
686 | if (jevent->enabled) { | |
687 | goto end; | |
688 | } | |
689 | ||
690 | ret = jul_enable_event(jevent); | |
691 | if (ret != LTTNG_OK) { | |
692 | goto error; | |
693 | } | |
694 | ||
695 | /* If the event was created prior to the enable, add it to the domain. */ | |
696 | if (created) { | |
697 | jul_add_event(jevent, &usess->domain_jul); | |
698 | } | |
699 | ||
700 | end: | |
701 | return LTTNG_OK; | |
702 | ||
703 | error: | |
704 | if (created) { | |
705 | jul_destroy_event(jevent); | |
706 | } | |
707 | return ret; | |
708 | } | |
709 | ||
710 | /* | |
711 | * Disable a single JUL event for a given UST session. | |
712 | * | |
713 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
714 | */ | |
715 | int event_jul_disable(struct ltt_ust_session *usess, char *event_name) | |
716 | { | |
717 | int ret; | |
718 | struct jul_event *jevent; | |
7923a38c DG |
719 | struct ltt_ust_event *uevent = NULL; |
720 | struct ltt_ust_channel *uchan = NULL; | |
721 | char *ust_event_name; | |
f20baf8e DG |
722 | |
723 | assert(usess); | |
724 | assert(event_name); | |
725 | ||
726 | DBG("Event JUL disabling %s for session %" PRIu64, event_name, usess->id); | |
727 | ||
4a4ab2c3 | 728 | jevent = jul_find_event_by_name(event_name, &usess->domain_jul); |
f20baf8e DG |
729 | if (!jevent) { |
730 | ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; | |
731 | goto error; | |
732 | } | |
733 | ||
734 | /* Already disabled? */ | |
735 | if (!jevent->enabled) { | |
736 | goto end; | |
737 | } | |
738 | ||
7923a38c DG |
739 | /* |
740 | * Disable it on the UST side. First get the channel reference then find | |
741 | * the event and finally disable it. | |
742 | */ | |
743 | uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, | |
744 | DEFAULT_JUL_CHANNEL_NAME); | |
745 | if (!uchan) { | |
746 | ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; | |
747 | goto error; | |
748 | } | |
749 | ||
750 | if (is_root) { | |
751 | ust_event_name = DEFAULT_SYS_JUL_EVENT_NAME; | |
752 | } else { | |
753 | ust_event_name = DEFAULT_USER_JUL_EVENT_NAME; | |
754 | } | |
755 | ||
756 | /* | |
757 | * The loglevel is hardcoded with 0 here since the JUL ust event is set | |
758 | * with the loglevel type to ALL thus the loglevel stays 0. The event's | |
759 | * filter is the one handling the loglevel for JUL. | |
760 | */ | |
761 | uevent = trace_ust_find_event(uchan->events, ust_event_name, | |
762 | jevent->filter, 0, NULL); | |
763 | /* If the JUL event exists, it must be available on the UST side. */ | |
764 | assert(uevent); | |
765 | ||
766 | ret = ust_app_disable_event_glb(usess, uchan, uevent); | |
767 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { | |
768 | ret = LTTNG_ERR_UST_DISABLE_FAIL; | |
769 | goto error; | |
770 | } | |
771 | ||
f20baf8e DG |
772 | ret = jul_disable_event(jevent); |
773 | if (ret != LTTNG_OK) { | |
774 | goto error; | |
775 | } | |
776 | ||
777 | end: | |
778 | return LTTNG_OK; | |
779 | ||
780 | error: | |
781 | return ret; | |
782 | } | |
783 | /* | |
784 | * Disable all JUL event for a given UST session. | |
785 | * | |
786 | * Return LTTNG_OK on success or else a LTTNG_ERR* code. | |
787 | */ | |
788 | int event_jul_disable_all(struct ltt_ust_session *usess) | |
789 | { | |
790 | int ret, do_disable = 0; | |
791 | struct jul_event *jevent; | |
792 | struct lttng_ht_iter iter; | |
793 | ||
794 | assert(usess); | |
795 | ||
796 | /* Enable event on JUL application through TCP socket. */ | |
797 | ret = event_jul_disable(usess, "*"); | |
798 | if (ret != LTTNG_OK) { | |
799 | if (ret == LTTNG_ERR_UST_EVENT_NOT_FOUND) { | |
800 | /* | |
801 | * This means that no enable all was done before but still a user | |
802 | * could want to disable everything even though the * wild card | |
803 | * event does not exists. | |
804 | */ | |
805 | do_disable = 1; | |
806 | } else { | |
807 | goto error; | |
808 | } | |
809 | } | |
810 | ||
811 | /* Flag every event that they are now enabled. */ | |
812 | rcu_read_lock(); | |
813 | cds_lfht_for_each_entry(usess->domain_jul.events->ht, &iter.iter, jevent, | |
814 | node.node) { | |
815 | if (jevent->enabled && do_disable) { | |
816 | ret = event_jul_disable(usess, jevent->name); | |
817 | if (ret != LTTNG_OK) { | |
818 | rcu_read_unlock(); | |
819 | goto error; | |
820 | } | |
821 | } | |
822 | jevent->enabled = 0; | |
823 | } | |
824 | rcu_read_unlock(); | |
825 | ||
826 | ret = LTTNG_OK; | |
827 | ||
828 | error: | |
829 | return ret; | |
830 | } |