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 <sys/types.h>
27 #include <urcu/compiler.h>
28 #include <lttng/ust-error.h>
30 #include <common/common.h>
31 #include <common/sessiond-comm/sessiond-comm.h>
36 #include "ust-consumer.h"
40 * Match function for the hash table lookup.
42 * It matches an ust app event based on three attributes which are the event
43 * name, the filter bytecode and the loglevel.
45 static int ht_match_ust_app_event(struct cds_lfht_node
*node
, const void *_key
)
47 struct ust_app_event
*event
;
48 const struct ust_app_ht_key
*key
;
53 event
= caa_container_of(node
, struct ust_app_event
, node
.node
);
56 /* Match the 3 elements of the key: name, filter and loglevel. */
59 if (strncmp(event
->attr
.name
, key
->name
, sizeof(event
->attr
.name
)) != 0) {
64 if (event
->attr
.loglevel
!= key
->loglevel
) {
65 if (event
->attr
.loglevel_type
== LTTNG_UST_LOGLEVEL_ALL
66 && key
->loglevel
== 0 && event
->attr
.loglevel
== -1) {
68 * Match is accepted. This is because on event creation, the
69 * loglevel is set to -1 if the event loglevel type is ALL so 0 and
70 * -1 are accepted for this loglevel type since 0 is the one set by
71 * the API when receiving an enable event.
78 /* One of the filters is NULL, fail. */
79 if ((key
->filter
&& !event
->filter
) || (!key
->filter
&& event
->filter
)) {
83 if (key
->filter
&& event
->filter
) {
84 /* Both filters exists, check length followed by the bytecode. */
85 if (event
->filter
->len
!= key
->filter
->len
||
86 memcmp(event
->filter
->data
, key
->filter
->data
,
87 event
->filter
->len
) != 0) {
100 * Unique add of an ust app event in the given ht. This uses the custom
101 * ht_match_ust_app_event match function and the event name as hash.
103 static void add_unique_ust_app_event(struct lttng_ht
*ht
,
104 struct ust_app_event
*event
)
106 struct cds_lfht_node
*node_ptr
;
107 struct ust_app_ht_key key
;
113 key
.name
= event
->attr
.name
;
114 key
.filter
= event
->filter
;
115 key
.loglevel
= event
->attr
.loglevel
;
117 node_ptr
= cds_lfht_add_unique(ht
->ht
,
118 ht
->hash_fct(event
->node
.key
, lttng_ht_seed
),
119 ht_match_ust_app_event
, &key
, &event
->node
.node
);
120 assert(node_ptr
== &event
->node
.node
);
124 * Delete ust context safely. RCU read lock must be held before calling
128 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
)
131 ustctl_release_object(sock
, ua_ctx
->obj
);
138 * Delete ust app event safely. RCU read lock must be held before calling
142 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
144 free(ua_event
->filter
);
146 if (ua_event
->obj
!= NULL
) {
147 ustctl_release_object(sock
, ua_event
->obj
);
154 * Delete ust app stream safely. RCU read lock must be held before calling
158 void delete_ust_app_stream(int sock
, struct ltt_ust_stream
*stream
)
161 ustctl_release_object(sock
, stream
->obj
);
162 lttng_fd_put(LTTNG_FD_APPS
, 2);
169 * Delete ust app channel safely. RCU read lock must be held before calling
173 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
)
176 struct lttng_ht_iter iter
;
177 struct ust_app_event
*ua_event
;
178 struct ust_app_ctx
*ua_ctx
;
179 struct ltt_ust_stream
*stream
, *stmp
;
182 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
183 cds_list_del(&stream
->list
);
184 delete_ust_app_stream(sock
, stream
);
188 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
189 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
191 delete_ust_app_ctx(sock
, ua_ctx
);
193 lttng_ht_destroy(ua_chan
->ctx
);
196 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
198 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
200 delete_ust_app_event(sock
, ua_event
);
202 lttng_ht_destroy(ua_chan
->events
);
204 if (ua_chan
->obj
!= NULL
) {
205 ustctl_release_object(sock
, ua_chan
->obj
);
206 lttng_fd_put(LTTNG_FD_APPS
, 2);
213 * Delete ust app session safely. RCU read lock must be held before calling
217 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
)
220 struct lttng_ht_iter iter
;
221 struct ust_app_channel
*ua_chan
;
223 if (ua_sess
->metadata
) {
224 if (ua_sess
->metadata
->stream_obj
) {
225 ustctl_release_object(sock
, ua_sess
->metadata
->stream_obj
);
226 lttng_fd_put(LTTNG_FD_APPS
, 2);
227 free(ua_sess
->metadata
->stream_obj
);
229 if (ua_sess
->metadata
->obj
) {
230 ustctl_release_object(sock
, ua_sess
->metadata
->obj
);
231 lttng_fd_put(LTTNG_FD_APPS
, 2);
232 free(ua_sess
->metadata
->obj
);
234 trace_ust_destroy_metadata(ua_sess
->metadata
);
237 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
239 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
241 delete_ust_app_channel(sock
, ua_chan
);
243 lttng_ht_destroy(ua_sess
->channels
);
245 if (ua_sess
->handle
!= -1) {
246 ustctl_release_handle(sock
, ua_sess
->handle
);
252 * Delete a traceable application structure from the global list. Never call
253 * this function outside of a call_rcu call.
256 void delete_ust_app(struct ust_app
*app
)
259 struct lttng_ht_iter iter
;
260 struct ust_app_session
*ua_sess
;
264 /* Delete ust app sessions info */
269 cds_lfht_for_each_entry(app
->sessions
->ht
, &iter
.iter
, ua_sess
,
271 ret
= lttng_ht_del(app
->sessions
, &iter
);
273 delete_ust_app_session(app
->sock
, ua_sess
);
275 lttng_ht_destroy(app
->sessions
);
278 * Wait until we have deleted the application from the sock hash table
279 * before closing this socket, otherwise an application could re-use the
280 * socket ID and race with the teardown, using the same hash table entry.
282 * It's OK to leave the close in call_rcu. We want it to stay unique for
283 * all RCU readers that could run concurrently with unregister app,
284 * therefore we _need_ to only close that socket after a grace period. So
285 * it should stay in this RCU callback.
287 * This close() is a very important step of the synchronization model so
288 * every modification to this function must be carefully reviewed.
294 lttng_fd_put(LTTNG_FD_APPS
, 1);
296 DBG2("UST app pid %d deleted", app
->pid
);
303 * URCU intermediate call to delete an UST app.
306 void delete_ust_app_rcu(struct rcu_head
*head
)
308 struct lttng_ht_node_ulong
*node
=
309 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
310 struct ust_app
*app
=
311 caa_container_of(node
, struct ust_app
, pid_n
);
313 DBG3("Call RCU deleting app PID %d", app
->pid
);
318 * Alloc new UST app session.
321 struct ust_app_session
*alloc_ust_app_session(void)
323 struct ust_app_session
*ua_sess
;
325 /* Init most of the default value by allocating and zeroing */
326 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
327 if (ua_sess
== NULL
) {
332 ua_sess
->handle
= -1;
333 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
342 * Alloc new UST app channel.
345 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
346 struct lttng_ust_channel
*attr
)
348 struct ust_app_channel
*ua_chan
;
350 /* Init most of the default value by allocating and zeroing */
351 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
352 if (ua_chan
== NULL
) {
357 /* Setup channel name */
358 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
359 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
361 ua_chan
->enabled
= 1;
362 ua_chan
->handle
= -1;
363 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
364 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
365 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
367 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
369 /* Copy attributes */
371 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
374 DBG3("UST app channel %s allocated", ua_chan
->name
);
383 * Alloc new UST app event.
386 struct ust_app_event
*alloc_ust_app_event(char *name
,
387 struct lttng_ust_event
*attr
)
389 struct ust_app_event
*ua_event
;
391 /* Init most of the default value by allocating and zeroing */
392 ua_event
= zmalloc(sizeof(struct ust_app_event
));
393 if (ua_event
== NULL
) {
398 ua_event
->enabled
= 1;
399 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
400 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
401 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
403 /* Copy attributes */
405 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
408 DBG3("UST app event %s allocated", ua_event
->name
);
417 * Alloc new UST app context.
420 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
422 struct ust_app_ctx
*ua_ctx
;
424 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
425 if (ua_ctx
== NULL
) {
430 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
433 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
440 * Allocate a filter and copy the given original filter.
442 * Return allocated filter or NULL on error.
444 static struct lttng_ust_filter_bytecode
*alloc_copy_ust_app_filter(
445 struct lttng_ust_filter_bytecode
*orig_f
)
447 struct lttng_ust_filter_bytecode
*filter
= NULL
;
449 /* Copy filter bytecode */
450 filter
= zmalloc(sizeof(*filter
) + orig_f
->len
);
452 PERROR("zmalloc alloc ust app filter");
456 memcpy(filter
, orig_f
, sizeof(*filter
) + orig_f
->len
);
463 * Find an ust_app using the sock and return it. RCU read side lock must be
464 * held before calling this helper function.
467 struct ust_app
*find_app_by_sock(int sock
)
469 struct lttng_ht_node_ulong
*node
;
470 struct lttng_ht_iter iter
;
472 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
473 node
= lttng_ht_iter_get_node_ulong(&iter
);
475 DBG2("UST app find by sock %d not found", sock
);
479 return caa_container_of(node
, struct ust_app
, sock_n
);
486 * Lookup for an ust app event based on event name, filter bytecode and the
489 * Return an ust_app_event object or NULL on error.
491 static struct ust_app_event
*find_ust_app_event(struct lttng_ht
*ht
,
492 char *name
, struct lttng_ust_filter_bytecode
*filter
, int loglevel
)
494 struct lttng_ht_iter iter
;
495 struct lttng_ht_node_str
*node
;
496 struct ust_app_event
*event
= NULL
;
497 struct ust_app_ht_key key
;
502 /* Setup key for event lookup. */
505 key
.loglevel
= loglevel
;
507 /* Lookup using the event name as hash and a custom match fct. */
508 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
509 ht_match_ust_app_event
, &key
, &iter
.iter
);
510 node
= lttng_ht_iter_get_node_str(&iter
);
515 event
= caa_container_of(node
, struct ust_app_event
, node
);
522 * Create the channel context on the tracer.
525 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
526 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
530 health_code_update(&health_thread_cmd
);
532 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
533 ua_chan
->obj
, &ua_ctx
->obj
);
538 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
540 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
543 health_code_update(&health_thread_cmd
);
548 * Set the filter on the tracer.
551 int set_ust_event_filter(struct ust_app_event
*ua_event
,
556 health_code_update(&health_thread_cmd
);
558 if (!ua_event
->filter
) {
563 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
569 DBG2("UST filter set successfully for event %s", ua_event
->name
);
572 health_code_update(&health_thread_cmd
);
577 * Disable the specified event on to UST tracer for the UST session.
579 static int disable_ust_event(struct ust_app
*app
,
580 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
584 health_code_update(&health_thread_cmd
);
586 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
588 ERR("UST app event %s disable failed for app (pid: %d) "
589 "and session handle %d with ret %d",
590 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
594 DBG2("UST app event %s disabled successfully for app (pid: %d)",
595 ua_event
->attr
.name
, app
->pid
);
598 health_code_update(&health_thread_cmd
);
603 * Disable the specified channel on to UST tracer for the UST session.
605 static int disable_ust_channel(struct ust_app
*app
,
606 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
610 health_code_update(&health_thread_cmd
);
612 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
614 ERR("UST app channel %s disable failed for app (pid: %d) "
615 "and session handle %d with ret %d",
616 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
620 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
621 ua_chan
->name
, app
->pid
);
624 health_code_update(&health_thread_cmd
);
629 * Enable the specified channel on to UST tracer for the UST session.
631 static int enable_ust_channel(struct ust_app
*app
,
632 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
636 health_code_update(&health_thread_cmd
);
638 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
640 ERR("UST app channel %s enable failed for app (pid: %d) "
641 "and session handle %d with ret %d",
642 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
646 ua_chan
->enabled
= 1;
648 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
649 ua_chan
->name
, app
->pid
);
652 health_code_update(&health_thread_cmd
);
657 * Enable the specified event on to UST tracer for the UST session.
659 static int enable_ust_event(struct ust_app
*app
,
660 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
664 health_code_update(&health_thread_cmd
);
666 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
668 ERR("UST app event %s enable failed for app (pid: %d) "
669 "and session handle %d with ret %d",
670 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
674 DBG2("UST app event %s enabled successfully for app (pid: %d)",
675 ua_event
->attr
.name
, app
->pid
);
678 health_code_update(&health_thread_cmd
);
683 * Open metadata onto the UST tracer for a UST session.
685 static int open_ust_metadata(struct ust_app
*app
,
686 struct ust_app_session
*ua_sess
)
689 struct lttng_ust_channel_attr uattr
;
691 health_code_update(&health_thread_cmd
);
693 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
694 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
695 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
696 uattr
.switch_timer_interval
=
697 ua_sess
->metadata
->attr
.switch_timer_interval
;
698 uattr
.read_timer_interval
=
699 ua_sess
->metadata
->attr
.read_timer_interval
;
700 uattr
.output
= ua_sess
->metadata
->attr
.output
;
702 /* We are going to receive 2 fds, we need to reserve them. */
703 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
705 ERR("Exhausted number of available FD upon metadata open");
708 /* UST tracer metadata creation */
709 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
710 &ua_sess
->metadata
->obj
);
712 ERR("UST app open metadata failed for app pid:%d with ret %d",
717 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
720 health_code_update(&health_thread_cmd
);
725 * Create stream onto the UST tracer for a UST session.
727 static int create_ust_stream(struct ust_app
*app
,
728 struct ust_app_session
*ua_sess
)
732 health_code_update(&health_thread_cmd
);
734 /* We are going to receive 2 fds, we need to reserve them. */
735 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
737 ERR("Exhausted number of available FD upon metadata stream create");
740 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
741 &ua_sess
->metadata
->stream_obj
);
743 ERR("UST create metadata stream failed");
748 health_code_update(&health_thread_cmd
);
753 * Create the specified channel onto the UST tracer for a UST session.
755 static int create_ust_channel(struct ust_app
*app
,
756 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
760 health_code_update(&health_thread_cmd
);
762 /* TODO: remove cast and use lttng-ust-abi.h */
764 /* We are going to receive 2 fds, we need to reserve them. */
765 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
767 ERR("Exhausted number of available FD upon create channel");
771 health_code_update(&health_thread_cmd
);
773 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
774 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
776 ERR("Creating channel %s for app (pid: %d, sock: %d) "
777 "and session handle %d with ret %d",
778 ua_chan
->name
, app
->pid
, app
->sock
,
779 ua_sess
->handle
, ret
);
780 lttng_fd_put(LTTNG_FD_APPS
, 2);
784 ua_chan
->handle
= ua_chan
->obj
->handle
;
786 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
787 ua_chan
->name
, app
->pid
, app
->sock
);
789 health_code_update(&health_thread_cmd
);
791 /* If channel is not enabled, disable it on the tracer */
792 if (!ua_chan
->enabled
) {
793 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
800 health_code_update(&health_thread_cmd
);
805 * Create the specified event onto the UST tracer for a UST session.
808 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
809 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
813 health_code_update(&health_thread_cmd
);
815 /* Create UST event on tracer */
816 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
819 ERR("Error ustctl create event %s for app pid: %d with ret %d",
820 ua_event
->attr
.name
, app
->pid
, ret
);
824 ua_event
->handle
= ua_event
->obj
->handle
;
826 DBG2("UST app event %s created successfully for pid:%d",
827 ua_event
->attr
.name
, app
->pid
);
829 health_code_update(&health_thread_cmd
);
831 /* Set filter if one is present. */
832 if (ua_event
->filter
) {
833 ret
= set_ust_event_filter(ua_event
, app
);
839 /* If event not enabled, disable it on the tracer */
840 if (ua_event
->enabled
== 0) {
841 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
844 * If we hit an EPERM, something is wrong with our disable call. If
845 * we get an EEXIST, there is a problem on the tracer side since we
849 case -LTTNG_UST_ERR_PERM
:
850 /* Code flow problem */
852 case -LTTNG_UST_ERR_EXIST
:
853 /* It's OK for our use case. */
864 health_code_update(&health_thread_cmd
);
869 * Copy data between an UST app event and a LTT event.
871 static void shadow_copy_event(struct ust_app_event
*ua_event
,
872 struct ltt_ust_event
*uevent
)
874 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
875 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
877 ua_event
->enabled
= uevent
->enabled
;
879 /* Copy event attributes */
880 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
882 /* Copy filter bytecode */
883 if (uevent
->filter
) {
884 ua_event
->filter
= alloc_copy_ust_app_filter(uevent
->filter
);
885 /* Filter might be NULL here in case of ENONEM. */
890 * Copy data between an UST app channel and a LTT channel.
892 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
893 struct ltt_ust_channel
*uchan
)
895 struct lttng_ht_iter iter
;
896 struct ltt_ust_event
*uevent
;
897 struct ltt_ust_context
*uctx
;
898 struct ust_app_event
*ua_event
;
899 struct ust_app_ctx
*ua_ctx
;
901 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
903 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
904 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
905 /* Copy event attributes */
906 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
908 ua_chan
->enabled
= uchan
->enabled
;
910 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
911 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
912 if (ua_ctx
== NULL
) {
915 lttng_ht_node_init_ulong(&ua_ctx
->node
,
916 (unsigned long) ua_ctx
->ctx
.ctx
);
917 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
920 /* Copy all events from ltt ust channel to ust app channel */
921 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
922 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
923 uevent
->filter
, uevent
->attr
.loglevel
);
924 if (ua_event
== NULL
) {
925 DBG2("UST event %s not found on shadow copy channel",
927 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
928 if (ua_event
== NULL
) {
931 shadow_copy_event(ua_event
, uevent
);
932 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
936 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
940 * Copy data between a UST app session and a regular LTT session.
942 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
943 struct ltt_ust_session
*usess
, struct ust_app
*app
)
945 struct lttng_ht_node_str
*ua_chan_node
;
946 struct lttng_ht_iter iter
;
947 struct ltt_ust_channel
*uchan
;
948 struct ust_app_channel
*ua_chan
;
954 /* Get date and time for unique app path */
956 timeinfo
= localtime(&rawtime
);
957 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
959 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
961 ua_sess
->id
= usess
->id
;
962 ua_sess
->uid
= usess
->uid
;
963 ua_sess
->gid
= usess
->gid
;
965 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
968 PERROR("asprintf UST shadow copy session");
969 /* TODO: We cannot return an error from here.. */
973 /* TODO: support all UST domain */
975 /* Iterate over all channels in global domain. */
976 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
978 struct lttng_ht_iter uiter
;
980 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
981 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
982 if (ua_chan_node
!= NULL
) {
983 /* Session exist. Contiuing. */
987 DBG2("Channel %s not found on shadow session copy, creating it",
989 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
990 if (ua_chan
== NULL
) {
991 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
995 shadow_copy_channel(ua_chan
, uchan
);
996 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1001 * Lookup sesison wrapper.
1004 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
1005 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
1007 /* Get right UST app session from app */
1008 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
1012 * Return ust app session from the app session hashtable using the UST session
1015 static struct ust_app_session
*lookup_session_by_app(
1016 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1018 struct lttng_ht_iter iter
;
1019 struct lttng_ht_node_ulong
*node
;
1021 __lookup_session_by_app(usess
, app
, &iter
);
1022 node
= lttng_ht_iter_get_node_ulong(&iter
);
1027 return caa_container_of(node
, struct ust_app_session
, node
);
1034 * Create a UST session onto the tracer of app and add it the session
1037 * Return ust app session or NULL on error.
1039 static struct ust_app_session
*create_ust_app_session(
1040 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1043 struct ust_app_session
*ua_sess
;
1045 health_code_update(&health_thread_cmd
);
1047 ua_sess
= lookup_session_by_app(usess
, app
);
1048 if (ua_sess
== NULL
) {
1049 DBG2("UST app pid: %d session id %d not found, creating it",
1050 app
->pid
, usess
->id
);
1051 ua_sess
= alloc_ust_app_session();
1052 if (ua_sess
== NULL
) {
1053 /* Only malloc can failed so something is really wrong */
1056 shadow_copy_session(ua_sess
, usess
, app
);
1059 health_code_update(&health_thread_cmd
);
1061 if (ua_sess
->handle
== -1) {
1062 ret
= ustctl_create_session(app
->sock
);
1064 ERR("Creating session for app pid %d", app
->pid
);
1065 delete_ust_app_session(-1, ua_sess
);
1066 /* This means that the tracer is gone... */
1067 ua_sess
= (void*) -1UL;
1071 ua_sess
->handle
= ret
;
1073 /* Add ust app session to app's HT */
1074 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
1075 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
1077 DBG2("UST app session created successfully with handle %d", ret
);
1081 health_code_update(&health_thread_cmd
);
1086 * Create a context for the channel on the tracer.
1089 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
1090 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
1091 struct ust_app
*app
)
1094 struct lttng_ht_iter iter
;
1095 struct lttng_ht_node_ulong
*node
;
1096 struct ust_app_ctx
*ua_ctx
;
1098 DBG2("UST app adding context to channel %s", ua_chan
->name
);
1100 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1101 node
= lttng_ht_iter_get_node_ulong(&iter
);
1107 ua_ctx
= alloc_ust_app_ctx(uctx
);
1108 if (ua_ctx
== NULL
) {
1114 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1115 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1117 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
1127 * Enable on the tracer side a ust app event for the session and channel.
1130 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1131 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1135 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1140 ua_event
->enabled
= 1;
1147 * Disable on the tracer side a ust app event for the session and channel.
1149 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1150 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1154 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1159 ua_event
->enabled
= 0;
1166 * Lookup ust app channel for session and disable it on the tracer side.
1169 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1170 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1174 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1179 ua_chan
->enabled
= 0;
1186 * Lookup ust app channel for session and enable it on the tracer side.
1188 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1189 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1192 struct lttng_ht_iter iter
;
1193 struct lttng_ht_node_str
*ua_chan_node
;
1194 struct ust_app_channel
*ua_chan
;
1196 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1197 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1198 if (ua_chan_node
== NULL
) {
1199 DBG2("Unable to find channel %s in ust session id %u",
1200 uchan
->name
, ua_sess
->id
);
1204 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1206 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1216 * Create UST app channel and create it on the tracer.
1218 static struct ust_app_channel
*create_ust_app_channel(
1219 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
1220 struct ust_app
*app
)
1223 struct lttng_ht_iter iter
;
1224 struct lttng_ht_node_str
*ua_chan_node
;
1225 struct ust_app_channel
*ua_chan
;
1227 /* Lookup channel in the ust app session */
1228 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1229 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1230 if (ua_chan_node
!= NULL
) {
1231 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1235 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1236 if (ua_chan
== NULL
) {
1237 /* Only malloc can fail here */
1240 shadow_copy_channel(ua_chan
, uchan
);
1242 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1244 /* Not found previously means that it does not exist on the tracer */
1245 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1249 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1251 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1258 delete_ust_app_channel(-1, ua_chan
);
1263 * Create UST app event and create it on the tracer side.
1266 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1267 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1268 struct ust_app
*app
)
1271 struct ust_app_event
*ua_event
;
1273 /* Get event node */
1274 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
1275 uevent
->filter
, uevent
->attr
.loglevel
);
1276 if (ua_event
!= NULL
) {
1281 /* Does not exist so create one */
1282 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1283 if (ua_event
== NULL
) {
1284 /* Only malloc can failed so something is really wrong */
1288 shadow_copy_event(ua_event
, uevent
);
1290 /* Create it on the tracer side */
1291 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1293 /* Not found previously means that it does not exist on the tracer */
1294 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1298 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
1300 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1307 /* Valid. Calling here is already in a read side lock */
1308 delete_ust_app_event(-1, ua_event
);
1313 * Create UST metadata and open it on the tracer side.
1315 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1316 char *pathname
, struct ust_app
*app
)
1320 if (ua_sess
->metadata
== NULL
) {
1321 /* Allocate UST metadata */
1322 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1323 if (ua_sess
->metadata
== NULL
) {
1324 /* malloc() failed */
1328 ret
= open_ust_metadata(app
, ua_sess
);
1330 DBG3("Opening metadata failed. Cleaning up memory");
1332 /* Cleanup failed metadata struct */
1333 free(ua_sess
->metadata
);
1335 * This is very important because delete_ust_app_session check if
1336 * the pointer is null or not in order to delete the metadata.
1338 ua_sess
->metadata
= NULL
;
1342 DBG2("UST metadata opened for app pid %d", app
->pid
);
1345 /* Open UST metadata stream */
1346 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1347 ret
= create_ust_stream(app
, ua_sess
);
1352 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1353 "%s/metadata", ua_sess
->path
);
1355 PERROR("asprintf UST create stream");
1359 DBG2("UST metadata stream object created for app pid %d",
1362 ERR("Attempting to create stream without metadata opened");
1373 * Return pointer to traceable apps list.
1375 struct lttng_ht
*ust_app_get_ht(void)
1381 * Return ust app pointer or NULL if not found.
1383 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1385 struct lttng_ht_node_ulong
*node
;
1386 struct lttng_ht_iter iter
;
1389 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1390 node
= lttng_ht_iter_get_node_ulong(&iter
);
1392 DBG2("UST app no found with pid %d", pid
);
1397 DBG2("Found UST app by pid %d", pid
);
1399 return caa_container_of(node
, struct ust_app
, pid_n
);
1407 * Using pid and uid (of the app), allocate a new ust_app struct and
1408 * add it to the global traceable app list.
1410 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1411 * bitness is not supported.
1413 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1415 struct ust_app
*lta
;
1418 if ((msg
->bits_per_long
== 64 &&
1419 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
1420 || (msg
->bits_per_long
== 32 &&
1421 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
1422 ERR("Registration failed: application \"%s\" (pid: %d) has "
1423 "%d-bit long, but no consumerd for this long size is available.\n",
1424 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1429 lttng_fd_put(LTTNG_FD_APPS
, 1);
1432 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1433 ERR("Registration failed: application \"%s\" (pid: %d) has "
1434 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1435 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1440 lttng_fd_put(LTTNG_FD_APPS
, 1);
1443 lta
= zmalloc(sizeof(struct ust_app
));
1449 lta
->ppid
= msg
->ppid
;
1450 lta
->uid
= msg
->uid
;
1451 lta
->gid
= msg
->gid
;
1452 lta
->compatible
= 0; /* Not compatible until proven */
1453 lta
->bits_per_long
= msg
->bits_per_long
;
1454 lta
->v_major
= msg
->major
;
1455 lta
->v_minor
= msg
->minor
;
1456 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1457 lta
->name
[16] = '\0';
1458 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1460 lta
->pid
= msg
->pid
;
1461 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1463 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1468 * On a re-registration, we want to kick out the previous registration of
1471 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1474 * The socket _should_ be unique until _we_ call close. So, a add_unique
1475 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1476 * already in the table.
1478 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1482 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1483 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1484 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1490 * Unregister app by removing it from the global traceable app list and freeing
1493 * The socket is already closed at this point so no close to sock.
1495 void ust_app_unregister(int sock
)
1497 struct ust_app
*lta
;
1498 struct lttng_ht_node_ulong
*node
;
1499 struct lttng_ht_iter iter
;
1504 /* Get the node reference for a call_rcu */
1505 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1506 node
= lttng_ht_iter_get_node_ulong(&iter
);
1508 ERR("Unable to find app by sock %d", sock
);
1512 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1514 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1516 /* Remove application from PID hash table */
1517 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1520 /* Assign second node for deletion */
1521 iter
.iter
.node
= <a
->pid_n
.node
;
1524 * Ignore return value since the node might have been removed before by an
1525 * add replace during app registration because the PID can be reassigned by
1528 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1530 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
1535 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1543 * Return traceable_app_count
1545 unsigned long ust_app_list_count(void)
1547 unsigned long count
;
1550 count
= lttng_ht_get_count(ust_app_ht
);
1557 * Fill events array with all events name of all registered apps.
1559 int ust_app_list_events(struct lttng_event
**events
)
1562 size_t nbmem
, count
= 0;
1563 struct lttng_ht_iter iter
;
1564 struct ust_app
*app
;
1565 struct lttng_event
*tmp
;
1567 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1568 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1570 PERROR("zmalloc ust app events");
1577 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1578 struct lttng_ust_tracepoint_iter uiter
;
1580 health_code_update(&health_thread_cmd
);
1582 if (!app
->compatible
) {
1584 * TODO: In time, we should notice the caller of this error by
1585 * telling him that this is a version error.
1589 handle
= ustctl_tracepoint_list(app
->sock
);
1591 ERR("UST app list events getting handle failed for app pid %d",
1596 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1597 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1598 health_code_update(&health_thread_cmd
);
1599 if (count
>= nbmem
) {
1600 /* In case the realloc fails, we free the memory */
1601 void *tmp_ptr
= (void *) tmp
;
1602 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1605 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event
));
1607 PERROR("realloc ust app events");
1613 memcpy(tmp
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1614 tmp
[count
].loglevel
= uiter
.loglevel
;
1615 tmp
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1616 tmp
[count
].pid
= app
->pid
;
1617 tmp
[count
].enabled
= -1;
1625 DBG2("UST app list events done (%zu events)", count
);
1630 health_code_update(&health_thread_cmd
);
1635 * Fill events array with all events name of all registered apps.
1637 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1640 size_t nbmem
, count
= 0;
1641 struct lttng_ht_iter iter
;
1642 struct ust_app
*app
;
1643 struct lttng_event_field
*tmp
;
1645 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1646 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1648 PERROR("zmalloc ust app event fields");
1655 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1656 struct lttng_ust_field_iter uiter
;
1658 health_code_update(&health_thread_cmd
);
1660 if (!app
->compatible
) {
1662 * TODO: In time, we should notice the caller of this error by
1663 * telling him that this is a version error.
1667 handle
= ustctl_tracepoint_field_list(app
->sock
);
1669 ERR("UST app list event fields getting handle failed for app pid %d",
1674 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1675 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1676 health_code_update(&health_thread_cmd
);
1677 if (count
>= nbmem
) {
1678 /* In case the realloc fails, we free the memory */
1679 void *tmp_ptr
= (void *) tmp
;
1680 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1683 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event_field
));
1685 PERROR("realloc ust app event fields");
1692 memcpy(tmp
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1693 tmp
[count
].type
= uiter
.type
;
1694 tmp
[count
].nowrite
= uiter
.nowrite
;
1696 memcpy(tmp
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1697 tmp
[count
].event
.loglevel
= uiter
.loglevel
;
1698 tmp
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1699 tmp
[count
].event
.pid
= app
->pid
;
1700 tmp
[count
].event
.enabled
= -1;
1708 DBG2("UST app list event fields done (%zu events)", count
);
1713 health_code_update(&health_thread_cmd
);
1718 * Free and clean all traceable apps of the global list.
1720 void ust_app_clean_list(void)
1723 struct ust_app
*app
;
1724 struct lttng_ht_iter iter
;
1726 DBG2("UST app cleaning registered apps hash table");
1730 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1731 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1733 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
1736 /* Cleanup socket hash table */
1737 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
1739 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1743 /* Destroy is done only when the ht is empty */
1744 lttng_ht_destroy(ust_app_ht
);
1745 lttng_ht_destroy(ust_app_ht_by_sock
);
1751 * Init UST app hash table.
1753 void ust_app_ht_alloc(void)
1755 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1756 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1760 * For a specific UST session, disable the channel for all registered apps.
1762 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1763 struct ltt_ust_channel
*uchan
)
1766 struct lttng_ht_iter iter
;
1767 struct lttng_ht_node_str
*ua_chan_node
;
1768 struct ust_app
*app
;
1769 struct ust_app_session
*ua_sess
;
1770 struct ust_app_channel
*ua_chan
;
1772 if (usess
== NULL
|| uchan
== NULL
) {
1773 ERR("Disabling UST global channel with NULL values");
1778 DBG2("UST app disabling channel %s from global domain for session id %d",
1779 uchan
->name
, usess
->id
);
1783 /* For every registered applications */
1784 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1785 struct lttng_ht_iter uiter
;
1786 if (!app
->compatible
) {
1788 * TODO: In time, we should notice the caller of this error by
1789 * telling him that this is a version error.
1793 ua_sess
= lookup_session_by_app(usess
, app
);
1794 if (ua_sess
== NULL
) {
1799 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1800 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1801 /* If the session if found for the app, the channel must be there */
1802 assert(ua_chan_node
);
1804 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1805 /* The channel must not be already disabled */
1806 assert(ua_chan
->enabled
== 1);
1808 /* Disable channel onto application */
1809 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1811 /* XXX: We might want to report this error at some point... */
1823 * For a specific UST session, enable the channel for all registered apps.
1825 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1826 struct ltt_ust_channel
*uchan
)
1829 struct lttng_ht_iter iter
;
1830 struct ust_app
*app
;
1831 struct ust_app_session
*ua_sess
;
1833 if (usess
== NULL
|| uchan
== NULL
) {
1834 ERR("Adding UST global channel to NULL values");
1839 DBG2("UST app enabling channel %s to global domain for session id %d",
1840 uchan
->name
, usess
->id
);
1844 /* For every registered applications */
1845 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1846 if (!app
->compatible
) {
1848 * TODO: In time, we should notice the caller of this error by
1849 * telling him that this is a version error.
1853 ua_sess
= lookup_session_by_app(usess
, app
);
1854 if (ua_sess
== NULL
) {
1858 /* Enable channel onto application */
1859 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1861 /* XXX: We might want to report this error at some point... */
1873 * Disable an event in a channel and for a specific session.
1875 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1876 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1879 struct lttng_ht_iter iter
, uiter
;
1880 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1881 struct ust_app
*app
;
1882 struct ust_app_session
*ua_sess
;
1883 struct ust_app_channel
*ua_chan
;
1884 struct ust_app_event
*ua_event
;
1886 DBG("UST app disabling event %s for all apps in channel "
1887 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1891 /* For all registered applications */
1892 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1893 if (!app
->compatible
) {
1895 * TODO: In time, we should notice the caller of this error by
1896 * telling him that this is a version error.
1900 ua_sess
= lookup_session_by_app(usess
, app
);
1901 if (ua_sess
== NULL
) {
1906 /* Lookup channel in the ust app session */
1907 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1908 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1909 if (ua_chan_node
== NULL
) {
1910 DBG2("Channel %s not found in session id %d for app pid %d."
1911 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1914 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1916 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1917 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1918 if (ua_event_node
== NULL
) {
1919 DBG2("Event %s not found in channel %s for app pid %d."
1920 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1923 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1925 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1927 /* XXX: Report error someday... */
1938 * For a specific UST session and UST channel, the event for all
1941 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1942 struct ltt_ust_channel
*uchan
)
1945 struct lttng_ht_iter iter
, uiter
;
1946 struct lttng_ht_node_str
*ua_chan_node
;
1947 struct ust_app
*app
;
1948 struct ust_app_session
*ua_sess
;
1949 struct ust_app_channel
*ua_chan
;
1950 struct ust_app_event
*ua_event
;
1952 DBG("UST app disabling all event for all apps in channel "
1953 "%s for session id %d", uchan
->name
, usess
->id
);
1957 /* For all registered applications */
1958 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1959 if (!app
->compatible
) {
1961 * TODO: In time, we should notice the caller of this error by
1962 * telling him that this is a version error.
1966 ua_sess
= lookup_session_by_app(usess
, app
);
1967 /* If ua_sess is NULL, there is a code flow error */
1970 /* Lookup channel in the ust app session */
1971 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1972 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1973 /* If the channel is not found, there is a code flow error */
1974 assert(ua_chan_node
);
1976 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1978 /* Disable each events of channel */
1979 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
1981 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1983 /* XXX: Report error someday... */
1995 * For a specific UST session, create the channel for all registered apps.
1997 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
1998 struct ltt_ust_channel
*uchan
)
2001 struct lttng_ht_iter iter
;
2002 struct ust_app
*app
;
2003 struct ust_app_session
*ua_sess
;
2004 struct ust_app_channel
*ua_chan
;
2006 /* Very wrong code flow */
2010 DBG2("UST app adding channel %s to global domain for session id %d",
2011 uchan
->name
, usess
->id
);
2015 /* For every registered applications */
2016 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2017 if (!app
->compatible
) {
2019 * TODO: In time, we should notice the caller of this error by
2020 * telling him that this is a version error.
2025 * Create session on the tracer side and add it to app session HT. Note
2026 * that if session exist, it will simply return a pointer to the ust
2029 ua_sess
= create_ust_app_session(usess
, app
);
2030 if (ua_sess
== NULL
) {
2031 /* The malloc() failed. */
2034 } else if (ua_sess
== (void *) -1UL) {
2035 /* The application's socket is not valid. Contiuing */
2040 /* Create channel onto application */
2041 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
2042 if (ua_chan
== NULL
) {
2043 /* Major problem here and it's maybe the tracer or malloc() */
2056 * Enable event for a specific session and channel on the tracer.
2058 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
2059 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2062 struct lttng_ht_iter iter
, uiter
;
2063 struct lttng_ht_node_str
*ua_chan_node
;
2064 struct ust_app
*app
;
2065 struct ust_app_session
*ua_sess
;
2066 struct ust_app_channel
*ua_chan
;
2067 struct ust_app_event
*ua_event
;
2069 DBG("UST app enabling event %s for all apps for session id %d",
2070 uevent
->attr
.name
, usess
->id
);
2073 * NOTE: At this point, this function is called only if the session and
2074 * channel passed are already created for all apps. and enabled on the
2080 /* For all registered applications */
2081 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2082 if (!app
->compatible
) {
2084 * TODO: In time, we should notice the caller of this error by
2085 * telling him that this is a version error.
2089 ua_sess
= lookup_session_by_app(usess
, app
);
2090 /* If ua_sess is NULL, there is a code flow error */
2093 /* Lookup channel in the ust app session */
2094 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2095 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2096 /* If the channel is not found, there is a code flow error */
2097 assert(ua_chan_node
);
2099 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2101 /* Get event node */
2102 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2103 uevent
->filter
, uevent
->attr
.loglevel
);
2104 if (ua_event
== NULL
) {
2105 DBG3("UST app enable event %s not found for app PID %d."
2106 "Skipping app", uevent
->attr
.name
, app
->pid
);
2110 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2122 * For a specific existing UST session and UST channel, creates the event for
2123 * all registered apps.
2125 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2126 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2129 struct lttng_ht_iter iter
, uiter
;
2130 struct lttng_ht_node_str
*ua_chan_node
;
2131 struct ust_app
*app
;
2132 struct ust_app_session
*ua_sess
;
2133 struct ust_app_channel
*ua_chan
;
2135 DBG("UST app creating event %s for all apps for session id %d",
2136 uevent
->attr
.name
, usess
->id
);
2140 /* For all registered applications */
2141 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2142 if (!app
->compatible
) {
2144 * TODO: In time, we should notice the caller of this error by
2145 * telling him that this is a version error.
2149 ua_sess
= lookup_session_by_app(usess
, app
);
2150 /* If ua_sess is NULL, there is a code flow error */
2153 /* Lookup channel in the ust app session */
2154 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2155 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2156 /* If the channel is not found, there is a code flow error */
2157 assert(ua_chan_node
);
2159 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2161 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2163 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
2164 /* Possible value at this point: -ENOMEM. If so, we stop! */
2167 DBG2("UST app event %s already exist on app PID %d",
2168 uevent
->attr
.name
, app
->pid
);
2179 * Start tracing for a specific UST session and app.
2181 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2184 struct lttng_ht_iter iter
;
2185 struct ust_app_session
*ua_sess
;
2186 struct ust_app_channel
*ua_chan
;
2187 struct ltt_ust_stream
*ustream
;
2188 struct consumer_socket
*socket
;
2190 DBG("Starting tracing for ust app pid %d", app
->pid
);
2194 if (!app
->compatible
) {
2198 ua_sess
= lookup_session_by_app(usess
, app
);
2199 if (ua_sess
== NULL
) {
2200 goto error_rcu_unlock
;
2203 /* Upon restart, we skip the setup, already done */
2204 if (ua_sess
->started
) {
2208 /* Create directories if consumer is LOCAL and has a path defined. */
2209 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
2210 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
2211 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
2212 S_IRWXU
| S_IRWXG
, usess
->uid
, usess
->gid
);
2214 if (ret
!= -EEXIST
) {
2215 ERR("Trace directory creation error");
2217 goto error_rcu_unlock
;
2222 /* Indicate that the session has been started once */
2223 ua_sess
->started
= 1;
2225 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2227 ret
= LTTNG_ERR_UST_META_FAIL
;
2228 goto error_rcu_unlock
;
2231 /* For each channel */
2232 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2234 /* Create all streams */
2236 /* Create UST stream */
2237 ustream
= zmalloc(sizeof(*ustream
));
2238 if (ustream
== NULL
) {
2239 PERROR("zmalloc ust stream");
2240 goto error_rcu_unlock
;
2243 /* We are going to receive 2 fds, we need to reserve them. */
2244 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2246 ERR("Exhausted number of available FD upon stream create");
2248 goto error_rcu_unlock
;
2251 health_code_update(&health_thread_cmd
);
2253 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2256 /* Got all streams */
2257 lttng_fd_put(LTTNG_FD_APPS
, 2);
2259 ret
= LTTNG_ERR_UST_STREAM_FAIL
;
2262 ustream
->handle
= ustream
->obj
->handle
;
2264 health_code_update(&health_thread_cmd
);
2266 /* Order is important */
2267 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2268 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2269 ua_chan
->name
, ua_chan
->streams
.count
);
2270 ua_chan
->streams
.count
++;
2272 PERROR("asprintf UST create stream");
2274 * XXX what should we do here with the
2279 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2283 health_code_update(&health_thread_cmd
);
2286 switch (app
->bits_per_long
) {
2288 socket
= consumer_find_socket(uatomic_read(&ust_consumerd64_fd
),
2290 if (socket
== NULL
) {
2295 socket
= consumer_find_socket(uatomic_read(&ust_consumerd32_fd
),
2297 if (socket
== NULL
) {
2303 goto error_rcu_unlock
;
2306 /* Setup UST consumer socket and send fds to it */
2307 ret
= ust_consumer_send_session(ua_sess
, usess
->consumer
, socket
);
2309 goto error_rcu_unlock
;
2312 health_code_update(&health_thread_cmd
);
2315 /* This start the UST tracing */
2316 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2318 ERR("Error starting tracing for app pid: %d", app
->pid
);
2319 goto error_rcu_unlock
;
2322 health_code_update(&health_thread_cmd
);
2324 /* Quiescent wait after starting trace */
2325 ustctl_wait_quiescent(app
->sock
);
2329 health_code_update(&health_thread_cmd
);
2334 health_code_update(&health_thread_cmd
);
2339 * Stop tracing for a specific UST session and app.
2341 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2344 struct lttng_ht_iter iter
;
2345 struct ust_app_session
*ua_sess
;
2346 struct ust_app_channel
*ua_chan
;
2348 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2352 if (!app
->compatible
) {
2356 ua_sess
= lookup_session_by_app(usess
, app
);
2357 if (ua_sess
== NULL
) {
2358 /* Only malloc can failed so something is really wrong */
2359 goto error_rcu_unlock
;
2363 * If started = 0, it means that stop trace has been called for a session
2364 * that was never started. This is a code flow error and should never
2367 assert(ua_sess
->started
== 1);
2369 health_code_update(&health_thread_cmd
);
2371 /* This inhibits UST tracing */
2372 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2374 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2375 goto error_rcu_unlock
;
2378 health_code_update(&health_thread_cmd
);
2380 /* Quiescent wait after stopping trace */
2381 ustctl_wait_quiescent(app
->sock
);
2383 health_code_update(&health_thread_cmd
);
2385 /* Flushing buffers */
2386 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2388 health_code_update(&health_thread_cmd
);
2389 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2391 ERR("UST app PID %d channel %s flush failed with ret %d",
2392 app
->pid
, ua_chan
->name
, ret
);
2393 /* Continuing flushing all buffers */
2398 health_code_update(&health_thread_cmd
);
2400 /* Flush all buffers before stopping */
2401 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2403 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2409 health_code_update(&health_thread_cmd
);
2414 health_code_update(&health_thread_cmd
);
2419 * Destroy a specific UST session in apps.
2421 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2423 struct ust_app_session
*ua_sess
;
2424 struct lttng_ust_object_data obj
;
2425 struct lttng_ht_iter iter
;
2426 struct lttng_ht_node_ulong
*node
;
2429 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2433 if (!app
->compatible
) {
2437 __lookup_session_by_app(usess
, app
, &iter
);
2438 node
= lttng_ht_iter_get_node_ulong(&iter
);
2440 /* Only malloc can failed so something is really wrong */
2441 goto error_rcu_unlock
;
2443 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2444 ret
= lttng_ht_del(app
->sessions
, &iter
);
2446 obj
.handle
= ua_sess
->handle
;
2449 obj
.memory_map_size
= 0;
2450 health_code_update(&health_thread_cmd
);
2451 ustctl_release_object(app
->sock
, &obj
);
2453 health_code_update(&health_thread_cmd
);
2454 delete_ust_app_session(app
->sock
, ua_sess
);
2456 /* Quiescent wait after stopping trace */
2457 ustctl_wait_quiescent(app
->sock
);
2461 health_code_update(&health_thread_cmd
);
2466 health_code_update(&health_thread_cmd
);
2471 * Start tracing for the UST session.
2473 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2476 struct lttng_ht_iter iter
;
2477 struct ust_app
*app
;
2479 DBG("Starting all UST traces");
2483 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2484 ret
= ust_app_start_trace(usess
, app
);
2486 /* Continue to next apps even on error */
2497 * Start tracing for the UST session.
2499 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2502 struct lttng_ht_iter iter
;
2503 struct ust_app
*app
;
2505 DBG("Stopping all UST traces");
2509 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2510 ret
= ust_app_stop_trace(usess
, app
);
2512 /* Continue to next apps even on error */
2523 * Destroy app UST session.
2525 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2528 struct lttng_ht_iter iter
;
2529 struct ust_app
*app
;
2531 DBG("Destroy all UST traces");
2535 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2536 ret
= ust_app_destroy_trace(usess
, app
);
2538 /* Continue to next apps even on error */
2549 * Add channels/events from UST global domain to registered apps at sock.
2551 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2554 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2555 struct ust_app
*app
;
2556 struct ust_app_session
*ua_sess
;
2557 struct ust_app_channel
*ua_chan
;
2558 struct ust_app_event
*ua_event
;
2559 struct ust_app_ctx
*ua_ctx
;
2561 if (usess
== NULL
) {
2562 ERR("No UST session on global update. Returning");
2566 DBG2("UST app global update for app sock %d for session id %d", sock
,
2571 app
= find_app_by_sock(sock
);
2573 ERR("Failed to update app sock %d", sock
);
2577 if (!app
->compatible
) {
2581 ua_sess
= create_ust_app_session(usess
, app
);
2582 if (ua_sess
== NULL
|| ua_sess
== (void *) -1UL) {
2583 /* Tracer is gone for this session and has been freed */
2588 * We can iterate safely here over all UST app session sicne the create ust
2589 * app session above made a shadow copy of the UST global domain from the
2592 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2594 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2596 /* FIXME: Should we quit here or continue... */
2600 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2602 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2604 /* FIXME: Should we quit here or continue... */
2610 /* For each events */
2611 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2613 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2615 /* FIXME: Should we quit here or continue... */
2619 ret
= set_ust_event_filter(ua_event
, app
);
2621 /* FIXME: Should we quit here or continue... */
2627 if (usess
->start_trace
) {
2628 ret
= ust_app_start_trace(usess
, app
);
2633 DBG2("UST trace started for app pid %d", app
->pid
);
2642 * Add context to a specific channel for global UST domain.
2644 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2645 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2648 struct lttng_ht_node_str
*ua_chan_node
;
2649 struct lttng_ht_iter iter
, uiter
;
2650 struct ust_app_channel
*ua_chan
= NULL
;
2651 struct ust_app_session
*ua_sess
;
2652 struct ust_app
*app
;
2656 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2657 if (!app
->compatible
) {
2659 * TODO: In time, we should notice the caller of this error by
2660 * telling him that this is a version error.
2664 ua_sess
= lookup_session_by_app(usess
, app
);
2665 if (ua_sess
== NULL
) {
2669 /* Lookup channel in the ust app session */
2670 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2671 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2672 if (ua_chan_node
== NULL
) {
2675 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2678 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2689 * Enable event for a channel from a UST session for a specific PID.
2691 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2692 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2695 struct lttng_ht_iter iter
;
2696 struct lttng_ht_node_str
*ua_chan_node
;
2697 struct ust_app
*app
;
2698 struct ust_app_session
*ua_sess
;
2699 struct ust_app_channel
*ua_chan
;
2700 struct ust_app_event
*ua_event
;
2702 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2706 app
= ust_app_find_by_pid(pid
);
2708 ERR("UST app enable event per PID %d not found", pid
);
2713 if (!app
->compatible
) {
2718 ua_sess
= lookup_session_by_app(usess
, app
);
2719 /* If ua_sess is NULL, there is a code flow error */
2722 /* Lookup channel in the ust app session */
2723 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2724 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2725 /* If the channel is not found, there is a code flow error */
2726 assert(ua_chan_node
);
2728 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2730 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2731 uevent
->filter
, uevent
->attr
.loglevel
);
2732 if (ua_event
== NULL
) {
2733 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2738 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2750 * Disable event for a channel from a UST session for a specific PID.
2752 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2753 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2756 struct lttng_ht_iter iter
;
2757 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2758 struct ust_app
*app
;
2759 struct ust_app_session
*ua_sess
;
2760 struct ust_app_channel
*ua_chan
;
2761 struct ust_app_event
*ua_event
;
2763 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2767 app
= ust_app_find_by_pid(pid
);
2769 ERR("UST app disable event per PID %d not found", pid
);
2774 if (!app
->compatible
) {
2779 ua_sess
= lookup_session_by_app(usess
, app
);
2780 /* If ua_sess is NULL, there is a code flow error */
2783 /* Lookup channel in the ust app session */
2784 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2785 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2786 if (ua_chan_node
== NULL
) {
2787 /* Channel does not exist, skip disabling */
2790 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2792 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2793 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2794 if (ua_event_node
== NULL
) {
2795 /* Event does not exist, skip disabling */
2798 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2800 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2811 * Validate version of UST apps and set the compatible bit.
2813 int ust_app_validate_version(int sock
)
2816 struct ust_app
*app
;
2820 app
= find_app_by_sock(sock
);
2823 health_code_update(&health_thread_cmd
);
2825 ret
= ustctl_tracer_version(sock
, &app
->version
);
2830 /* Validate version */
2831 if (app
->version
.major
!= UST_APP_MAJOR_VERSION
) {
2835 DBG2("UST app PID %d is compatible with internal major version %d "
2836 "(supporting == %d)", app
->pid
, app
->version
.major
,
2837 UST_APP_MAJOR_VERSION
);
2838 app
->compatible
= 1;
2840 health_code_update(&health_thread_cmd
);
2844 DBG2("UST app PID %d is not compatible with internal major version %d "
2845 "(supporting == %d)", app
->pid
, app
->version
.major
,
2846 UST_APP_MAJOR_VERSION
);
2847 app
->compatible
= 0;
2849 health_code_update(&health_thread_cmd
);
2854 * Calibrate registered applications.
2856 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2859 struct lttng_ht_iter iter
;
2860 struct ust_app
*app
;
2864 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2865 if (!app
->compatible
) {
2867 * TODO: In time, we should notice the caller of this error by
2868 * telling him that this is a version error.
2873 health_code_update(&health_thread_cmd
);
2875 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2879 /* Means that it's not implemented on the tracer side. */
2883 /* TODO: Report error to user */
2884 DBG2("Calibrate app PID %d returned with error %d",
2891 DBG("UST app global domain calibration finished");
2895 health_code_update(&health_thread_cmd
);