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