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