Generalize set_ust_event_exclusion to support multiple types of ust object
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
CommitLineData
54d01ffb 1/*
ab5be9fa
MJ
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
54d01ffb 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
54d01ffb 6 *
54d01ffb
DG
7 */
8
6c1c0768 9#define _LGPL_SOURCE
54d01ffb 10#include <urcu/list.h>
2bdd86d4 11#include <string.h>
54d01ffb 12
edf4b93e 13#include <common/compat/errno.h>
54d01ffb 14#include <lttng/lttng.h>
db758600 15#include <common/error.h>
10a8a223 16#include <common/sessiond-comm/sessiond-comm.h>
71a559f8
JG
17#include <common/filter.h>
18#include <common/context.h>
54d01ffb
DG
19
20#include "channel.h"
21#include "event.h"
4771f025 22#include "kernel.h"
be6a6276 23#include "lttng-sessiond.h"
75018ab6
JG
24#include "lttng-ust-ctl.h"
25#include "lttng-ust-error.h"
edb67388
DG
26#include "ust-app.h"
27#include "trace-kernel.h"
28#include "trace-ust.h"
7c1d2758 29#include "agent.h"
54d01ffb 30
025faf73
DG
31/*
32 * Add unique UST event based on the event name, filter bytecode and loglevel.
33 */
18eace3b
DG
34static void add_unique_ust_event(struct lttng_ht *ht,
35 struct ltt_ust_event *event)
36{
37 struct cds_lfht_node *node_ptr;
38 struct ltt_ust_ht_key key;
39
40 assert(ht);
41 assert(ht->ht);
42 assert(event);
43
44 key.name = event->attr.name;
45 key.filter = (struct lttng_filter_bytecode *) event->filter;
b953b8cd
PP
46 key.loglevel_type = event->attr.loglevel_type;
47 key.loglevel_value = event->attr.loglevel;
4031e53e 48 key.exclusion = event->exclusion;
18eace3b
DG
49
50 node_ptr = cds_lfht_add_unique(ht->ht,
51 ht->hash_fct(event->node.key, lttng_ht_seed),
52 trace_ust_ht_match_event, &key, &event->node.node);
53 assert(node_ptr == &event->node.node);
54}
55
54d01ffb 56/*
9550ee81
JR
57 * Disable kernel tracepoint events for a channel from the kernel session of
58 * a specified event_name and event type.
59 * On type LTTNG_EVENT_ALL all events with event_name are disabled.
60 * If event_name is NULL all events of the specified type are disabled.
54d01ffb 61 */
d0ae4ea8 62int event_kernel_disable_event(struct ltt_kernel_channel *kchan,
df4f5a87 63 const char *event_name, enum lttng_event_type type)
54d01ffb 64{
9550ee81 65 int ret, error = 0, found = 0;
54d01ffb
DG
66 struct ltt_kernel_event *kevent;
67
0525e9ae
DG
68 assert(kchan);
69
54d01ffb
DG
70 /* For each event in the kernel session */
71 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
d0ae4ea8
MD
72 if (type != LTTNG_EVENT_ALL && kevent->type != type)
73 continue;
9550ee81
JR
74 if (event_name != NULL && strcmp(event_name, kevent->event->name)) {
75 continue;
76 }
77 found++;
54d01ffb
DG
78 ret = kernel_disable_event(kevent);
79 if (ret < 0) {
9550ee81 80 error = 1;
54d01ffb
DG
81 continue;
82 }
83 }
9550ee81
JR
84 DBG("Disable kernel event: found %d events with name: %s and type: %d",
85 found, event_name ? event_name : "NULL", type);
7a3d1328 86
9550ee81
JR
87 if (event_name != NULL && !found) {
88 ret = LTTNG_ERR_NO_EVENT;
89 } else {
90 ret = error ? LTTNG_ERR_KERN_DISABLE_FAIL : LTTNG_OK;
91 }
92
93 return ret;
54d01ffb
DG
94}
95
96/*
7a3d1328 97 * Enable kernel tracepoint event for a channel from the kernel session.
49d21f93 98 * We own filter_expression and filter.
54d01ffb 99 */
d0ae4ea8 100int event_kernel_enable_event(struct ltt_kernel_channel *kchan,
00a62084
MD
101 struct lttng_event *event, char *filter_expression,
102 struct lttng_filter_bytecode *filter)
54d01ffb
DG
103{
104 int ret;
105 struct ltt_kernel_event *kevent;
106
0525e9ae
DG
107 assert(kchan);
108 assert(event);
109
00a62084
MD
110 kevent = trace_kernel_find_event(event->name, kchan,
111 event->type, filter);
54d01ffb 112 if (kevent == NULL) {
71a3bb01 113 ret = kernel_create_event(event, kchan, filter_expression, filter);
a969e101
MD
114 /* We have passed ownership */
115 filter_expression = NULL;
116 filter = NULL;
71a3bb01 117 if (ret) {
7a3d1328 118 goto end;
54d01ffb
DG
119 }
120 } else if (kevent->enabled == 0) {
121 ret = kernel_enable_event(kevent);
122 if (ret < 0) {
f73fabfd 123 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
7a3d1328 124 goto end;
54d01ffb 125 }
42224349
DG
126 } else {
127 /* At this point, the event is considered enabled */
f73fabfd 128 ret = LTTNG_ERR_KERN_EVENT_EXIST;
42224349 129 goto end;
54d01ffb 130 }
42224349 131
f73fabfd 132 ret = LTTNG_OK;
7a3d1328 133end:
a969e101
MD
134 free(filter_expression);
135 free(filter);
54d01ffb
DG
136 return ret;
137}
138
7f79d3a1
DG
139/*
140 * ============================
141 * UST : The Ultimate Frontier!
142 * ============================
143 */
144
2bdd86d4
MD
145/*
146 * Enable UST tracepoint event for a channel from a UST session.
49d21f93 147 * We own filter_expression, filter, and exclusion.
2bdd86d4 148 */
7972aab2 149int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
025faf73 150 struct ltt_ust_channel *uchan, struct lttng_event *event,
6b453b5e 151 char *filter_expression,
f1613f52 152 struct lttng_filter_bytecode *filter,
88f06f15
JG
153 struct lttng_event_exclusion *exclusion,
154 bool internal_event)
2bdd86d4 155{
88e3c2f5 156 int ret = LTTNG_OK, to_create = 0;
edb67388
DG
157 struct ltt_ust_event *uevent;
158
0525e9ae
DG
159 assert(usess);
160 assert(uchan);
161 assert(event);
162
18eace3b
DG
163 rcu_read_lock();
164
025faf73 165 uevent = trace_ust_find_event(uchan->events, event->name, filter,
abda88ad
JG
166 (enum lttng_ust_loglevel_type) event->loglevel_type,
167 event->loglevel, exclusion);
87c6e328 168 if (!uevent) {
39687410
FD
169 ret = trace_ust_create_event(event, filter_expression,
170 filter, exclusion, internal_event, &uevent);
49d21f93
MD
171 /* We have passed ownership */
172 filter_expression = NULL;
173 filter = NULL;
174 exclusion = NULL;
39687410 175 if (ret != LTTNG_OK) {
edb67388
DG
176 goto error;
177 }
025faf73 178
fc34caaa 179 /* Valid to set it after the goto error since uevent is still NULL */
edb67388
DG
180 to_create = 1;
181 }
2bdd86d4 182
7f79d3a1
DG
183 if (uevent->enabled) {
184 /* It's already enabled so everything is OK */
0359fdbc 185 assert(!to_create);
5bcdda4f 186 ret = LTTNG_ERR_UST_EVENT_ENABLED;
7f79d3a1
DG
187 goto end;
188 }
189
fc34caaa 190 uevent->enabled = 1;
88e3c2f5
JG
191 if (to_create) {
192 /* Add ltt ust event to channel */
193 add_unique_ust_event(uchan->events, uevent);
194 }
195
196 if (!usess->active) {
197 goto end;
198 }
fc34caaa 199
7972aab2
DG
200 if (to_create) {
201 /* Create event on all UST registered apps for session */
202 ret = ust_app_create_event_glb(usess, uchan, uevent);
203 } else {
204 /* Enable event on all UST registered apps for session */
205 ret = ust_app_enable_event_glb(usess, uchan, uevent);
206 }
48842b30 207
7972aab2
DG
208 if (ret < 0) {
209 if (ret == -LTTNG_UST_ERR_EXIST) {
210 ret = LTTNG_ERR_UST_EVENT_EXIST;
211 goto end;
212 } else {
213 ret = LTTNG_ERR_UST_ENABLE_FAIL;
214 goto error;
edb67388 215 }
2bdd86d4 216 }
48842b30 217
7f79d3a1
DG
218 DBG("Event UST %s %s in channel %s", uevent->attr.name,
219 to_create ? "created" : "enabled", uchan->name);
220
f73fabfd 221 ret = LTTNG_OK;
fc34caaa 222
fb89d070 223end:
18eace3b 224 rcu_read_unlock();
49d21f93
MD
225 free(filter_expression);
226 free(filter);
227 free(exclusion);
fc34caaa 228 return ret;
edb67388
DG
229
230error:
fc34caaa
DG
231 /*
232 * Only destroy event on creation time (not enabling time) because if the
233 * event is found in the channel (to_create == 0), it means that at some
234 * point the enable_event worked and it's thus valid to keep it alive.
235 * Destroying it also implies that we also destroy it's shadow copy to sync
236 * everyone up.
237 */
238 if (to_create) {
239 /* In this code path, the uevent was not added to the hash table */
240 trace_ust_destroy_event(uevent);
241 }
18eace3b 242 rcu_read_unlock();
49d21f93
MD
243 free(filter_expression);
244 free(filter);
245 free(exclusion);
2bdd86d4
MD
246 return ret;
247}
248
7f79d3a1
DG
249/*
250 * Disable UST tracepoint of a channel from a UST session.
251 */
7972aab2 252int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
df4f5a87 253 struct ltt_ust_channel *uchan, const char *event_name)
2bdd86d4
MD
254{
255 int ret;
7f79d3a1 256 struct ltt_ust_event *uevent;
18eace3b
DG
257 struct lttng_ht_node_str *node;
258 struct lttng_ht_iter iter;
18eace3b 259 struct lttng_ht *ht;
2bdd86d4 260
0525e9ae
DG
261 assert(usess);
262 assert(uchan);
263 assert(event_name);
264
18eace3b
DG
265 ht = uchan->events;
266
18eace3b 267 rcu_read_lock();
025faf73
DG
268
269 /*
270 * We use a custom lookup since we need the iterator for the next_duplicate
271 * call in the do while loop below.
272 */
273 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed),
274 trace_ust_ht_match_event_by_name, event_name, &iter.iter);
18eace3b
DG
275 node = lttng_ht_iter_get_node_str(&iter);
276 if (node == NULL) {
277 DBG2("Trace UST event NOT found by name %s", event_name);
f73fabfd 278 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
7f79d3a1 279 goto error;
2bdd86d4 280 }
7f79d3a1 281
18eace3b
DG
282 do {
283 uevent = caa_container_of(node, struct ltt_ust_event, node);
025faf73
DG
284 assert(uevent);
285
18eace3b
DG
286 if (uevent->enabled == 0) {
287 /* It's already disabled so everything is OK */
a1dcaf0f 288 goto next;
7f79d3a1 289 }
88e3c2f5
JG
290 uevent->enabled = 0;
291 DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
292 uchan->name);
18eace3b 293
88e3c2f5
JG
294 if (!usess->active) {
295 goto next;
296 }
7972aab2
DG
297 ret = ust_app_disable_event_glb(usess, uchan, uevent);
298 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
299 ret = LTTNG_ERR_UST_DISABLE_FAIL;
18eace3b
DG
300 goto error;
301 }
a1dcaf0f 302next:
18eace3b
DG
303 /* Get next duplicate event by name. */
304 cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
305 event_name, &iter.iter);
306 node = lttng_ht_iter_get_node_str(&iter);
307 } while (node);
7f79d3a1 308
f73fabfd 309 ret = LTTNG_OK;
7f79d3a1 310
7f79d3a1 311error:
18eace3b 312 rcu_read_unlock();
7f79d3a1
DG
313 return ret;
314}
315
b1e7fe2d
JR
316/*
317 * Disable all UST tracepoints for a channel from a UST session.
318 */
319int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
320 struct ltt_ust_channel *uchan)
321{
3e81c0f2 322 int ret, i, size, error = 0;
b1e7fe2d
JR
323 struct lttng_ht_iter iter;
324 struct ltt_ust_event *uevent = NULL;
325 struct lttng_event *events = NULL;
326
327 assert(usess);
328 assert(uchan);
329
330 rcu_read_lock();
331
332 /* Disabling existing events */
333 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
334 node.node) {
335 if (uevent->enabled == 1) {
336 ret = event_ust_disable_tracepoint(usess, uchan,
337 uevent->attr.name);
338 if (ret < 0) {
3e81c0f2 339 error = LTTNG_ERR_UST_DISABLE_FAIL;
b1e7fe2d
JR
340 continue;
341 }
342 }
343 }
344
345 /* Get all UST available events */
346 size = ust_app_list_events(&events);
347 if (size < 0) {
348 ret = LTTNG_ERR_UST_LIST_FAIL;
349 goto error;
350 }
351
352 for (i = 0; i < size; i++) {
353 ret = event_ust_disable_tracepoint(usess, uchan,
354 events[i].name);
3e81c0f2 355 if (ret < 0) {
b1e7fe2d 356 /* Continue to disable the rest... */
3e81c0f2 357 error = LTTNG_ERR_UST_DISABLE_FAIL;
b1e7fe2d
JR
358 continue;
359 }
360 }
361
3e81c0f2 362 ret = error ? error : LTTNG_OK;
b1e7fe2d
JR
363error:
364 rcu_read_unlock();
365 free(events);
366 return ret;
367}
368
f20baf8e 369/*
022d91ba 370 * Enable all agent event for a given UST session.
f20baf8e
DG
371 *
372 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
373 */
022d91ba 374int event_agent_enable_all(struct ltt_ust_session *usess,
fefd409b 375 struct agent *agt, struct lttng_event *event,
51755dc8 376 struct lttng_filter_bytecode *filter ,char *filter_expression)
f20baf8e
DG
377{
378 int ret;
fefd409b 379 struct agent_event *aevent;
f20baf8e
DG
380 struct lttng_ht_iter iter;
381
382 assert(usess);
383
022d91ba 384 DBG("Event agent enabling ALL events for session %" PRIu64, usess->id);
f20baf8e 385
022d91ba 386 /* Enable event on agent application through TCP socket. */
8404118c 387 ret = event_agent_enable(usess, agt, event, filter, filter_expression);
f20baf8e
DG
388 if (ret != LTTNG_OK) {
389 goto error;
390 }
391
392 /* Flag every event that they are now enabled. */
393 rcu_read_lock();
fefd409b 394 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
f20baf8e 395 node.node) {
fefd409b 396 aevent->enabled = 1;
f20baf8e
DG
397 }
398 rcu_read_unlock();
399
400 ret = LTTNG_OK;
401
402error:
403 return ret;
404}
405
71a559f8
JG
406/*
407 * Check if this event's filter requires the activation of application contexts
408 * and enable them in the agent.
b4bc01f7
MD
409 * TODO: bytecode iterator does not support non-legacy application
410 * contexts yet. Not an issue for now, since they are not generated by
411 * the lttng-ctl library.
71a559f8
JG
412 */
413static int add_filter_app_ctx(struct lttng_filter_bytecode *bytecode,
414 const char *filter_expression, struct agent *agt)
415{
416 int ret = LTTNG_OK;
417 char *provider_name = NULL, *ctx_name = NULL;
418 struct bytecode_symbol_iterator *it =
419 bytecode_symbol_iterator_create(bytecode);
420
421 if (!it) {
422 ret = LTTNG_ERR_NOMEM;
423 goto end;
424 }
425
426 do {
427 struct lttng_event_context ctx;
428 const char *symbol_name =
429 bytecode_symbol_iterator_get_name(it);
430
431 if (parse_application_context(symbol_name, &provider_name,
432 &ctx_name)) {
433 /* Not an application context. */
434 continue;
435 }
436
437 ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT;
438 ctx.u.app_ctx.provider_name = provider_name;
439 ctx.u.app_ctx.ctx_name = ctx_name;
440
441 /* Recognized an application context. */
442 DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.",
443 filter_expression, provider_name, ctx_name);
444
445 ret = agent_add_context(&ctx, agt);
446 if (ret != LTTNG_OK) {
447 ERR("Failed to add application context %s:%s.",
448 provider_name, ctx_name);
449 goto end;
450 }
451
452 ret = agent_enable_context(&ctx, agt->domain);
453 if (ret != LTTNG_OK) {
454 ERR("Failed to enable application context %s:%s.",
455 provider_name, ctx_name);
456 goto end;
457 }
458
459 free(provider_name);
460 free(ctx_name);
461 provider_name = ctx_name = NULL;
462 } while (bytecode_symbol_iterator_next(it) == 0);
463end:
464 free(provider_name);
465 free(ctx_name);
466 bytecode_symbol_iterator_destroy(it);
467 return ret;
468}
469
f20baf8e 470/*
022d91ba 471 * Enable a single agent event for a given UST session.
f20baf8e
DG
472 *
473 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
474 */
fefd409b
DG
475int event_agent_enable(struct ltt_ust_session *usess,
476 struct agent *agt, struct lttng_event *event,
8404118c
JG
477 struct lttng_filter_bytecode *filter,
478 char *filter_expression)
f20baf8e
DG
479{
480 int ret, created = 0;
fefd409b 481 struct agent_event *aevent;
f20baf8e
DG
482
483 assert(usess);
484 assert(event);
fefd409b 485 assert(agt);
f20baf8e 486
022d91ba 487 DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d "
51755dc8
JG
488 ", loglevel %d and filter \"%s\"", event->name,
489 usess->id, event->loglevel_type, event->loglevel,
490 filter_expression ? filter_expression : "NULL");
f20baf8e 491
a9319624 492 aevent = agent_find_event(event->name, event->loglevel_type,
71a559f8 493 event->loglevel, filter_expression, agt);
fefd409b 494 if (!aevent) {
a9319624
PP
495 aevent = agent_create_event(event->name, event->loglevel_type,
496 event->loglevel, filter,
51755dc8 497 filter_expression);
fefd409b 498 if (!aevent) {
f20baf8e
DG
499 ret = LTTNG_ERR_NOMEM;
500 goto error;
501 }
b0a23296
JG
502 filter = NULL;
503 filter_expression = NULL;
f20baf8e 504 created = 1;
6fe2a7d0 505 assert(!aevent->enabled);
f20baf8e
DG
506 }
507
bf7886d8
JR
508 if (created && aevent->filter) {
509 ret = add_filter_app_ctx(
510 aevent->filter, aevent->filter_expression, agt);
71a559f8
JG
511 if (ret != LTTNG_OK) {
512 goto error;
513 }
514 }
515
88e3c2f5
JG
516 /* Already enabled? */
517 if (aevent->enabled) {
518 ret = LTTNG_OK;
519 goto end;
520 }
521
fefd409b 522 ret = agent_enable_event(aevent, agt->domain);
f20baf8e
DG
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) {
fefd409b 529 agent_add_event(aevent, agt);
f20baf8e
DG
530 }
531
b0a23296
JG
532 ret = LTTNG_OK;
533 goto end;
f20baf8e
DG
534
535error:
536 if (created) {
fefd409b 537 agent_destroy_event(aevent);
f20baf8e 538 }
b0a23296
JG
539end:
540 free(filter);
541 free(filter_expression);
f20baf8e
DG
542 return ret;
543}
544
da6c3a50 545/*
d1ec8e20
JG
546 * Return the default event name associated with the provided UST domain. Return
547 * NULL on error.
da6c3a50
DG
548 */
549const char *event_get_default_agent_ust_name(enum lttng_domain_type domain)
550{
551 const char *default_event_name = NULL;
552
0e115563
DG
553 switch (domain) {
554 case LTTNG_DOMAIN_LOG4J:
d1ec8e20 555 default_event_name = DEFAULT_LOG4J_EVENT_NAME;
0e115563
DG
556 break;
557 case LTTNG_DOMAIN_JUL:
d1ec8e20 558 default_event_name = DEFAULT_JUL_EVENT_NAME;
0e115563
DG
559 break;
560 case LTTNG_DOMAIN_PYTHON:
e7c82272 561 default_event_name = DEFAULT_PYTHON_EVENT_NAME;
0e115563
DG
562 break;
563 default:
da6c3a50
DG
564 assert(0);
565 }
566
567 return default_event_name;
568}
569
f20baf8e 570/*
e261a6cc 571 * Disable a given agent event for a given UST session.
f20baf8e 572 *
e261a6cc 573 * Must be called with the RCU read lock held.
f20baf8e
DG
574 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
575 */
e261a6cc
PP
576static int event_agent_disable_one(struct ltt_ust_session *usess,
577 struct agent *agt, struct agent_event *aevent)
f20baf8e
DG
578{
579 int ret;
be6a6276
DG
580 struct ltt_ust_event *uevent = NULL;
581 struct ltt_ust_channel *uchan = NULL;
71aecbf8 582 const char *ust_event_name, *ust_channel_name;
f20baf8e 583
fefd409b 584 assert(agt);
f20baf8e 585 assert(usess);
e261a6cc 586 assert(aevent);
f20baf8e 587
e261a6cc
PP
588 DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64,
589 aevent->name, aevent->loglevel_type, aevent->loglevel_value,
590 usess->id);
f20baf8e
DG
591
592 /* Already disabled? */
fefd409b 593 if (!aevent->enabled) {
f20baf8e
DG
594 goto end;
595 }
596
71aecbf8
DG
597 if (agt->domain == LTTNG_DOMAIN_JUL) {
598 ust_channel_name = DEFAULT_JUL_CHANNEL_NAME;
599 } else if (agt->domain == LTTNG_DOMAIN_LOG4J) {
600 ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
0e115563
DG
601 } else if (agt->domain == LTTNG_DOMAIN_PYTHON) {
602 ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
71aecbf8
DG
603 } else {
604 ret = LTTNG_ERR_INVALID;
605 goto error;
606 }
607
be6a6276
DG
608 /*
609 * Disable it on the UST side. First get the channel reference then find
610 * the event and finally disable it.
611 */
612 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
71aecbf8 613 (char *) ust_channel_name);
be6a6276
DG
614 if (!uchan) {
615 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
616 goto error;
617 }
618
da6c3a50
DG
619 ust_event_name = event_get_default_agent_ust_name(agt->domain);
620 if (!ust_event_name) {
621 ret = LTTNG_ERR_FATAL;
622 goto error;
be6a6276
DG
623 }
624
625 /*
b953b8cd
PP
626 * Agent UST event has its loglevel type forced to
627 * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering
628 * happens thanks to an UST filter. The following -1 is actually
629 * ignored since the type is LTTNG_UST_LOGLEVEL_ALL.
be6a6276 630 */
da6c3a50 631 uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
b953b8cd 632 aevent->filter, LTTNG_UST_LOGLEVEL_ALL, -1, NULL);
022d91ba 633 /* If the agent event exists, it must be available on the UST side. */
be6a6276
DG
634 assert(uevent);
635
88e3c2f5
JG
636 if (usess->active) {
637 ret = ust_app_disable_event_glb(usess, uchan, uevent);
638 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
639 ret = LTTNG_ERR_UST_DISABLE_FAIL;
640 goto error;
641 }
be6a6276
DG
642 }
643
0dcfcf94
DG
644 /*
645 * Flag event that it's disabled so the shadow copy on the ust app side
646 * will disable it if an application shows up.
647 */
648 uevent->enabled = 0;
649
fefd409b 650 ret = agent_disable_event(aevent, agt->domain);
f20baf8e
DG
651 if (ret != LTTNG_OK) {
652 goto error;
653 }
654
655end:
656 return LTTNG_OK;
657
658error:
659 return ret;
660}
e261a6cc
PP
661
662/*
663 * Disable all agent events matching a given name for a given UST session.
664 *
665 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
666 */
667int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
df4f5a87 668 const char *event_name)
e261a6cc
PP
669{
670 int ret = LTTNG_OK;
671 struct agent_event *aevent;
672 struct lttng_ht_iter iter;
673 struct lttng_ht_node_str *node;
674
675 assert(agt);
676 assert(usess);
677 assert(event_name);
678
679 DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id);
680
681 rcu_read_lock();
682 agent_find_events_by_name(event_name, agt, &iter);
683 node = lttng_ht_iter_get_node_str(&iter);
684
685 if (node == NULL) {
686 DBG2("Event agent NOT found by name %s", event_name);
687 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
688 goto end;
689 }
690
691 do {
692 aevent = caa_container_of(node, struct agent_event, node);
693 ret = event_agent_disable_one(usess, agt, aevent);
694
695 if (ret != LTTNG_OK) {
696 goto end;
697 }
698
699 /* Get next duplicate agent event by name. */
700 agent_event_next_duplicate(event_name, agt, &iter);
701 node = lttng_ht_iter_get_node_str(&iter);
702 } while (node);
703end:
704 rcu_read_unlock();
705 return ret;
706}
f20baf8e 707/*
022d91ba 708 * Disable all agent event for a given UST session.
f20baf8e
DG
709 *
710 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
711 */
fefd409b
DG
712int event_agent_disable_all(struct ltt_ust_session *usess,
713 struct agent *agt)
f20baf8e 714{
0dcfcf94 715 int ret;
fefd409b 716 struct agent_event *aevent;
f20baf8e
DG
717 struct lttng_ht_iter iter;
718
fefd409b 719 assert(agt);
f20baf8e
DG
720 assert(usess);
721
0dcfcf94
DG
722 /*
723 * Disable event on agent application. Continue to disable all other events
724 * if the * event is not found.
725 */
fefd409b 726 ret = event_agent_disable(usess, agt, "*");
0dcfcf94
DG
727 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) {
728 goto error;
f20baf8e
DG
729 }
730
b9866e08 731 /* Disable every event. */
f20baf8e 732 rcu_read_lock();
fefd409b 733 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
f20baf8e 734 node.node) {
0dcfcf94
DG
735 if (!aevent->enabled) {
736 continue;
737 }
738
739 ret = event_agent_disable(usess, agt, aevent->name);
740 if (ret != LTTNG_OK) {
b9866e08 741 goto error_unlock;
f20baf8e 742 }
f20baf8e 743 }
f20baf8e
DG
744 ret = LTTNG_OK;
745
b9866e08
JG
746error_unlock:
747 rcu_read_unlock();
f20baf8e
DG
748error:
749 return ret;
750}
This page took 0.098507 seconds and 4 git commands to generate.