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