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
) {
121 /* Check exclusion counts first. */
122 if (event
->exclusion
->count
!= key
->exclusion
->count
) {
126 /* Compare names individually. */
127 for (i
= 0; i
< event
->exclusion
->count
; ++i
) {
130 const char *name_ev
=
131 LTTNG_EVENT_EXCLUSION_NAME_AT(
132 event
->exclusion
, i
);
135 * Compare this exclusion name to all the key's
138 for (j
= 0; j
< key
->exclusion
->count
; ++j
) {
139 const char *name_key
=
140 LTTNG_EVENT_EXCLUSION_NAME_AT(
143 if (!strncmp(name_ev
, name_key
,
144 LTTNG_SYMBOL_NAME_LEN
)) {
152 * If the current exclusion name was not found amongst
153 * the key's exclusion names, then there's no match.
168 * Find the channel in the hashtable and return channel pointer. RCU read side
169 * lock MUST be acquired before calling this.
171 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
174 struct lttng_ht_node_str
*node
;
175 struct lttng_ht_iter iter
;
178 * If we receive an empty string for channel name, it means the
179 * default channel name is requested.
182 name
= DEFAULT_CHANNEL_NAME
;
184 lttng_ht_lookup(ht
, (void *)name
, &iter
);
185 node
= lttng_ht_iter_get_node_str(&iter
);
190 DBG2("Trace UST channel %s found by name", name
);
192 return caa_container_of(node
, struct ltt_ust_channel
, node
);
195 DBG2("Trace UST channel %s not found by name", name
);
200 * Find the event in the hashtable and return event pointer. RCU read side lock
201 * MUST be acquired before calling this.
203 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
204 char *name
, struct lttng_filter_bytecode
*filter
,
205 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
206 struct lttng_event_exclusion
*exclusion
)
208 struct lttng_ht_node_str
*node
;
209 struct lttng_ht_iter iter
;
210 struct ltt_ust_ht_key key
;
217 key
.loglevel_type
= loglevel_type
;
218 key
.loglevel_value
= loglevel_value
;
219 key
.exclusion
= exclusion
;
221 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
222 trace_ust_ht_match_event
, &key
, &iter
.iter
);
223 node
= lttng_ht_iter_get_node_str(&iter
);
228 DBG2("Trace UST event %s found", key
.name
);
230 return caa_container_of(node
, struct ltt_ust_event
, node
);
233 DBG2("Trace UST event %s NOT found", key
.name
);
238 * Lookup an agent in the session agents hash table by domain type and return
239 * the object if found else NULL.
241 * RCU read side lock must be acquired before calling and only released
242 * once the agent is no longer in scope or being used.
244 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
245 enum lttng_domain_type domain_type
)
247 struct agent
*agt
= NULL
;
248 struct lttng_ht_node_u64
*node
;
249 struct lttng_ht_iter iter
;
254 DBG3("Trace ust agent lookup for domain %d", domain_type
);
258 lttng_ht_lookup(session
->agents
, &key
, &iter
);
259 node
= lttng_ht_iter_get_node_u64(&iter
);
263 agt
= caa_container_of(node
, struct agent
, node
);
270 * Allocate and initialize a ust session data structure.
272 * Return pointer to structure or NULL.
274 struct ltt_ust_session
*trace_ust_create_session(uint64_t session_id
)
276 struct ltt_ust_session
*lus
;
278 /* Allocate a new ltt ust session */
279 lus
= zmalloc(sizeof(struct ltt_ust_session
));
281 PERROR("create ust session zmalloc");
285 /* Init data structure */
286 lus
->id
= session_id
;
289 /* Set default metadata channel attribute. */
290 lus
->metadata_attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
291 lus
->metadata_attr
.subbuf_size
= default_get_metadata_subbuf_size();
292 lus
->metadata_attr
.num_subbuf
= DEFAULT_METADATA_SUBBUF_NUM
;
293 lus
->metadata_attr
.switch_timer_interval
= DEFAULT_METADATA_SWITCH_TIMER
;
294 lus
->metadata_attr
.read_timer_interval
= DEFAULT_METADATA_READ_TIMER
;
295 lus
->metadata_attr
.output
= LTTNG_UST_MMAP
;
298 * Default buffer type. This can be changed through an enable channel
299 * requesting a different type. Note that this can only be changed once
300 * during the session lifetime which is at the first enable channel and
301 * only before start. The flag buffer_type_changed indicates the status.
303 lus
->buffer_type
= LTTNG_BUFFER_PER_UID
;
304 /* Once set to 1, the buffer_type is immutable for the session. */
305 lus
->buffer_type_changed
= 0;
306 /* Init it in case it get used after allocation. */
307 CDS_INIT_LIST_HEAD(&lus
->buffer_reg_uid_list
);
309 /* Alloc UST global domain channels' HT */
310 lus
->domain_global
.channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
311 /* Alloc agent hash table. */
312 lus
->agents
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
314 lus
->consumer
= consumer_create_output(CONSUMER_DST_LOCAL
);
315 if (lus
->consumer
== NULL
) {
319 DBG2("UST trace session create successful");
324 ht_cleanup_push(lus
->domain_global
.channels
);
325 ht_cleanup_push(lus
->agents
);
332 * Allocate and initialize a ust channel data structure.
334 * Return pointer to structure or NULL.
336 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*chan
,
337 enum lttng_domain_type domain
)
339 struct ltt_ust_channel
*luc
;
343 luc
= zmalloc(sizeof(struct ltt_ust_channel
));
345 PERROR("ltt_ust_channel zmalloc");
349 luc
->domain
= domain
;
351 /* Copy UST channel attributes */
352 luc
->attr
.overwrite
= chan
->attr
.overwrite
;
353 luc
->attr
.subbuf_size
= chan
->attr
.subbuf_size
;
354 luc
->attr
.num_subbuf
= chan
->attr
.num_subbuf
;
355 luc
->attr
.switch_timer_interval
= chan
->attr
.switch_timer_interval
;
356 luc
->attr
.read_timer_interval
= chan
->attr
.read_timer_interval
;
357 luc
->attr
.output
= (enum lttng_ust_output
) chan
->attr
.output
;
359 /* Translate to UST output enum */
360 switch (luc
->attr
.output
) {
362 luc
->attr
.output
= LTTNG_UST_MMAP
;
367 * If we receive an empty string for channel name, it means the
368 * default channel name is requested.
370 if (chan
->name
[0] == '\0') {
371 strncpy(luc
->name
, DEFAULT_CHANNEL_NAME
, sizeof(luc
->name
));
373 /* Copy channel name */
374 strncpy(luc
->name
, chan
->name
, sizeof(luc
->name
));
376 luc
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
379 lttng_ht_node_init_str(&luc
->node
, luc
->name
);
380 CDS_INIT_LIST_HEAD(&luc
->ctx_list
);
382 /* Alloc hash tables */
383 luc
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
384 luc
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
386 /* On-disk circular buffer parameters */
387 luc
->tracefile_size
= chan
->attr
.tracefile_size
;
388 luc
->tracefile_count
= chan
->attr
.tracefile_count
;
390 DBG2("Trace UST channel %s created", luc
->name
);
397 * Validates an exclusion list.
399 * Returns 0 if valid, negative value if invalid.
401 static int validate_exclusion(struct lttng_event_exclusion
*exclusion
)
408 for (i
= 0; i
< exclusion
->count
; ++i
) {
411 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, i
);
413 for (j
= 0; j
< i
; ++j
) {
415 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, j
);
417 if (!strncmp(name_a
, name_b
, LTTNG_SYMBOL_NAME_LEN
)) {
430 * Allocate and initialize a ust event. Set name and event type.
431 * We own filter_expression, filter, and exclusion.
433 * Return pointer to structure or NULL.
435 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
,
436 char *filter_expression
,
437 struct lttng_filter_bytecode
*filter
,
438 struct lttng_event_exclusion
*exclusion
,
441 struct ltt_ust_event
*lue
;
445 if (exclusion
&& validate_exclusion(exclusion
)) {
449 lue
= zmalloc(sizeof(struct ltt_ust_event
));
451 PERROR("ust event zmalloc");
455 lue
->internal
= internal_event
;
458 case LTTNG_EVENT_PROBE
:
459 lue
->attr
.instrumentation
= LTTNG_UST_PROBE
;
461 case LTTNG_EVENT_FUNCTION
:
462 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
464 case LTTNG_EVENT_FUNCTION_ENTRY
:
465 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
467 case LTTNG_EVENT_TRACEPOINT
:
468 lue
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
471 ERR("Unknown ust instrumentation type (%d)", ev
->type
);
472 goto error_free_event
;
475 /* Copy event name */
476 strncpy(lue
->attr
.name
, ev
->name
, LTTNG_UST_SYM_NAME_LEN
);
477 lue
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
479 switch (ev
->loglevel_type
) {
480 case LTTNG_EVENT_LOGLEVEL_ALL
:
481 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
482 lue
->attr
.loglevel
= -1; /* Force to -1 */
484 case LTTNG_EVENT_LOGLEVEL_RANGE
:
485 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
486 lue
->attr
.loglevel
= ev
->loglevel
;
488 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
489 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
490 lue
->attr
.loglevel
= ev
->loglevel
;
493 ERR("Unknown ust loglevel type (%d)", ev
->loglevel_type
);
494 goto error_free_event
;
498 lue
->filter_expression
= filter_expression
;
499 lue
->filter
= filter
;
500 lue
->exclusion
= exclusion
;
503 lttng_ht_node_init_str(&lue
->node
, lue
->attr
.name
);
505 DBG2("Trace UST event %s, loglevel (%d,%d) created",
506 lue
->attr
.name
, lue
->attr
.loglevel_type
,
514 free(filter_expression
);
521 int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type
)
526 case LTTNG_EVENT_CONTEXT_VTID
:
527 utype
= LTTNG_UST_CONTEXT_VTID
;
529 case LTTNG_EVENT_CONTEXT_VPID
:
530 utype
= LTTNG_UST_CONTEXT_VPID
;
532 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
533 utype
= LTTNG_UST_CONTEXT_PTHREAD_ID
;
535 case LTTNG_EVENT_CONTEXT_PROCNAME
:
536 utype
= LTTNG_UST_CONTEXT_PROCNAME
;
538 case LTTNG_EVENT_CONTEXT_IP
:
539 utype
= LTTNG_UST_CONTEXT_IP
;
541 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
542 if (!ustctl_has_perf_counters()) {
544 WARN("Perf counters not implemented in UST");
546 utype
= LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
;
557 * Return 1 if contexts match, 0 otherwise.
559 int trace_ust_match_context(struct ltt_ust_context
*uctx
,
560 struct lttng_event_context
*ctx
)
564 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
568 if (uctx
->ctx
.ctx
!= utype
) {
572 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
573 if (uctx
->ctx
.u
.perf_counter
.type
574 != ctx
->u
.perf_counter
.type
) {
577 if (uctx
->ctx
.u
.perf_counter
.config
578 != ctx
->u
.perf_counter
.config
) {
581 if (strncmp(uctx
->ctx
.u
.perf_counter
.name
,
582 ctx
->u
.perf_counter
.name
,
583 LTTNG_UST_SYM_NAME_LEN
)) {
595 * Allocate and initialize an UST context.
597 * Return pointer to structure or NULL.
599 struct ltt_ust_context
*trace_ust_create_context(
600 struct lttng_event_context
*ctx
)
602 struct ltt_ust_context
*uctx
;
607 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
609 ERR("Invalid UST context");
613 uctx
= zmalloc(sizeof(struct ltt_ust_context
));
615 PERROR("zmalloc ltt_ust_context");
619 uctx
->ctx
.ctx
= (enum lttng_ust_context_type
) utype
;
621 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
622 uctx
->ctx
.u
.perf_counter
.type
= ctx
->u
.perf_counter
.type
;
623 uctx
->ctx
.u
.perf_counter
.config
= ctx
->u
.perf_counter
.config
;
624 strncpy(uctx
->ctx
.u
.perf_counter
.name
, ctx
->u
.perf_counter
.name
,
625 LTTNG_UST_SYM_NAME_LEN
);
626 uctx
->ctx
.u
.perf_counter
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
631 lttng_ht_node_init_ulong(&uctx
->node
, (unsigned long) uctx
->ctx
.ctx
);
640 void destroy_pid_tracker_node_rcu(struct rcu_head
*head
)
642 struct ust_pid_tracker_node
*tracker_node
=
643 caa_container_of(head
, struct ust_pid_tracker_node
, node
.head
);
648 void destroy_pid_tracker_node(struct ust_pid_tracker_node
*tracker_node
)
651 call_rcu(&tracker_node
->node
.head
, destroy_pid_tracker_node_rcu
);
655 int init_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
659 pid_tracker
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
660 if (!pid_tracker
->ht
) {
670 * Teardown pid tracker content, but don't free pid_tracker object.
673 void fini_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
675 struct ust_pid_tracker_node
*tracker_node
;
676 struct lttng_ht_iter iter
;
678 if (!pid_tracker
->ht
) {
682 cds_lfht_for_each_entry(pid_tracker
->ht
->ht
,
683 &iter
.iter
, tracker_node
, node
.node
) {
684 int ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
687 destroy_pid_tracker_node(tracker_node
);
690 ht_cleanup_push(pid_tracker
->ht
);
691 pid_tracker
->ht
= NULL
;
695 struct ust_pid_tracker_node
*pid_tracker_lookup(
696 struct ust_pid_tracker
*pid_tracker
, int pid
,
697 struct lttng_ht_iter
*iter
)
699 unsigned long _pid
= (unsigned long) pid
;
700 struct lttng_ht_node_ulong
*node
;
702 lttng_ht_lookup(pid_tracker
->ht
, (void *) _pid
, iter
);
703 node
= lttng_ht_iter_get_node_ulong(iter
);
705 return caa_container_of(node
, struct ust_pid_tracker_node
,
713 int pid_tracker_add_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
715 int retval
= LTTNG_OK
;
716 struct ust_pid_tracker_node
*tracker_node
;
717 struct lttng_ht_iter iter
;
720 retval
= LTTNG_ERR_INVALID
;
723 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
725 /* Already exists. */
726 retval
= LTTNG_ERR_PID_TRACKED
;
729 tracker_node
= zmalloc(sizeof(*tracker_node
));
731 retval
= LTTNG_ERR_NOMEM
;
734 lttng_ht_node_init_ulong(&tracker_node
->node
, (unsigned long) pid
);
735 lttng_ht_add_unique_ulong(pid_tracker
->ht
, &tracker_node
->node
);
741 int pid_tracker_del_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
743 int retval
= LTTNG_OK
, ret
;
744 struct ust_pid_tracker_node
*tracker_node
;
745 struct lttng_ht_iter iter
;
748 retval
= LTTNG_ERR_INVALID
;
751 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
754 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
757 ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
760 destroy_pid_tracker_node(tracker_node
);
766 * The session lock is held when calling this function.
768 int trace_ust_pid_tracker_lookup(struct ltt_ust_session
*session
, int pid
)
770 struct lttng_ht_iter iter
;
772 if (!session
->pid_tracker
.ht
) {
775 if (pid_tracker_lookup(&session
->pid_tracker
, pid
, &iter
)) {
782 * Called with the session lock held.
784 int trace_ust_track_pid(struct ltt_ust_session
*session
, int pid
)
786 int retval
= LTTNG_OK
;
789 /* Track all pids: destroy tracker if exists. */
790 if (session
->pid_tracker
.ht
) {
791 fini_pid_tracker(&session
->pid_tracker
);
792 /* Ensure all apps have session. */
793 ust_app_global_update_all(session
);
798 if (!session
->pid_tracker
.ht
) {
799 /* Create tracker. */
800 if (init_pid_tracker(&session
->pid_tracker
)) {
801 ERR("Error initializing PID tracker");
802 retval
= LTTNG_ERR_NOMEM
;
805 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
806 if (ret
!= LTTNG_OK
) {
808 fini_pid_tracker(&session
->pid_tracker
);
811 /* Remove all apps from session except pid. */
812 ust_app_global_update_all(session
);
816 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
817 if (ret
!= LTTNG_OK
) {
821 /* Add session to application */
822 app
= ust_app_find_by_pid(pid
);
824 ust_app_global_update(session
, app
);
833 * Called with the session lock held.
835 int trace_ust_untrack_pid(struct ltt_ust_session
*session
, int pid
)
837 int retval
= LTTNG_OK
;
840 /* Create empty tracker, replace old tracker. */
841 struct ust_pid_tracker tmp_tracker
;
843 tmp_tracker
= session
->pid_tracker
;
844 if (init_pid_tracker(&session
->pid_tracker
)) {
845 ERR("Error initializing PID tracker");
846 retval
= LTTNG_ERR_NOMEM
;
847 /* Rollback operation. */
848 session
->pid_tracker
= tmp_tracker
;
851 fini_pid_tracker(&tmp_tracker
);
853 /* Remove session from all applications */
854 ust_app_global_update_all(session
);
859 if (!session
->pid_tracker
.ht
) {
860 /* No PID being tracked. */
861 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
864 /* Remove PID from tracker */
865 ret
= pid_tracker_del_pid(&session
->pid_tracker
, pid
);
866 if (ret
!= LTTNG_OK
) {
870 /* Remove session from application. */
871 app
= ust_app_find_by_pid(pid
);
873 ust_app_global_update(session
, app
);
881 * Called with session lock held.
883 ssize_t
trace_ust_list_tracker_pids(struct ltt_ust_session
*session
,
886 struct ust_pid_tracker_node
*tracker_node
;
887 struct lttng_ht_iter iter
;
888 unsigned long count
, i
= 0;
893 if (!session
->pid_tracker
.ht
) {
894 /* Tracker disabled. Set first entry to -1. */
895 pids
= zmalloc(sizeof(*pids
));
906 cds_lfht_count_nodes(session
->pid_tracker
.ht
->ht
,
907 &approx
[0], &count
, &approx
[1]);
908 pids
= zmalloc(sizeof(*pids
) * count
);
913 cds_lfht_for_each_entry(session
->pid_tracker
.ht
->ht
,
914 &iter
.iter
, tracker_node
, node
.node
) {
915 pids
[i
++] = tracker_node
->node
.key
;
925 * RCU safe free context structure.
927 static void destroy_context_rcu(struct rcu_head
*head
)
929 struct lttng_ht_node_ulong
*node
=
930 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
931 struct ltt_ust_context
*ctx
=
932 caa_container_of(node
, struct ltt_ust_context
, node
);
938 * Cleanup UST context hash table.
940 static void destroy_contexts(struct lttng_ht
*ht
)
943 struct lttng_ht_node_ulong
*node
;
944 struct lttng_ht_iter iter
;
945 struct ltt_ust_context
*ctx
;
950 cds_lfht_for_each_entry(ht
->ht
, &iter
.iter
, node
, node
) {
951 /* Remove from ordered list. */
952 ctx
= caa_container_of(node
, struct ltt_ust_context
, node
);
953 cds_list_del(&ctx
->list
);
954 /* Remove from channel's hash table. */
955 ret
= lttng_ht_del(ht
, &iter
);
957 call_rcu(&node
->head
, destroy_context_rcu
);
966 * Cleanup ust event structure.
968 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
972 DBG2("Trace destroy UST event %s", event
->attr
.name
);
973 free(event
->filter_expression
);
975 free(event
->exclusion
);
980 * URCU intermediate call to complete destroy event.
982 static void destroy_event_rcu(struct rcu_head
*head
)
984 struct lttng_ht_node_str
*node
=
985 caa_container_of(head
, struct lttng_ht_node_str
, head
);
986 struct ltt_ust_event
*event
=
987 caa_container_of(node
, struct ltt_ust_event
, node
);
989 trace_ust_destroy_event(event
);
993 * Cleanup UST events hashtable.
995 static void destroy_events(struct lttng_ht
*events
)
998 struct lttng_ht_node_str
*node
;
999 struct lttng_ht_iter iter
;
1004 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
1005 ret
= lttng_ht_del(events
, &iter
);
1007 call_rcu(&node
->head
, destroy_event_rcu
);
1011 ht_cleanup_push(events
);
1015 * Cleanup ust channel structure.
1017 * Should _NOT_ be called with RCU read lock held.
1019 static void _trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
1023 DBG2("Trace destroy UST channel %s", channel
->name
);
1029 * URCU intermediate call to complete destroy channel.
1031 static void destroy_channel_rcu(struct rcu_head
*head
)
1033 struct lttng_ht_node_str
*node
=
1034 caa_container_of(head
, struct lttng_ht_node_str
, head
);
1035 struct ltt_ust_channel
*channel
=
1036 caa_container_of(node
, struct ltt_ust_channel
, node
);
1038 _trace_ust_destroy_channel(channel
);
1041 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
1043 /* Destroying all events of the channel */
1044 destroy_events(channel
->events
);
1045 /* Destroying all context of the channel */
1046 destroy_contexts(channel
->ctx
);
1048 call_rcu(&channel
->node
.head
, destroy_channel_rcu
);
1052 * Remove an UST channel from a channel HT.
1054 void trace_ust_delete_channel(struct lttng_ht
*ht
,
1055 struct ltt_ust_channel
*channel
)
1058 struct lttng_ht_iter iter
;
1063 iter
.iter
.node
= &channel
->node
.node
;
1064 ret
= lttng_ht_del(ht
, &iter
);
1069 * Iterate over a hash table containing channels and cleanup safely.
1071 static void destroy_channels(struct lttng_ht
*channels
)
1073 struct lttng_ht_node_str
*node
;
1074 struct lttng_ht_iter iter
;
1079 cds_lfht_for_each_entry(channels
->ht
, &iter
.iter
, node
, node
) {
1080 struct ltt_ust_channel
*chan
=
1081 caa_container_of(node
, struct ltt_ust_channel
, node
);
1083 trace_ust_delete_channel(channels
, chan
);
1084 trace_ust_destroy_channel(chan
);
1088 ht_cleanup_push(channels
);
1092 * Cleanup UST global domain.
1094 static void destroy_domain_global(struct ltt_ust_domain_global
*dom
)
1098 destroy_channels(dom
->channels
);
1102 * Cleanup ust session structure
1104 * Should *NOT* be called with RCU read-side lock held.
1106 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
1109 struct buffer_reg_uid
*reg
, *sreg
;
1110 struct lttng_ht_iter iter
;
1114 DBG2("Trace UST destroy session %" PRIu64
, session
->id
);
1116 /* Cleaning up UST domain */
1117 destroy_domain_global(&session
->domain_global
);
1120 cds_lfht_for_each_entry(session
->agents
->ht
, &iter
.iter
, agt
, node
.node
) {
1121 int ret
= lttng_ht_del(session
->agents
, &iter
);
1128 ht_cleanup_push(session
->agents
);
1130 /* Cleanup UID buffer registry object(s). */
1131 cds_list_for_each_entry_safe(reg
, sreg
, &session
->buffer_reg_uid_list
,
1133 cds_list_del(®
->lnode
);
1134 buffer_reg_uid_remove(reg
);
1135 buffer_reg_uid_destroy(reg
, session
->consumer
);
1138 consumer_output_put(session
->consumer
);
1140 fini_pid_tracker(&session
->pid_tracker
);