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