Introduce event type field in common structure
[lttng-ust.git] / liblttng-ust / lttng-events.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng per-session event registry.
7 */
8
9 #define _LGPL_SOURCE
10 #include <stdio.h>
11 #include <assert.h>
12 #include <errno.h>
13 #include <limits.h>
14 #include <pthread.h>
15 #include <sys/shm.h>
16 #include <sys/ipc.h>
17 #include <stdint.h>
18 #include <stddef.h>
19 #include <inttypes.h>
20 #include <time.h>
21 #include <stdbool.h>
22 #include <unistd.h>
23 #include <dlfcn.h>
24 #include <lttng/ust-endian.h>
25
26 #include <urcu/arch.h>
27 #include <urcu/compiler.h>
28 #include <urcu/hlist.h>
29 #include <urcu/list.h>
30 #include <urcu/uatomic.h>
31
32 #include <lttng/tracepoint.h>
33 #include <lttng/ust-events.h>
34
35 #include <usterr-signal-safe.h>
36 #include <ust-helper.h>
37 #include <lttng/ust-ctl.h>
38 #include <ust-comm.h>
39 #include <ust-fd.h>
40 #include <ust-dynamic-type.h>
41 #include <ust-context-provider.h>
42 #include "error.h"
43 #include "compat.h"
44 #include "lttng-ust-uuid.h"
45
46 #include "tracepoint-internal.h"
47 #include "string-utils.h"
48 #include "lttng-bytecode.h"
49 #include "lttng-tracer.h"
50 #include "lttng-tracer-core.h"
51 #include "lttng-ust-statedump.h"
52 #include "context-internal.h"
53 #include "ust-events-internal.h"
54 #include "wait.h"
55 #include "../libringbuffer/shm.h"
56 #include "../libcounter/counter.h"
57 #include "jhash.h"
58 #include <lttng/ust-abi.h>
59
60 /*
61 * All operations within this file are called by the communication
62 * thread, under ust_lock protection.
63 */
64
65 static CDS_LIST_HEAD(sessions);
66 static CDS_LIST_HEAD(event_notifier_groups);
67
68 struct cds_list_head *lttng_get_sessions(void)
69 {
70 return &sessions;
71 }
72
73 static void _lttng_event_recorder_destroy(struct lttng_ust_event_recorder *event_recorder);
74 static void _lttng_event_notifier_destroy(
75 struct lttng_ust_event_notifier *event_notifier);
76 static void _lttng_enum_destroy(struct lttng_enum *_enum);
77
78 static
79 void lttng_session_lazy_sync_event_enablers(struct lttng_session *session);
80 static
81 void lttng_session_sync_event_enablers(struct lttng_session *session);
82 static
83 void lttng_event_notifier_group_sync_enablers(
84 struct lttng_event_notifier_group *event_notifier_group);
85 static
86 void lttng_enabler_destroy(struct lttng_enabler *enabler);
87
88 /*
89 * Called with ust lock held.
90 */
91 int lttng_session_active(void)
92 {
93 struct lttng_ust_session_private *iter;
94
95 cds_list_for_each_entry(iter, &sessions, node) {
96 if (iter->pub->active)
97 return 1;
98 }
99 return 0;
100 }
101
102 static
103 int lttng_loglevel_match(int loglevel,
104 unsigned int has_loglevel,
105 enum lttng_ust_abi_loglevel_type req_type,
106 int req_loglevel)
107 {
108 if (!has_loglevel)
109 loglevel = TRACE_DEFAULT;
110 switch (req_type) {
111 case LTTNG_UST_ABI_LOGLEVEL_RANGE:
112 if (loglevel <= req_loglevel
113 || (req_loglevel == -1 && loglevel <= TRACE_DEBUG))
114 return 1;
115 else
116 return 0;
117 case LTTNG_UST_ABI_LOGLEVEL_SINGLE:
118 if (loglevel == req_loglevel
119 || (req_loglevel == -1 && loglevel <= TRACE_DEBUG))
120 return 1;
121 else
122 return 0;
123 case LTTNG_UST_ABI_LOGLEVEL_ALL:
124 default:
125 if (loglevel <= TRACE_DEBUG)
126 return 1;
127 else
128 return 0;
129 }
130 }
131
132 struct lttng_session *lttng_session_create(void)
133 {
134 struct lttng_session *session;
135 struct lttng_ust_session_private *session_priv;
136 int i;
137
138 session = zmalloc(sizeof(struct lttng_session));
139 if (!session)
140 return NULL;
141 session->struct_size = sizeof(struct lttng_session);
142 session_priv = zmalloc(sizeof(struct lttng_ust_session_private));
143 if (!session_priv) {
144 free(session);
145 return NULL;
146 }
147 session->priv = session_priv;
148 session_priv->pub = session;
149 if (lttng_context_init_all(&session->priv->ctx)) {
150 free(session_priv);
151 free(session);
152 return NULL;
153 }
154 CDS_INIT_LIST_HEAD(&session->priv->chan_head);
155 CDS_INIT_LIST_HEAD(&session->priv->events_head);
156 CDS_INIT_LIST_HEAD(&session->priv->enums_head);
157 CDS_INIT_LIST_HEAD(&session->priv->enablers_head);
158 for (i = 0; i < LTTNG_UST_EVENT_HT_SIZE; i++)
159 CDS_INIT_HLIST_HEAD(&session->priv->events_ht.table[i]);
160 for (i = 0; i < LTTNG_UST_ENUM_HT_SIZE; i++)
161 CDS_INIT_HLIST_HEAD(&session->priv->enums_ht.table[i]);
162 cds_list_add(&session->priv->node, &sessions);
163 return session;
164 }
165
166 struct lttng_counter *lttng_ust_counter_create(
167 const char *counter_transport_name,
168 size_t number_dimensions, const struct lttng_counter_dimension *dimensions)
169 {
170 struct lttng_counter_transport *counter_transport = NULL;
171 struct lttng_counter *counter = NULL;
172
173 counter_transport = lttng_counter_transport_find(counter_transport_name);
174 if (!counter_transport)
175 goto notransport;
176 counter = zmalloc(sizeof(struct lttng_counter));
177 if (!counter)
178 goto nomem;
179
180 counter->ops = &counter_transport->ops;
181 counter->transport = counter_transport;
182
183 counter->counter = counter->ops->counter_create(
184 number_dimensions, dimensions, 0,
185 -1, 0, NULL, false);
186 if (!counter->counter) {
187 goto create_error;
188 }
189
190 return counter;
191
192 create_error:
193 free(counter);
194 nomem:
195 notransport:
196 return NULL;
197 }
198
199 static
200 void lttng_ust_counter_destroy(struct lttng_counter *counter)
201 {
202 counter->ops->counter_destroy(counter->counter);
203 free(counter);
204 }
205
206 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void)
207 {
208 struct lttng_event_notifier_group *event_notifier_group;
209 int i;
210
211 event_notifier_group = zmalloc(sizeof(struct lttng_event_notifier_group));
212 if (!event_notifier_group)
213 return NULL;
214
215 /* Add all contexts. */
216 if (lttng_context_init_all(&event_notifier_group->ctx)) {
217 free(event_notifier_group);
218 return NULL;
219 }
220
221 CDS_INIT_LIST_HEAD(&event_notifier_group->enablers_head);
222 CDS_INIT_LIST_HEAD(&event_notifier_group->event_notifiers_head);
223 for (i = 0; i < LTTNG_UST_EVENT_NOTIFIER_HT_SIZE; i++)
224 CDS_INIT_HLIST_HEAD(&event_notifier_group->event_notifiers_ht.table[i]);
225
226 cds_list_add(&event_notifier_group->node, &event_notifier_groups);
227
228 return event_notifier_group;
229 }
230
231 /*
232 * Only used internally at session destruction.
233 */
234 static
235 void _lttng_channel_unmap(struct lttng_channel *lttng_chan)
236 {
237 struct channel *chan;
238 struct lttng_ust_shm_handle *handle;
239
240 cds_list_del(&lttng_chan->node);
241 lttng_destroy_context(lttng_chan->ctx);
242 chan = lttng_chan->chan;
243 handle = lttng_chan->handle;
244 /*
245 * note: lttng_chan is private data contained within handle. It
246 * will be freed along with the handle.
247 */
248 channel_destroy(chan, handle, 0);
249 }
250
251 static
252 void register_event_recorder(struct lttng_ust_event_recorder *event_recorder)
253 {
254 int ret;
255 const struct lttng_event_desc *desc;
256
257 assert(event_recorder->parent->priv->registered == 0);
258 desc = event_recorder->parent->priv->desc;
259 ret = __tracepoint_probe_register_queue_release(desc->name,
260 desc->probe_callback,
261 event_recorder, desc->signature);
262 WARN_ON_ONCE(ret);
263 if (!ret)
264 event_recorder->parent->priv->registered = 1;
265 }
266
267 static
268 void register_event_notifier(struct lttng_ust_event_notifier *event_notifier)
269 {
270 int ret;
271 const struct lttng_event_desc *desc;
272
273 assert(event_notifier->parent->priv->registered == 0);
274 desc = event_notifier->parent->priv->desc;
275 ret = __tracepoint_probe_register_queue_release(desc->name,
276 desc->u.ext.event_notifier_callback, event_notifier, desc->signature);
277 WARN_ON_ONCE(ret);
278 if (!ret)
279 event_notifier->parent->priv->registered = 1;
280 }
281
282 static
283 void unregister_event_recorder(struct lttng_ust_event_recorder *event_recorder)
284 {
285 int ret;
286 const struct lttng_event_desc *desc;
287
288 assert(event_recorder->parent->priv->registered == 1);
289 desc = event_recorder->parent->priv->desc;
290 ret = __tracepoint_probe_unregister_queue_release(desc->name,
291 desc->probe_callback,
292 event_recorder);
293 WARN_ON_ONCE(ret);
294 if (!ret)
295 event_recorder->parent->priv->registered = 0;
296 }
297
298 static
299 void unregister_event_notifier(struct lttng_ust_event_notifier *event_notifier)
300 {
301 int ret;
302 const struct lttng_event_desc *desc;
303
304 assert(event_notifier->parent->priv->registered == 1);
305 desc = event_notifier->parent->priv->desc;
306 ret = __tracepoint_probe_unregister_queue_release(desc->name,
307 desc->u.ext.event_notifier_callback, event_notifier);
308 WARN_ON_ONCE(ret);
309 if (!ret)
310 event_notifier->parent->priv->registered = 0;
311 }
312
313 /*
314 * Only used internally at session destruction.
315 */
316 static
317 void _lttng_event_recorder_unregister(struct lttng_ust_event_recorder *event_recorder)
318 {
319 if (event_recorder->parent->priv->registered)
320 unregister_event_recorder(event_recorder);
321 }
322
323 /*
324 * Only used internally at session destruction.
325 */
326 static
327 void _lttng_event_notifier_unregister(struct lttng_ust_event_notifier *event_notifier)
328 {
329 if (event_notifier->parent->priv->registered)
330 unregister_event_notifier(event_notifier);
331 }
332
333 void lttng_session_destroy(struct lttng_session *session)
334 {
335 struct lttng_channel *chan, *tmpchan;
336 struct lttng_ust_event_recorder_private *event_recorder_priv, *tmpevent_recorder_priv;
337 struct lttng_enum *_enum, *tmp_enum;
338 struct lttng_event_enabler *event_enabler, *event_tmpenabler;
339
340 CMM_ACCESS_ONCE(session->active) = 0;
341 cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) {
342 _lttng_event_recorder_unregister(event_recorder_priv->pub);
343 }
344 lttng_ust_urcu_synchronize_rcu(); /* Wait for in-flight events to complete */
345 __tracepoint_probe_prune_release_queue();
346 cds_list_for_each_entry_safe(event_enabler, event_tmpenabler,
347 &session->priv->enablers_head, node)
348 lttng_event_enabler_destroy(event_enabler);
349 cds_list_for_each_entry_safe(event_recorder_priv, tmpevent_recorder_priv,
350 &session->priv->events_head, node)
351 _lttng_event_recorder_destroy(event_recorder_priv->pub);
352 cds_list_for_each_entry_safe(_enum, tmp_enum,
353 &session->priv->enums_head, node)
354 _lttng_enum_destroy(_enum);
355 cds_list_for_each_entry_safe(chan, tmpchan, &session->priv->chan_head, node)
356 _lttng_channel_unmap(chan);
357 cds_list_del(&session->priv->node);
358 lttng_destroy_context(session->priv->ctx);
359 free(session->priv);
360 free(session);
361 }
362
363 void lttng_event_notifier_group_destroy(
364 struct lttng_event_notifier_group *event_notifier_group)
365 {
366 int close_ret;
367 struct lttng_event_notifier_enabler *notifier_enabler, *tmpnotifier_enabler;
368 struct lttng_ust_event_notifier_private *notifier_priv, *tmpnotifier_priv;
369
370 if (!event_notifier_group) {
371 return;
372 }
373
374 cds_list_for_each_entry(notifier_priv,
375 &event_notifier_group->event_notifiers_head, node)
376 _lttng_event_notifier_unregister(notifier_priv->pub);
377
378 lttng_ust_urcu_synchronize_rcu();
379
380 cds_list_for_each_entry_safe(notifier_enabler, tmpnotifier_enabler,
381 &event_notifier_group->enablers_head, node)
382 lttng_event_notifier_enabler_destroy(notifier_enabler);
383
384 cds_list_for_each_entry_safe(notifier_priv, tmpnotifier_priv,
385 &event_notifier_group->event_notifiers_head, node)
386 _lttng_event_notifier_destroy(notifier_priv->pub);
387
388 if (event_notifier_group->error_counter)
389 lttng_ust_counter_destroy(event_notifier_group->error_counter);
390
391 /* Close the notification fd to the listener of event_notifiers. */
392
393 lttng_ust_lock_fd_tracker();
394 close_ret = close(event_notifier_group->notification_fd);
395 if (!close_ret) {
396 lttng_ust_delete_fd_from_tracker(
397 event_notifier_group->notification_fd);
398 } else {
399 PERROR("close");
400 abort();
401 }
402 lttng_ust_unlock_fd_tracker();
403
404 cds_list_del(&event_notifier_group->node);
405
406 free(event_notifier_group);
407 }
408
409 static
410 void lttng_enabler_destroy(struct lttng_enabler *enabler)
411 {
412 struct lttng_ust_bytecode_node *filter_node, *tmp_filter_node;
413 struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node;
414
415 if (!enabler) {
416 return;
417 }
418
419 /* Destroy filter bytecode */
420 cds_list_for_each_entry_safe(filter_node, tmp_filter_node,
421 &enabler->filter_bytecode_head, node) {
422 free(filter_node);
423 }
424
425 /* Destroy excluders */
426 cds_list_for_each_entry_safe(excluder_node, tmp_excluder_node,
427 &enabler->excluder_head, node) {
428 free(excluder_node);
429 }
430 }
431
432 void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler *event_notifier_enabler)
433 {
434 if (!event_notifier_enabler) {
435 return;
436 }
437
438 cds_list_del(&event_notifier_enabler->node);
439
440 lttng_enabler_destroy(lttng_event_notifier_enabler_as_enabler(event_notifier_enabler));
441
442 free(event_notifier_enabler);
443 }
444
445 static
446 int lttng_enum_create(const struct lttng_enum_desc *desc,
447 struct lttng_session *session)
448 {
449 const char *enum_name = desc->name;
450 struct lttng_enum *_enum;
451 struct cds_hlist_head *head;
452 int ret = 0;
453 size_t name_len = strlen(enum_name);
454 uint32_t hash;
455 int notify_socket;
456
457 /* Check if this enum is already registered for this session. */
458 hash = jhash(enum_name, name_len, 0);
459 head = &session->priv->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
460
461 _enum = lttng_ust_enum_get_from_desc(session, desc);
462 if (_enum) {
463 ret = -EEXIST;
464 goto exist;
465 }
466
467 notify_socket = lttng_get_notify_socket(session->priv->owner);
468 if (notify_socket < 0) {
469 ret = notify_socket;
470 goto socket_error;
471 }
472
473 _enum = zmalloc(sizeof(*_enum));
474 if (!_enum) {
475 ret = -ENOMEM;
476 goto cache_error;
477 }
478 _enum->session = session;
479 _enum->desc = desc;
480
481 ret = ustcomm_register_enum(notify_socket,
482 session->priv->objd,
483 enum_name,
484 desc->nr_entries,
485 desc->entries,
486 &_enum->id);
487 if (ret < 0) {
488 DBG("Error (%d) registering enumeration to sessiond", ret);
489 goto sessiond_register_error;
490 }
491 cds_list_add(&_enum->node, &session->priv->enums_head);
492 cds_hlist_add_head(&_enum->hlist, head);
493 return 0;
494
495 sessiond_register_error:
496 free(_enum);
497 cache_error:
498 socket_error:
499 exist:
500 return ret;
501 }
502
503 static
504 int lttng_create_enum_check(const struct lttng_type *type,
505 struct lttng_session *session)
506 {
507 switch (type->atype) {
508 case atype_enum_nestable:
509 {
510 const struct lttng_enum_desc *enum_desc;
511 int ret;
512
513 enum_desc = type->u.enum_nestable.desc;
514 ret = lttng_enum_create(enum_desc, session);
515 if (ret && ret != -EEXIST) {
516 DBG("Unable to create enum error: (%d)", ret);
517 return ret;
518 }
519 break;
520 }
521 case atype_dynamic:
522 {
523 const struct lttng_event_field *tag_field_generic;
524 const struct lttng_enum_desc *enum_desc;
525 int ret;
526
527 tag_field_generic = lttng_ust_dynamic_type_tag_field();
528 enum_desc = tag_field_generic->type.u.enum_nestable.desc;
529 ret = lttng_enum_create(enum_desc, session);
530 if (ret && ret != -EEXIST) {
531 DBG("Unable to create enum error: (%d)", ret);
532 return ret;
533 }
534 break;
535 }
536 default:
537 /* TODO: nested types when they become supported. */
538 break;
539 }
540 return 0;
541 }
542
543 static
544 int lttng_create_all_event_enums(size_t nr_fields,
545 const struct lttng_event_field *event_fields,
546 struct lttng_session *session)
547 {
548 size_t i;
549 int ret;
550
551 /* For each field, ensure enum is part of the session. */
552 for (i = 0; i < nr_fields; i++) {
553 const struct lttng_type *type = &event_fields[i].type;
554
555 ret = lttng_create_enum_check(type, session);
556 if (ret)
557 return ret;
558 }
559 return 0;
560 }
561
562 static
563 int lttng_create_all_ctx_enums(size_t nr_fields,
564 const struct lttng_ctx_field *ctx_fields,
565 struct lttng_session *session)
566 {
567 size_t i;
568 int ret;
569
570 /* For each field, ensure enum is part of the session. */
571 for (i = 0; i < nr_fields; i++) {
572 const struct lttng_type *type = &ctx_fields[i].event_field.type;
573
574 ret = lttng_create_enum_check(type, session);
575 if (ret)
576 return ret;
577 }
578 return 0;
579 }
580
581 /*
582 * Ensure that a state-dump will be performed for this session at the end
583 * of the current handle_message().
584 */
585 int lttng_session_statedump(struct lttng_session *session)
586 {
587 session->priv->statedump_pending = 1;
588 lttng_ust_sockinfo_session_enabled(session->priv->owner);
589 return 0;
590 }
591
592 int lttng_session_enable(struct lttng_session *session)
593 {
594 int ret = 0;
595 struct lttng_channel *chan;
596 int notify_socket;
597
598 if (session->active) {
599 ret = -EBUSY;
600 goto end;
601 }
602
603 notify_socket = lttng_get_notify_socket(session->priv->owner);
604 if (notify_socket < 0)
605 return notify_socket;
606
607 /* Set transient enabler state to "enabled" */
608 session->priv->tstate = 1;
609
610 /* We need to sync enablers with session before activation. */
611 lttng_session_sync_event_enablers(session);
612
613 /*
614 * Snapshot the number of events per channel to know the type of header
615 * we need to use.
616 */
617 cds_list_for_each_entry(chan, &session->priv->chan_head, node) {
618 const struct lttng_ctx *ctx;
619 const struct lttng_ctx_field *fields = NULL;
620 size_t nr_fields = 0;
621 uint32_t chan_id;
622
623 /* don't change it if session stop/restart */
624 if (chan->header_type)
625 continue;
626 ctx = chan->ctx;
627 if (ctx) {
628 nr_fields = ctx->nr_fields;
629 fields = ctx->fields;
630 ret = lttng_create_all_ctx_enums(nr_fields, fields,
631 session);
632 if (ret < 0) {
633 DBG("Error (%d) adding enum to session", ret);
634 return ret;
635 }
636 }
637 ret = ustcomm_register_channel(notify_socket,
638 session,
639 session->priv->objd,
640 chan->objd,
641 nr_fields,
642 fields,
643 &chan_id,
644 &chan->header_type);
645 if (ret) {
646 DBG("Error (%d) registering channel to sessiond", ret);
647 return ret;
648 }
649 if (chan_id != chan->id) {
650 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
651 chan_id, chan->id);
652 return -EINVAL;
653 }
654 }
655
656 /* Set atomically the state to "active" */
657 CMM_ACCESS_ONCE(session->active) = 1;
658 CMM_ACCESS_ONCE(session->priv->been_active) = 1;
659
660 ret = lttng_session_statedump(session);
661 if (ret)
662 return ret;
663 end:
664 return ret;
665 }
666
667 int lttng_session_disable(struct lttng_session *session)
668 {
669 int ret = 0;
670
671 if (!session->active) {
672 ret = -EBUSY;
673 goto end;
674 }
675 /* Set atomically the state to "inactive" */
676 CMM_ACCESS_ONCE(session->active) = 0;
677
678 /* Set transient enabler state to "disabled" */
679 session->priv->tstate = 0;
680 lttng_session_sync_event_enablers(session);
681 end:
682 return ret;
683 }
684
685 int lttng_channel_enable(struct lttng_channel *channel)
686 {
687 int ret = 0;
688
689 if (channel->enabled) {
690 ret = -EBUSY;
691 goto end;
692 }
693 /* Set transient enabler state to "enabled" */
694 channel->tstate = 1;
695 lttng_session_sync_event_enablers(channel->session);
696 /* Set atomically the state to "enabled" */
697 CMM_ACCESS_ONCE(channel->enabled) = 1;
698 end:
699 return ret;
700 }
701
702 int lttng_channel_disable(struct lttng_channel *channel)
703 {
704 int ret = 0;
705
706 if (!channel->enabled) {
707 ret = -EBUSY;
708 goto end;
709 }
710 /* Set atomically the state to "disabled" */
711 CMM_ACCESS_ONCE(channel->enabled) = 0;
712 /* Set transient enabler state to "enabled" */
713 channel->tstate = 0;
714 lttng_session_sync_event_enablers(channel->session);
715 end:
716 return ret;
717 }
718
719 static inline
720 struct cds_hlist_head *borrow_hash_table_bucket(
721 struct cds_hlist_head *hash_table,
722 unsigned int hash_table_size,
723 const struct lttng_event_desc *desc)
724 {
725 const char *event_name;
726 size_t name_len;
727 uint32_t hash;
728
729 event_name = desc->name;
730 name_len = strlen(event_name);
731
732 hash = jhash(event_name, name_len, 0);
733 return &hash_table[hash & (hash_table_size - 1)];
734 }
735
736 /*
737 * Supports event creation while tracing session is active.
738 */
739 static
740 int lttng_event_recorder_create(const struct lttng_event_desc *desc,
741 struct lttng_channel *chan)
742 {
743 struct lttng_ust_event_recorder *event_recorder;
744 struct lttng_ust_event_recorder_private *event_recorder_priv;
745 struct lttng_session *session = chan->session;
746 struct cds_hlist_head *head;
747 int ret = 0;
748 int notify_socket, loglevel;
749 const char *uri;
750
751 head = borrow_hash_table_bucket(chan->session->priv->events_ht.table,
752 LTTNG_UST_EVENT_HT_SIZE, desc);
753
754 notify_socket = lttng_get_notify_socket(session->priv->owner);
755 if (notify_socket < 0) {
756 ret = notify_socket;
757 goto socket_error;
758 }
759
760 ret = lttng_create_all_event_enums(desc->nr_fields, desc->fields,
761 session);
762 if (ret < 0) {
763 DBG("Error (%d) adding enum to session", ret);
764 goto create_enum_error;
765 }
766
767 /*
768 * Check if loglevel match. Refuse to connect event if not.
769 */
770 event_recorder = zmalloc(sizeof(struct lttng_ust_event_recorder));
771 if (!event_recorder) {
772 ret = -ENOMEM;
773 goto cache_error;
774 }
775 event_recorder->struct_size = sizeof(struct lttng_ust_event_recorder);
776
777 event_recorder->parent = zmalloc(sizeof(struct lttng_ust_event_common));
778 if (!event_recorder->parent) {
779 ret = -ENOMEM;
780 goto parent_error;
781 }
782 event_recorder->parent->struct_size = sizeof(struct lttng_ust_event_common);
783 event_recorder->parent->type = LTTNG_UST_EVENT_TYPE_RECORDER;
784
785 event_recorder_priv = zmalloc(sizeof(struct lttng_ust_event_recorder_private));
786 if (!event_recorder_priv) {
787 ret = -ENOMEM;
788 goto priv_error;
789 }
790 event_recorder->priv = event_recorder_priv;
791 event_recorder_priv->pub = event_recorder;
792 event_recorder->parent->priv = &event_recorder_priv->parent;
793 event_recorder_priv->parent.pub = event_recorder->parent;
794
795 event_recorder->chan = chan;
796
797 /* Event will be enabled by enabler sync. */
798 event_recorder->parent->enabled = 0;
799 event_recorder->parent->priv->registered = 0;
800 CDS_INIT_LIST_HEAD(&event_recorder->parent->filter_bytecode_runtime_head);
801 CDS_INIT_LIST_HEAD(&event_recorder->parent->priv->enablers_ref_head);
802 event_recorder->parent->priv->desc = desc;
803
804 if (desc->loglevel)
805 loglevel = *(*event_recorder->parent->priv->desc->loglevel);
806 else
807 loglevel = TRACE_DEFAULT;
808 if (desc->u.ext.model_emf_uri)
809 uri = *(desc->u.ext.model_emf_uri);
810 else
811 uri = NULL;
812
813 /* Fetch event ID from sessiond */
814 ret = ustcomm_register_event(notify_socket,
815 session,
816 session->priv->objd,
817 chan->objd,
818 desc->name,
819 loglevel,
820 desc->signature,
821 desc->nr_fields,
822 desc->fields,
823 uri,
824 &event_recorder->id);
825 if (ret < 0) {
826 DBG("Error (%d) registering event to sessiond", ret);
827 goto sessiond_register_error;
828 }
829
830 cds_list_add(&event_recorder->priv->node, &chan->session->priv->events_head);
831 cds_hlist_add_head(&event_recorder->priv->hlist, head);
832 return 0;
833
834 sessiond_register_error:
835 free(event_recorder_priv);
836 priv_error:
837 free(event_recorder->parent);
838 parent_error:
839 free(event_recorder);
840 cache_error:
841 create_enum_error:
842 socket_error:
843 return ret;
844 }
845
846 static
847 int lttng_event_notifier_create(const struct lttng_event_desc *desc,
848 uint64_t token, uint64_t error_counter_index,
849 struct lttng_event_notifier_group *event_notifier_group)
850 {
851 struct lttng_ust_event_notifier *event_notifier;
852 struct lttng_ust_event_notifier_private *event_notifier_priv;
853 struct cds_hlist_head *head;
854 int ret = 0;
855
856 /*
857 * Get the hashtable bucket the created lttng_event_notifier object
858 * should be inserted.
859 */
860 head = borrow_hash_table_bucket(
861 event_notifier_group->event_notifiers_ht.table,
862 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, desc);
863
864 event_notifier = zmalloc(sizeof(struct lttng_ust_event_notifier));
865 if (!event_notifier) {
866 ret = -ENOMEM;
867 goto error;
868 }
869 event_notifier->struct_size = sizeof(struct lttng_ust_event_notifier);
870
871 event_notifier->parent = zmalloc(sizeof(struct lttng_ust_event_common));
872 if (!event_notifier->parent) {
873 ret = -ENOMEM;
874 goto parent_error;
875 }
876 event_notifier->parent->struct_size = sizeof(struct lttng_ust_event_common);
877 event_notifier->parent->type = LTTNG_UST_EVENT_TYPE_NOTIFIER;
878
879 event_notifier_priv = zmalloc(sizeof(struct lttng_ust_event_notifier_private));
880 if (!event_notifier_priv) {
881 ret = -ENOMEM;
882 goto priv_error;
883 }
884 event_notifier->priv = event_notifier_priv;
885 event_notifier_priv->pub = event_notifier;
886 event_notifier->parent->priv = &event_notifier_priv->parent;
887 event_notifier_priv->parent.pub = event_notifier->parent;
888
889 event_notifier_priv->group = event_notifier_group;
890 event_notifier_priv->parent.user_token = token;
891 event_notifier_priv->error_counter_index = error_counter_index;
892
893 /* Event notifier will be enabled by enabler sync. */
894 event_notifier->parent->enabled = 0;
895 event_notifier_priv->parent.registered = 0;
896
897 CDS_INIT_LIST_HEAD(&event_notifier->parent->filter_bytecode_runtime_head);
898 CDS_INIT_LIST_HEAD(&event_notifier->capture_bytecode_runtime_head);
899 CDS_INIT_LIST_HEAD(&event_notifier_priv->parent.enablers_ref_head);
900 event_notifier_priv->parent.desc = desc;
901 event_notifier->notification_send = lttng_event_notifier_notification_send;
902
903 cds_list_add(&event_notifier_priv->node,
904 &event_notifier_group->event_notifiers_head);
905 cds_hlist_add_head(&event_notifier_priv->hlist, head);
906
907 return 0;
908
909 priv_error:
910 free(event_notifier->parent);
911 parent_error:
912 free(event_notifier);
913 error:
914 return ret;
915 }
916
917 static
918 void _lttng_event_notifier_destroy(struct lttng_ust_event_notifier *event_notifier)
919 {
920 struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref;
921
922 /* Remove from event_notifier list. */
923 cds_list_del(&event_notifier->priv->node);
924 /* Remove from event_notifier hash table. */
925 cds_hlist_del(&event_notifier->priv->hlist);
926
927 lttng_free_event_filter_runtime(event_notifier->parent);
928
929 /* Free event_notifier enabler refs */
930 cds_list_for_each_entry_safe(enabler_ref, tmp_enabler_ref,
931 &event_notifier->priv->parent.enablers_ref_head, node)
932 free(enabler_ref);
933 free(event_notifier->priv);
934 free(event_notifier->parent);
935 free(event_notifier);
936 }
937
938 static
939 int lttng_desc_match_star_glob_enabler(const struct lttng_event_desc *desc,
940 struct lttng_enabler *enabler)
941 {
942 int loglevel = 0;
943 unsigned int has_loglevel = 0;
944
945 assert(enabler->format_type == LTTNG_ENABLER_FORMAT_STAR_GLOB);
946 if (!strutils_star_glob_match(enabler->event_param.name, SIZE_MAX,
947 desc->name, SIZE_MAX))
948 return 0;
949 if (desc->loglevel) {
950 loglevel = *(*desc->loglevel);
951 has_loglevel = 1;
952 }
953 if (!lttng_loglevel_match(loglevel,
954 has_loglevel,
955 enabler->event_param.loglevel_type,
956 enabler->event_param.loglevel))
957 return 0;
958 return 1;
959 }
960
961 static
962 int lttng_desc_match_event_enabler(const struct lttng_event_desc *desc,
963 struct lttng_enabler *enabler)
964 {
965 int loglevel = 0;
966 unsigned int has_loglevel = 0;
967
968 assert(enabler->format_type == LTTNG_ENABLER_FORMAT_EVENT);
969 if (strcmp(desc->name, enabler->event_param.name))
970 return 0;
971 if (desc->loglevel) {
972 loglevel = *(*desc->loglevel);
973 has_loglevel = 1;
974 }
975 if (!lttng_loglevel_match(loglevel,
976 has_loglevel,
977 enabler->event_param.loglevel_type,
978 enabler->event_param.loglevel))
979 return 0;
980 return 1;
981 }
982
983 static
984 int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
985 struct lttng_enabler *enabler)
986 {
987 switch (enabler->format_type) {
988 case LTTNG_ENABLER_FORMAT_STAR_GLOB:
989 {
990 struct lttng_ust_excluder_node *excluder;
991
992 if (!lttng_desc_match_star_glob_enabler(desc, enabler)) {
993 return 0;
994 }
995
996 /*
997 * If the matching event matches with an excluder,
998 * return 'does not match'
999 */
1000 cds_list_for_each_entry(excluder, &enabler->excluder_head, node) {
1001 int count;
1002
1003 for (count = 0; count < excluder->excluder.count; count++) {
1004 int len;
1005 char *excluder_name;
1006
1007 excluder_name = (char *) (excluder->excluder.names)
1008 + count * LTTNG_UST_ABI_SYM_NAME_LEN;
1009 len = strnlen(excluder_name, LTTNG_UST_ABI_SYM_NAME_LEN);
1010 if (len > 0 && strutils_star_glob_match(excluder_name, len, desc->name, SIZE_MAX))
1011 return 0;
1012 }
1013 }
1014 return 1;
1015 }
1016 case LTTNG_ENABLER_FORMAT_EVENT:
1017 return lttng_desc_match_event_enabler(desc, enabler);
1018 default:
1019 return -EINVAL;
1020 }
1021 }
1022
1023 static
1024 int lttng_event_enabler_match_event(struct lttng_event_enabler *event_enabler,
1025 struct lttng_ust_event_recorder *event_recorder)
1026 {
1027 if (lttng_desc_match_enabler(event_recorder->parent->priv->desc,
1028 lttng_event_enabler_as_enabler(event_enabler))
1029 && event_recorder->chan == event_enabler->chan)
1030 return 1;
1031 else
1032 return 0;
1033 }
1034
1035 static
1036 int lttng_event_notifier_enabler_match_event_notifier(
1037 struct lttng_event_notifier_enabler *event_notifier_enabler,
1038 struct lttng_ust_event_notifier *event_notifier)
1039 {
1040 int desc_matches = lttng_desc_match_enabler(event_notifier->priv->parent.desc,
1041 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler));
1042
1043 if (desc_matches && event_notifier->priv->group == event_notifier_enabler->group &&
1044 event_notifier->priv->parent.user_token == event_notifier_enabler->user_token)
1045 return 1;
1046 else
1047 return 0;
1048 }
1049
1050 static
1051 struct lttng_enabler_ref *lttng_enabler_ref(
1052 struct cds_list_head *enabler_ref_list,
1053 struct lttng_enabler *enabler)
1054 {
1055 struct lttng_enabler_ref *enabler_ref;
1056
1057 cds_list_for_each_entry(enabler_ref, enabler_ref_list, node) {
1058 if (enabler_ref->ref == enabler)
1059 return enabler_ref;
1060 }
1061 return NULL;
1062 }
1063
1064 /*
1065 * Create struct lttng_event if it is missing and present in the list of
1066 * tracepoint probes.
1067 */
1068 static
1069 void lttng_create_event_if_missing(struct lttng_event_enabler *event_enabler)
1070 {
1071 struct lttng_session *session = event_enabler->chan->session;
1072 struct lttng_probe_desc *probe_desc;
1073 const struct lttng_event_desc *desc;
1074 struct lttng_ust_event_recorder_private *event_recorder_priv;
1075 int i;
1076 struct cds_list_head *probe_list;
1077
1078 probe_list = lttng_get_probe_list_head();
1079 /*
1080 * For each probe event, if we find that a probe event matches
1081 * our enabler, create an associated lttng_event if not
1082 * already present.
1083 */
1084 cds_list_for_each_entry(probe_desc, probe_list, head) {
1085 for (i = 0; i < probe_desc->nr_events; i++) {
1086 int ret;
1087 bool found = false;
1088 struct cds_hlist_head *head;
1089 struct cds_hlist_node *node;
1090
1091 desc = probe_desc->event_desc[i];
1092 if (!lttng_desc_match_enabler(desc,
1093 lttng_event_enabler_as_enabler(event_enabler)))
1094 continue;
1095
1096 head = borrow_hash_table_bucket(
1097 session->priv->events_ht.table,
1098 LTTNG_UST_EVENT_HT_SIZE, desc);
1099
1100 cds_hlist_for_each_entry(event_recorder_priv, node, head, hlist) {
1101 if (event_recorder_priv->parent.desc == desc
1102 && event_recorder_priv->pub->chan == event_enabler->chan) {
1103 found = true;
1104 break;
1105 }
1106 }
1107 if (found)
1108 continue;
1109
1110 /*
1111 * We need to create an event for this
1112 * event probe.
1113 */
1114 ret = lttng_event_recorder_create(probe_desc->event_desc[i],
1115 event_enabler->chan);
1116 if (ret) {
1117 DBG("Unable to create event %s, error %d\n",
1118 probe_desc->event_desc[i]->name, ret);
1119 }
1120 }
1121 }
1122 }
1123
1124 static
1125 void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc,
1126 void (*event_func)(struct lttng_session *session,
1127 struct lttng_ust_event_recorder *event_recorder),
1128 void (*event_notifier_func)(struct lttng_ust_event_notifier *event_notifier))
1129 {
1130 struct cds_hlist_node *node, *tmp_node;
1131 struct cds_list_head *sessionsp;
1132 unsigned int i;
1133
1134 /* Get handle on list of sessions. */
1135 sessionsp = lttng_get_sessions();
1136
1137 /*
1138 * Iterate over all events in the probe provider descriptions and
1139 * sessions to queue the unregistration of the events.
1140 */
1141 for (i = 0; i < provider_desc->nr_events; i++) {
1142 const struct lttng_event_desc *event_desc;
1143 struct lttng_event_notifier_group *event_notifier_group;
1144 struct lttng_ust_event_notifier_private *event_notifier_priv;
1145 struct lttng_ust_session_private *session_priv;
1146 struct cds_hlist_head *head;
1147 struct lttng_ust_event_recorder_private *event_recorder_priv;
1148
1149 event_desc = provider_desc->event_desc[i];
1150
1151 /*
1152 * Iterate over all session to find the current event
1153 * description.
1154 */
1155 cds_list_for_each_entry(session_priv, sessionsp, node) {
1156 /*
1157 * Get the list of events in the hashtable bucket and
1158 * iterate to find the event matching this descriptor.
1159 */
1160 head = borrow_hash_table_bucket(
1161 session_priv->events_ht.table,
1162 LTTNG_UST_EVENT_HT_SIZE, event_desc);
1163
1164 cds_hlist_for_each_entry_safe(event_recorder_priv, node, tmp_node, head, hlist) {
1165 if (event_desc == event_recorder_priv->parent.desc) {
1166 event_func(session_priv->pub, event_recorder_priv->pub);
1167 break;
1168 }
1169 }
1170 }
1171
1172 /*
1173 * Iterate over all event_notifier groups to find the current event
1174 * description.
1175 */
1176 cds_list_for_each_entry(event_notifier_group, &event_notifier_groups, node) {
1177 /*
1178 * Get the list of event_notifiers in the hashtable bucket and
1179 * iterate to find the event_notifier matching this
1180 * descriptor.
1181 */
1182 head = borrow_hash_table_bucket(
1183 event_notifier_group->event_notifiers_ht.table,
1184 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, event_desc);
1185
1186 cds_hlist_for_each_entry_safe(event_notifier_priv, node, tmp_node, head, hlist) {
1187 if (event_desc == event_notifier_priv->parent.desc) {
1188 event_notifier_func(event_notifier_priv->pub);
1189 break;
1190 }
1191 }
1192 }
1193 }
1194 }
1195
1196 static
1197 void _unregister_event_recorder(struct lttng_session *session,
1198 struct lttng_ust_event_recorder *event_recorder)
1199 {
1200 _lttng_event_recorder_unregister(event_recorder);
1201 }
1202
1203 static
1204 void _event_enum_destroy(struct lttng_session *session,
1205 struct lttng_ust_event_recorder *event_recorder)
1206 {
1207 unsigned int i;
1208
1209 /* Destroy enums of the current event. */
1210 for (i = 0; i < event_recorder->parent->priv->desc->nr_fields; i++) {
1211 const struct lttng_enum_desc *enum_desc;
1212 const struct lttng_event_field *field;
1213 struct lttng_enum *curr_enum;
1214
1215 field = &(event_recorder->parent->priv->desc->fields[i]);
1216 switch (field->type.atype) {
1217 case atype_enum_nestable:
1218 enum_desc = field->type.u.enum_nestable.desc;
1219 break;
1220 default:
1221 continue;
1222 }
1223
1224 curr_enum = lttng_ust_enum_get_from_desc(session, enum_desc);
1225 if (curr_enum) {
1226 _lttng_enum_destroy(curr_enum);
1227 }
1228 }
1229
1230 /* Destroy event. */
1231 _lttng_event_recorder_destroy(event_recorder);
1232 }
1233
1234 /*
1235 * Iterate over all the UST sessions to unregister and destroy all probes from
1236 * the probe provider descriptor received as argument. Must me called with the
1237 * ust_lock held.
1238 */
1239 void lttng_probe_provider_unregister_events(
1240 struct lttng_probe_desc *provider_desc)
1241 {
1242 /*
1243 * Iterate over all events in the probe provider descriptions and sessions
1244 * to queue the unregistration of the events.
1245 */
1246 probe_provider_event_for_each(provider_desc, _unregister_event_recorder,
1247 _lttng_event_notifier_unregister);
1248
1249 /* Wait for grace period. */
1250 lttng_ust_urcu_synchronize_rcu();
1251 /* Prune the unregistration queue. */
1252 __tracepoint_probe_prune_release_queue();
1253
1254 /*
1255 * It is now safe to destroy the events and remove them from the event list
1256 * and hashtables.
1257 */
1258 probe_provider_event_for_each(provider_desc, _event_enum_destroy,
1259 _lttng_event_notifier_destroy);
1260 }
1261
1262 /*
1263 * Create events associated with an event enabler (if not already present),
1264 * and add backward reference from the event to the enabler.
1265 */
1266 static
1267 int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler)
1268 {
1269 struct lttng_session *session = event_enabler->chan->session;
1270 struct lttng_ust_event_recorder_private *event_recorder_priv;
1271
1272 if (!lttng_event_enabler_as_enabler(event_enabler)->enabled)
1273 goto end;
1274
1275 /* First ensure that probe events are created for this enabler. */
1276 lttng_create_event_if_missing(event_enabler);
1277
1278 /* For each event matching enabler in session event list. */
1279 cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) {
1280 struct lttng_enabler_ref *enabler_ref;
1281
1282 if (!lttng_event_enabler_match_event(event_enabler, event_recorder_priv->pub))
1283 continue;
1284
1285 enabler_ref = lttng_enabler_ref(&event_recorder_priv->parent.enablers_ref_head,
1286 lttng_event_enabler_as_enabler(event_enabler));
1287 if (!enabler_ref) {
1288 /*
1289 * If no backward ref, create it.
1290 * Add backward ref from event to enabler.
1291 */
1292 enabler_ref = zmalloc(sizeof(*enabler_ref));
1293 if (!enabler_ref)
1294 return -ENOMEM;
1295 enabler_ref->ref = lttng_event_enabler_as_enabler(
1296 event_enabler);
1297 cds_list_add(&enabler_ref->node,
1298 &event_recorder_priv->parent.enablers_ref_head);
1299 }
1300
1301 /*
1302 * Link filter bytecodes if not linked yet.
1303 */
1304 lttng_enabler_link_bytecode(event_recorder_priv->parent.desc,
1305 &session->priv->ctx,
1306 &event_recorder_priv->pub->parent->filter_bytecode_runtime_head,
1307 &lttng_event_enabler_as_enabler(event_enabler)->filter_bytecode_head);
1308
1309 /* TODO: merge event context. */
1310 }
1311 end:
1312 return 0;
1313 }
1314
1315 /*
1316 * Called at library load: connect the probe on all enablers matching
1317 * this event.
1318 * Called with session mutex held.
1319 */
1320 int lttng_fix_pending_events(void)
1321 {
1322 struct lttng_ust_session_private *session_priv;
1323
1324 cds_list_for_each_entry(session_priv, &sessions, node) {
1325 lttng_session_lazy_sync_event_enablers(session_priv->pub);
1326 }
1327 return 0;
1328 }
1329
1330 int lttng_fix_pending_event_notifiers(void)
1331 {
1332 struct lttng_event_notifier_group *event_notifier_group;
1333
1334 cds_list_for_each_entry(event_notifier_group, &event_notifier_groups, node) {
1335 lttng_event_notifier_group_sync_enablers(event_notifier_group);
1336 }
1337 return 0;
1338 }
1339
1340 /*
1341 * For each session of the owner thread, execute pending statedump.
1342 * Only dump state for the sessions owned by the caller thread, because
1343 * we don't keep ust_lock across the entire iteration.
1344 */
1345 void lttng_handle_pending_statedump(void *owner)
1346 {
1347 struct lttng_ust_session_private *session_priv;
1348
1349 /* Execute state dump */
1350 do_lttng_ust_statedump(owner);
1351
1352 /* Clear pending state dump */
1353 if (ust_lock()) {
1354 goto end;
1355 }
1356 cds_list_for_each_entry(session_priv, &sessions, node) {
1357 if (session_priv->owner != owner)
1358 continue;
1359 if (!session_priv->statedump_pending)
1360 continue;
1361 session_priv->statedump_pending = 0;
1362 }
1363 end:
1364 ust_unlock();
1365 return;
1366 }
1367
1368 /*
1369 * Only used internally at session destruction.
1370 */
1371 static
1372 void _lttng_event_recorder_destroy(struct lttng_ust_event_recorder *event_recorder)
1373 {
1374 struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref;
1375
1376 /* Remove from event list. */
1377 cds_list_del(&event_recorder->priv->node);
1378 /* Remove from event hash table. */
1379 cds_hlist_del(&event_recorder->priv->hlist);
1380
1381 lttng_destroy_context(event_recorder->ctx);
1382 lttng_free_event_filter_runtime(event_recorder->parent);
1383 /* Free event enabler refs */
1384 cds_list_for_each_entry_safe(enabler_ref, tmp_enabler_ref,
1385 &event_recorder->parent->priv->enablers_ref_head, node)
1386 free(enabler_ref);
1387 free(event_recorder->priv);
1388 free(event_recorder->parent);
1389 free(event_recorder);
1390 }
1391
1392 static
1393 void _lttng_enum_destroy(struct lttng_enum *_enum)
1394 {
1395 cds_list_del(&_enum->node);
1396 cds_hlist_del(&_enum->hlist);
1397 free(_enum);
1398 }
1399
1400 void lttng_ust_abi_events_exit(void)
1401 {
1402 struct lttng_ust_session_private *session_priv, *tmpsession_priv;
1403
1404 cds_list_for_each_entry_safe(session_priv, tmpsession_priv, &sessions, node)
1405 lttng_session_destroy(session_priv->pub);
1406 }
1407
1408 /*
1409 * Enabler management.
1410 */
1411 struct lttng_event_enabler *lttng_event_enabler_create(
1412 enum lttng_enabler_format_type format_type,
1413 struct lttng_ust_abi_event *event_param,
1414 struct lttng_channel *chan)
1415 {
1416 struct lttng_event_enabler *event_enabler;
1417
1418 event_enabler = zmalloc(sizeof(*event_enabler));
1419 if (!event_enabler)
1420 return NULL;
1421 event_enabler->base.format_type = format_type;
1422 CDS_INIT_LIST_HEAD(&event_enabler->base.filter_bytecode_head);
1423 CDS_INIT_LIST_HEAD(&event_enabler->base.excluder_head);
1424 memcpy(&event_enabler->base.event_param, event_param,
1425 sizeof(event_enabler->base.event_param));
1426 event_enabler->chan = chan;
1427 /* ctx left NULL */
1428 event_enabler->base.enabled = 0;
1429 cds_list_add(&event_enabler->node, &event_enabler->chan->session->priv->enablers_head);
1430 lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
1431
1432 return event_enabler;
1433 }
1434
1435 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
1436 struct lttng_event_notifier_group *event_notifier_group,
1437 enum lttng_enabler_format_type format_type,
1438 struct lttng_ust_abi_event_notifier *event_notifier_param)
1439 {
1440 struct lttng_event_notifier_enabler *event_notifier_enabler;
1441
1442 event_notifier_enabler = zmalloc(sizeof(*event_notifier_enabler));
1443 if (!event_notifier_enabler)
1444 return NULL;
1445 event_notifier_enabler->base.format_type = format_type;
1446 CDS_INIT_LIST_HEAD(&event_notifier_enabler->base.filter_bytecode_head);
1447 CDS_INIT_LIST_HEAD(&event_notifier_enabler->capture_bytecode_head);
1448 CDS_INIT_LIST_HEAD(&event_notifier_enabler->base.excluder_head);
1449
1450 event_notifier_enabler->user_token = event_notifier_param->event.token;
1451 event_notifier_enabler->error_counter_index = event_notifier_param->error_counter_index;
1452 event_notifier_enabler->num_captures = 0;
1453
1454 memcpy(&event_notifier_enabler->base.event_param.name,
1455 event_notifier_param->event.name,
1456 sizeof(event_notifier_enabler->base.event_param.name));
1457 event_notifier_enabler->base.event_param.instrumentation =
1458 event_notifier_param->event.instrumentation;
1459 event_notifier_enabler->base.event_param.loglevel =
1460 event_notifier_param->event.loglevel;
1461 event_notifier_enabler->base.event_param.loglevel_type =
1462 event_notifier_param->event.loglevel_type;
1463
1464 event_notifier_enabler->base.enabled = 0;
1465 event_notifier_enabler->group = event_notifier_group;
1466
1467 cds_list_add(&event_notifier_enabler->node,
1468 &event_notifier_group->enablers_head);
1469
1470 lttng_event_notifier_group_sync_enablers(event_notifier_group);
1471
1472 return event_notifier_enabler;
1473 }
1474
1475 int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler)
1476 {
1477 lttng_event_enabler_as_enabler(event_enabler)->enabled = 1;
1478 lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
1479
1480 return 0;
1481 }
1482
1483 int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler)
1484 {
1485 lttng_event_enabler_as_enabler(event_enabler)->enabled = 0;
1486 lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
1487
1488 return 0;
1489 }
1490
1491 static
1492 void _lttng_enabler_attach_filter_bytecode(struct lttng_enabler *enabler,
1493 struct lttng_ust_bytecode_node **bytecode)
1494 {
1495 (*bytecode)->enabler = enabler;
1496 cds_list_add_tail(&(*bytecode)->node, &enabler->filter_bytecode_head);
1497 /* Take ownership of bytecode */
1498 *bytecode = NULL;
1499 }
1500
1501 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event_enabler,
1502 struct lttng_ust_bytecode_node **bytecode)
1503 {
1504 _lttng_enabler_attach_filter_bytecode(
1505 lttng_event_enabler_as_enabler(event_enabler), bytecode);
1506
1507 lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
1508 return 0;
1509 }
1510
1511 static
1512 void _lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
1513 struct lttng_ust_excluder_node **excluder)
1514 {
1515 (*excluder)->enabler = enabler;
1516 cds_list_add_tail(&(*excluder)->node, &enabler->excluder_head);
1517 /* Take ownership of excluder */
1518 *excluder = NULL;
1519 }
1520
1521 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabler,
1522 struct lttng_ust_excluder_node **excluder)
1523 {
1524 _lttng_enabler_attach_exclusion(
1525 lttng_event_enabler_as_enabler(event_enabler), excluder);
1526
1527 lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
1528 return 0;
1529 }
1530
1531 int lttng_event_notifier_enabler_enable(
1532 struct lttng_event_notifier_enabler *event_notifier_enabler)
1533 {
1534 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled = 1;
1535 lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
1536
1537 return 0;
1538 }
1539
1540 int lttng_event_notifier_enabler_disable(
1541 struct lttng_event_notifier_enabler *event_notifier_enabler)
1542 {
1543 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled = 0;
1544 lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
1545
1546 return 0;
1547 }
1548
1549 int lttng_event_notifier_enabler_attach_filter_bytecode(
1550 struct lttng_event_notifier_enabler *event_notifier_enabler,
1551 struct lttng_ust_bytecode_node **bytecode)
1552 {
1553 _lttng_enabler_attach_filter_bytecode(
1554 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler),
1555 bytecode);
1556
1557 lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
1558 return 0;
1559 }
1560
1561 int lttng_event_notifier_enabler_attach_capture_bytecode(
1562 struct lttng_event_notifier_enabler *event_notifier_enabler,
1563 struct lttng_ust_bytecode_node **bytecode)
1564 {
1565 (*bytecode)->enabler = lttng_event_notifier_enabler_as_enabler(
1566 event_notifier_enabler);
1567 cds_list_add_tail(&(*bytecode)->node,
1568 &event_notifier_enabler->capture_bytecode_head);
1569 /* Take ownership of bytecode */
1570 *bytecode = NULL;
1571 event_notifier_enabler->num_captures++;
1572
1573 lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
1574 return 0;
1575 }
1576
1577 int lttng_event_notifier_enabler_attach_exclusion(
1578 struct lttng_event_notifier_enabler *event_notifier_enabler,
1579 struct lttng_ust_excluder_node **excluder)
1580 {
1581 _lttng_enabler_attach_exclusion(
1582 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler),
1583 excluder);
1584
1585 lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
1586 return 0;
1587 }
1588
1589 int lttng_attach_context(struct lttng_ust_abi_context *context_param,
1590 union lttng_ust_abi_args *uargs,
1591 struct lttng_ctx **ctx, struct lttng_session *session)
1592 {
1593 /*
1594 * We cannot attach a context after trace has been started for a
1595 * session because the metadata does not allow expressing this
1596 * information outside of the original channel scope.
1597 */
1598 if (session->priv->been_active)
1599 return -EPERM;
1600
1601 switch (context_param->ctx) {
1602 case LTTNG_UST_ABI_CONTEXT_PTHREAD_ID:
1603 return lttng_add_pthread_id_to_ctx(ctx);
1604 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER:
1605 {
1606 struct lttng_ust_abi_perf_counter_ctx *perf_ctx_param;
1607
1608 perf_ctx_param = &context_param->u.perf_counter;
1609 return lttng_add_perf_counter_to_ctx(
1610 perf_ctx_param->type,
1611 perf_ctx_param->config,
1612 perf_ctx_param->name,
1613 ctx);
1614 }
1615 case LTTNG_UST_ABI_CONTEXT_VTID:
1616 return lttng_add_vtid_to_ctx(ctx);
1617 case LTTNG_UST_ABI_CONTEXT_VPID:
1618 return lttng_add_vpid_to_ctx(ctx);
1619 case LTTNG_UST_ABI_CONTEXT_PROCNAME:
1620 return lttng_add_procname_to_ctx(ctx);
1621 case LTTNG_UST_ABI_CONTEXT_IP:
1622 return lttng_add_ip_to_ctx(ctx);
1623 case LTTNG_UST_ABI_CONTEXT_CPU_ID:
1624 return lttng_add_cpu_id_to_ctx(ctx);
1625 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT:
1626 return lttng_ust_add_app_context_to_ctx_rcu(uargs->app_context.ctxname,
1627 ctx);
1628 case LTTNG_UST_ABI_CONTEXT_CGROUP_NS:
1629 return lttng_add_cgroup_ns_to_ctx(ctx);
1630 case LTTNG_UST_ABI_CONTEXT_IPC_NS:
1631 return lttng_add_ipc_ns_to_ctx(ctx);
1632 case LTTNG_UST_ABI_CONTEXT_MNT_NS:
1633 return lttng_add_mnt_ns_to_ctx(ctx);
1634 case LTTNG_UST_ABI_CONTEXT_NET_NS:
1635 return lttng_add_net_ns_to_ctx(ctx);
1636 case LTTNG_UST_ABI_CONTEXT_PID_NS:
1637 return lttng_add_pid_ns_to_ctx(ctx);
1638 case LTTNG_UST_ABI_CONTEXT_TIME_NS:
1639 return lttng_add_time_ns_to_ctx(ctx);
1640 case LTTNG_UST_ABI_CONTEXT_USER_NS:
1641 return lttng_add_user_ns_to_ctx(ctx);
1642 case LTTNG_UST_ABI_CONTEXT_UTS_NS:
1643 return lttng_add_uts_ns_to_ctx(ctx);
1644 case LTTNG_UST_ABI_CONTEXT_VUID:
1645 return lttng_add_vuid_to_ctx(ctx);
1646 case LTTNG_UST_ABI_CONTEXT_VEUID:
1647 return lttng_add_veuid_to_ctx(ctx);
1648 case LTTNG_UST_ABI_CONTEXT_VSUID:
1649 return lttng_add_vsuid_to_ctx(ctx);
1650 case LTTNG_UST_ABI_CONTEXT_VGID:
1651 return lttng_add_vgid_to_ctx(ctx);
1652 case LTTNG_UST_ABI_CONTEXT_VEGID:
1653 return lttng_add_vegid_to_ctx(ctx);
1654 case LTTNG_UST_ABI_CONTEXT_VSGID:
1655 return lttng_add_vsgid_to_ctx(ctx);
1656 default:
1657 return -EINVAL;
1658 }
1659 }
1660
1661 int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
1662 struct lttng_ust_abi_context *context_param)
1663 {
1664 return -ENOSYS;
1665 }
1666
1667 void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler)
1668 {
1669 if (!event_enabler) {
1670 return;
1671 }
1672 cds_list_del(&event_enabler->node);
1673
1674 lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler));
1675
1676 lttng_destroy_context(event_enabler->ctx);
1677 free(event_enabler);
1678 }
1679
1680 /*
1681 * lttng_session_sync_event_enablers should be called just before starting a
1682 * session.
1683 */
1684 static
1685 void lttng_session_sync_event_enablers(struct lttng_session *session)
1686 {
1687 struct lttng_event_enabler *event_enabler;
1688 struct lttng_ust_event_recorder_private *event_recorder_priv;
1689
1690 cds_list_for_each_entry(event_enabler, &session->priv->enablers_head, node)
1691 lttng_event_enabler_ref_events(event_enabler);
1692 /*
1693 * For each event, if at least one of its enablers is enabled,
1694 * and its channel and session transient states are enabled, we
1695 * enable the event, else we disable it.
1696 */
1697 cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) {
1698 struct lttng_enabler_ref *enabler_ref;
1699 struct lttng_bytecode_runtime *runtime;
1700 int enabled = 0, has_enablers_without_bytecode = 0;
1701
1702 /* Enable events */
1703 cds_list_for_each_entry(enabler_ref,
1704 &event_recorder_priv->parent.enablers_ref_head, node) {
1705 if (enabler_ref->ref->enabled) {
1706 enabled = 1;
1707 break;
1708 }
1709 }
1710 /*
1711 * Enabled state is based on union of enablers, with
1712 * intesection of session and channel transient enable
1713 * states.
1714 */
1715 enabled = enabled && session->priv->tstate && event_recorder_priv->pub->chan->tstate;
1716
1717 CMM_STORE_SHARED(event_recorder_priv->pub->parent->enabled, enabled);
1718 /*
1719 * Sync tracepoint registration with event enabled
1720 * state.
1721 */
1722 if (enabled) {
1723 if (!event_recorder_priv->parent.registered)
1724 register_event_recorder(event_recorder_priv->pub);
1725 } else {
1726 if (event_recorder_priv->parent.registered)
1727 unregister_event_recorder(event_recorder_priv->pub);
1728 }
1729
1730 /* Check if has enablers without bytecode enabled */
1731 cds_list_for_each_entry(enabler_ref,
1732 &event_recorder_priv->parent.enablers_ref_head, node) {
1733 if (enabler_ref->ref->enabled
1734 && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) {
1735 has_enablers_without_bytecode = 1;
1736 break;
1737 }
1738 }
1739 event_recorder_priv->pub->parent->has_enablers_without_bytecode =
1740 has_enablers_without_bytecode;
1741
1742 /* Enable filters */
1743 cds_list_for_each_entry(runtime,
1744 &event_recorder_priv->pub->parent->filter_bytecode_runtime_head, node) {
1745 lttng_bytecode_filter_sync_state(runtime);
1746 }
1747 }
1748 __tracepoint_probe_prune_release_queue();
1749 }
1750
1751 /* Support for event notifier is introduced by probe provider major version 2. */
1752 static
1753 bool lttng_ust_probe_supports_event_notifier(struct lttng_probe_desc *probe_desc)
1754 {
1755 return probe_desc->major >= 2;
1756 }
1757
1758 static
1759 void lttng_create_event_notifier_if_missing(
1760 struct lttng_event_notifier_enabler *event_notifier_enabler)
1761 {
1762 struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group;
1763 struct lttng_probe_desc *probe_desc;
1764 struct cds_list_head *probe_list;
1765 int i;
1766
1767 probe_list = lttng_get_probe_list_head();
1768
1769 cds_list_for_each_entry(probe_desc, probe_list, head) {
1770 for (i = 0; i < probe_desc->nr_events; i++) {
1771 int ret;
1772 bool found = false;
1773 const struct lttng_event_desc *desc;
1774 struct lttng_ust_event_notifier_private *event_notifier_priv;
1775 struct cds_hlist_head *head;
1776 struct cds_hlist_node *node;
1777
1778 desc = probe_desc->event_desc[i];
1779
1780 if (!lttng_desc_match_enabler(desc,
1781 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)))
1782 continue;
1783
1784 /*
1785 * Given the current event_notifier group, get the bucket that
1786 * the target event_notifier would be if it was already
1787 * created.
1788 */
1789 head = borrow_hash_table_bucket(
1790 event_notifier_group->event_notifiers_ht.table,
1791 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, desc);
1792
1793 cds_hlist_for_each_entry(event_notifier_priv, node, head, hlist) {
1794 /*
1795 * Check if event_notifier already exists by checking
1796 * if the event_notifier and enabler share the same
1797 * description and id.
1798 */
1799 if (event_notifier_priv->parent.desc == desc &&
1800 event_notifier_priv->parent.user_token == event_notifier_enabler->user_token) {
1801 found = true;
1802 break;
1803 }
1804 }
1805
1806 if (found)
1807 continue;
1808
1809 /* Check that the probe supports event notifiers, else report the error. */
1810 if (!lttng_ust_probe_supports_event_notifier(probe_desc)) {
1811 ERR("Probe \"%s\" contains event \"%s\" which matches an enabled event notifier, "
1812 "but its version (%u.%u) is too old and does not implement event notifiers. "
1813 "It needs to be recompiled against a newer version of LTTng-UST, otherwise "
1814 "this event will not generate any notification.",
1815 probe_desc->provider,
1816 desc->name,
1817 probe_desc->major,
1818 probe_desc->minor);
1819 continue;
1820 }
1821 /*
1822 * We need to create a event_notifier for this event probe.
1823 */
1824 ret = lttng_event_notifier_create(desc,
1825 event_notifier_enabler->user_token,
1826 event_notifier_enabler->error_counter_index,
1827 event_notifier_group);
1828 if (ret) {
1829 DBG("Unable to create event_notifier %s, error %d\n",
1830 probe_desc->event_desc[i]->name, ret);
1831 }
1832 }
1833 }
1834 }
1835
1836 /*
1837 * Create event_notifiers associated with a event_notifier enabler (if not already present).
1838 */
1839 static
1840 int lttng_event_notifier_enabler_ref_event_notifiers(
1841 struct lttng_event_notifier_enabler *event_notifier_enabler)
1842 {
1843 struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group;
1844 struct lttng_ust_event_notifier_private *event_notifier_priv;
1845
1846 /*
1847 * Only try to create event_notifiers for enablers that are enabled, the user
1848 * might still be attaching filter or exclusion to the
1849 * event_notifier_enabler.
1850 */
1851 if (!lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled)
1852 goto end;
1853
1854 /* First, ensure that probe event_notifiers are created for this enabler. */
1855 lttng_create_event_notifier_if_missing(event_notifier_enabler);
1856
1857 /* Link the created event_notifier with its associated enabler. */
1858 cds_list_for_each_entry(event_notifier_priv, &event_notifier_group->event_notifiers_head, node) {
1859 struct lttng_enabler_ref *enabler_ref;
1860
1861 if (!lttng_event_notifier_enabler_match_event_notifier(event_notifier_enabler, event_notifier_priv->pub))
1862 continue;
1863
1864 enabler_ref = lttng_enabler_ref(&event_notifier_priv->parent.enablers_ref_head,
1865 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler));
1866 if (!enabler_ref) {
1867 /*
1868 * If no backward ref, create it.
1869 * Add backward ref from event_notifier to enabler.
1870 */
1871 enabler_ref = zmalloc(sizeof(*enabler_ref));
1872 if (!enabler_ref)
1873 return -ENOMEM;
1874
1875 enabler_ref->ref = lttng_event_notifier_enabler_as_enabler(
1876 event_notifier_enabler);
1877 cds_list_add(&enabler_ref->node,
1878 &event_notifier_priv->parent.enablers_ref_head);
1879 }
1880
1881 /*
1882 * Link filter bytecodes if not linked yet.
1883 */
1884 lttng_enabler_link_bytecode(event_notifier_priv->parent.desc,
1885 &event_notifier_group->ctx,
1886 &event_notifier_priv->pub->parent->filter_bytecode_runtime_head,
1887 &lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->filter_bytecode_head);
1888
1889 /*
1890 * Link capture bytecodes if not linked yet.
1891 */
1892 lttng_enabler_link_bytecode(event_notifier_priv->parent.desc,
1893 &event_notifier_group->ctx, &event_notifier_priv->pub->capture_bytecode_runtime_head,
1894 &event_notifier_enabler->capture_bytecode_head);
1895
1896 event_notifier_priv->num_captures = event_notifier_enabler->num_captures;
1897 }
1898 end:
1899 return 0;
1900 }
1901
1902 static
1903 void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group *event_notifier_group)
1904 {
1905 struct lttng_event_notifier_enabler *event_notifier_enabler;
1906 struct lttng_ust_event_notifier_private *event_notifier_priv;
1907
1908 cds_list_for_each_entry(event_notifier_enabler, &event_notifier_group->enablers_head, node)
1909 lttng_event_notifier_enabler_ref_event_notifiers(event_notifier_enabler);
1910
1911 /*
1912 * For each event_notifier, if at least one of its enablers is enabled,
1913 * we enable the event_notifier, else we disable it.
1914 */
1915 cds_list_for_each_entry(event_notifier_priv, &event_notifier_group->event_notifiers_head, node) {
1916 struct lttng_enabler_ref *enabler_ref;
1917 struct lttng_bytecode_runtime *runtime;
1918 int enabled = 0, has_enablers_without_bytecode = 0;
1919
1920 /* Enable event_notifiers */
1921 cds_list_for_each_entry(enabler_ref,
1922 &event_notifier_priv->parent.enablers_ref_head, node) {
1923 if (enabler_ref->ref->enabled) {
1924 enabled = 1;
1925 break;
1926 }
1927 }
1928
1929 CMM_STORE_SHARED(event_notifier_priv->pub->parent->enabled, enabled);
1930 /*
1931 * Sync tracepoint registration with event_notifier enabled
1932 * state.
1933 */
1934 if (enabled) {
1935 if (!event_notifier_priv->parent.registered)
1936 register_event_notifier(event_notifier_priv->pub);
1937 } else {
1938 if (event_notifier_priv->parent.registered)
1939 unregister_event_notifier(event_notifier_priv->pub);
1940 }
1941
1942 /* Check if has enablers without bytecode enabled */
1943 cds_list_for_each_entry(enabler_ref,
1944 &event_notifier_priv->parent.enablers_ref_head, node) {
1945 if (enabler_ref->ref->enabled
1946 && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) {
1947 has_enablers_without_bytecode = 1;
1948 break;
1949 }
1950 }
1951 event_notifier_priv->pub->parent->has_enablers_without_bytecode =
1952 has_enablers_without_bytecode;
1953
1954 /* Enable filters */
1955 cds_list_for_each_entry(runtime,
1956 &event_notifier_priv->pub->parent->filter_bytecode_runtime_head, node) {
1957 lttng_bytecode_filter_sync_state(runtime);
1958 }
1959
1960 /* Enable captures. */
1961 cds_list_for_each_entry(runtime,
1962 &event_notifier_priv->pub->capture_bytecode_runtime_head, node) {
1963 lttng_bytecode_capture_sync_state(runtime);
1964 }
1965 }
1966 __tracepoint_probe_prune_release_queue();
1967 }
1968
1969 /*
1970 * Apply enablers to session events, adding events to session if need
1971 * be. It is required after each modification applied to an active
1972 * session, and right before session "start".
1973 * "lazy" sync means we only sync if required.
1974 */
1975 static
1976 void lttng_session_lazy_sync_event_enablers(struct lttng_session *session)
1977 {
1978 /* We can skip if session is not active */
1979 if (!session->active)
1980 return;
1981 lttng_session_sync_event_enablers(session);
1982 }
1983
1984 /*
1985 * Update all sessions with the given app context.
1986 * Called with ust lock held.
1987 * This is invoked when an application context gets loaded/unloaded. It
1988 * ensures the context callbacks are in sync with the application
1989 * context (either app context callbacks, or dummy callbacks).
1990 */
1991 void lttng_ust_context_set_session_provider(const char *name,
1992 size_t (*get_size)(struct lttng_ctx_field *field, size_t offset),
1993 void (*record)(struct lttng_ctx_field *field,
1994 struct lttng_ust_lib_ring_buffer_ctx *ctx,
1995 struct lttng_channel *chan),
1996 void (*get_value)(struct lttng_ctx_field *field,
1997 struct lttng_ctx_value *value))
1998 {
1999 struct lttng_ust_session_private *session_priv;
2000
2001 cds_list_for_each_entry(session_priv, &sessions, node) {
2002 struct lttng_channel *chan;
2003 struct lttng_ust_event_recorder_private *event_recorder_priv;
2004 int ret;
2005
2006 ret = lttng_ust_context_set_provider_rcu(&session_priv->ctx,
2007 name, get_size, record, get_value);
2008 if (ret)
2009 abort();
2010 cds_list_for_each_entry(chan, &session_priv->chan_head, node) {
2011 ret = lttng_ust_context_set_provider_rcu(&chan->ctx,
2012 name, get_size, record, get_value);
2013 if (ret)
2014 abort();
2015 }
2016 cds_list_for_each_entry(event_recorder_priv, &session_priv->events_head, node) {
2017 ret = lttng_ust_context_set_provider_rcu(&event_recorder_priv->pub->ctx,
2018 name, get_size, record, get_value);
2019 if (ret)
2020 abort();
2021 }
2022 }
2023 }
2024
2025 /*
2026 * Update all event_notifier groups with the given app context.
2027 * Called with ust lock held.
2028 * This is invoked when an application context gets loaded/unloaded. It
2029 * ensures the context callbacks are in sync with the application
2030 * context (either app context callbacks, or dummy callbacks).
2031 */
2032 void lttng_ust_context_set_event_notifier_group_provider(const char *name,
2033 size_t (*get_size)(struct lttng_ctx_field *field, size_t offset),
2034 void (*record)(struct lttng_ctx_field *field,
2035 struct lttng_ust_lib_ring_buffer_ctx *ctx,
2036 struct lttng_channel *chan),
2037 void (*get_value)(struct lttng_ctx_field *field,
2038 struct lttng_ctx_value *value))
2039 {
2040 struct lttng_event_notifier_group *event_notifier_group;
2041
2042 cds_list_for_each_entry(event_notifier_group, &event_notifier_groups, node) {
2043 int ret;
2044
2045 ret = lttng_ust_context_set_provider_rcu(
2046 &event_notifier_group->ctx,
2047 name, get_size, record, get_value);
2048 if (ret)
2049 abort();
2050 }
2051 }
This page took 0.090682 seconds and 5 git commands to generate.