5d1475190d6ef82f49c418c52fa654ea2c070b29
[lttng-ust.git] / liblttng-ust / ltt-events.c
1 /*
2 * ltt-events.c
3 *
4 * Holds LTTng per-session event registry.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #define _GNU_SOURCE
24 #include <stdio.h>
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
27 #include <pthread.h>
28 #include <errno.h>
29 #include <sys/shm.h>
30 #include <sys/ipc.h>
31 #include <stdint.h>
32 #include <stddef.h>
33 #include <inttypes.h>
34 #include <time.h>
35 #include <lttng/ust-endian.h>
36 #include "clock.h"
37
38 #include <urcu-bp.h>
39 #include <urcu/compiler.h>
40 #include <urcu/uatomic.h>
41 #include <urcu/arch.h>
42
43 #include <lttng/tracepoint.h>
44 #include <lttng/ust-events.h>
45
46 #include <usterr-signal-safe.h>
47 #include <helper.h>
48 #include "error.h"
49 #include "compat.h"
50 #include "lttng-ust-uuid.h"
51
52 #include "tracepoint-internal.h"
53 #include "ltt-tracer.h"
54 #include "ltt-tracer-core.h"
55 #include "wait.h"
56 #include "../libringbuffer/shm.h"
57 #include "jhash.h"
58
59 /*
60 * The sessions mutex is the centralized mutex across UST tracing
61 * control and probe registration. All operations within this file are
62 * called by the communication thread, under ust_lock protection.
63 */
64 static pthread_mutex_t sessions_mutex = PTHREAD_MUTEX_INITIALIZER;
65
66 void ust_lock(void)
67 {
68 pthread_mutex_lock(&sessions_mutex);
69 }
70
71 void ust_unlock(void)
72 {
73 pthread_mutex_unlock(&sessions_mutex);
74 }
75
76 static CDS_LIST_HEAD(sessions);
77
78 /*
79 * Wildcard list, containing the active wildcards.
80 * Protected by ust lock.
81 */
82 static CDS_LIST_HEAD(wildcard_list);
83
84 /*
85 * Pending probes hash table, containing the registered ltt events for
86 * which tracepoint probes are still missing. Protected by the sessions
87 * mutex.
88 */
89 #define PENDING_PROBE_HASH_BITS 6
90 #define PENDING_PROBE_HASH_SIZE (1 << PENDING_PROBE_HASH_BITS)
91 static struct cds_hlist_head pending_probe_table[PENDING_PROBE_HASH_SIZE];
92
93 struct ust_pending_probe {
94 struct ltt_event *event;
95 struct cds_hlist_node node;
96 enum lttng_ust_loglevel_type loglevel_type;
97 int loglevel;
98 char name[];
99 };
100
101 static void _ltt_event_destroy(struct ltt_event *event);
102 static void _ltt_wildcard_destroy(struct session_wildcard *sw);
103 static void _ltt_channel_destroy(struct ltt_channel *chan);
104 static int _ltt_event_unregister(struct ltt_event *event);
105 static
106 int _ltt_event_metadata_statedump(struct ltt_session *session,
107 struct ltt_channel *chan,
108 struct ltt_event *event);
109 static
110 int _ltt_session_metadata_statedump(struct ltt_session *session);
111
112 int ltt_loglevel_match(const struct lttng_event_desc *desc,
113 enum lttng_ust_loglevel_type req_type,
114 int req_loglevel)
115 {
116 int ev_loglevel;
117
118 if (req_type == LTTNG_UST_LOGLEVEL_ALL)
119 return 1;
120 if (!desc->loglevel)
121 ev_loglevel = TRACE_DEFAULT;
122 else
123 ev_loglevel = *(*desc->loglevel);
124 switch (req_type) {
125 case LTTNG_UST_LOGLEVEL_RANGE:
126 if (ev_loglevel <= req_loglevel || req_loglevel == -1)
127 return 1;
128 else
129 return 0;
130 case LTTNG_UST_LOGLEVEL_SINGLE:
131 if (ev_loglevel == req_loglevel || req_loglevel == -1)
132 return 1;
133 else
134 return 0;
135 case LTTNG_UST_LOGLEVEL_ALL:
136 default:
137 return 1;
138 }
139 }
140
141 /*
142 * Return wildcard for a given event name if the event name match the
143 * one of the wildcards.
144 * Must be called with ust lock held.
145 * Returns NULL if not present.
146 */
147 static
148 struct wildcard_entry *match_wildcard(const struct lttng_event_desc *desc)
149 {
150 struct wildcard_entry *e;
151
152 cds_list_for_each_entry(e, &wildcard_list, list) {
153 /* If only contain '*' */
154 if (strlen(e->name) == 1)
155 goto possible_match;
156 /* Compare excluding final '*' */
157 if (!strncmp(desc->name, e->name, strlen(e->name) - 1))
158 goto possible_match;
159 continue; /* goto next, no match */
160 possible_match:
161 if (ltt_loglevel_match(desc,
162 e->loglevel_type,
163 e->loglevel)) {
164 return e;
165 }
166 /* no match, loop to next */
167 }
168 return NULL;
169 }
170
171 /*
172 * called at event creation if probe is missing.
173 * called with session mutex held.
174 */
175 static
176 int add_pending_probe(struct ltt_event *event, const char *name,
177 enum lttng_ust_loglevel_type loglevel_type,
178 int loglevel)
179 {
180 struct cds_hlist_head *head;
181 struct ust_pending_probe *e;
182 size_t name_len = strlen(name) + 1;
183 uint32_t hash;
184
185 if (name_len > LTTNG_UST_SYM_NAME_LEN) {
186 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN);
187 name_len = LTTNG_UST_SYM_NAME_LEN;
188 }
189 hash = jhash(name, name_len - 1, 0);
190 head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)];
191 e = zmalloc(sizeof(struct ust_pending_probe) + name_len);
192 if (!e)
193 return -ENOMEM;
194 memcpy(&e->name[0], name, name_len);
195 e->name[name_len - 1] = '\0';
196 e->loglevel_type = loglevel_type;
197 e->loglevel = loglevel;
198 cds_hlist_add_head(&e->node, head);
199 e->event = event;
200 event->pending_probe = e;
201 return 0;
202 }
203
204 /*
205 * remove a pending probe. called when at event teardown and when an
206 * event is fixed (probe is loaded).
207 * called with session mutex held.
208 */
209 static
210 void remove_pending_probe(struct ust_pending_probe *e)
211 {
212 if (!e)
213 return;
214 cds_hlist_del(&e->node);
215 free(e);
216 }
217
218 /*
219 * Called at library load: connect the probe on the events pending on
220 * probe load.
221 * called with session mutex held.
222 */
223 int pending_probe_fix_events(const struct lttng_event_desc *desc)
224 {
225 struct cds_hlist_head *head;
226 struct cds_hlist_node *node, *p;
227 struct ust_pending_probe *e;
228 const char *name = desc->name;
229 int ret = 0;
230 struct lttng_ust_event event_param;
231 size_t name_len = strlen(name) + 1;
232 uint32_t hash;
233
234 /* Wildcard */
235 {
236 struct wildcard_entry *wildcard;
237
238 wildcard = match_wildcard(desc);
239 if (strcmp(desc->name, "lttng_ust:metadata") && wildcard) {
240 struct session_wildcard *sw;
241
242 cds_list_for_each_entry(sw, &wildcard->session_list,
243 session_list) {
244 struct ltt_event *ev;
245 int ret;
246
247 memcpy(&event_param, &sw->event_param,
248 sizeof(event_param));
249 memcpy(event_param.name,
250 desc->name,
251 sizeof(event_param.name));
252 /* create event */
253 ret = ltt_event_create(sw->chan,
254 &event_param, &ev);
255 if (ret) {
256 DBG("Error creating event");
257 continue;
258 }
259 cds_list_add(&ev->wildcard_list,
260 &sw->events);
261 lttng_filter_event_link_bytecode(ev,
262 sw->filter_bytecode);
263 }
264 }
265 }
266
267 if (name_len > LTTNG_UST_SYM_NAME_LEN) {
268 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN);
269 name_len = LTTNG_UST_SYM_NAME_LEN;
270 }
271 hash = jhash(name, name_len - 1, 0);
272 head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)];
273 cds_hlist_for_each_entry_safe(e, node, p, head, node) {
274 struct ltt_event *event;
275 struct ltt_channel *chan;
276
277 if (!ltt_loglevel_match(desc,
278 e->loglevel_type,
279 e->loglevel)) {
280 continue;
281 }
282 if (strncmp(name, e->name, LTTNG_UST_SYM_NAME_LEN - 1)) {
283 continue;
284 }
285 event = e->event;
286 chan = event->chan;
287 assert(!event->desc);
288 event->desc = desc;
289 event->pending_probe = NULL;
290 remove_pending_probe(e);
291 ret |= __tracepoint_probe_register(name,
292 event->desc->probe_callback,
293 event, event->desc->signature);
294 if (ret)
295 continue;
296 event->id = chan->free_event_id++;
297 ret |= _ltt_event_metadata_statedump(chan->session, chan,
298 event);
299 lttng_filter_event_link_bytecode(event,
300 event->filter_bytecode);
301 }
302 return ret;
303 }
304
305 void synchronize_trace(void)
306 {
307 synchronize_rcu();
308 }
309
310 struct ltt_session *ltt_session_create(void)
311 {
312 struct ltt_session *session;
313 int ret;
314
315 session = zmalloc(sizeof(struct ltt_session));
316 if (!session)
317 return NULL;
318 CDS_INIT_LIST_HEAD(&session->chan);
319 CDS_INIT_LIST_HEAD(&session->events);
320 CDS_INIT_LIST_HEAD(&session->wildcards);
321 ret = lttng_ust_uuid_generate(session->uuid);
322 if (ret != 0) {
323 session->uuid[0] = '\0';
324 }
325 cds_list_add(&session->list, &sessions);
326 return session;
327 }
328
329 void ltt_session_destroy(struct ltt_session *session)
330 {
331 struct ltt_channel *chan, *tmpchan;
332 struct ltt_event *event, *tmpevent;
333 struct session_wildcard *wildcard, *tmpwildcard;
334 int ret;
335
336 CMM_ACCESS_ONCE(session->active) = 0;
337 cds_list_for_each_entry(event, &session->events, list) {
338 ret = _ltt_event_unregister(event);
339 WARN_ON(ret);
340 }
341 synchronize_trace(); /* Wait for in-flight events to complete */
342 cds_list_for_each_entry_safe(wildcard, tmpwildcard, &session->wildcards, list)
343 _ltt_wildcard_destroy(wildcard);
344 cds_list_for_each_entry_safe(event, tmpevent, &session->events, list)
345 _ltt_event_destroy(event);
346 cds_list_for_each_entry_safe(chan, tmpchan, &session->chan, list)
347 _ltt_channel_destroy(chan);
348 cds_list_del(&session->list);
349 free(session);
350 }
351
352 int ltt_session_enable(struct ltt_session *session)
353 {
354 int ret = 0;
355 struct ltt_channel *chan;
356
357 if (session->active) {
358 ret = -EBUSY;
359 goto end;
360 }
361
362 /*
363 * Snapshot the number of events per channel to know the type of header
364 * we need to use.
365 */
366 cds_list_for_each_entry(chan, &session->chan, list) {
367 if (chan->header_type)
368 continue; /* don't change it if session stop/restart */
369 if (chan->free_event_id < 31)
370 chan->header_type = 1; /* compact */
371 else
372 chan->header_type = 2; /* large */
373 }
374
375 CMM_ACCESS_ONCE(session->active) = 1;
376 CMM_ACCESS_ONCE(session->been_active) = 1;
377 ret = _ltt_session_metadata_statedump(session);
378 if (ret)
379 CMM_ACCESS_ONCE(session->active) = 0;
380 end:
381 return ret;
382 }
383
384 int ltt_session_disable(struct ltt_session *session)
385 {
386 int ret = 0;
387
388 if (!session->active) {
389 ret = -EBUSY;
390 goto end;
391 }
392 CMM_ACCESS_ONCE(session->active) = 0;
393 end:
394 return ret;
395 }
396
397 int ltt_channel_enable(struct ltt_channel *channel)
398 {
399 int old;
400
401 if (channel == channel->session->metadata)
402 return -EPERM;
403 old = uatomic_xchg(&channel->enabled, 1);
404 if (old)
405 return -EEXIST;
406 return 0;
407 }
408
409 int ltt_channel_disable(struct ltt_channel *channel)
410 {
411 int old;
412
413 if (channel == channel->session->metadata)
414 return -EPERM;
415 old = uatomic_xchg(&channel->enabled, 0);
416 if (!old)
417 return -EEXIST;
418 return 0;
419 }
420
421 int ltt_event_enable(struct ltt_event *event)
422 {
423 int old;
424
425 if (event->chan == event->chan->session->metadata)
426 return -EPERM;
427 old = uatomic_xchg(&event->enabled, 1);
428 if (old)
429 return -EEXIST;
430 return 0;
431 }
432
433 int ltt_event_disable(struct ltt_event *event)
434 {
435 int old;
436
437 if (event->chan == event->chan->session->metadata)
438 return -EPERM;
439 old = uatomic_xchg(&event->enabled, 0);
440 if (!old)
441 return -EEXIST;
442 return 0;
443 }
444
445 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
446 const char *transport_name,
447 void *buf_addr,
448 size_t subbuf_size, size_t num_subbuf,
449 unsigned int switch_timer_interval,
450 unsigned int read_timer_interval,
451 int **shm_fd, int **wait_fd,
452 uint64_t **memory_map_size,
453 struct ltt_channel *chan_priv_init)
454 {
455 struct ltt_channel *chan = NULL;
456 struct ltt_transport *transport;
457
458 if (session->been_active)
459 goto active; /* Refuse to add channel to active session */
460 transport = ltt_transport_find(transport_name);
461 if (!transport) {
462 DBG("LTTng transport %s not found\n",
463 transport_name);
464 goto notransport;
465 }
466 chan_priv_init->id = session->free_chan_id++;
467 chan_priv_init->session = session;
468 /*
469 * Note: the channel creation op already writes into the packet
470 * headers. Therefore the "chan" information used as input
471 * should be already accessible.
472 */
473 chan = transport->ops.channel_create(transport_name, buf_addr,
474 subbuf_size, num_subbuf, switch_timer_interval,
475 read_timer_interval, shm_fd, wait_fd,
476 memory_map_size, chan_priv_init);
477 if (!chan)
478 goto create_error;
479 chan->enabled = 1;
480 chan->ops = &transport->ops;
481 cds_list_add(&chan->list, &session->chan);
482 return chan;
483
484 create_error:
485 notransport:
486 active:
487 return NULL;
488 }
489
490 /*
491 * Only used internally at session destruction.
492 */
493 static
494 void _ltt_channel_destroy(struct ltt_channel *chan)
495 {
496 cds_list_del(&chan->list);
497 lttng_destroy_context(chan->ctx);
498 chan->ops->channel_destroy(chan);
499 }
500
501 /*
502 * Supports event creation while tracing session is active.
503 */
504 int ltt_event_create(struct ltt_channel *chan,
505 struct lttng_ust_event *event_param,
506 struct ltt_event **_event)
507 {
508 const struct lttng_event_desc *desc = NULL; /* silence gcc */
509 struct ltt_event *event;
510 int ret = 0;
511
512 if (chan->used_event_id == -1U) {
513 ret = -ENOMEM;
514 goto full;
515 }
516 /*
517 * This is O(n^2) (for each event, the loop is called at event
518 * creation). Might require a hash if we have lots of events.
519 */
520 cds_list_for_each_entry(event, &chan->session->events, list) {
521 if (event->desc && !strncmp(event->desc->name,
522 event_param->name,
523 LTTNG_UST_SYM_NAME_LEN - 1)) {
524 ret = -EEXIST;
525 goto exist;
526 }
527 }
528
529 /*
530 * Check if loglevel match. Refuse to connect event if not.
531 */
532 if (event_param->instrumentation == LTTNG_UST_TRACEPOINT) {
533 desc = ltt_event_get(event_param->name);
534 if (desc) {
535 if (!ltt_loglevel_match(desc,
536 event_param->loglevel_type,
537 event_param->loglevel)) {
538 ret = -EPERM;
539 goto no_loglevel_match;
540 }
541 }
542 /*
543 * If descriptor is not there, it will be added to
544 * pending probes.
545 */
546 }
547 event = zmalloc(sizeof(struct ltt_event));
548 if (!event) {
549 ret = -ENOMEM;
550 goto cache_error;
551 }
552 event->chan = chan;
553 /*
554 * used_event_id counts the maximum number of event IDs that can
555 * register if all probes register.
556 */
557 chan->used_event_id++;
558 event->enabled = 1;
559 event->instrumentation = event_param->instrumentation;
560 /* Populate ltt_event structure before tracepoint registration. */
561 cmm_smp_wmb();
562 switch (event_param->instrumentation) {
563 case LTTNG_UST_TRACEPOINT:
564 event->desc = desc;
565 if (event->desc) {
566 ret = __tracepoint_probe_register(event_param->name,
567 event->desc->probe_callback,
568 event, event->desc->signature);
569 if (ret)
570 goto register_error;
571 event->id = chan->free_event_id++;
572 } else {
573 /*
574 * If the probe is not present, event->desc stays NULL,
575 * waiting for the probe to register, and the event->id
576 * stays unallocated.
577 */
578 ret = add_pending_probe(event, event_param->name,
579 event_param->loglevel_type,
580 event_param->loglevel);
581 if (ret)
582 goto add_pending_error;
583 }
584 break;
585 default:
586 WARN_ON_ONCE(1);
587 }
588 if (event->desc) {
589 ret = _ltt_event_metadata_statedump(chan->session, chan, event);
590 if (ret)
591 goto statedump_error;
592 }
593 cds_list_add(&event->list, &chan->session->events);
594 *_event = event;
595 return 0;
596
597 statedump_error:
598 if (event->desc) {
599 WARN_ON_ONCE(__tracepoint_probe_unregister(event_param->name,
600 event->desc->probe_callback,
601 event));
602 ltt_event_put(event->desc);
603 }
604 add_pending_error:
605 register_error:
606 free(event);
607 cache_error:
608 no_loglevel_match:
609 exist:
610 full:
611 return ret;
612 }
613
614 /*
615 * Only used internally at session destruction.
616 */
617 int _ltt_event_unregister(struct ltt_event *event)
618 {
619 int ret = -EINVAL;
620
621 switch (event->instrumentation) {
622 case LTTNG_UST_TRACEPOINT:
623 if (event->desc) {
624 ret = __tracepoint_probe_unregister(event->desc->name,
625 event->desc->probe_callback,
626 event);
627 if (ret)
628 return ret;
629 } else {
630 remove_pending_probe(event->pending_probe);
631 ret = 0;
632 }
633 break;
634 default:
635 WARN_ON_ONCE(1);
636 }
637 return ret;
638 }
639
640 /*
641 * Only used internally at session destruction.
642 */
643 static
644 void _ltt_event_destroy(struct ltt_event *event)
645 {
646 switch (event->instrumentation) {
647 case LTTNG_UST_TRACEPOINT:
648 if (event->desc) {
649 ltt_event_put(event->desc);
650 }
651 break;
652 default:
653 WARN_ON_ONCE(1);
654 }
655 cds_list_del(&event->list);
656 lttng_destroy_context(event->ctx);
657 free(event->filter_bytecode);
658 free(event->filter_data);
659 free(event);
660 }
661
662 /*
663 * We have exclusive access to our metadata buffer (protected by the
664 * ust_lock), so we can do racy operations such as looking for
665 * remaining space left in packet and write, since mutual exclusion
666 * protects us from concurrent writes.
667 */
668 int lttng_metadata_printf(struct ltt_session *session,
669 const char *fmt, ...)
670 {
671 struct lttng_ust_lib_ring_buffer_ctx ctx;
672 struct ltt_channel *chan = session->metadata;
673 char *str = NULL;
674 int ret = 0, waitret;
675 size_t len, reserve_len, pos;
676 va_list ap;
677
678 WARN_ON_ONCE(!CMM_ACCESS_ONCE(session->active));
679
680 va_start(ap, fmt);
681 ret = vasprintf(&str, fmt, ap);
682 va_end(ap);
683 if (ret < 0)
684 return -ENOMEM;
685
686 len = strlen(str);
687 pos = 0;
688
689 for (pos = 0; pos < len; pos += reserve_len) {
690 reserve_len = min_t(size_t,
691 chan->ops->packet_avail_size(chan->chan, chan->handle),
692 len - pos);
693 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
694 sizeof(char), -1, chan->handle);
695 /*
696 * We don't care about metadata buffer's records lost
697 * count, because we always retry here. Report error if
698 * we need to bail out after timeout or being
699 * interrupted.
700 */
701 waitret = wait_cond_interruptible_timeout(
702 ({
703 ret = chan->ops->event_reserve(&ctx, 0);
704 ret != -ENOBUFS || !ret;
705 }),
706 LTTNG_METADATA_TIMEOUT_MSEC);
707 if (waitret == -ETIMEDOUT || waitret == -EINTR || ret) {
708 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
709 waitret == -EINTR ? "interrupted" :
710 (ret == -ENOBUFS ? "timeout" : "I/O error"));
711 if (waitret == -EINTR)
712 ret = waitret;
713 goto end;
714 }
715 chan->ops->event_write(&ctx, &str[pos], reserve_len);
716 chan->ops->event_commit(&ctx);
717 }
718 end:
719 free(str);
720 return ret;
721 }
722
723 static
724 int _ltt_field_statedump(struct ltt_session *session,
725 const struct lttng_event_field *field)
726 {
727 int ret = 0;
728
729 if (field->nowrite)
730 return 0;
731
732 switch (field->type.atype) {
733 case atype_integer:
734 ret = lttng_metadata_printf(session,
735 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
736 field->type.u.basic.integer.size,
737 field->type.u.basic.integer.alignment,
738 field->type.u.basic.integer.signedness,
739 (field->type.u.basic.integer.encoding == lttng_encode_none)
740 ? "none"
741 : (field->type.u.basic.integer.encoding == lttng_encode_UTF8)
742 ? "UTF8"
743 : "ASCII",
744 field->type.u.basic.integer.base,
745 #if (BYTE_ORDER == BIG_ENDIAN)
746 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
747 #else
748 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
749 #endif
750 field->name);
751 break;
752 case atype_float:
753 ret = lttng_metadata_printf(session,
754 " floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
755 field->type.u.basic._float.exp_dig,
756 field->type.u.basic._float.mant_dig,
757 field->type.u.basic._float.alignment,
758 #if (BYTE_ORDER == BIG_ENDIAN)
759 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
760 #else
761 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
762 #endif
763 field->name);
764 break;
765 case atype_enum:
766 ret = lttng_metadata_printf(session,
767 " %s %s;\n",
768 field->type.u.basic.enumeration.name,
769 field->name);
770 break;
771 case atype_array:
772 {
773 const struct lttng_basic_type *elem_type;
774
775 elem_type = &field->type.u.array.elem_type;
776 ret = lttng_metadata_printf(session,
777 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
778 elem_type->u.basic.integer.size,
779 elem_type->u.basic.integer.alignment,
780 elem_type->u.basic.integer.signedness,
781 (elem_type->u.basic.integer.encoding == lttng_encode_none)
782 ? "none"
783 : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
784 ? "UTF8"
785 : "ASCII",
786 elem_type->u.basic.integer.base,
787 #if (BYTE_ORDER == BIG_ENDIAN)
788 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
789 #else
790 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
791 #endif
792 field->name, field->type.u.array.length);
793 break;
794 }
795 case atype_sequence:
796 {
797 const struct lttng_basic_type *elem_type;
798 const struct lttng_basic_type *length_type;
799
800 elem_type = &field->type.u.sequence.elem_type;
801 length_type = &field->type.u.sequence.length_type;
802 ret = lttng_metadata_printf(session,
803 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
804 length_type->u.basic.integer.size,
805 (unsigned int) length_type->u.basic.integer.alignment,
806 length_type->u.basic.integer.signedness,
807 (length_type->u.basic.integer.encoding == lttng_encode_none)
808 ? "none"
809 : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8)
810 ? "UTF8"
811 : "ASCII"),
812 length_type->u.basic.integer.base,
813 #if (BYTE_ORDER == BIG_ENDIAN)
814 length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
815 #else
816 length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
817 #endif
818 field->name);
819 if (ret)
820 return ret;
821
822 ret = lttng_metadata_printf(session,
823 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
824 elem_type->u.basic.integer.size,
825 (unsigned int) elem_type->u.basic.integer.alignment,
826 elem_type->u.basic.integer.signedness,
827 (elem_type->u.basic.integer.encoding == lttng_encode_none)
828 ? "none"
829 : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
830 ? "UTF8"
831 : "ASCII"),
832 elem_type->u.basic.integer.base,
833 #if (BYTE_ORDER == BIG_ENDIAN)
834 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
835 #else
836 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
837 #endif
838 field->name,
839 field->name);
840 break;
841 }
842
843 case atype_string:
844 /* Default encoding is UTF8 */
845 ret = lttng_metadata_printf(session,
846 " string%s _%s;\n",
847 field->type.u.basic.string.encoding == lttng_encode_ASCII ?
848 " { encoding = ASCII; }" : "",
849 field->name);
850 break;
851 default:
852 WARN_ON_ONCE(1);
853 return -EINVAL;
854 }
855 return ret;
856 }
857
858 static
859 int _ltt_context_metadata_statedump(struct ltt_session *session,
860 struct lttng_ctx *ctx)
861 {
862 int ret = 0;
863 int i;
864
865 if (!ctx)
866 return 0;
867 for (i = 0; i < ctx->nr_fields; i++) {
868 const struct lttng_ctx_field *field = &ctx->fields[i];
869
870 ret = _ltt_field_statedump(session, &field->event_field);
871 if (ret)
872 return ret;
873 }
874 return ret;
875 }
876
877 static
878 int _ltt_fields_metadata_statedump(struct ltt_session *session,
879 struct ltt_event *event)
880 {
881 const struct lttng_event_desc *desc = event->desc;
882 int ret = 0;
883 int i;
884
885 for (i = 0; i < desc->nr_fields; i++) {
886 const struct lttng_event_field *field = &desc->fields[i];
887
888 ret = _ltt_field_statedump(session, field);
889 if (ret)
890 return ret;
891 }
892 return ret;
893 }
894
895 static
896 int _ltt_event_metadata_statedump(struct ltt_session *session,
897 struct ltt_channel *chan,
898 struct ltt_event *event)
899 {
900 int ret = 0;
901 int loglevel = TRACE_DEFAULT;
902
903 if (event->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
904 return 0;
905 if (chan == session->metadata)
906 return 0;
907 /*
908 * Don't print events for which probe load is pending.
909 */
910 if (!event->desc)
911 return 0;
912
913 ret = lttng_metadata_printf(session,
914 "event {\n"
915 " name = \"%s\";\n"
916 " id = %u;\n"
917 " stream_id = %u;\n",
918 event->desc->name,
919 event->id,
920 event->chan->id);
921 if (ret)
922 goto end;
923
924 if (event->desc->loglevel)
925 loglevel = *(*event->desc->loglevel);
926
927 ret = lttng_metadata_printf(session,
928 " loglevel = %d;\n",
929 loglevel);
930 if (ret)
931 goto end;
932
933 if (event->desc->u.ext.model_emf_uri) {
934 ret = lttng_metadata_printf(session,
935 " model.emf.uri = \"%s\";\n",
936 *(event->desc->u.ext.model_emf_uri));
937 if (ret)
938 goto end;
939 }
940
941 if (event->ctx) {
942 ret = lttng_metadata_printf(session,
943 " context := struct {\n");
944 if (ret)
945 goto end;
946 }
947 ret = _ltt_context_metadata_statedump(session, event->ctx);
948 if (ret)
949 goto end;
950 if (event->ctx) {
951 ret = lttng_metadata_printf(session,
952 " };\n");
953 if (ret)
954 goto end;
955 }
956
957 ret = lttng_metadata_printf(session,
958 " fields := struct {\n"
959 );
960 if (ret)
961 goto end;
962
963 ret = _ltt_fields_metadata_statedump(session, event);
964 if (ret)
965 goto end;
966
967 /*
968 * LTTng space reservation can only reserve multiples of the
969 * byte size.
970 */
971 ret = lttng_metadata_printf(session,
972 " };\n"
973 "};\n\n");
974 if (ret)
975 goto end;
976
977 event->metadata_dumped = 1;
978 end:
979 return ret;
980
981 }
982
983 static
984 int _ltt_channel_metadata_statedump(struct ltt_session *session,
985 struct ltt_channel *chan)
986 {
987 int ret = 0;
988
989 if (chan->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
990 return 0;
991 if (chan == session->metadata)
992 return 0;
993
994 WARN_ON_ONCE(!chan->header_type);
995 ret = lttng_metadata_printf(session,
996 "stream {\n"
997 " id = %u;\n"
998 " event.header := %s;\n"
999 " packet.context := struct packet_context;\n",
1000 chan->id,
1001 chan->header_type == 1 ? "struct event_header_compact" :
1002 "struct event_header_large");
1003 if (ret)
1004 goto end;
1005
1006 if (chan->ctx) {
1007 ret = lttng_metadata_printf(session,
1008 " event.context := struct {\n");
1009 if (ret)
1010 goto end;
1011 }
1012 ret = _ltt_context_metadata_statedump(session, chan->ctx);
1013 if (ret)
1014 goto end;
1015 if (chan->ctx) {
1016 ret = lttng_metadata_printf(session,
1017 " };\n");
1018 if (ret)
1019 goto end;
1020 }
1021
1022 ret = lttng_metadata_printf(session,
1023 "};\n\n");
1024
1025 chan->metadata_dumped = 1;
1026 end:
1027 return ret;
1028 }
1029
1030 static
1031 int _ltt_stream_packet_context_declare(struct ltt_session *session)
1032 {
1033 return lttng_metadata_printf(session,
1034 "struct packet_context {\n"
1035 " uint64_clock_monotonic_t timestamp_begin;\n"
1036 " uint64_clock_monotonic_t timestamp_end;\n"
1037 " unsigned long events_discarded;\n"
1038 " uint32_t content_size;\n"
1039 " uint32_t packet_size;\n"
1040 " uint32_t cpu_id;\n"
1041 "};\n\n"
1042 );
1043 }
1044
1045 /*
1046 * Compact header:
1047 * id: range: 0 - 30.
1048 * id 31 is reserved to indicate an extended header.
1049 *
1050 * Large header:
1051 * id: range: 0 - 65534.
1052 * id 65535 is reserved to indicate an extended header.
1053 */
1054 static
1055 int _ltt_event_header_declare(struct ltt_session *session)
1056 {
1057 return lttng_metadata_printf(session,
1058 "struct event_header_compact {\n"
1059 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
1060 " variant <id> {\n"
1061 " struct {\n"
1062 " uint27_clock_monotonic_t timestamp;\n"
1063 " } compact;\n"
1064 " struct {\n"
1065 " uint32_t id;\n"
1066 " uint64_clock_monotonic_t timestamp;\n"
1067 " } extended;\n"
1068 " } v;\n"
1069 "} align(%u);\n"
1070 "\n"
1071 "struct event_header_large {\n"
1072 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
1073 " variant <id> {\n"
1074 " struct {\n"
1075 " uint32_clock_monotonic_t timestamp;\n"
1076 " } compact;\n"
1077 " struct {\n"
1078 " uint32_t id;\n"
1079 " uint64_clock_monotonic_t timestamp;\n"
1080 " } extended;\n"
1081 " } v;\n"
1082 "} align(%u);\n\n",
1083 lttng_alignof(uint32_t) * CHAR_BIT,
1084 lttng_alignof(uint16_t) * CHAR_BIT
1085 );
1086 }
1087
1088 /*
1089 * Approximation of NTP time of day to clock monotonic correlation,
1090 * taken at start of trace.
1091 * Yes, this is only an approximation. Yes, we can (and will) do better
1092 * in future versions.
1093 */
1094 static
1095 uint64_t measure_clock_offset(void)
1096 {
1097 uint64_t offset, monotonic[2], realtime;
1098 struct timespec rts = { 0, 0 };
1099 int ret;
1100
1101 monotonic[0] = trace_clock_read64();
1102 ret = clock_gettime(CLOCK_REALTIME, &rts);
1103 if (ret < 0)
1104 return 0;
1105 monotonic[1] = trace_clock_read64();
1106 offset = (monotonic[0] + monotonic[1]) >> 1;
1107 realtime = (uint64_t) rts.tv_sec * 1000000000ULL;
1108 realtime += rts.tv_nsec;
1109 offset = realtime - offset;
1110 return offset;
1111 }
1112
1113 /*
1114 * Output metadata into this session's metadata buffers.
1115 */
1116 static
1117 int _ltt_session_metadata_statedump(struct ltt_session *session)
1118 {
1119 unsigned char *uuid_c = session->uuid;
1120 char uuid_s[LTTNG_UST_UUID_STR_LEN],
1121 clock_uuid_s[LTTNG_UST_UUID_STR_LEN];
1122 struct ltt_channel *chan;
1123 struct ltt_event *event;
1124 int ret = 0;
1125 char procname[LTTNG_UST_PROCNAME_LEN] = "";
1126 char hostname[HOST_NAME_MAX];
1127
1128 if (!CMM_ACCESS_ONCE(session->active))
1129 return 0;
1130 if (session->metadata_dumped)
1131 goto skip_session;
1132 if (!session->metadata) {
1133 DBG("LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
1134 return -EPERM;
1135 }
1136
1137 snprintf(uuid_s, sizeof(uuid_s),
1138 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1139 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
1140 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
1141 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
1142 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
1143
1144 ret = lttng_metadata_printf(session,
1145 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
1146 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
1147 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
1148 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
1149 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
1150 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
1151 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
1152 "\n"
1153 "trace {\n"
1154 " major = %u;\n"
1155 " minor = %u;\n"
1156 " uuid = \"%s\";\n"
1157 " byte_order = %s;\n"
1158 " packet.header := struct {\n"
1159 " uint32_t magic;\n"
1160 " uint8_t uuid[16];\n"
1161 " uint32_t stream_id;\n"
1162 " };\n"
1163 "};\n\n",
1164 lttng_alignof(uint8_t) * CHAR_BIT,
1165 lttng_alignof(uint16_t) * CHAR_BIT,
1166 lttng_alignof(uint32_t) * CHAR_BIT,
1167 lttng_alignof(uint64_t) * CHAR_BIT,
1168 sizeof(unsigned long) * CHAR_BIT,
1169 lttng_alignof(unsigned long) * CHAR_BIT,
1170 CTF_SPEC_MAJOR,
1171 CTF_SPEC_MINOR,
1172 uuid_s,
1173 #if (BYTE_ORDER == BIG_ENDIAN)
1174 "be"
1175 #else
1176 "le"
1177 #endif
1178 );
1179 if (ret)
1180 goto end;
1181
1182 /* ignore error, just use empty string if error. */
1183 hostname[0] = '\0';
1184 ret = gethostname(hostname, sizeof(hostname));
1185 if (ret && errno == ENAMETOOLONG)
1186 hostname[HOST_NAME_MAX - 1] = '\0';
1187 lttng_ust_getprocname(procname);
1188 procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0';
1189 ret = lttng_metadata_printf(session,
1190 "env {\n"
1191 " hostname = \"%s\";\n"
1192 " vpid = %d;\n"
1193 " procname = \"%s\";\n"
1194 " domain = \"ust\";\n"
1195 " tracer_name = \"lttng-ust\";\n"
1196 " tracer_major = %u;\n"
1197 " tracer_minor = %u;\n"
1198 " tracer_patchlevel = %u;\n"
1199 "};\n\n",
1200 hostname,
1201 (int) getpid(),
1202 procname,
1203 LTTNG_UST_MAJOR_VERSION,
1204 LTTNG_UST_MINOR_VERSION,
1205 LTTNG_UST_PATCHLEVEL_VERSION
1206 );
1207 if (ret)
1208 goto end;
1209
1210 ret = lttng_metadata_printf(session,
1211 "clock {\n"
1212 " name = %s;\n",
1213 "monotonic"
1214 );
1215 if (ret)
1216 goto end;
1217
1218 if (!trace_clock_uuid(clock_uuid_s)) {
1219 ret = lttng_metadata_printf(session,
1220 " uuid = \"%s\";\n",
1221 clock_uuid_s
1222 );
1223 if (ret)
1224 goto end;
1225 }
1226
1227 ret = lttng_metadata_printf(session,
1228 " description = \"Monotonic Clock\";\n"
1229 " freq = %" PRIu64 "; /* Frequency, in Hz */\n"
1230 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1231 " offset = %" PRIu64 ";\n"
1232 "};\n\n",
1233 trace_clock_freq(),
1234 measure_clock_offset()
1235 );
1236 if (ret)
1237 goto end;
1238
1239 ret = lttng_metadata_printf(session,
1240 "typealias integer {\n"
1241 " size = 27; align = 1; signed = false;\n"
1242 " map = clock.monotonic.value;\n"
1243 "} := uint27_clock_monotonic_t;\n"
1244 "\n"
1245 "typealias integer {\n"
1246 " size = 32; align = %u; signed = false;\n"
1247 " map = clock.monotonic.value;\n"
1248 "} := uint32_clock_monotonic_t;\n"
1249 "\n"
1250 "typealias integer {\n"
1251 " size = 64; align = %u; signed = false;\n"
1252 " map = clock.monotonic.value;\n"
1253 "} := uint64_clock_monotonic_t;\n\n",
1254 lttng_alignof(uint32_t) * CHAR_BIT,
1255 lttng_alignof(uint64_t) * CHAR_BIT
1256 );
1257 if (ret)
1258 goto end;
1259
1260 ret = _ltt_stream_packet_context_declare(session);
1261 if (ret)
1262 goto end;
1263
1264 ret = _ltt_event_header_declare(session);
1265 if (ret)
1266 goto end;
1267
1268 skip_session:
1269 cds_list_for_each_entry(chan, &session->chan, list) {
1270 ret = _ltt_channel_metadata_statedump(session, chan);
1271 if (ret)
1272 goto end;
1273 }
1274
1275 cds_list_for_each_entry(event, &session->events, list) {
1276 ret = _ltt_event_metadata_statedump(session, event->chan, event);
1277 if (ret)
1278 goto end;
1279 }
1280 session->metadata_dumped = 1;
1281 end:
1282 return ret;
1283 }
1284
1285 void lttng_ust_events_exit(void)
1286 {
1287 struct ltt_session *session, *tmpsession;
1288
1289 cds_list_for_each_entry_safe(session, tmpsession, &sessions, list)
1290 ltt_session_destroy(session);
1291 }
1292
1293 /* WILDCARDS */
1294
1295 static
1296 int wildcard_same_loglevel(struct wildcard_entry *e,
1297 enum lttng_ust_loglevel_type loglevel_type,
1298 int loglevel)
1299 {
1300 if (e->loglevel_type == loglevel_type && e->loglevel == loglevel)
1301 return 1;
1302 else
1303 return 0;
1304 }
1305
1306 #if 0
1307 static
1308 int wildcard_is_within(struct wildcard_entry *e,
1309 enum lttng_ust_loglevel_type loglevel_type,
1310 int loglevel)
1311 {
1312 if (e->loglevel_type == LTTNG_UST_LOGLEVEL_ALL
1313 || e->loglevel == -1)
1314 return 1;
1315 switch (e->loglevel_type) {
1316 case LTTNG_UST_LOGLEVEL_RANGE:
1317 switch (loglevel_type) {
1318 case LTTNG_UST_LOGLEVEL_RANGE:
1319 if (e->loglevel >= loglevel)
1320 return 1;
1321 else
1322 return 0;
1323 case LTTNG_UST_LOGLEVEL_SINGLE:
1324 if (e->loglevel <= 0 && loglevel == 0)
1325 return 1;
1326 else
1327 return 0;
1328 }
1329 case LTTNG_UST_LOGLEVEL_SINGLE:
1330 switch (loglevel_type) {
1331 case LTTNG_UST_LOGLEVEL_RANGE:
1332 if (loglevel <= 0)
1333 return 1;
1334 else
1335 return 0;
1336 case LTTNG_UST_LOGLEVEL_SINGLE:
1337 if (e->loglevel == loglevel)
1338 return 1;
1339 else
1340 return 0;
1341 }
1342 }
1343 }
1344 #endif
1345
1346 /*
1347 * Add the wildcard to the wildcard list. Must be called with
1348 * ust lock held.
1349 */
1350 static
1351 struct session_wildcard *add_wildcard(struct ltt_channel *chan,
1352 struct lttng_ust_event *event_param)
1353 {
1354 struct wildcard_entry *e;
1355 struct session_wildcard *sw;
1356 size_t name_len = strlen(event_param->name) + 1;
1357 int found = 0;
1358
1359 /*
1360 * Try to find global wildcard entry. Given that this is shared
1361 * across all sessions, we need to check for exact loglevel
1362 * match, not just whether contained within the existing ones.
1363 */
1364 cds_list_for_each_entry(e, &wildcard_list, list) {
1365 if (!strncmp(event_param->name, e->name,
1366 LTTNG_UST_SYM_NAME_LEN - 1)) {
1367 if (wildcard_same_loglevel(e,
1368 event_param->loglevel_type,
1369 event_param->loglevel)) {
1370 found = 1;
1371 break;
1372 }
1373 }
1374 }
1375
1376 if (!found) {
1377 /*
1378 * Create global wildcard entry if not found. Using
1379 * zmalloc here to allocate a variable length element.
1380 * Could cause some memory fragmentation if overused.
1381 */
1382 e = zmalloc(sizeof(struct wildcard_entry) + name_len);
1383 if (!e)
1384 return ERR_PTR(-ENOMEM);
1385 memcpy(&e->name[0], event_param->name, name_len);
1386 e->loglevel_type = event_param->loglevel_type;
1387 e->loglevel = event_param->loglevel;
1388 cds_list_add(&e->list, &wildcard_list);
1389 CDS_INIT_LIST_HEAD(&e->session_list);
1390 }
1391
1392 /* session wildcard */
1393 cds_list_for_each_entry(sw, &e->session_list, session_list) {
1394 if (chan == sw->chan) {
1395 DBG("wildcard %s busy for this channel",
1396 event_param->name);
1397 return ERR_PTR(-EEXIST); /* Already there */
1398 }
1399 }
1400 sw = zmalloc(sizeof(struct session_wildcard));
1401 if (!sw)
1402 return ERR_PTR(-ENOMEM);
1403 sw->chan = chan;
1404 sw->enabled = 1;
1405 memcpy(&sw->event_param, event_param, sizeof(sw->event_param));
1406 sw->event_param.instrumentation = LTTNG_UST_TRACEPOINT;
1407 sw->event_param.loglevel_type = event_param->loglevel_type;
1408 sw->event_param.loglevel = event_param->loglevel;
1409 CDS_INIT_LIST_HEAD(&sw->events);
1410 cds_list_add(&sw->list, &chan->session->wildcards);
1411 cds_list_add(&sw->session_list, &e->session_list);
1412 sw->entry = e;
1413 ltt_probes_create_wildcard_events(e, sw);
1414 return sw;
1415 }
1416
1417 /*
1418 * Remove the wildcard from the wildcard list. Must be called with
1419 * ust_lock held. Only called at session teardown.
1420 */
1421 static
1422 void _remove_wildcard(struct session_wildcard *wildcard)
1423 {
1424 struct ltt_event *ev, *tmp;
1425
1426 /*
1427 * Just remove the events owned (for enable/disable) by this
1428 * wildcard from the list. The session teardown will take care
1429 * of freeing the event memory.
1430 */
1431 cds_list_for_each_entry_safe(ev, tmp, &wildcard->events,
1432 wildcard_list) {
1433 cds_list_del(&ev->wildcard_list);
1434 }
1435 cds_list_del(&wildcard->session_list);
1436 cds_list_del(&wildcard->list);
1437 if (cds_list_empty(&wildcard->entry->session_list)) {
1438 cds_list_del(&wildcard->entry->list);
1439 free(wildcard->entry);
1440 }
1441 free(wildcard->filter_bytecode);
1442 free(wildcard);
1443 }
1444
1445 int ltt_wildcard_create(struct ltt_channel *chan,
1446 struct lttng_ust_event *event_param,
1447 struct session_wildcard **_sw)
1448 {
1449 struct session_wildcard *sw;
1450
1451 sw = add_wildcard(chan, event_param);
1452 if (!sw || IS_ERR(sw)) {
1453 return PTR_ERR(sw);
1454 }
1455 *_sw = sw;
1456 return 0;
1457 }
1458
1459 static
1460 void _ltt_wildcard_destroy(struct session_wildcard *sw)
1461 {
1462 _remove_wildcard(sw);
1463 }
1464
1465 int ltt_wildcard_enable(struct session_wildcard *wildcard)
1466 {
1467 struct ltt_event *ev;
1468 int ret;
1469
1470 if (wildcard->enabled)
1471 return -EEXIST;
1472 cds_list_for_each_entry(ev, &wildcard->events, wildcard_list) {
1473 ret = ltt_event_enable(ev);
1474 if (ret) {
1475 DBG("Error: enable error.\n");
1476 return ret;
1477 }
1478 }
1479 wildcard->enabled = 1;
1480 return 0;
1481 }
1482
1483 int ltt_wildcard_disable(struct session_wildcard *wildcard)
1484 {
1485 struct ltt_event *ev;
1486 int ret;
1487
1488 if (!wildcard->enabled)
1489 return -EEXIST;
1490 cds_list_for_each_entry(ev, &wildcard->events, wildcard_list) {
1491 ret = ltt_event_disable(ev);
1492 if (ret) {
1493 DBG("Error: disable error.\n");
1494 return ret;
1495 }
1496 }
1497 wildcard->enabled = 0;
1498 return 0;
1499 }
1500
1501 /*
1502 * Take the TLS "fault" in libuuid if dlopen'd, which can take the
1503 * dynamic linker mutex, outside of the UST lock, since the UST lock is
1504 * taken in constructors, which are called with dynamic linker mutex
1505 * held.
1506 */
1507 void lttng_fixup_event_tls(void)
1508 {
1509 unsigned char uuid[LTTNG_UST_UUID_STR_LEN];
1510
1511 (void) lttng_ust_uuid_generate(uuid);
1512 }
This page took 0.05672 seconds and 3 git commands to generate.