Sync lttng-modules ABI in internal kernel-ioctl.h
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
1 /*
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include <urcu/list.h>
11 #include <string.h>
12
13 #include <common/compat/errno.h>
14 #include <lttng/lttng.h>
15 #include <lttng/condition/condition.h>
16 #include <lttng/condition/event-rule-matches.h>
17 #include <lttng/event-rule/event-rule.h>
18 #include <lttng/event-rule/event-rule-internal.h>
19 #include <common/bytecode/bytecode.h>
20 #include <common/error.h>
21 #include <common/sessiond-comm/sessiond-comm.h>
22 #include <common/filter.h>
23 #include <common/context.h>
24
25 #include "channel.h"
26 #include "event.h"
27 #include "kernel.h"
28 #include "lttng-sessiond.h"
29 #include "lttng-ust-ctl.h"
30 #include "lttng-ust-error.h"
31 #include "ust-app.h"
32 #include "trace-kernel.h"
33 #include "trace-ust.h"
34 #include "agent.h"
35 #include "utils.h"
36
37 /*
38 * Add unique UST event based on the event name, filter bytecode and loglevel.
39 */
40 static void add_unique_ust_event(struct lttng_ht *ht,
41 struct ltt_ust_event *event)
42 {
43 struct cds_lfht_node *node_ptr;
44 struct ltt_ust_ht_key key;
45
46 assert(ht);
47 assert(ht->ht);
48 assert(event);
49
50 key.name = event->attr.name;
51 key.filter = (struct lttng_bytecode *) event->filter;
52 key.loglevel_type = event->attr.loglevel_type;
53 key.loglevel_value = event->attr.loglevel;
54 key.exclusion = event->exclusion;
55
56 node_ptr = cds_lfht_add_unique(ht->ht,
57 ht->hash_fct(event->node.key, lttng_ht_seed),
58 trace_ust_ht_match_event, &key, &event->node.node);
59 assert(node_ptr == &event->node.node);
60 }
61
62 /*
63 * Disable kernel tracepoint events for a channel from the kernel session of
64 * a specified event_name and event type.
65 * On type LTTNG_EVENT_ALL all events with event_name are disabled.
66 * If event_name is NULL all events of the specified type are disabled.
67 */
68 int event_kernel_disable_event(struct ltt_kernel_channel *kchan,
69 const char *event_name, enum lttng_event_type type)
70 {
71 int ret, error = 0, found = 0;
72 struct ltt_kernel_event *kevent;
73
74 assert(kchan);
75
76 /* For each event in the kernel session */
77 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
78 if (type != LTTNG_EVENT_ALL && kevent->type != type)
79 continue;
80 if (event_name != NULL && strcmp(event_name, kevent->event->name)) {
81 continue;
82 }
83 found++;
84 ret = kernel_disable_event(kevent);
85 if (ret < 0) {
86 error = 1;
87 continue;
88 }
89 }
90 DBG("Disable kernel event: found %d events with name: %s and type: %d",
91 found, event_name ? event_name : "NULL", type);
92
93 if (event_name != NULL && !found) {
94 ret = LTTNG_ERR_NO_EVENT;
95 } else {
96 ret = error ? LTTNG_ERR_KERN_DISABLE_FAIL : LTTNG_OK;
97 }
98
99 return ret;
100 }
101
102 /*
103 * Enable kernel tracepoint event for a channel from the kernel session.
104 * We own filter_expression and filter.
105 */
106 int event_kernel_enable_event(struct ltt_kernel_channel *kchan,
107 struct lttng_event *event, char *filter_expression,
108 struct lttng_bytecode *filter)
109 {
110 int ret;
111 struct ltt_kernel_event *kevent;
112
113 assert(kchan);
114 assert(event);
115
116 kevent = trace_kernel_find_event(event->name, kchan,
117 event->type, filter);
118 if (kevent == NULL) {
119 ret = kernel_create_event(event, kchan, filter_expression, filter);
120 /* We have passed ownership */
121 filter_expression = NULL;
122 filter = NULL;
123 if (ret) {
124 goto end;
125 }
126 } else if (kevent->enabled == 0) {
127 ret = kernel_enable_event(kevent);
128 if (ret < 0) {
129 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
130 goto end;
131 }
132 } else {
133 /* At this point, the event is considered enabled */
134 ret = LTTNG_ERR_KERN_EVENT_EXIST;
135 goto end;
136 }
137
138 ret = LTTNG_OK;
139 end:
140 free(filter_expression);
141 free(filter);
142 return ret;
143 }
144
145 /*
146 * ============================
147 * UST : The Ultimate Frontier!
148 * ============================
149 */
150
151 /*
152 * Enable UST tracepoint event for a channel from a UST session.
153 * We own filter_expression, filter, and exclusion.
154 */
155 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
156 struct ltt_ust_channel *uchan, struct lttng_event *event,
157 char *filter_expression,
158 struct lttng_bytecode *filter,
159 struct lttng_event_exclusion *exclusion,
160 bool internal_event)
161 {
162 int ret = LTTNG_OK, to_create = 0;
163 struct ltt_ust_event *uevent;
164
165 assert(usess);
166 assert(uchan);
167 assert(event);
168
169 rcu_read_lock();
170
171 uevent = trace_ust_find_event(uchan->events, event->name, filter,
172 (enum lttng_ust_abi_loglevel_type) event->loglevel_type,
173 event->loglevel, exclusion);
174 if (!uevent) {
175 ret = trace_ust_create_event(event, filter_expression,
176 filter, exclusion, internal_event, &uevent);
177 /* We have passed ownership */
178 filter_expression = NULL;
179 filter = NULL;
180 exclusion = NULL;
181 if (ret != LTTNG_OK) {
182 goto error;
183 }
184
185 /* Valid to set it after the goto error since uevent is still NULL */
186 to_create = 1;
187 }
188
189 if (uevent->enabled) {
190 /* It's already enabled so everything is OK */
191 assert(!to_create);
192 ret = LTTNG_ERR_UST_EVENT_ENABLED;
193 goto end;
194 }
195
196 uevent->enabled = 1;
197 if (to_create) {
198 /* Add ltt ust event to channel */
199 add_unique_ust_event(uchan->events, uevent);
200 }
201
202 if (!usess->active) {
203 goto end;
204 }
205
206 if (to_create) {
207 /* Create event on all UST registered apps for session */
208 ret = ust_app_create_event_glb(usess, uchan, uevent);
209 } else {
210 /* Enable event on all UST registered apps for session */
211 ret = ust_app_enable_event_glb(usess, uchan, uevent);
212 }
213
214 if (ret < 0) {
215 if (ret == -LTTNG_UST_ERR_EXIST) {
216 ret = LTTNG_ERR_UST_EVENT_EXIST;
217 goto end;
218 } else {
219 ret = LTTNG_ERR_UST_ENABLE_FAIL;
220 goto error;
221 }
222 }
223
224 DBG("Event UST %s %s in channel %s", uevent->attr.name,
225 to_create ? "created" : "enabled", uchan->name);
226
227 ret = LTTNG_OK;
228
229 end:
230 rcu_read_unlock();
231 free(filter_expression);
232 free(filter);
233 free(exclusion);
234 return ret;
235
236 error:
237 /*
238 * Only destroy event on creation time (not enabling time) because if the
239 * event is found in the channel (to_create == 0), it means that at some
240 * point the enable_event worked and it's thus valid to keep it alive.
241 * Destroying it also implies that we also destroy it's shadow copy to sync
242 * everyone up.
243 */
244 if (to_create) {
245 /* In this code path, the uevent was not added to the hash table */
246 trace_ust_destroy_event(uevent);
247 }
248 rcu_read_unlock();
249 free(filter_expression);
250 free(filter);
251 free(exclusion);
252 return ret;
253 }
254
255 /*
256 * Disable UST tracepoint of a channel from a UST session.
257 */
258 int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
259 struct ltt_ust_channel *uchan, const char *event_name)
260 {
261 int ret;
262 struct ltt_ust_event *uevent;
263 struct lttng_ht_node_str *node;
264 struct lttng_ht_iter iter;
265 struct lttng_ht *ht;
266
267 assert(usess);
268 assert(uchan);
269 assert(event_name);
270
271 ht = uchan->events;
272
273 rcu_read_lock();
274
275 /*
276 * We use a custom lookup since we need the iterator for the next_duplicate
277 * call in the do while loop below.
278 */
279 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed),
280 trace_ust_ht_match_event_by_name, event_name, &iter.iter);
281 node = lttng_ht_iter_get_node_str(&iter);
282 if (node == NULL) {
283 DBG2("Trace UST event NOT found by name %s", event_name);
284 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
285 goto error;
286 }
287
288 do {
289 uevent = caa_container_of(node, struct ltt_ust_event, node);
290 assert(uevent);
291
292 if (uevent->enabled == 0) {
293 /* It's already disabled so everything is OK */
294 goto next;
295 }
296 uevent->enabled = 0;
297 DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
298 uchan->name);
299
300 if (!usess->active) {
301 goto next;
302 }
303 ret = ust_app_disable_event_glb(usess, uchan, uevent);
304 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
305 ret = LTTNG_ERR_UST_DISABLE_FAIL;
306 goto error;
307 }
308 next:
309 /* Get next duplicate event by name. */
310 cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
311 event_name, &iter.iter);
312 node = lttng_ht_iter_get_node_str(&iter);
313 } while (node);
314
315 ret = LTTNG_OK;
316
317 error:
318 rcu_read_unlock();
319 return ret;
320 }
321
322 /*
323 * Disable all UST tracepoints for a channel from a UST session.
324 */
325 int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
326 struct ltt_ust_channel *uchan)
327 {
328 int ret, i, size, error = 0;
329 struct lttng_ht_iter iter;
330 struct ltt_ust_event *uevent = NULL;
331 struct lttng_event *events = NULL;
332
333 assert(usess);
334 assert(uchan);
335
336 rcu_read_lock();
337
338 /* Disabling existing events */
339 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
340 node.node) {
341 if (uevent->enabled == 1) {
342 ret = event_ust_disable_tracepoint(usess, uchan,
343 uevent->attr.name);
344 if (ret < 0) {
345 error = LTTNG_ERR_UST_DISABLE_FAIL;
346 continue;
347 }
348 }
349 }
350
351 /* Get all UST available events */
352 size = ust_app_list_events(&events);
353 if (size < 0) {
354 ret = LTTNG_ERR_UST_LIST_FAIL;
355 goto error;
356 }
357
358 for (i = 0; i < size; i++) {
359 ret = event_ust_disable_tracepoint(usess, uchan,
360 events[i].name);
361 if (ret < 0) {
362 /* Continue to disable the rest... */
363 error = LTTNG_ERR_UST_DISABLE_FAIL;
364 continue;
365 }
366 }
367
368 ret = error ? error : LTTNG_OK;
369 error:
370 rcu_read_unlock();
371 free(events);
372 return ret;
373 }
374
375 static void agent_enable_all(struct agent *agt)
376 {
377 struct agent_event *aevent;
378 struct lttng_ht_iter iter;
379
380 /* Flag every event as enabled. */
381 rcu_read_lock();
382 cds_lfht_for_each_entry (
383 agt->events->ht, &iter.iter, aevent, node.node) {
384 aevent->enabled_count++;
385 }
386 rcu_read_unlock();
387 }
388
389 /*
390 * Enable all agent event for a given UST session.
391 *
392 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
393 */
394 int event_agent_enable_all(struct ltt_ust_session *usess,
395 struct agent *agt, struct lttng_event *event,
396 struct lttng_bytecode *filter ,char *filter_expression)
397 {
398 int ret;
399
400 assert(usess);
401
402 DBG("Event agent enabling ALL events for session %" PRIu64, usess->id);
403
404 /* Enable event on agent application through TCP socket. */
405 ret = event_agent_enable(usess, agt, event, filter, filter_expression);
406 if (ret != LTTNG_OK) {
407 goto error;
408 }
409
410 agent_enable_all(agt);
411
412 ret = LTTNG_OK;
413
414 error:
415 return ret;
416 }
417
418 /*
419 * Check if this event's filter requires the activation of application contexts
420 * and enable them in the agent.
421 * TODO: bytecode iterator does not support non-legacy application
422 * contexts yet. Not an issue for now, since they are not generated by
423 * the lttng-ctl library.
424 */
425 static int add_filter_app_ctx(struct lttng_bytecode *bytecode,
426 const char *filter_expression, struct agent *agt)
427 {
428 int ret = LTTNG_OK;
429 char *provider_name = NULL, *ctx_name = NULL;
430 struct bytecode_symbol_iterator *it =
431 bytecode_symbol_iterator_create(bytecode);
432
433 if (!it) {
434 ret = LTTNG_ERR_NOMEM;
435 goto end;
436 }
437
438 do {
439 struct lttng_event_context ctx;
440 const char *symbol_name =
441 bytecode_symbol_iterator_get_name(it);
442
443 if (parse_application_context(symbol_name, &provider_name,
444 &ctx_name)) {
445 /* Not an application context. */
446 continue;
447 }
448
449 ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT;
450 ctx.u.app_ctx.provider_name = provider_name;
451 ctx.u.app_ctx.ctx_name = ctx_name;
452
453 /* Recognized an application context. */
454 DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.",
455 filter_expression, provider_name, ctx_name);
456
457 ret = agent_add_context(&ctx, agt);
458 if (ret != LTTNG_OK) {
459 ERR("Failed to add application context %s:%s.",
460 provider_name, ctx_name);
461 goto end;
462 }
463
464 ret = agent_enable_context(&ctx, agt->domain);
465 if (ret != LTTNG_OK) {
466 ERR("Failed to enable application context %s:%s.",
467 provider_name, ctx_name);
468 goto end;
469 }
470
471 free(provider_name);
472 free(ctx_name);
473 provider_name = ctx_name = NULL;
474 } while (bytecode_symbol_iterator_next(it) == 0);
475 end:
476 free(provider_name);
477 free(ctx_name);
478 bytecode_symbol_iterator_destroy(it);
479 return ret;
480 }
481
482 static int agent_enable(struct agent *agt,
483 struct lttng_event *event,
484 struct lttng_bytecode *filter,
485 char *filter_expression)
486 {
487 int ret, created = 0;
488 struct agent_event *aevent;
489
490 assert(event);
491 assert(agt);
492
493 aevent = agent_find_event(event->name, event->loglevel_type,
494 event->loglevel, filter_expression, agt);
495 if (!aevent) {
496 aevent = agent_create_event(event->name, event->loglevel_type,
497 event->loglevel, filter,
498 filter_expression);
499 if (!aevent) {
500 ret = LTTNG_ERR_NOMEM;
501 goto error;
502 }
503 filter = NULL;
504 filter_expression = NULL;
505 created = 1;
506 assert(!AGENT_EVENT_IS_ENABLED(aevent));
507 }
508
509 if (created && aevent->filter) {
510 ret = add_filter_app_ctx(
511 aevent->filter, aevent->filter_expression, agt);
512 if (ret != LTTNG_OK) {
513 goto error;
514 }
515 }
516
517 /* Already enabled? */
518 if (AGENT_EVENT_IS_ENABLED(aevent)) {
519 ret = LTTNG_OK;
520 goto end;
521 }
522
523 ret = agent_enable_event(aevent, agt->domain);
524 if (ret != LTTNG_OK) {
525 goto error;
526 }
527
528 /* If the event was created prior to the enable, add it to the domain. */
529 if (created) {
530 agent_add_event(aevent, agt);
531 }
532
533 ret = LTTNG_OK;
534 goto end;
535
536 error:
537 if (created) {
538 agent_destroy_event(aevent);
539 }
540 end:
541 free(filter);
542 free(filter_expression);
543 return ret;
544 }
545
546 /*
547 * Enable a single agent event for a given UST session.
548 *
549 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
550 */
551 int event_agent_enable(struct ltt_ust_session *usess,
552 struct agent *agt,
553 struct lttng_event *event,
554 struct lttng_bytecode *filter,
555 char *filter_expression)
556 {
557 assert(usess);
558 assert(event);
559 assert(agt);
560
561 DBG("Enabling agent event: event pattern = '%s', session id = %" PRIu64 ", loglevel type = %d, loglevel = %d, filter expression = '%s'",
562 event->name, usess->id, event->loglevel_type,
563 event->loglevel,
564 filter_expression ? filter_expression : "(none)");
565
566 return agent_enable(agt, event, filter, filter_expression);
567 }
568
569 /*
570 * Enable a single agent event for a trigger.
571 *
572 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
573 */
574 int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
575 {
576 int ret;
577 enum lttng_condition_status c_status;
578 enum lttng_trigger_status t_status;
579 enum lttng_domain_type d_type;
580 const struct lttng_condition *condition;
581 const struct lttng_event_rule *rule;
582 const char *filter_expression;
583 char *filter_expression_copy = NULL;
584 const struct lttng_bytecode *filter_bytecode;
585 struct lttng_bytecode *filter_bytecode_copy = NULL;
586 struct lttng_event *event = NULL;
587 uid_t trigger_owner_uid = 0;
588 const char *trigger_name;
589
590 assert(trigger);
591 assert(agt);
592
593 t_status = lttng_trigger_get_name(trigger, &trigger_name);
594 if (t_status != LTTNG_TRIGGER_STATUS_OK) {
595 trigger_name = "(anonymous)";
596 }
597
598 t_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner_uid);
599 assert(t_status == LTTNG_TRIGGER_STATUS_OK);
600
601 condition = lttng_trigger_get_const_condition(trigger);
602
603 assert(lttng_condition_get_type(condition) ==
604 LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
605
606 c_status = lttng_condition_event_rule_matches_get_rule(
607 condition, &rule);
608 assert(c_status == LTTNG_CONDITION_STATUS_OK);
609
610 assert(lttng_event_rule_get_type(rule) ==
611 LTTNG_EVENT_RULE_TYPE_TRACEPOINT);
612
613 d_type = lttng_event_rule_get_domain_type(rule);
614 assert(d_type == agt->domain);
615
616 event = lttng_event_rule_generate_lttng_event(rule);
617 if (!event) {
618 ret = LTTNG_ERR_NOMEM;
619 goto end;
620 }
621
622 /* Get the internal filter expression and bytecode. */
623 filter_expression = lttng_event_rule_get_filter(rule);
624 if (filter_expression) {
625 filter_expression_copy = strdup(filter_expression);
626 if (!filter_expression_copy) {
627 ret = LTTNG_ERR_NOMEM;
628 goto end;
629 }
630
631 /* Get the filter bytecode */
632 filter_bytecode = lttng_event_rule_get_filter_bytecode(rule);
633 if (filter_bytecode) {
634 filter_bytecode_copy =
635 lttng_bytecode_copy(filter_bytecode);
636 if (!filter_bytecode_copy) {
637 ret = LTTNG_ERR_NOMEM;
638 goto end;
639 }
640 }
641 }
642
643 DBG("Enabling agent event from trigger: trigger name = '%s', trigger owner uid = %d, token = %" PRIu64,
644 trigger_name, trigger_owner_uid,
645 lttng_trigger_get_tracer_token(trigger));
646
647 ret = agent_enable(agt, event, filter_bytecode_copy,
648 filter_expression_copy);
649 /* Ownership was passed even in case of error. */
650 filter_expression_copy = NULL;
651 filter_bytecode_copy = NULL;
652
653 end:
654 free(filter_expression_copy);
655 free(filter_bytecode_copy);
656 free(event);
657 return ret;
658 }
659
660 /*
661 * Return the default event name associated with the provided UST domain. Return
662 * NULL on error.
663 */
664 const char *event_get_default_agent_ust_name(enum lttng_domain_type domain)
665 {
666 const char *default_event_name = NULL;
667
668 switch (domain) {
669 case LTTNG_DOMAIN_LOG4J:
670 default_event_name = DEFAULT_LOG4J_EVENT_NAME;
671 break;
672 case LTTNG_DOMAIN_JUL:
673 default_event_name = DEFAULT_JUL_EVENT_NAME;
674 break;
675 case LTTNG_DOMAIN_PYTHON:
676 default_event_name = DEFAULT_PYTHON_EVENT_NAME;
677 break;
678 default:
679 assert(0);
680 }
681
682 return default_event_name;
683 }
684
685 static int trigger_agent_disable_one(const struct lttng_trigger *trigger,
686 struct agent *agt,
687 struct agent_event *aevent)
688
689 {
690 int ret;
691
692 assert(agt);
693 assert(trigger);
694 assert(aevent);
695
696 /*
697 * Actual ust event un-registration happens on the trigger
698 * un-registration at that point.
699 */
700
701 DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for trigger %" PRIu64,
702 aevent->name, aevent->loglevel_type,
703 aevent->loglevel_value, lttng_trigger_get_tracer_token(trigger));
704
705 /* Already disabled? */
706 if (!AGENT_EVENT_IS_ENABLED(aevent)) {
707 goto end;
708 }
709
710 ret = agent_disable_event(aevent, agt->domain);
711 if (ret != LTTNG_OK) {
712 goto error;
713 }
714
715 end:
716 return LTTNG_OK;
717
718 error:
719 return ret;
720 }
721
722 /*
723 * Disable a given agent event for a given UST session.
724 *
725 * Must be called with the RCU read lock held.
726 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
727 */
728 static int event_agent_disable_one(struct ltt_ust_session *usess,
729 struct agent *agt, struct agent_event *aevent)
730 {
731 int ret;
732 struct ltt_ust_event *uevent = NULL;
733 struct ltt_ust_channel *uchan = NULL;
734 const char *ust_event_name, *ust_channel_name;
735
736 assert(agt);
737 assert(usess);
738 assert(aevent);
739
740 DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64,
741 aevent->name, aevent->loglevel_type, aevent->loglevel_value,
742 usess->id);
743
744 /* Already disabled? */
745 if (!AGENT_EVENT_IS_ENABLED(aevent)) {
746 goto end;
747 }
748
749 if (agt->domain == LTTNG_DOMAIN_JUL) {
750 ust_channel_name = DEFAULT_JUL_CHANNEL_NAME;
751 } else if (agt->domain == LTTNG_DOMAIN_LOG4J) {
752 ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
753 } else if (agt->domain == LTTNG_DOMAIN_PYTHON) {
754 ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
755 } else {
756 ret = LTTNG_ERR_INVALID;
757 goto error;
758 }
759
760 /*
761 * Disable it on the UST side. First get the channel reference then find
762 * the event and finally disable it.
763 */
764 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
765 (char *) ust_channel_name);
766 if (!uchan) {
767 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
768 goto error;
769 }
770
771 ust_event_name = event_get_default_agent_ust_name(agt->domain);
772 if (!ust_event_name) {
773 ret = LTTNG_ERR_FATAL;
774 goto error;
775 }
776
777 /*
778 * Agent UST event has its loglevel type forced to
779 * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering
780 * happens thanks to an UST filter. The following -1 is actually
781 * ignored since the type is LTTNG_UST_LOGLEVEL_ALL.
782 */
783 uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
784 aevent->filter, LTTNG_UST_ABI_LOGLEVEL_ALL, -1, NULL);
785 /* If the agent event exists, it must be available on the UST side. */
786 assert(uevent);
787
788 if (usess->active) {
789 ret = ust_app_disable_event_glb(usess, uchan, uevent);
790 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
791 ret = LTTNG_ERR_UST_DISABLE_FAIL;
792 goto error;
793 }
794 }
795
796 /*
797 * Flag event that it's disabled so the shadow copy on the ust app side
798 * will disable it if an application shows up.
799 */
800 uevent->enabled = 0;
801
802 ret = agent_disable_event(aevent, agt->domain);
803 if (ret != LTTNG_OK) {
804 goto error;
805 }
806
807 end:
808 return LTTNG_OK;
809
810 error:
811 return ret;
812 }
813
814 /*
815 * Disable agent event matching a given trigger.
816 *
817 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
818 */
819 int trigger_agent_disable(
820 const struct lttng_trigger *trigger, struct agent *agt)
821 {
822 int ret = LTTNG_OK;
823 struct agent_event *aevent;
824
825 assert(trigger);
826 assert(agt);
827
828 DBG("Event agent disabling for trigger %" PRIu64,
829 lttng_trigger_get_tracer_token(trigger));
830
831 rcu_read_lock();
832 aevent = agent_find_event_by_trigger(trigger, agt);
833
834 if (aevent == NULL) {
835 DBG2("Event agent NOT found by trigger %" PRIu64,
836 lttng_trigger_get_tracer_token(trigger));
837 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
838 goto end;
839 }
840
841 ret = trigger_agent_disable_one(trigger, agt, aevent);
842
843 if (ret != LTTNG_OK) {
844 goto end;
845 }
846
847 end:
848 rcu_read_unlock();
849 return ret;
850 }
851
852 /*
853 * Disable all agent events matching a given name for a given UST session.
854 *
855 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
856 */
857 int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
858 const char *event_name)
859 {
860 int ret = LTTNG_OK;
861 struct agent_event *aevent;
862 struct lttng_ht_iter iter;
863 struct lttng_ht_node_str *node;
864
865 assert(agt);
866 assert(usess);
867 assert(event_name);
868
869 DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id);
870
871 rcu_read_lock();
872 agent_find_events_by_name(event_name, agt, &iter);
873 node = lttng_ht_iter_get_node_str(&iter);
874
875 if (node == NULL) {
876 DBG2("Event agent NOT found by name %s", event_name);
877 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
878 goto end;
879 }
880
881 do {
882 aevent = caa_container_of(node, struct agent_event, node);
883 ret = event_agent_disable_one(usess, agt, aevent);
884
885 if (ret != LTTNG_OK) {
886 goto end;
887 }
888
889 /* Get next duplicate agent event by name. */
890 agent_event_next_duplicate(event_name, agt, &iter);
891 node = lttng_ht_iter_get_node_str(&iter);
892 } while (node);
893 end:
894 rcu_read_unlock();
895 return ret;
896 }
897 /*
898 * Disable all agent event for a given UST session.
899 *
900 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
901 */
902 int event_agent_disable_all(struct ltt_ust_session *usess,
903 struct agent *agt)
904 {
905 int ret;
906 struct agent_event *aevent;
907 struct lttng_ht_iter iter;
908
909 assert(agt);
910 assert(usess);
911
912 /*
913 * Disable event on agent application. Continue to disable all other events
914 * if the * event is not found.
915 */
916 ret = event_agent_disable(usess, agt, "*");
917 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) {
918 goto error;
919 }
920
921 /* Disable every event. */
922 rcu_read_lock();
923 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
924 node.node) {
925 if (!AGENT_EVENT_IS_ENABLED(aevent)) {
926 continue;
927 }
928
929 ret = event_agent_disable(usess, agt, aevent->name);
930 if (ret != LTTNG_OK) {
931 goto error_unlock;
932 }
933 }
934 ret = LTTNG_OK;
935
936 error_unlock:
937 rcu_read_unlock();
938 error:
939 return ret;
940 }
This page took 0.084711 seconds and 4 git commands to generate.