2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <common/common.h>
26 #include <common/defaults.h>
28 #include "buffer-registry.h"
29 #include "trace-ust.h"
35 * Match function for the events hash table lookup.
37 * Matches by name only. Used by the disable command.
39 int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
42 struct ltt_ust_event
*event
;
48 event
= caa_container_of(node
, struct ltt_ust_event
, node
.node
);
52 if (strncmp(event
->attr
.name
, name
, sizeof(event
->attr
.name
)) != 0) {
64 * Match function for the hash table lookup.
66 * It matches an ust event based on three attributes which are the event name,
67 * the filter bytecode and the loglevel.
69 int trace_ust_ht_match_event(struct cds_lfht_node
*node
, const void *_key
)
71 struct ltt_ust_event
*event
;
72 const struct ltt_ust_ht_key
*key
;
73 int ev_loglevel_value
;
79 event
= caa_container_of(node
, struct ltt_ust_event
, node
.node
);
81 ev_loglevel_value
= event
->attr
.loglevel
;
83 /* Match the 4 elements of the key: name, filter, loglevel, exclusions. */
86 if (strncmp(event
->attr
.name
, key
->name
, sizeof(event
->attr
.name
)) != 0) {
90 /* Event loglevel value and type. */
91 ll_match
= loglevels_match(event
->attr
.loglevel_type
,
92 ev_loglevel_value
, key
->loglevel_type
,
93 key
->loglevel_value
, LTTNG_UST_LOGLEVEL_ALL
);
99 /* Only one of the filters is NULL, fail. */
100 if ((key
->filter
&& !event
->filter
) || (!key
->filter
&& event
->filter
)) {
104 if (key
->filter
&& event
->filter
) {
105 /* Both filters exists, check length followed by the bytecode. */
106 if (event
->filter
->len
!= key
->filter
->len
||
107 memcmp(event
->filter
->data
, key
->filter
->data
,
108 event
->filter
->len
) != 0) {
113 /* If only one of the exclusions is NULL, fail. */
114 if ((key
->exclusion
&& !event
->exclusion
) || (!key
->exclusion
&& event
->exclusion
)) {
118 if (key
->exclusion
&& event
->exclusion
) {
119 /* Both exclusions exist; check count followed by names. */
120 if (event
->exclusion
->count
!= key
->exclusion
->count
||
121 memcmp(event
->exclusion
->names
, key
->exclusion
->names
,
122 event
->exclusion
->count
* LTTNG_SYMBOL_NAME_LEN
) != 0) {
134 * Find the channel in the hashtable and return channel pointer. RCU read side
135 * lock MUST be acquired before calling this.
137 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
140 struct lttng_ht_node_str
*node
;
141 struct lttng_ht_iter iter
;
144 * If we receive an empty string for channel name, it means the
145 * default channel name is requested.
148 name
= DEFAULT_CHANNEL_NAME
;
150 lttng_ht_lookup(ht
, (void *)name
, &iter
);
151 node
= lttng_ht_iter_get_node_str(&iter
);
156 DBG2("Trace UST channel %s found by name", name
);
158 return caa_container_of(node
, struct ltt_ust_channel
, node
);
161 DBG2("Trace UST channel %s not found by name", name
);
166 * Find the event in the hashtable and return event pointer. RCU read side lock
167 * MUST be acquired before calling this.
169 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
170 char *name
, struct lttng_filter_bytecode
*filter
,
171 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
172 struct lttng_event_exclusion
*exclusion
)
174 struct lttng_ht_node_str
*node
;
175 struct lttng_ht_iter iter
;
176 struct ltt_ust_ht_key key
;
183 key
.loglevel_type
= loglevel_type
;
184 key
.loglevel_value
= loglevel_value
;
185 key
.exclusion
= exclusion
;
187 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
188 trace_ust_ht_match_event
, &key
, &iter
.iter
);
189 node
= lttng_ht_iter_get_node_str(&iter
);
194 DBG2("Trace UST event %s found", key
.name
);
196 return caa_container_of(node
, struct ltt_ust_event
, node
);
199 DBG2("Trace UST event %s NOT found", key
.name
);
204 * Lookup an agent in the session agents hash table by domain type and return
205 * the object if found else NULL.
207 * RCU read side lock must be acquired before calling and only released
208 * once the agent is no longer in scope or being used.
210 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
211 enum lttng_domain_type domain_type
)
213 struct agent
*agt
= NULL
;
214 struct lttng_ht_node_u64
*node
;
215 struct lttng_ht_iter iter
;
220 DBG3("Trace ust agent lookup for domain %d", domain_type
);
224 lttng_ht_lookup(session
->agents
, &key
, &iter
);
225 node
= lttng_ht_iter_get_node_u64(&iter
);
229 agt
= caa_container_of(node
, struct agent
, node
);
236 * Allocate and initialize a ust session data structure.
238 * Return pointer to structure or NULL.
240 struct ltt_ust_session
*trace_ust_create_session(uint64_t session_id
)
242 struct ltt_ust_session
*lus
;
244 /* Allocate a new ltt ust session */
245 lus
= zmalloc(sizeof(struct ltt_ust_session
));
247 PERROR("create ust session zmalloc");
251 /* Init data structure */
252 lus
->id
= session_id
;
255 /* Set default metadata channel attribute. */
256 lus
->metadata_attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
257 lus
->metadata_attr
.subbuf_size
= default_get_metadata_subbuf_size();
258 lus
->metadata_attr
.num_subbuf
= DEFAULT_METADATA_SUBBUF_NUM
;
259 lus
->metadata_attr
.switch_timer_interval
= DEFAULT_METADATA_SWITCH_TIMER
;
260 lus
->metadata_attr
.read_timer_interval
= DEFAULT_METADATA_READ_TIMER
;
261 lus
->metadata_attr
.output
= LTTNG_UST_MMAP
;
264 * Default buffer type. This can be changed through an enable channel
265 * requesting a different type. Note that this can only be changed once
266 * during the session lifetime which is at the first enable channel and
267 * only before start. The flag buffer_type_changed indicates the status.
269 lus
->buffer_type
= LTTNG_BUFFER_PER_UID
;
270 /* Once set to 1, the buffer_type is immutable for the session. */
271 lus
->buffer_type_changed
= 0;
272 /* Init it in case it get used after allocation. */
273 CDS_INIT_LIST_HEAD(&lus
->buffer_reg_uid_list
);
275 /* Alloc UST global domain channels' HT */
276 lus
->domain_global
.channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
277 /* Alloc agent hash table. */
278 lus
->agents
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
280 lus
->consumer
= consumer_create_output(CONSUMER_DST_LOCAL
);
281 if (lus
->consumer
== NULL
) {
285 DBG2("UST trace session create successful");
290 ht_cleanup_push(lus
->domain_global
.channels
);
291 ht_cleanup_push(lus
->agents
);
298 * Allocate and initialize a ust channel data structure.
300 * Return pointer to structure or NULL.
302 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*chan
,
303 enum lttng_domain_type domain
)
305 struct ltt_ust_channel
*luc
;
309 luc
= zmalloc(sizeof(struct ltt_ust_channel
));
311 PERROR("ltt_ust_channel zmalloc");
315 luc
->domain
= domain
;
317 /* Copy UST channel attributes */
318 luc
->attr
.overwrite
= chan
->attr
.overwrite
;
319 luc
->attr
.subbuf_size
= chan
->attr
.subbuf_size
;
320 luc
->attr
.num_subbuf
= chan
->attr
.num_subbuf
;
321 luc
->attr
.switch_timer_interval
= chan
->attr
.switch_timer_interval
;
322 luc
->attr
.read_timer_interval
= chan
->attr
.read_timer_interval
;
323 luc
->attr
.output
= (enum lttng_ust_output
) chan
->attr
.output
;
325 /* Translate to UST output enum */
326 switch (luc
->attr
.output
) {
328 luc
->attr
.output
= LTTNG_UST_MMAP
;
333 * If we receive an empty string for channel name, it means the
334 * default channel name is requested.
336 if (chan
->name
[0] == '\0') {
337 strncpy(luc
->name
, DEFAULT_CHANNEL_NAME
, sizeof(luc
->name
));
339 /* Copy channel name */
340 strncpy(luc
->name
, chan
->name
, sizeof(luc
->name
));
342 luc
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
345 lttng_ht_node_init_str(&luc
->node
, luc
->name
);
346 CDS_INIT_LIST_HEAD(&luc
->ctx_list
);
348 /* Alloc hash tables */
349 luc
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
350 luc
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
352 /* On-disk circular buffer parameters */
353 luc
->tracefile_size
= chan
->attr
.tracefile_size
;
354 luc
->tracefile_count
= chan
->attr
.tracefile_count
;
356 DBG2("Trace UST channel %s created", luc
->name
);
363 * Allocate and initialize a ust event. Set name and event type.
364 * We own filter_expression, filter, and exclusion.
366 * Return pointer to structure or NULL.
368 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
,
369 char *filter_expression
,
370 struct lttng_filter_bytecode
*filter
,
371 struct lttng_event_exclusion
*exclusion
,
374 struct ltt_ust_event
*lue
;
378 lue
= zmalloc(sizeof(struct ltt_ust_event
));
380 PERROR("ust event zmalloc");
384 lue
->internal
= internal_event
;
387 case LTTNG_EVENT_PROBE
:
388 lue
->attr
.instrumentation
= LTTNG_UST_PROBE
;
390 case LTTNG_EVENT_FUNCTION
:
391 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
393 case LTTNG_EVENT_FUNCTION_ENTRY
:
394 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
396 case LTTNG_EVENT_TRACEPOINT
:
397 lue
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
400 ERR("Unknown ust instrumentation type (%d)", ev
->type
);
401 goto error_free_event
;
404 /* Copy event name */
405 strncpy(lue
->attr
.name
, ev
->name
, LTTNG_UST_SYM_NAME_LEN
);
406 lue
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
408 switch (ev
->loglevel_type
) {
409 case LTTNG_EVENT_LOGLEVEL_ALL
:
410 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
411 lue
->attr
.loglevel
= -1; /* Force to -1 */
413 case LTTNG_EVENT_LOGLEVEL_RANGE
:
414 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
415 lue
->attr
.loglevel
= ev
->loglevel
;
417 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
418 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
419 lue
->attr
.loglevel
= ev
->loglevel
;
422 ERR("Unknown ust loglevel type (%d)", ev
->loglevel_type
);
423 goto error_free_event
;
427 lue
->filter_expression
= filter_expression
;
428 lue
->filter
= filter
;
429 lue
->exclusion
= exclusion
;
432 lttng_ht_node_init_str(&lue
->node
, lue
->attr
.name
);
434 DBG2("Trace UST event %s, loglevel (%d,%d) created",
435 lue
->attr
.name
, lue
->attr
.loglevel_type
,
443 free(filter_expression
);
450 int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type
)
455 case LTTNG_EVENT_CONTEXT_VTID
:
456 utype
= LTTNG_UST_CONTEXT_VTID
;
458 case LTTNG_EVENT_CONTEXT_VPID
:
459 utype
= LTTNG_UST_CONTEXT_VPID
;
461 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
462 utype
= LTTNG_UST_CONTEXT_PTHREAD_ID
;
464 case LTTNG_EVENT_CONTEXT_PROCNAME
:
465 utype
= LTTNG_UST_CONTEXT_PROCNAME
;
467 case LTTNG_EVENT_CONTEXT_IP
:
468 utype
= LTTNG_UST_CONTEXT_IP
;
470 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
471 if (!ustctl_has_perf_counters()) {
473 WARN("Perf counters not implemented in UST");
475 utype
= LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
;
479 ERR("Invalid UST context");
487 * Return 1 if contexts match, 0 otherwise.
489 int trace_ust_match_context(struct ltt_ust_context
*uctx
,
490 struct lttng_event_context
*ctx
)
494 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
498 if (uctx
->ctx
.ctx
!= utype
) {
502 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
503 if (uctx
->ctx
.u
.perf_counter
.type
504 != ctx
->u
.perf_counter
.type
) {
507 if (uctx
->ctx
.u
.perf_counter
.config
508 != ctx
->u
.perf_counter
.config
) {
511 if (strncmp(uctx
->ctx
.u
.perf_counter
.name
,
512 ctx
->u
.perf_counter
.name
,
513 LTTNG_UST_SYM_NAME_LEN
)) {
525 * Allocate and initialize an UST context.
527 * Return pointer to structure or NULL.
529 struct ltt_ust_context
*trace_ust_create_context(
530 struct lttng_event_context
*ctx
)
532 struct ltt_ust_context
*uctx
;
537 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
542 uctx
= zmalloc(sizeof(struct ltt_ust_context
));
544 PERROR("zmalloc ltt_ust_context");
548 uctx
->ctx
.ctx
= (enum lttng_ust_context_type
) utype
;
550 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
551 uctx
->ctx
.u
.perf_counter
.type
= ctx
->u
.perf_counter
.type
;
552 uctx
->ctx
.u
.perf_counter
.config
= ctx
->u
.perf_counter
.config
;
553 strncpy(uctx
->ctx
.u
.perf_counter
.name
, ctx
->u
.perf_counter
.name
,
554 LTTNG_UST_SYM_NAME_LEN
);
555 uctx
->ctx
.u
.perf_counter
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
560 lttng_ht_node_init_ulong(&uctx
->node
, (unsigned long) uctx
->ctx
.ctx
);
569 void destroy_pid_tracker_node_rcu(struct rcu_head
*head
)
571 struct ust_pid_tracker_node
*tracker_node
=
572 caa_container_of(head
, struct ust_pid_tracker_node
, node
.head
);
577 void destroy_pid_tracker_node(struct ust_pid_tracker_node
*tracker_node
)
580 call_rcu(&tracker_node
->node
.head
, destroy_pid_tracker_node_rcu
);
584 int init_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
588 pid_tracker
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
589 if (!pid_tracker
->ht
) {
599 * Teardown pid tracker content, but don't free pid_tracker object.
602 void fini_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
604 struct ust_pid_tracker_node
*tracker_node
;
605 struct lttng_ht_iter iter
;
607 if (!pid_tracker
->ht
) {
611 cds_lfht_for_each_entry(pid_tracker
->ht
->ht
,
612 &iter
.iter
, tracker_node
, node
.node
) {
613 int ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
616 destroy_pid_tracker_node(tracker_node
);
619 ht_cleanup_push(pid_tracker
->ht
);
620 pid_tracker
->ht
= NULL
;
624 struct ust_pid_tracker_node
*pid_tracker_lookup(
625 struct ust_pid_tracker
*pid_tracker
, int pid
,
626 struct lttng_ht_iter
*iter
)
628 unsigned long _pid
= (unsigned long) pid
;
629 struct lttng_ht_node_ulong
*node
;
631 lttng_ht_lookup(pid_tracker
->ht
, (void *) _pid
, iter
);
632 node
= lttng_ht_iter_get_node_ulong(iter
);
634 return caa_container_of(node
, struct ust_pid_tracker_node
,
642 int pid_tracker_add_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
644 int retval
= LTTNG_OK
;
645 struct ust_pid_tracker_node
*tracker_node
;
646 struct lttng_ht_iter iter
;
649 retval
= LTTNG_ERR_INVALID
;
652 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
654 /* Already exists. */
655 retval
= LTTNG_ERR_PID_TRACKED
;
658 tracker_node
= zmalloc(sizeof(*tracker_node
));
660 retval
= LTTNG_ERR_NOMEM
;
663 lttng_ht_node_init_ulong(&tracker_node
->node
, (unsigned long) pid
);
664 lttng_ht_add_unique_ulong(pid_tracker
->ht
, &tracker_node
->node
);
670 int pid_tracker_del_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
672 int retval
= LTTNG_OK
, ret
;
673 struct ust_pid_tracker_node
*tracker_node
;
674 struct lttng_ht_iter iter
;
677 retval
= LTTNG_ERR_INVALID
;
680 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
683 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
686 ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
689 destroy_pid_tracker_node(tracker_node
);
695 * The session lock is held when calling this function.
697 int trace_ust_pid_tracker_lookup(struct ltt_ust_session
*session
, int pid
)
699 struct lttng_ht_iter iter
;
701 if (!session
->pid_tracker
.ht
) {
704 if (pid_tracker_lookup(&session
->pid_tracker
, pid
, &iter
)) {
711 * Called with the session lock held.
713 int trace_ust_track_pid(struct ltt_ust_session
*session
, int pid
)
715 int retval
= LTTNG_OK
;
718 /* Track all pids: destroy tracker if exists. */
719 if (session
->pid_tracker
.ht
) {
720 fini_pid_tracker(&session
->pid_tracker
);
721 /* Ensure all apps have session. */
722 ust_app_global_update_all(session
);
727 if (!session
->pid_tracker
.ht
) {
728 /* Create tracker. */
729 if (init_pid_tracker(&session
->pid_tracker
)) {
730 ERR("Error initializing PID tracker");
731 retval
= LTTNG_ERR_NOMEM
;
734 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
735 if (ret
!= LTTNG_OK
) {
737 fini_pid_tracker(&session
->pid_tracker
);
740 /* Remove all apps from session except pid. */
741 ust_app_global_update_all(session
);
745 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
746 if (ret
!= LTTNG_OK
) {
750 /* Add session to application */
751 app
= ust_app_find_by_pid(pid
);
753 ust_app_global_update(session
, app
);
762 * Called with the session lock held.
764 int trace_ust_untrack_pid(struct ltt_ust_session
*session
, int pid
)
766 int retval
= LTTNG_OK
;
769 /* Create empty tracker, replace old tracker. */
770 struct ust_pid_tracker tmp_tracker
;
772 tmp_tracker
= session
->pid_tracker
;
773 if (init_pid_tracker(&session
->pid_tracker
)) {
774 ERR("Error initializing PID tracker");
775 retval
= LTTNG_ERR_NOMEM
;
776 /* Rollback operation. */
777 session
->pid_tracker
= tmp_tracker
;
780 fini_pid_tracker(&tmp_tracker
);
782 /* Remove session from all applications */
783 ust_app_global_update_all(session
);
788 if (!session
->pid_tracker
.ht
) {
789 /* No PID being tracked. */
790 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
793 /* Remove PID from tracker */
794 ret
= pid_tracker_del_pid(&session
->pid_tracker
, pid
);
795 if (ret
!= LTTNG_OK
) {
799 /* Remove session from application. */
800 app
= ust_app_find_by_pid(pid
);
802 ust_app_global_update(session
, app
);
810 * Called with session lock held.
812 ssize_t
trace_ust_list_tracker_pids(struct ltt_ust_session
*session
,
815 struct ust_pid_tracker_node
*tracker_node
;
816 struct lttng_ht_iter iter
;
817 unsigned long count
, i
= 0;
822 if (!session
->pid_tracker
.ht
) {
823 /* Tracker disabled. Set first entry to -1. */
824 pids
= zmalloc(sizeof(*pids
));
835 cds_lfht_count_nodes(session
->pid_tracker
.ht
->ht
,
836 &approx
[0], &count
, &approx
[1]);
837 pids
= zmalloc(sizeof(*pids
) * count
);
842 cds_lfht_for_each_entry(session
->pid_tracker
.ht
->ht
,
843 &iter
.iter
, tracker_node
, node
.node
) {
844 pids
[i
++] = tracker_node
->node
.key
;
854 * RCU safe free context structure.
856 static void destroy_context_rcu(struct rcu_head
*head
)
858 struct lttng_ht_node_ulong
*node
=
859 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
860 struct ltt_ust_context
*ctx
=
861 caa_container_of(node
, struct ltt_ust_context
, node
);
867 * Cleanup UST context hash table.
869 static void destroy_contexts(struct lttng_ht
*ht
)
872 struct lttng_ht_node_ulong
*node
;
873 struct lttng_ht_iter iter
;
874 struct ltt_ust_context
*ctx
;
879 cds_lfht_for_each_entry(ht
->ht
, &iter
.iter
, node
, node
) {
880 /* Remove from ordered list. */
881 ctx
= caa_container_of(node
, struct ltt_ust_context
, node
);
882 cds_list_del(&ctx
->list
);
883 /* Remove from channel's hash table. */
884 ret
= lttng_ht_del(ht
, &iter
);
886 call_rcu(&node
->head
, destroy_context_rcu
);
895 * Cleanup ust event structure.
897 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
901 DBG2("Trace destroy UST event %s", event
->attr
.name
);
902 free(event
->filter_expression
);
904 free(event
->exclusion
);
909 * URCU intermediate call to complete destroy event.
911 static void destroy_event_rcu(struct rcu_head
*head
)
913 struct lttng_ht_node_str
*node
=
914 caa_container_of(head
, struct lttng_ht_node_str
, head
);
915 struct ltt_ust_event
*event
=
916 caa_container_of(node
, struct ltt_ust_event
, node
);
918 trace_ust_destroy_event(event
);
922 * Cleanup UST events hashtable.
924 static void destroy_events(struct lttng_ht
*events
)
927 struct lttng_ht_node_str
*node
;
928 struct lttng_ht_iter iter
;
933 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
934 ret
= lttng_ht_del(events
, &iter
);
936 call_rcu(&node
->head
, destroy_event_rcu
);
940 ht_cleanup_push(events
);
944 * Cleanup ust channel structure.
946 * Should _NOT_ be called with RCU read lock held.
948 static void _trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
952 DBG2("Trace destroy UST channel %s", channel
->name
);
958 * URCU intermediate call to complete destroy channel.
960 static void destroy_channel_rcu(struct rcu_head
*head
)
962 struct lttng_ht_node_str
*node
=
963 caa_container_of(head
, struct lttng_ht_node_str
, head
);
964 struct ltt_ust_channel
*channel
=
965 caa_container_of(node
, struct ltt_ust_channel
, node
);
967 _trace_ust_destroy_channel(channel
);
970 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
972 /* Destroying all events of the channel */
973 destroy_events(channel
->events
);
974 /* Destroying all context of the channel */
975 destroy_contexts(channel
->ctx
);
977 call_rcu(&channel
->node
.head
, destroy_channel_rcu
);
981 * Remove an UST channel from a channel HT.
983 void trace_ust_delete_channel(struct lttng_ht
*ht
,
984 struct ltt_ust_channel
*channel
)
987 struct lttng_ht_iter iter
;
992 iter
.iter
.node
= &channel
->node
.node
;
993 ret
= lttng_ht_del(ht
, &iter
);
998 * Iterate over a hash table containing channels and cleanup safely.
1000 static void destroy_channels(struct lttng_ht
*channels
)
1002 struct lttng_ht_node_str
*node
;
1003 struct lttng_ht_iter iter
;
1008 cds_lfht_for_each_entry(channels
->ht
, &iter
.iter
, node
, node
) {
1009 struct ltt_ust_channel
*chan
=
1010 caa_container_of(node
, struct ltt_ust_channel
, node
);
1012 trace_ust_delete_channel(channels
, chan
);
1013 trace_ust_destroy_channel(chan
);
1017 ht_cleanup_push(channels
);
1021 * Cleanup UST global domain.
1023 static void destroy_domain_global(struct ltt_ust_domain_global
*dom
)
1027 destroy_channels(dom
->channels
);
1031 * Cleanup ust session structure
1033 * Should *NOT* be called with RCU read-side lock held.
1035 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
1038 struct buffer_reg_uid
*reg
, *sreg
;
1039 struct lttng_ht_iter iter
;
1043 DBG2("Trace UST destroy session %" PRIu64
, session
->id
);
1045 /* Cleaning up UST domain */
1046 destroy_domain_global(&session
->domain_global
);
1049 cds_lfht_for_each_entry(session
->agents
->ht
, &iter
.iter
, agt
, node
.node
) {
1050 int ret
= lttng_ht_del(session
->agents
, &iter
);
1057 ht_cleanup_push(session
->agents
);
1059 /* Cleanup UID buffer registry object(s). */
1060 cds_list_for_each_entry_safe(reg
, sreg
, &session
->buffer_reg_uid_list
,
1062 cds_list_del(®
->lnode
);
1063 buffer_reg_uid_remove(reg
);
1064 buffer_reg_uid_destroy(reg
, session
->consumer
);
1067 consumer_output_put(session
->consumer
);
1069 fini_pid_tracker(&session
->pid_tracker
);