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