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