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 * Validates an exclusion list.
365 * Returns 0 if valid, negative value if invalid.
367 static int validate_exclusion(struct lttng_event_exclusion
*exclusion
)
374 for (i
= 0; i
< exclusion
->count
; ++i
) {
377 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, i
);
379 for (j
= 0; j
< i
; ++j
) {
381 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, j
);
383 if (!strncmp(name_a
, name_b
, LTTNG_SYMBOL_NAME_LEN
)) {
396 * Allocate and initialize a ust event. Set name and event type.
397 * We own filter_expression, filter, and exclusion.
399 * Return pointer to structure or NULL.
401 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
,
402 char *filter_expression
,
403 struct lttng_filter_bytecode
*filter
,
404 struct lttng_event_exclusion
*exclusion
,
407 struct ltt_ust_event
*lue
;
411 if (exclusion
&& validate_exclusion(exclusion
)) {
415 lue
= zmalloc(sizeof(struct ltt_ust_event
));
417 PERROR("ust event zmalloc");
421 lue
->internal
= internal_event
;
424 case LTTNG_EVENT_PROBE
:
425 lue
->attr
.instrumentation
= LTTNG_UST_PROBE
;
427 case LTTNG_EVENT_FUNCTION
:
428 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
430 case LTTNG_EVENT_FUNCTION_ENTRY
:
431 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
433 case LTTNG_EVENT_TRACEPOINT
:
434 lue
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
437 ERR("Unknown ust instrumentation type (%d)", ev
->type
);
438 goto error_free_event
;
441 /* Copy event name */
442 strncpy(lue
->attr
.name
, ev
->name
, LTTNG_UST_SYM_NAME_LEN
);
443 lue
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
445 switch (ev
->loglevel_type
) {
446 case LTTNG_EVENT_LOGLEVEL_ALL
:
447 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
448 lue
->attr
.loglevel
= -1; /* Force to -1 */
450 case LTTNG_EVENT_LOGLEVEL_RANGE
:
451 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
452 lue
->attr
.loglevel
= ev
->loglevel
;
454 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
455 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
456 lue
->attr
.loglevel
= ev
->loglevel
;
459 ERR("Unknown ust loglevel type (%d)", ev
->loglevel_type
);
460 goto error_free_event
;
464 lue
->filter_expression
= filter_expression
;
465 lue
->filter
= filter
;
466 lue
->exclusion
= exclusion
;
469 lttng_ht_node_init_str(&lue
->node
, lue
->attr
.name
);
471 DBG2("Trace UST event %s, loglevel (%d,%d) created",
472 lue
->attr
.name
, lue
->attr
.loglevel_type
,
480 free(filter_expression
);
487 int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type
)
492 case LTTNG_EVENT_CONTEXT_VTID
:
493 utype
= LTTNG_UST_CONTEXT_VTID
;
495 case LTTNG_EVENT_CONTEXT_VPID
:
496 utype
= LTTNG_UST_CONTEXT_VPID
;
498 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
499 utype
= LTTNG_UST_CONTEXT_PTHREAD_ID
;
501 case LTTNG_EVENT_CONTEXT_PROCNAME
:
502 utype
= LTTNG_UST_CONTEXT_PROCNAME
;
504 case LTTNG_EVENT_CONTEXT_IP
:
505 utype
= LTTNG_UST_CONTEXT_IP
;
507 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
508 if (!ustctl_has_perf_counters()) {
510 WARN("Perf counters not implemented in UST");
512 utype
= LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
;
516 ERR("Invalid UST context");
524 * Return 1 if contexts match, 0 otherwise.
526 int trace_ust_match_context(struct ltt_ust_context
*uctx
,
527 struct lttng_event_context
*ctx
)
531 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
535 if (uctx
->ctx
.ctx
!= utype
) {
539 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
540 if (uctx
->ctx
.u
.perf_counter
.type
541 != ctx
->u
.perf_counter
.type
) {
544 if (uctx
->ctx
.u
.perf_counter
.config
545 != ctx
->u
.perf_counter
.config
) {
548 if (strncmp(uctx
->ctx
.u
.perf_counter
.name
,
549 ctx
->u
.perf_counter
.name
,
550 LTTNG_UST_SYM_NAME_LEN
)) {
562 * Allocate and initialize an UST context.
564 * Return pointer to structure or NULL.
566 struct ltt_ust_context
*trace_ust_create_context(
567 struct lttng_event_context
*ctx
)
569 struct ltt_ust_context
*uctx
;
574 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
579 uctx
= zmalloc(sizeof(struct ltt_ust_context
));
581 PERROR("zmalloc ltt_ust_context");
585 uctx
->ctx
.ctx
= (enum lttng_ust_context_type
) utype
;
587 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
588 uctx
->ctx
.u
.perf_counter
.type
= ctx
->u
.perf_counter
.type
;
589 uctx
->ctx
.u
.perf_counter
.config
= ctx
->u
.perf_counter
.config
;
590 strncpy(uctx
->ctx
.u
.perf_counter
.name
, ctx
->u
.perf_counter
.name
,
591 LTTNG_UST_SYM_NAME_LEN
);
592 uctx
->ctx
.u
.perf_counter
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
597 lttng_ht_node_init_ulong(&uctx
->node
, (unsigned long) uctx
->ctx
.ctx
);
606 void destroy_pid_tracker_node_rcu(struct rcu_head
*head
)
608 struct ust_pid_tracker_node
*tracker_node
=
609 caa_container_of(head
, struct ust_pid_tracker_node
, node
.head
);
614 void destroy_pid_tracker_node(struct ust_pid_tracker_node
*tracker_node
)
617 call_rcu(&tracker_node
->node
.head
, destroy_pid_tracker_node_rcu
);
621 int init_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
625 pid_tracker
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
626 if (!pid_tracker
->ht
) {
636 * Teardown pid tracker content, but don't free pid_tracker object.
639 void fini_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
641 struct ust_pid_tracker_node
*tracker_node
;
642 struct lttng_ht_iter iter
;
644 if (!pid_tracker
->ht
) {
648 cds_lfht_for_each_entry(pid_tracker
->ht
->ht
,
649 &iter
.iter
, tracker_node
, node
.node
) {
650 int ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
653 destroy_pid_tracker_node(tracker_node
);
656 ht_cleanup_push(pid_tracker
->ht
);
657 pid_tracker
->ht
= NULL
;
661 struct ust_pid_tracker_node
*pid_tracker_lookup(
662 struct ust_pid_tracker
*pid_tracker
, int pid
,
663 struct lttng_ht_iter
*iter
)
665 unsigned long _pid
= (unsigned long) pid
;
666 struct lttng_ht_node_ulong
*node
;
668 lttng_ht_lookup(pid_tracker
->ht
, (void *) _pid
, iter
);
669 node
= lttng_ht_iter_get_node_ulong(iter
);
671 return caa_container_of(node
, struct ust_pid_tracker_node
,
679 int pid_tracker_add_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
681 int retval
= LTTNG_OK
;
682 struct ust_pid_tracker_node
*tracker_node
;
683 struct lttng_ht_iter iter
;
686 retval
= LTTNG_ERR_INVALID
;
689 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
691 /* Already exists. */
692 retval
= LTTNG_ERR_PID_TRACKED
;
695 tracker_node
= zmalloc(sizeof(*tracker_node
));
697 retval
= LTTNG_ERR_NOMEM
;
700 lttng_ht_node_init_ulong(&tracker_node
->node
, (unsigned long) pid
);
701 lttng_ht_add_unique_ulong(pid_tracker
->ht
, &tracker_node
->node
);
707 int pid_tracker_del_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
709 int retval
= LTTNG_OK
, ret
;
710 struct ust_pid_tracker_node
*tracker_node
;
711 struct lttng_ht_iter iter
;
714 retval
= LTTNG_ERR_INVALID
;
717 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
720 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
723 ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
726 destroy_pid_tracker_node(tracker_node
);
732 * The session lock is held when calling this function.
734 int trace_ust_pid_tracker_lookup(struct ltt_ust_session
*session
, int pid
)
736 struct lttng_ht_iter iter
;
738 if (!session
->pid_tracker
.ht
) {
741 if (pid_tracker_lookup(&session
->pid_tracker
, pid
, &iter
)) {
748 * Called with the session lock held.
750 int trace_ust_track_pid(struct ltt_ust_session
*session
, int pid
)
752 int retval
= LTTNG_OK
;
755 /* Track all pids: destroy tracker if exists. */
756 if (session
->pid_tracker
.ht
) {
757 fini_pid_tracker(&session
->pid_tracker
);
758 /* Ensure all apps have session. */
759 ust_app_global_update_all(session
);
764 if (!session
->pid_tracker
.ht
) {
765 /* Create tracker. */
766 if (init_pid_tracker(&session
->pid_tracker
)) {
767 ERR("Error initializing PID tracker");
768 retval
= LTTNG_ERR_NOMEM
;
771 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
772 if (ret
!= LTTNG_OK
) {
774 fini_pid_tracker(&session
->pid_tracker
);
777 /* Remove all apps from session except pid. */
778 ust_app_global_update_all(session
);
782 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
783 if (ret
!= LTTNG_OK
) {
787 /* Add session to application */
788 app
= ust_app_find_by_pid(pid
);
790 ust_app_global_update(session
, app
);
799 * Called with the session lock held.
801 int trace_ust_untrack_pid(struct ltt_ust_session
*session
, int pid
)
803 int retval
= LTTNG_OK
;
806 /* Create empty tracker, replace old tracker. */
807 struct ust_pid_tracker tmp_tracker
;
809 tmp_tracker
= session
->pid_tracker
;
810 if (init_pid_tracker(&session
->pid_tracker
)) {
811 ERR("Error initializing PID tracker");
812 retval
= LTTNG_ERR_NOMEM
;
813 /* Rollback operation. */
814 session
->pid_tracker
= tmp_tracker
;
817 fini_pid_tracker(&tmp_tracker
);
819 /* Remove session from all applications */
820 ust_app_global_update_all(session
);
825 if (!session
->pid_tracker
.ht
) {
826 /* No PID being tracked. */
827 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
830 /* Remove PID from tracker */
831 ret
= pid_tracker_del_pid(&session
->pid_tracker
, pid
);
832 if (ret
!= LTTNG_OK
) {
836 /* Remove session from application. */
837 app
= ust_app_find_by_pid(pid
);
839 ust_app_global_update(session
, app
);
847 * Called with session lock held.
849 ssize_t
trace_ust_list_tracker_pids(struct ltt_ust_session
*session
,
852 struct ust_pid_tracker_node
*tracker_node
;
853 struct lttng_ht_iter iter
;
854 unsigned long count
, i
= 0;
859 if (!session
->pid_tracker
.ht
) {
860 /* Tracker disabled. Set first entry to -1. */
861 pids
= zmalloc(sizeof(*pids
));
872 cds_lfht_count_nodes(session
->pid_tracker
.ht
->ht
,
873 &approx
[0], &count
, &approx
[1]);
874 pids
= zmalloc(sizeof(*pids
) * count
);
879 cds_lfht_for_each_entry(session
->pid_tracker
.ht
->ht
,
880 &iter
.iter
, tracker_node
, node
.node
) {
881 pids
[i
++] = tracker_node
->node
.key
;
891 * RCU safe free context structure.
893 static void destroy_context_rcu(struct rcu_head
*head
)
895 struct lttng_ht_node_ulong
*node
=
896 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
897 struct ltt_ust_context
*ctx
=
898 caa_container_of(node
, struct ltt_ust_context
, node
);
904 * Cleanup UST context hash table.
906 static void destroy_contexts(struct lttng_ht
*ht
)
909 struct lttng_ht_node_ulong
*node
;
910 struct lttng_ht_iter iter
;
911 struct ltt_ust_context
*ctx
;
916 cds_lfht_for_each_entry(ht
->ht
, &iter
.iter
, node
, node
) {
917 /* Remove from ordered list. */
918 ctx
= caa_container_of(node
, struct ltt_ust_context
, node
);
919 cds_list_del(&ctx
->list
);
920 /* Remove from channel's hash table. */
921 ret
= lttng_ht_del(ht
, &iter
);
923 call_rcu(&node
->head
, destroy_context_rcu
);
932 * Cleanup ust event structure.
934 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
938 DBG2("Trace destroy UST event %s", event
->attr
.name
);
939 free(event
->filter_expression
);
941 free(event
->exclusion
);
946 * URCU intermediate call to complete destroy event.
948 static void destroy_event_rcu(struct rcu_head
*head
)
950 struct lttng_ht_node_str
*node
=
951 caa_container_of(head
, struct lttng_ht_node_str
, head
);
952 struct ltt_ust_event
*event
=
953 caa_container_of(node
, struct ltt_ust_event
, node
);
955 trace_ust_destroy_event(event
);
959 * Cleanup UST events hashtable.
961 static void destroy_events(struct lttng_ht
*events
)
964 struct lttng_ht_node_str
*node
;
965 struct lttng_ht_iter iter
;
970 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
971 ret
= lttng_ht_del(events
, &iter
);
973 call_rcu(&node
->head
, destroy_event_rcu
);
977 ht_cleanup_push(events
);
981 * Cleanup ust channel structure.
983 * Should _NOT_ be called with RCU read lock held.
985 static void _trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
989 DBG2("Trace destroy UST channel %s", channel
->name
);
995 * URCU intermediate call to complete destroy channel.
997 static void destroy_channel_rcu(struct rcu_head
*head
)
999 struct lttng_ht_node_str
*node
=
1000 caa_container_of(head
, struct lttng_ht_node_str
, head
);
1001 struct ltt_ust_channel
*channel
=
1002 caa_container_of(node
, struct ltt_ust_channel
, node
);
1004 _trace_ust_destroy_channel(channel
);
1007 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
1009 /* Destroying all events of the channel */
1010 destroy_events(channel
->events
);
1011 /* Destroying all context of the channel */
1012 destroy_contexts(channel
->ctx
);
1014 call_rcu(&channel
->node
.head
, destroy_channel_rcu
);
1018 * Remove an UST channel from a channel HT.
1020 void trace_ust_delete_channel(struct lttng_ht
*ht
,
1021 struct ltt_ust_channel
*channel
)
1024 struct lttng_ht_iter iter
;
1029 iter
.iter
.node
= &channel
->node
.node
;
1030 ret
= lttng_ht_del(ht
, &iter
);
1035 * Iterate over a hash table containing channels and cleanup safely.
1037 static void destroy_channels(struct lttng_ht
*channels
)
1039 struct lttng_ht_node_str
*node
;
1040 struct lttng_ht_iter iter
;
1045 cds_lfht_for_each_entry(channels
->ht
, &iter
.iter
, node
, node
) {
1046 struct ltt_ust_channel
*chan
=
1047 caa_container_of(node
, struct ltt_ust_channel
, node
);
1049 trace_ust_delete_channel(channels
, chan
);
1050 trace_ust_destroy_channel(chan
);
1054 ht_cleanup_push(channels
);
1058 * Cleanup UST global domain.
1060 static void destroy_domain_global(struct ltt_ust_domain_global
*dom
)
1064 destroy_channels(dom
->channels
);
1068 * Cleanup ust session structure
1070 * Should *NOT* be called with RCU read-side lock held.
1072 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
1075 struct buffer_reg_uid
*reg
, *sreg
;
1076 struct lttng_ht_iter iter
;
1080 DBG2("Trace UST destroy session %" PRIu64
, session
->id
);
1082 /* Cleaning up UST domain */
1083 destroy_domain_global(&session
->domain_global
);
1086 cds_lfht_for_each_entry(session
->agents
->ht
, &iter
.iter
, agt
, node
.node
) {
1087 int ret
= lttng_ht_del(session
->agents
, &iter
);
1094 ht_cleanup_push(session
->agents
);
1096 /* Cleanup UID buffer registry object(s). */
1097 cds_list_for_each_entry_safe(reg
, sreg
, &session
->buffer_reg_uid_list
,
1099 cds_list_del(®
->lnode
);
1100 buffer_reg_uid_remove(reg
);
1101 buffer_reg_uid_destroy(reg
, session
->consumer
);
1104 consumer_output_put(session
->consumer
);
1106 fini_pid_tracker(&session
->pid_tracker
);