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 /* The session is already scheduled for teardown. */
276 delete_ust_app_session(app
->sock
, ua_sess
);
278 lttng_ht_destroy(app
->sessions
);
281 * Wait until we have deleted the application from the sock hash table
282 * before closing this socket, otherwise an application could re-use the
283 * socket ID and race with the teardown, using the same hash table entry.
285 * It's OK to leave the close in call_rcu. We want it to stay unique for
286 * all RCU readers that could run concurrently with unregister app,
287 * therefore we _need_ to only close that socket after a grace period. So
288 * it should stay in this RCU callback.
290 * This close() is a very important step of the synchronization model so
291 * every modification to this function must be carefully reviewed.
297 lttng_fd_put(LTTNG_FD_APPS
, 1);
299 DBG2("UST app pid %d deleted", app
->pid
);
306 * URCU intermediate call to delete an UST app.
309 void delete_ust_app_rcu(struct rcu_head
*head
)
311 struct lttng_ht_node_ulong
*node
=
312 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
313 struct ust_app
*app
=
314 caa_container_of(node
, struct ust_app
, pid_n
);
316 DBG3("Call RCU deleting app PID %d", app
->pid
);
321 * Alloc new UST app session.
324 struct ust_app_session
*alloc_ust_app_session(void)
326 struct ust_app_session
*ua_sess
;
328 /* Init most of the default value by allocating and zeroing */
329 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
330 if (ua_sess
== NULL
) {
335 ua_sess
->handle
= -1;
336 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
345 * Alloc new UST app channel.
348 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
349 struct lttng_ust_channel
*attr
)
351 struct ust_app_channel
*ua_chan
;
353 /* Init most of the default value by allocating and zeroing */
354 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
355 if (ua_chan
== NULL
) {
360 /* Setup channel name */
361 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
362 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
364 ua_chan
->enabled
= 1;
365 ua_chan
->handle
= -1;
366 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
367 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
368 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
370 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
372 /* Copy attributes */
374 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
377 DBG3("UST app channel %s allocated", ua_chan
->name
);
386 * Alloc new UST app event.
389 struct ust_app_event
*alloc_ust_app_event(char *name
,
390 struct lttng_ust_event
*attr
)
392 struct ust_app_event
*ua_event
;
394 /* Init most of the default value by allocating and zeroing */
395 ua_event
= zmalloc(sizeof(struct ust_app_event
));
396 if (ua_event
== NULL
) {
401 ua_event
->enabled
= 1;
402 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
403 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
404 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
406 /* Copy attributes */
408 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
411 DBG3("UST app event %s allocated", ua_event
->name
);
420 * Alloc new UST app context.
423 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
425 struct ust_app_ctx
*ua_ctx
;
427 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
428 if (ua_ctx
== NULL
) {
433 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
436 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
443 * Allocate a filter and copy the given original filter.
445 * Return allocated filter or NULL on error.
447 static struct lttng_ust_filter_bytecode
*alloc_copy_ust_app_filter(
448 struct lttng_ust_filter_bytecode
*orig_f
)
450 struct lttng_ust_filter_bytecode
*filter
= NULL
;
452 /* Copy filter bytecode */
453 filter
= zmalloc(sizeof(*filter
) + orig_f
->len
);
455 PERROR("zmalloc alloc ust app filter");
459 memcpy(filter
, orig_f
, sizeof(*filter
) + orig_f
->len
);
466 * Find an ust_app using the sock and return it. RCU read side lock must be
467 * held before calling this helper function.
470 struct ust_app
*find_app_by_sock(int sock
)
472 struct lttng_ht_node_ulong
*node
;
473 struct lttng_ht_iter iter
;
475 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
476 node
= lttng_ht_iter_get_node_ulong(&iter
);
478 DBG2("UST app find by sock %d not found", sock
);
482 return caa_container_of(node
, struct ust_app
, sock_n
);
489 * Lookup for an ust app event based on event name, filter bytecode and the
492 * Return an ust_app_event object or NULL on error.
494 static struct ust_app_event
*find_ust_app_event(struct lttng_ht
*ht
,
495 char *name
, struct lttng_ust_filter_bytecode
*filter
, int loglevel
)
497 struct lttng_ht_iter iter
;
498 struct lttng_ht_node_str
*node
;
499 struct ust_app_event
*event
= NULL
;
500 struct ust_app_ht_key key
;
505 /* Setup key for event lookup. */
508 key
.loglevel
= loglevel
;
510 /* Lookup using the event name as hash and a custom match fct. */
511 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
512 ht_match_ust_app_event
, &key
, &iter
.iter
);
513 node
= lttng_ht_iter_get_node_str(&iter
);
518 event
= caa_container_of(node
, struct ust_app_event
, node
);
525 * Create the channel context on the tracer.
528 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
529 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
533 health_code_update(&health_thread_cmd
);
535 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
536 ua_chan
->obj
, &ua_ctx
->obj
);
541 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
543 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
546 health_code_update(&health_thread_cmd
);
551 * Set the filter on the tracer.
554 int set_ust_event_filter(struct ust_app_event
*ua_event
,
559 health_code_update(&health_thread_cmd
);
561 if (!ua_event
->filter
) {
566 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
572 DBG2("UST filter set successfully for event %s", ua_event
->name
);
575 health_code_update(&health_thread_cmd
);
580 * Disable the specified event on to UST tracer for the UST session.
582 static int disable_ust_event(struct ust_app
*app
,
583 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
587 health_code_update(&health_thread_cmd
);
589 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
591 ERR("UST app event %s disable failed for app (pid: %d) "
592 "and session handle %d with ret %d",
593 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
597 DBG2("UST app event %s disabled successfully for app (pid: %d)",
598 ua_event
->attr
.name
, app
->pid
);
601 health_code_update(&health_thread_cmd
);
606 * Disable the specified channel on to UST tracer for the UST session.
608 static int disable_ust_channel(struct ust_app
*app
,
609 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
613 health_code_update(&health_thread_cmd
);
615 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
617 ERR("UST app channel %s disable failed for app (pid: %d) "
618 "and session handle %d with ret %d",
619 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
623 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
624 ua_chan
->name
, app
->pid
);
627 health_code_update(&health_thread_cmd
);
632 * Enable the specified channel on to UST tracer for the UST session.
634 static int enable_ust_channel(struct ust_app
*app
,
635 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
639 health_code_update(&health_thread_cmd
);
641 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
643 ERR("UST app channel %s enable failed for app (pid: %d) "
644 "and session handle %d with ret %d",
645 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
649 ua_chan
->enabled
= 1;
651 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
652 ua_chan
->name
, app
->pid
);
655 health_code_update(&health_thread_cmd
);
660 * Enable the specified event on to UST tracer for the UST session.
662 static int enable_ust_event(struct ust_app
*app
,
663 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
667 health_code_update(&health_thread_cmd
);
669 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
671 ERR("UST app event %s enable failed for app (pid: %d) "
672 "and session handle %d with ret %d",
673 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
677 DBG2("UST app event %s enabled successfully for app (pid: %d)",
678 ua_event
->attr
.name
, app
->pid
);
681 health_code_update(&health_thread_cmd
);
686 * Open metadata onto the UST tracer for a UST session.
688 static int open_ust_metadata(struct ust_app
*app
,
689 struct ust_app_session
*ua_sess
)
692 struct lttng_ust_channel_attr uattr
;
694 health_code_update(&health_thread_cmd
);
696 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
697 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
698 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
699 uattr
.switch_timer_interval
=
700 ua_sess
->metadata
->attr
.switch_timer_interval
;
701 uattr
.read_timer_interval
=
702 ua_sess
->metadata
->attr
.read_timer_interval
;
703 uattr
.output
= ua_sess
->metadata
->attr
.output
;
705 /* We are going to receive 2 fds, we need to reserve them. */
706 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
708 ERR("Exhausted number of available FD upon metadata open");
711 /* UST tracer metadata creation */
712 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
713 &ua_sess
->metadata
->obj
);
715 ERR("UST app open metadata failed for app pid:%d with ret %d",
720 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
723 health_code_update(&health_thread_cmd
);
728 * Create stream onto the UST tracer for a UST session.
730 static int create_ust_stream(struct ust_app
*app
,
731 struct ust_app_session
*ua_sess
)
735 health_code_update(&health_thread_cmd
);
737 /* We are going to receive 2 fds, we need to reserve them. */
738 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
740 ERR("Exhausted number of available FD upon metadata stream create");
743 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
744 &ua_sess
->metadata
->stream_obj
);
746 ERR("UST create metadata stream failed");
751 health_code_update(&health_thread_cmd
);
756 * Create the specified channel onto the UST tracer for a UST session.
758 static int create_ust_channel(struct ust_app
*app
,
759 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
763 health_code_update(&health_thread_cmd
);
765 /* TODO: remove cast and use lttng-ust-abi.h */
767 /* We are going to receive 2 fds, we need to reserve them. */
768 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
770 ERR("Exhausted number of available FD upon create channel");
774 health_code_update(&health_thread_cmd
);
776 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
777 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
779 ERR("Creating channel %s for app (pid: %d, sock: %d) "
780 "and session handle %d with ret %d",
781 ua_chan
->name
, app
->pid
, app
->sock
,
782 ua_sess
->handle
, ret
);
783 lttng_fd_put(LTTNG_FD_APPS
, 2);
787 ua_chan
->handle
= ua_chan
->obj
->handle
;
789 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
790 ua_chan
->name
, app
->pid
, app
->sock
);
792 health_code_update(&health_thread_cmd
);
794 /* If channel is not enabled, disable it on the tracer */
795 if (!ua_chan
->enabled
) {
796 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
803 health_code_update(&health_thread_cmd
);
808 * Create the specified event onto the UST tracer for a UST session.
811 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
812 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
816 health_code_update(&health_thread_cmd
);
818 /* Create UST event on tracer */
819 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
822 ERR("Error ustctl create event %s for app pid: %d with ret %d",
823 ua_event
->attr
.name
, app
->pid
, ret
);
827 ua_event
->handle
= ua_event
->obj
->handle
;
829 DBG2("UST app event %s created successfully for pid:%d",
830 ua_event
->attr
.name
, app
->pid
);
832 health_code_update(&health_thread_cmd
);
834 /* Set filter if one is present. */
835 if (ua_event
->filter
) {
836 ret
= set_ust_event_filter(ua_event
, app
);
842 /* If event not enabled, disable it on the tracer */
843 if (ua_event
->enabled
== 0) {
844 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
847 * If we hit an EPERM, something is wrong with our disable call. If
848 * we get an EEXIST, there is a problem on the tracer side since we
852 case -LTTNG_UST_ERR_PERM
:
853 /* Code flow problem */
855 case -LTTNG_UST_ERR_EXIST
:
856 /* It's OK for our use case. */
867 health_code_update(&health_thread_cmd
);
872 * Copy data between an UST app event and a LTT event.
874 static void shadow_copy_event(struct ust_app_event
*ua_event
,
875 struct ltt_ust_event
*uevent
)
877 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
878 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
880 ua_event
->enabled
= uevent
->enabled
;
882 /* Copy event attributes */
883 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
885 /* Copy filter bytecode */
886 if (uevent
->filter
) {
887 ua_event
->filter
= alloc_copy_ust_app_filter(uevent
->filter
);
888 /* Filter might be NULL here in case of ENONEM. */
893 * Copy data between an UST app channel and a LTT channel.
895 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
896 struct ltt_ust_channel
*uchan
)
898 struct lttng_ht_iter iter
;
899 struct ltt_ust_event
*uevent
;
900 struct ltt_ust_context
*uctx
;
901 struct ust_app_event
*ua_event
;
902 struct ust_app_ctx
*ua_ctx
;
904 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
906 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
907 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
908 /* Copy event attributes */
909 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
911 ua_chan
->enabled
= uchan
->enabled
;
913 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
914 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
915 if (ua_ctx
== NULL
) {
918 lttng_ht_node_init_ulong(&ua_ctx
->node
,
919 (unsigned long) ua_ctx
->ctx
.ctx
);
920 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
923 /* Copy all events from ltt ust channel to ust app channel */
924 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
925 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
926 uevent
->filter
, uevent
->attr
.loglevel
);
927 if (ua_event
== NULL
) {
928 DBG2("UST event %s not found on shadow copy channel",
930 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
931 if (ua_event
== NULL
) {
934 shadow_copy_event(ua_event
, uevent
);
935 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
939 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
943 * Copy data between a UST app session and a regular LTT session.
945 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
946 struct ltt_ust_session
*usess
, struct ust_app
*app
)
948 struct lttng_ht_node_str
*ua_chan_node
;
949 struct lttng_ht_iter iter
;
950 struct ltt_ust_channel
*uchan
;
951 struct ust_app_channel
*ua_chan
;
957 /* Get date and time for unique app path */
959 timeinfo
= localtime(&rawtime
);
960 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
962 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
964 ua_sess
->id
= usess
->id
;
965 ua_sess
->uid
= usess
->uid
;
966 ua_sess
->gid
= usess
->gid
;
968 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
971 PERROR("asprintf UST shadow copy session");
972 /* TODO: We cannot return an error from here.. */
976 /* TODO: support all UST domain */
978 /* Iterate over all channels in global domain. */
979 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
981 struct lttng_ht_iter uiter
;
983 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
984 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
985 if (ua_chan_node
!= NULL
) {
986 /* Session exist. Contiuing. */
990 DBG2("Channel %s not found on shadow session copy, creating it",
992 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
993 if (ua_chan
== NULL
) {
994 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
998 shadow_copy_channel(ua_chan
, uchan
);
999 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1004 * Lookup sesison wrapper.
1007 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
1008 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
1010 /* Get right UST app session from app */
1011 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
1015 * Return ust app session from the app session hashtable using the UST session
1018 static struct ust_app_session
*lookup_session_by_app(
1019 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1021 struct lttng_ht_iter iter
;
1022 struct lttng_ht_node_ulong
*node
;
1024 __lookup_session_by_app(usess
, app
, &iter
);
1025 node
= lttng_ht_iter_get_node_ulong(&iter
);
1030 return caa_container_of(node
, struct ust_app_session
, node
);
1037 * Create a UST session onto the tracer of app and add it the session
1040 * Return ust app session or NULL on error.
1042 static struct ust_app_session
*create_ust_app_session(
1043 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1046 struct ust_app_session
*ua_sess
;
1048 health_code_update(&health_thread_cmd
);
1050 ua_sess
= lookup_session_by_app(usess
, app
);
1051 if (ua_sess
== NULL
) {
1052 DBG2("UST app pid: %d session id %d not found, creating it",
1053 app
->pid
, usess
->id
);
1054 ua_sess
= alloc_ust_app_session();
1055 if (ua_sess
== NULL
) {
1056 /* Only malloc can failed so something is really wrong */
1059 shadow_copy_session(ua_sess
, usess
, app
);
1062 health_code_update(&health_thread_cmd
);
1064 if (ua_sess
->handle
== -1) {
1065 ret
= ustctl_create_session(app
->sock
);
1067 ERR("Creating session for app pid %d", app
->pid
);
1068 delete_ust_app_session(-1, ua_sess
);
1069 /* This means that the tracer is gone... */
1070 ua_sess
= (void*) -1UL;
1074 ua_sess
->handle
= ret
;
1076 /* Add ust app session to app's HT */
1077 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
1078 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
1080 DBG2("UST app session created successfully with handle %d", ret
);
1084 health_code_update(&health_thread_cmd
);
1089 * Create a context for the channel on the tracer.
1092 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
1093 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
1094 struct ust_app
*app
)
1097 struct lttng_ht_iter iter
;
1098 struct lttng_ht_node_ulong
*node
;
1099 struct ust_app_ctx
*ua_ctx
;
1101 DBG2("UST app adding context to channel %s", ua_chan
->name
);
1103 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1104 node
= lttng_ht_iter_get_node_ulong(&iter
);
1110 ua_ctx
= alloc_ust_app_ctx(uctx
);
1111 if (ua_ctx
== NULL
) {
1117 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1118 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1120 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
1130 * Enable on the tracer side a ust app event for the session and channel.
1133 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1134 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1138 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1143 ua_event
->enabled
= 1;
1150 * Disable on the tracer side a ust app event for the session and channel.
1152 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1153 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1157 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1162 ua_event
->enabled
= 0;
1169 * Lookup ust app channel for session and disable it on the tracer side.
1172 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1173 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1177 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1182 ua_chan
->enabled
= 0;
1189 * Lookup ust app channel for session and enable it on the tracer side.
1191 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1192 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1195 struct lttng_ht_iter iter
;
1196 struct lttng_ht_node_str
*ua_chan_node
;
1197 struct ust_app_channel
*ua_chan
;
1199 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1200 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1201 if (ua_chan_node
== NULL
) {
1202 DBG2("Unable to find channel %s in ust session id %u",
1203 uchan
->name
, ua_sess
->id
);
1207 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1209 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1219 * Create UST app channel and create it on the tracer.
1221 static struct ust_app_channel
*create_ust_app_channel(
1222 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
1223 struct ust_app
*app
)
1226 struct lttng_ht_iter iter
;
1227 struct lttng_ht_node_str
*ua_chan_node
;
1228 struct ust_app_channel
*ua_chan
;
1230 /* Lookup channel in the ust app session */
1231 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1232 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1233 if (ua_chan_node
!= NULL
) {
1234 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1238 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1239 if (ua_chan
== NULL
) {
1240 /* Only malloc can fail here */
1243 shadow_copy_channel(ua_chan
, uchan
);
1245 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1247 /* Not found previously means that it does not exist on the tracer */
1248 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1252 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1254 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1261 delete_ust_app_channel(-1, ua_chan
);
1266 * Create UST app event and create it on the tracer side.
1269 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1270 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1271 struct ust_app
*app
)
1274 struct ust_app_event
*ua_event
;
1276 /* Get event node */
1277 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
1278 uevent
->filter
, uevent
->attr
.loglevel
);
1279 if (ua_event
!= NULL
) {
1284 /* Does not exist so create one */
1285 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1286 if (ua_event
== NULL
) {
1287 /* Only malloc can failed so something is really wrong */
1291 shadow_copy_event(ua_event
, uevent
);
1293 /* Create it on the tracer side */
1294 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1296 /* Not found previously means that it does not exist on the tracer */
1297 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1301 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
1303 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1310 /* Valid. Calling here is already in a read side lock */
1311 delete_ust_app_event(-1, ua_event
);
1316 * Create UST metadata and open it on the tracer side.
1318 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1319 char *pathname
, struct ust_app
*app
)
1323 if (ua_sess
->metadata
== NULL
) {
1324 /* Allocate UST metadata */
1325 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1326 if (ua_sess
->metadata
== NULL
) {
1327 /* malloc() failed */
1331 ret
= open_ust_metadata(app
, ua_sess
);
1333 DBG3("Opening metadata failed. Cleaning up memory");
1335 /* Cleanup failed metadata struct */
1336 free(ua_sess
->metadata
);
1338 * This is very important because delete_ust_app_session check if
1339 * the pointer is null or not in order to delete the metadata.
1341 ua_sess
->metadata
= NULL
;
1345 DBG2("UST metadata opened for app pid %d", app
->pid
);
1348 /* Open UST metadata stream */
1349 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1350 ret
= create_ust_stream(app
, ua_sess
);
1355 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1356 "%s/metadata", ua_sess
->path
);
1358 PERROR("asprintf UST create stream");
1362 DBG2("UST metadata stream object created for app pid %d",
1365 ERR("Attempting to create stream without metadata opened");
1376 * Return pointer to traceable apps list.
1378 struct lttng_ht
*ust_app_get_ht(void)
1384 * Return ust app pointer or NULL if not found.
1386 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1388 struct lttng_ht_node_ulong
*node
;
1389 struct lttng_ht_iter iter
;
1392 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1393 node
= lttng_ht_iter_get_node_ulong(&iter
);
1395 DBG2("UST app no found with pid %d", pid
);
1400 DBG2("Found UST app by pid %d", pid
);
1402 return caa_container_of(node
, struct ust_app
, pid_n
);
1410 * Using pid and uid (of the app), allocate a new ust_app struct and
1411 * add it to the global traceable app list.
1413 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1414 * bitness is not supported.
1416 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1418 struct ust_app
*lta
;
1421 if ((msg
->bits_per_long
== 64 &&
1422 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
1423 || (msg
->bits_per_long
== 32 &&
1424 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
1425 ERR("Registration failed: application \"%s\" (pid: %d) has "
1426 "%d-bit long, but no consumerd for this long size is available.\n",
1427 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1432 lttng_fd_put(LTTNG_FD_APPS
, 1);
1435 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1436 ERR("Registration failed: application \"%s\" (pid: %d) has "
1437 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1438 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1443 lttng_fd_put(LTTNG_FD_APPS
, 1);
1446 lta
= zmalloc(sizeof(struct ust_app
));
1452 lta
->ppid
= msg
->ppid
;
1453 lta
->uid
= msg
->uid
;
1454 lta
->gid
= msg
->gid
;
1455 lta
->compatible
= 0; /* Not compatible until proven */
1456 lta
->bits_per_long
= msg
->bits_per_long
;
1457 lta
->v_major
= msg
->major
;
1458 lta
->v_minor
= msg
->minor
;
1459 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1460 lta
->name
[16] = '\0';
1461 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1463 lta
->pid
= msg
->pid
;
1464 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1466 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1471 * On a re-registration, we want to kick out the previous registration of
1474 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1477 * The socket _should_ be unique until _we_ call close. So, a add_unique
1478 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1479 * already in the table.
1481 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1485 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1486 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1487 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1493 * Unregister app by removing it from the global traceable app list and freeing
1496 * The socket is already closed at this point so no close to sock.
1498 void ust_app_unregister(int sock
)
1500 struct ust_app
*lta
;
1501 struct lttng_ht_node_ulong
*node
;
1502 struct lttng_ht_iter iter
;
1507 /* Get the node reference for a call_rcu */
1508 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1509 node
= lttng_ht_iter_get_node_ulong(&iter
);
1511 ERR("Unable to find app by sock %d", sock
);
1515 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1517 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1519 /* Remove application from PID hash table */
1520 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1523 /* Assign second node for deletion */
1524 iter
.iter
.node
= <a
->pid_n
.node
;
1527 * Ignore return value since the node might have been removed before by an
1528 * add replace during app registration because the PID can be reassigned by
1531 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1533 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
1538 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1546 * Return traceable_app_count
1548 unsigned long ust_app_list_count(void)
1550 unsigned long count
;
1553 count
= lttng_ht_get_count(ust_app_ht
);
1560 * Fill events array with all events name of all registered apps.
1562 int ust_app_list_events(struct lttng_event
**events
)
1565 size_t nbmem
, count
= 0;
1566 struct lttng_ht_iter iter
;
1567 struct ust_app
*app
;
1568 struct lttng_event
*tmp
;
1570 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1571 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1573 PERROR("zmalloc ust app events");
1580 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1581 struct lttng_ust_tracepoint_iter uiter
;
1583 health_code_update(&health_thread_cmd
);
1585 if (!app
->compatible
) {
1587 * TODO: In time, we should notice the caller of this error by
1588 * telling him that this is a version error.
1592 handle
= ustctl_tracepoint_list(app
->sock
);
1594 ERR("UST app list events getting handle failed for app pid %d",
1599 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1600 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1601 health_code_update(&health_thread_cmd
);
1602 if (count
>= nbmem
) {
1603 /* In case the realloc fails, we free the memory */
1604 void *tmp_ptr
= (void *) tmp
;
1605 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1608 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event
));
1610 PERROR("realloc ust app events");
1616 memcpy(tmp
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1617 tmp
[count
].loglevel
= uiter
.loglevel
;
1618 tmp
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1619 tmp
[count
].pid
= app
->pid
;
1620 tmp
[count
].enabled
= -1;
1628 DBG2("UST app list events done (%zu events)", count
);
1633 health_code_update(&health_thread_cmd
);
1638 * Fill events array with all events name of all registered apps.
1640 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1643 size_t nbmem
, count
= 0;
1644 struct lttng_ht_iter iter
;
1645 struct ust_app
*app
;
1646 struct lttng_event_field
*tmp
;
1648 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1649 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1651 PERROR("zmalloc ust app event fields");
1658 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1659 struct lttng_ust_field_iter uiter
;
1661 health_code_update(&health_thread_cmd
);
1663 if (!app
->compatible
) {
1665 * TODO: In time, we should notice the caller of this error by
1666 * telling him that this is a version error.
1670 handle
= ustctl_tracepoint_field_list(app
->sock
);
1672 ERR("UST app list event fields getting handle failed for app pid %d",
1677 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1678 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1679 health_code_update(&health_thread_cmd
);
1680 if (count
>= nbmem
) {
1681 /* In case the realloc fails, we free the memory */
1682 void *tmp_ptr
= (void *) tmp
;
1683 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1686 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event_field
));
1688 PERROR("realloc ust app event fields");
1695 memcpy(tmp
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1696 tmp
[count
].type
= uiter
.type
;
1697 tmp
[count
].nowrite
= uiter
.nowrite
;
1699 memcpy(tmp
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1700 tmp
[count
].event
.loglevel
= uiter
.loglevel
;
1701 tmp
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1702 tmp
[count
].event
.pid
= app
->pid
;
1703 tmp
[count
].event
.enabled
= -1;
1711 DBG2("UST app list event fields done (%zu events)", count
);
1716 health_code_update(&health_thread_cmd
);
1721 * Free and clean all traceable apps of the global list.
1723 void ust_app_clean_list(void)
1726 struct ust_app
*app
;
1727 struct lttng_ht_iter iter
;
1729 DBG2("UST app cleaning registered apps hash table");
1733 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1734 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1736 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
1739 /* Cleanup socket hash table */
1740 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
1742 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1746 /* Destroy is done only when the ht is empty */
1747 lttng_ht_destroy(ust_app_ht
);
1748 lttng_ht_destroy(ust_app_ht_by_sock
);
1754 * Init UST app hash table.
1756 void ust_app_ht_alloc(void)
1758 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1759 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1763 * For a specific UST session, disable the channel for all registered apps.
1765 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1766 struct ltt_ust_channel
*uchan
)
1769 struct lttng_ht_iter iter
;
1770 struct lttng_ht_node_str
*ua_chan_node
;
1771 struct ust_app
*app
;
1772 struct ust_app_session
*ua_sess
;
1773 struct ust_app_channel
*ua_chan
;
1775 if (usess
== NULL
|| uchan
== NULL
) {
1776 ERR("Disabling UST global channel with NULL values");
1781 DBG2("UST app disabling channel %s from global domain for session id %d",
1782 uchan
->name
, usess
->id
);
1786 /* For every registered applications */
1787 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1788 struct lttng_ht_iter uiter
;
1789 if (!app
->compatible
) {
1791 * TODO: In time, we should notice the caller of this error by
1792 * telling him that this is a version error.
1796 ua_sess
= lookup_session_by_app(usess
, app
);
1797 if (ua_sess
== NULL
) {
1802 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1803 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1804 /* If the session if found for the app, the channel must be there */
1805 assert(ua_chan_node
);
1807 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1808 /* The channel must not be already disabled */
1809 assert(ua_chan
->enabled
== 1);
1811 /* Disable channel onto application */
1812 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1814 /* XXX: We might want to report this error at some point... */
1826 * For a specific UST session, enable the channel for all registered apps.
1828 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1829 struct ltt_ust_channel
*uchan
)
1832 struct lttng_ht_iter iter
;
1833 struct ust_app
*app
;
1834 struct ust_app_session
*ua_sess
;
1836 if (usess
== NULL
|| uchan
== NULL
) {
1837 ERR("Adding UST global channel to NULL values");
1842 DBG2("UST app enabling channel %s to global domain for session id %d",
1843 uchan
->name
, usess
->id
);
1847 /* For every registered applications */
1848 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1849 if (!app
->compatible
) {
1851 * TODO: In time, we should notice the caller of this error by
1852 * telling him that this is a version error.
1856 ua_sess
= lookup_session_by_app(usess
, app
);
1857 if (ua_sess
== NULL
) {
1861 /* Enable channel onto application */
1862 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1864 /* XXX: We might want to report this error at some point... */
1876 * Disable an event in a channel and for a specific session.
1878 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1879 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1882 struct lttng_ht_iter iter
, uiter
;
1883 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1884 struct ust_app
*app
;
1885 struct ust_app_session
*ua_sess
;
1886 struct ust_app_channel
*ua_chan
;
1887 struct ust_app_event
*ua_event
;
1889 DBG("UST app disabling event %s for all apps in channel "
1890 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1894 /* For all registered applications */
1895 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1896 if (!app
->compatible
) {
1898 * TODO: In time, we should notice the caller of this error by
1899 * telling him that this is a version error.
1903 ua_sess
= lookup_session_by_app(usess
, app
);
1904 if (ua_sess
== NULL
) {
1909 /* Lookup channel in the ust app session */
1910 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1911 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1912 if (ua_chan_node
== NULL
) {
1913 DBG2("Channel %s not found in session id %d for app pid %d."
1914 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1917 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1919 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1920 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1921 if (ua_event_node
== NULL
) {
1922 DBG2("Event %s not found in channel %s for app pid %d."
1923 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1926 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1928 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1930 /* XXX: Report error someday... */
1941 * For a specific UST session and UST channel, the event for all
1944 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1945 struct ltt_ust_channel
*uchan
)
1948 struct lttng_ht_iter iter
, uiter
;
1949 struct lttng_ht_node_str
*ua_chan_node
;
1950 struct ust_app
*app
;
1951 struct ust_app_session
*ua_sess
;
1952 struct ust_app_channel
*ua_chan
;
1953 struct ust_app_event
*ua_event
;
1955 DBG("UST app disabling all event for all apps in channel "
1956 "%s for session id %d", uchan
->name
, usess
->id
);
1960 /* For all registered applications */
1961 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1962 if (!app
->compatible
) {
1964 * TODO: In time, we should notice the caller of this error by
1965 * telling him that this is a version error.
1969 ua_sess
= lookup_session_by_app(usess
, app
);
1971 /* The application has problem or is probably dead. */
1975 /* Lookup channel in the ust app session */
1976 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1977 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1978 /* If the channel is not found, there is a code flow error */
1979 assert(ua_chan_node
);
1981 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1983 /* Disable each events of channel */
1984 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
1986 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1988 /* XXX: Report error someday... */
2000 * For a specific UST session, create the channel for all registered apps.
2002 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
2003 struct ltt_ust_channel
*uchan
)
2006 struct lttng_ht_iter iter
;
2007 struct ust_app
*app
;
2008 struct ust_app_session
*ua_sess
;
2009 struct ust_app_channel
*ua_chan
;
2011 /* Very wrong code flow */
2015 DBG2("UST app adding channel %s to global domain for session id %d",
2016 uchan
->name
, usess
->id
);
2020 /* For every registered applications */
2021 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2022 if (!app
->compatible
) {
2024 * TODO: In time, we should notice the caller of this error by
2025 * telling him that this is a version error.
2030 * Create session on the tracer side and add it to app session HT. Note
2031 * that if session exist, it will simply return a pointer to the ust
2034 ua_sess
= create_ust_app_session(usess
, app
);
2035 if (ua_sess
== NULL
) {
2036 /* The malloc() failed. */
2039 } else if (ua_sess
== (void *) -1UL) {
2040 /* The application's socket is not valid. Contiuing */
2045 /* Create channel onto application */
2046 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
2047 if (ua_chan
== NULL
) {
2048 /* Major problem here and it's maybe the tracer or malloc() */
2061 * Enable event for a specific session and channel on the tracer.
2063 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
2064 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2067 struct lttng_ht_iter iter
, uiter
;
2068 struct lttng_ht_node_str
*ua_chan_node
;
2069 struct ust_app
*app
;
2070 struct ust_app_session
*ua_sess
;
2071 struct ust_app_channel
*ua_chan
;
2072 struct ust_app_event
*ua_event
;
2074 DBG("UST app enabling event %s for all apps for session id %d",
2075 uevent
->attr
.name
, usess
->id
);
2078 * NOTE: At this point, this function is called only if the session and
2079 * channel passed are already created for all apps. and enabled on the
2085 /* For all registered applications */
2086 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2087 if (!app
->compatible
) {
2089 * TODO: In time, we should notice the caller of this error by
2090 * telling him that this is a version error.
2094 ua_sess
= lookup_session_by_app(usess
, app
);
2096 /* The application has problem or is probably dead. */
2100 /* Lookup channel in the ust app session */
2101 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2102 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2103 /* If the channel is not found, there is a code flow error */
2104 assert(ua_chan_node
);
2106 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2108 /* Get event node */
2109 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2110 uevent
->filter
, uevent
->attr
.loglevel
);
2111 if (ua_event
== NULL
) {
2112 DBG3("UST app enable event %s not found for app PID %d."
2113 "Skipping app", uevent
->attr
.name
, app
->pid
);
2117 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2129 * For a specific existing UST session and UST channel, creates the event for
2130 * all registered apps.
2132 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2133 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2136 struct lttng_ht_iter iter
, uiter
;
2137 struct lttng_ht_node_str
*ua_chan_node
;
2138 struct ust_app
*app
;
2139 struct ust_app_session
*ua_sess
;
2140 struct ust_app_channel
*ua_chan
;
2142 DBG("UST app creating event %s for all apps for session id %d",
2143 uevent
->attr
.name
, usess
->id
);
2147 /* For all registered applications */
2148 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2149 if (!app
->compatible
) {
2151 * TODO: In time, we should notice the caller of this error by
2152 * telling him that this is a version error.
2156 ua_sess
= lookup_session_by_app(usess
, app
);
2158 /* The application has problem or is probably dead. */
2162 /* Lookup channel in the ust app session */
2163 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2164 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2165 /* If the channel is not found, there is a code flow error */
2166 assert(ua_chan_node
);
2168 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2170 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2172 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
2173 /* Possible value at this point: -ENOMEM. If so, we stop! */
2176 DBG2("UST app event %s already exist on app PID %d",
2177 uevent
->attr
.name
, app
->pid
);
2188 * Start tracing for a specific UST session and app.
2190 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2193 struct lttng_ht_iter iter
;
2194 struct ust_app_session
*ua_sess
;
2195 struct ust_app_channel
*ua_chan
;
2196 struct ltt_ust_stream
*ustream
;
2197 struct consumer_socket
*socket
;
2199 DBG("Starting tracing for ust app pid %d", app
->pid
);
2203 if (!app
->compatible
) {
2207 ua_sess
= lookup_session_by_app(usess
, app
);
2208 if (ua_sess
== NULL
) {
2209 goto error_rcu_unlock
;
2212 /* Upon restart, we skip the setup, already done */
2213 if (ua_sess
->started
) {
2217 /* Create directories if consumer is LOCAL and has a path defined. */
2218 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
2219 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
2220 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
2221 S_IRWXU
| S_IRWXG
, usess
->uid
, usess
->gid
);
2223 if (ret
!= -EEXIST
) {
2224 ERR("Trace directory creation error");
2226 goto error_rcu_unlock
;
2231 /* Indicate that the session has been started once */
2232 ua_sess
->started
= 1;
2234 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2236 ret
= LTTNG_ERR_UST_META_FAIL
;
2237 goto error_rcu_unlock
;
2240 /* For each channel */
2241 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2243 /* Create all streams */
2245 /* Create UST stream */
2246 ustream
= zmalloc(sizeof(*ustream
));
2247 if (ustream
== NULL
) {
2248 PERROR("zmalloc ust stream");
2249 goto error_rcu_unlock
;
2252 /* We are going to receive 2 fds, we need to reserve them. */
2253 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2255 ERR("Exhausted number of available FD upon stream create");
2257 goto error_rcu_unlock
;
2260 health_code_update(&health_thread_cmd
);
2262 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2265 /* Got all streams */
2266 lttng_fd_put(LTTNG_FD_APPS
, 2);
2268 ret
= LTTNG_ERR_UST_STREAM_FAIL
;
2271 ustream
->handle
= ustream
->obj
->handle
;
2273 health_code_update(&health_thread_cmd
);
2275 /* Order is important */
2276 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2277 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2278 ua_chan
->name
, ua_chan
->streams
.count
);
2279 ua_chan
->streams
.count
++;
2281 PERROR("asprintf UST create stream");
2283 * XXX what should we do here with the
2288 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2292 health_code_update(&health_thread_cmd
);
2295 switch (app
->bits_per_long
) {
2297 socket
= consumer_find_socket(uatomic_read(&ust_consumerd64_fd
),
2299 if (socket
== NULL
) {
2304 socket
= consumer_find_socket(uatomic_read(&ust_consumerd32_fd
),
2306 if (socket
== NULL
) {
2312 goto error_rcu_unlock
;
2315 /* Setup UST consumer socket and send fds to it */
2316 ret
= ust_consumer_send_session(ua_sess
, usess
->consumer
, socket
);
2318 goto error_rcu_unlock
;
2321 health_code_update(&health_thread_cmd
);
2324 /* This start the UST tracing */
2325 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2327 ERR("Error starting tracing for app pid: %d", app
->pid
);
2328 goto error_rcu_unlock
;
2331 health_code_update(&health_thread_cmd
);
2333 /* Quiescent wait after starting trace */
2334 ustctl_wait_quiescent(app
->sock
);
2338 health_code_update(&health_thread_cmd
);
2343 health_code_update(&health_thread_cmd
);
2348 * Stop tracing for a specific UST session and app.
2350 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2353 struct lttng_ht_iter iter
;
2354 struct ust_app_session
*ua_sess
;
2355 struct ust_app_channel
*ua_chan
;
2357 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2361 if (!app
->compatible
) {
2365 ua_sess
= lookup_session_by_app(usess
, app
);
2366 if (ua_sess
== NULL
) {
2367 /* Only malloc can failed so something is really wrong */
2368 goto error_rcu_unlock
;
2372 * If started = 0, it means that stop trace has been called for a session
2373 * that was never started. This is a code flow error and should never
2376 assert(ua_sess
->started
== 1);
2378 health_code_update(&health_thread_cmd
);
2380 /* This inhibits UST tracing */
2381 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2383 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2384 goto error_rcu_unlock
;
2387 health_code_update(&health_thread_cmd
);
2389 /* Quiescent wait after stopping trace */
2390 ustctl_wait_quiescent(app
->sock
);
2392 health_code_update(&health_thread_cmd
);
2394 /* Flushing buffers */
2395 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2397 health_code_update(&health_thread_cmd
);
2398 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2400 ERR("UST app PID %d channel %s flush failed with ret %d",
2401 app
->pid
, ua_chan
->name
, ret
);
2402 /* Continuing flushing all buffers */
2407 health_code_update(&health_thread_cmd
);
2409 /* Flush all buffers before stopping */
2410 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2412 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2418 health_code_update(&health_thread_cmd
);
2423 health_code_update(&health_thread_cmd
);
2428 * Destroy a specific UST session in apps.
2430 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2432 struct ust_app_session
*ua_sess
;
2433 struct lttng_ust_object_data obj
;
2434 struct lttng_ht_iter iter
;
2435 struct lttng_ht_node_ulong
*node
;
2438 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2442 if (!app
->compatible
) {
2446 __lookup_session_by_app(usess
, app
, &iter
);
2447 node
= lttng_ht_iter_get_node_ulong(&iter
);
2449 /* Only malloc can failed so something is really wrong */
2450 goto error_rcu_unlock
;
2452 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2453 ret
= lttng_ht_del(app
->sessions
, &iter
);
2455 /* Already scheduled for teardown. */
2459 obj
.handle
= ua_sess
->handle
;
2462 obj
.memory_map_size
= 0;
2463 health_code_update(&health_thread_cmd
);
2464 ustctl_release_object(app
->sock
, &obj
);
2466 health_code_update(&health_thread_cmd
);
2467 delete_ust_app_session(app
->sock
, ua_sess
);
2469 /* Quiescent wait after stopping trace */
2470 ustctl_wait_quiescent(app
->sock
);
2474 health_code_update(&health_thread_cmd
);
2479 health_code_update(&health_thread_cmd
);
2484 * Start tracing for the UST session.
2486 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2489 struct lttng_ht_iter iter
;
2490 struct ust_app
*app
;
2492 DBG("Starting all UST traces");
2496 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2497 ret
= ust_app_start_trace(usess
, app
);
2499 /* Continue to next apps even on error */
2510 * Start tracing for the UST session.
2512 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2515 struct lttng_ht_iter iter
;
2516 struct ust_app
*app
;
2518 DBG("Stopping all UST traces");
2522 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2523 ret
= ust_app_stop_trace(usess
, app
);
2525 /* Continue to next apps even on error */
2536 * Destroy app UST session.
2538 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2541 struct lttng_ht_iter iter
;
2542 struct ust_app
*app
;
2544 DBG("Destroy all UST traces");
2548 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2549 ret
= ust_app_destroy_trace(usess
, app
);
2551 /* Continue to next apps even on error */
2562 * Add channels/events from UST global domain to registered apps at sock.
2564 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2567 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2568 struct ust_app
*app
;
2569 struct ust_app_session
*ua_sess
;
2570 struct ust_app_channel
*ua_chan
;
2571 struct ust_app_event
*ua_event
;
2572 struct ust_app_ctx
*ua_ctx
;
2574 if (usess
== NULL
) {
2575 ERR("No UST session on global update. Returning");
2579 DBG2("UST app global update for app sock %d for session id %d", sock
,
2584 app
= find_app_by_sock(sock
);
2586 ERR("Failed to update app sock %d", sock
);
2590 if (!app
->compatible
) {
2594 ua_sess
= create_ust_app_session(usess
, app
);
2595 if (ua_sess
== NULL
|| ua_sess
== (void *) -1UL) {
2596 /* Tracer is gone for this session and has been freed */
2601 * We can iterate safely here over all UST app session sicne the create ust
2602 * app session above made a shadow copy of the UST global domain from the
2605 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2607 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2609 /* FIXME: Should we quit here or continue... */
2613 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2615 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2617 /* FIXME: Should we quit here or continue... */
2623 /* For each events */
2624 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2626 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2628 /* FIXME: Should we quit here or continue... */
2632 ret
= set_ust_event_filter(ua_event
, app
);
2634 /* FIXME: Should we quit here or continue... */
2640 if (usess
->start_trace
) {
2641 ret
= ust_app_start_trace(usess
, app
);
2646 DBG2("UST trace started for app pid %d", app
->pid
);
2655 * Add context to a specific channel for global UST domain.
2657 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2658 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2661 struct lttng_ht_node_str
*ua_chan_node
;
2662 struct lttng_ht_iter iter
, uiter
;
2663 struct ust_app_channel
*ua_chan
= NULL
;
2664 struct ust_app_session
*ua_sess
;
2665 struct ust_app
*app
;
2669 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2670 if (!app
->compatible
) {
2672 * TODO: In time, we should notice the caller of this error by
2673 * telling him that this is a version error.
2677 ua_sess
= lookup_session_by_app(usess
, app
);
2678 if (ua_sess
== NULL
) {
2682 /* Lookup channel in the ust app session */
2683 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2684 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2685 if (ua_chan_node
== NULL
) {
2688 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2691 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2702 * Enable event for a channel from a UST session for a specific PID.
2704 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2705 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2708 struct lttng_ht_iter iter
;
2709 struct lttng_ht_node_str
*ua_chan_node
;
2710 struct ust_app
*app
;
2711 struct ust_app_session
*ua_sess
;
2712 struct ust_app_channel
*ua_chan
;
2713 struct ust_app_event
*ua_event
;
2715 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2719 app
= ust_app_find_by_pid(pid
);
2721 ERR("UST app enable event per PID %d not found", pid
);
2726 if (!app
->compatible
) {
2731 ua_sess
= lookup_session_by_app(usess
, app
);
2733 /* The application has problem or is probably dead. */
2737 /* Lookup channel in the ust app session */
2738 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2739 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2740 /* If the channel is not found, there is a code flow error */
2741 assert(ua_chan_node
);
2743 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2745 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2746 uevent
->filter
, uevent
->attr
.loglevel
);
2747 if (ua_event
== NULL
) {
2748 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2753 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2765 * Disable event for a channel from a UST session for a specific PID.
2767 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2768 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2771 struct lttng_ht_iter iter
;
2772 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2773 struct ust_app
*app
;
2774 struct ust_app_session
*ua_sess
;
2775 struct ust_app_channel
*ua_chan
;
2776 struct ust_app_event
*ua_event
;
2778 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2782 app
= ust_app_find_by_pid(pid
);
2784 ERR("UST app disable event per PID %d not found", pid
);
2789 if (!app
->compatible
) {
2794 ua_sess
= lookup_session_by_app(usess
, app
);
2796 /* The application has problem or is probably dead. */
2800 /* Lookup channel in the ust app session */
2801 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2802 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2803 if (ua_chan_node
== NULL
) {
2804 /* Channel does not exist, skip disabling */
2807 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2809 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2810 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2811 if (ua_event_node
== NULL
) {
2812 /* Event does not exist, skip disabling */
2815 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2817 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2828 * Validate version of UST apps and set the compatible bit.
2830 int ust_app_validate_version(int sock
)
2833 struct ust_app
*app
;
2837 app
= find_app_by_sock(sock
);
2840 health_code_update(&health_thread_cmd
);
2842 ret
= ustctl_tracer_version(sock
, &app
->version
);
2847 /* Validate version */
2848 if (app
->version
.major
!= UST_APP_MAJOR_VERSION
) {
2852 DBG2("UST app PID %d is compatible with internal major version %d "
2853 "(supporting == %d)", app
->pid
, app
->version
.major
,
2854 UST_APP_MAJOR_VERSION
);
2855 app
->compatible
= 1;
2857 health_code_update(&health_thread_cmd
);
2861 DBG2("UST app PID %d is not compatible with internal major version %d "
2862 "(supporting == %d)", app
->pid
, app
->version
.major
,
2863 UST_APP_MAJOR_VERSION
);
2864 app
->compatible
= 0;
2866 health_code_update(&health_thread_cmd
);
2871 * Calibrate registered applications.
2873 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2876 struct lttng_ht_iter iter
;
2877 struct ust_app
*app
;
2881 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2882 if (!app
->compatible
) {
2884 * TODO: In time, we should notice the caller of this error by
2885 * telling him that this is a version error.
2890 health_code_update(&health_thread_cmd
);
2892 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2896 /* Means that it's not implemented on the tracer side. */
2900 /* TODO: Report error to user */
2901 DBG2("Calibrate app PID %d returned with error %d",
2908 DBG("UST app global domain calibration finished");
2912 health_code_update(&health_thread_cmd
);