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