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 ust_app_session
*ua_sess
, *tmp_ua_sess
;
263 /* Delete ust app sessions info */
267 lttng_ht_destroy(app
->sessions
);
270 cds_list_for_each_entry_safe(ua_sess
, tmp_ua_sess
, &app
->teardown_head
,
272 /* Free every object in the session and the session. */
273 delete_ust_app_session(sock
, ua_sess
);
277 * Wait until we have deleted the application from the sock hash table
278 * before closing this socket, otherwise an application could re-use the
279 * socket ID and race with the teardown, using the same hash table entry.
281 * It's OK to leave the close in call_rcu. We want it to stay unique for
282 * all RCU readers that could run concurrently with unregister app,
283 * therefore we _need_ to only close that socket after a grace period. So
284 * it should stay in this RCU callback.
286 * This close() is a very important step of the synchronization model so
287 * every modification to this function must be carefully reviewed.
293 lttng_fd_put(LTTNG_FD_APPS
, 1);
295 DBG2("UST app pid %d deleted", app
->pid
);
302 * URCU intermediate call to delete an UST app.
305 void delete_ust_app_rcu(struct rcu_head
*head
)
307 struct lttng_ht_node_ulong
*node
=
308 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
309 struct ust_app
*app
=
310 caa_container_of(node
, struct ust_app
, pid_n
);
312 DBG3("Call RCU deleting app PID %d", app
->pid
);
317 * Alloc new UST app session.
320 struct ust_app_session
*alloc_ust_app_session(void)
322 struct ust_app_session
*ua_sess
;
324 /* Init most of the default value by allocating and zeroing */
325 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
326 if (ua_sess
== NULL
) {
331 ua_sess
->handle
= -1;
332 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
341 * Alloc new UST app channel.
344 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
345 struct lttng_ust_channel
*attr
)
347 struct ust_app_channel
*ua_chan
;
349 /* Init most of the default value by allocating and zeroing */
350 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
351 if (ua_chan
== NULL
) {
356 /* Setup channel name */
357 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
358 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
360 ua_chan
->enabled
= 1;
361 ua_chan
->handle
= -1;
362 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
363 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
364 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
366 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
368 /* Copy attributes */
370 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
373 DBG3("UST app channel %s allocated", ua_chan
->name
);
382 * Alloc new UST app event.
385 struct ust_app_event
*alloc_ust_app_event(char *name
,
386 struct lttng_ust_event
*attr
)
388 struct ust_app_event
*ua_event
;
390 /* Init most of the default value by allocating and zeroing */
391 ua_event
= zmalloc(sizeof(struct ust_app_event
));
392 if (ua_event
== NULL
) {
397 ua_event
->enabled
= 1;
398 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
399 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
400 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
402 /* Copy attributes */
404 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
407 DBG3("UST app event %s allocated", ua_event
->name
);
416 * Alloc new UST app context.
419 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
421 struct ust_app_ctx
*ua_ctx
;
423 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
424 if (ua_ctx
== NULL
) {
429 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
432 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
439 * Allocate a filter and copy the given original filter.
441 * Return allocated filter or NULL on error.
443 static struct lttng_ust_filter_bytecode
*alloc_copy_ust_app_filter(
444 struct lttng_ust_filter_bytecode
*orig_f
)
446 struct lttng_ust_filter_bytecode
*filter
= NULL
;
448 /* Copy filter bytecode */
449 filter
= zmalloc(sizeof(*filter
) + orig_f
->len
);
451 PERROR("zmalloc alloc ust app filter");
455 memcpy(filter
, orig_f
, sizeof(*filter
) + orig_f
->len
);
462 * Find an ust_app using the sock and return it. RCU read side lock must be
463 * held before calling this helper function.
466 struct ust_app
*find_app_by_sock(int sock
)
468 struct lttng_ht_node_ulong
*node
;
469 struct lttng_ht_iter iter
;
471 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
472 node
= lttng_ht_iter_get_node_ulong(&iter
);
474 DBG2("UST app find by sock %d not found", sock
);
478 return caa_container_of(node
, struct ust_app
, sock_n
);
485 * Lookup for an ust app event based on event name, filter bytecode and the
488 * Return an ust_app_event object or NULL on error.
490 static struct ust_app_event
*find_ust_app_event(struct lttng_ht
*ht
,
491 char *name
, struct lttng_ust_filter_bytecode
*filter
, int loglevel
)
493 struct lttng_ht_iter iter
;
494 struct lttng_ht_node_str
*node
;
495 struct ust_app_event
*event
= NULL
;
496 struct ust_app_ht_key key
;
501 /* Setup key for event lookup. */
504 key
.loglevel
= loglevel
;
506 /* Lookup using the event name as hash and a custom match fct. */
507 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
508 ht_match_ust_app_event
, &key
, &iter
.iter
);
509 node
= lttng_ht_iter_get_node_str(&iter
);
514 event
= caa_container_of(node
, struct ust_app_event
, node
);
521 * Create the channel context on the tracer.
524 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
525 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
529 health_code_update(&health_thread_cmd
);
531 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
532 ua_chan
->obj
, &ua_ctx
->obj
);
537 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
539 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
542 health_code_update(&health_thread_cmd
);
547 * Set the filter on the tracer.
550 int set_ust_event_filter(struct ust_app_event
*ua_event
,
555 health_code_update(&health_thread_cmd
);
557 if (!ua_event
->filter
) {
562 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
568 DBG2("UST filter set successfully for event %s", ua_event
->name
);
571 health_code_update(&health_thread_cmd
);
576 * Disable the specified event on to UST tracer for the UST session.
578 static int disable_ust_event(struct ust_app
*app
,
579 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
583 health_code_update(&health_thread_cmd
);
585 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
587 ERR("UST app event %s disable failed for app (pid: %d) "
588 "and session handle %d with ret %d",
589 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
593 DBG2("UST app event %s disabled successfully for app (pid: %d)",
594 ua_event
->attr
.name
, app
->pid
);
597 health_code_update(&health_thread_cmd
);
602 * Disable the specified channel on to UST tracer for the UST session.
604 static int disable_ust_channel(struct ust_app
*app
,
605 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
609 health_code_update(&health_thread_cmd
);
611 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
613 ERR("UST app channel %s disable failed for app (pid: %d) "
614 "and session handle %d with ret %d",
615 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
619 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
620 ua_chan
->name
, app
->pid
);
623 health_code_update(&health_thread_cmd
);
628 * Enable the specified channel on to UST tracer for the UST session.
630 static int enable_ust_channel(struct ust_app
*app
,
631 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
635 health_code_update(&health_thread_cmd
);
637 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
639 ERR("UST app channel %s enable failed for app (pid: %d) "
640 "and session handle %d with ret %d",
641 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
645 ua_chan
->enabled
= 1;
647 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
648 ua_chan
->name
, app
->pid
);
651 health_code_update(&health_thread_cmd
);
656 * Enable the specified event on to UST tracer for the UST session.
658 static int enable_ust_event(struct ust_app
*app
,
659 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
663 health_code_update(&health_thread_cmd
);
665 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
667 ERR("UST app event %s enable failed for app (pid: %d) "
668 "and session handle %d with ret %d",
669 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
673 DBG2("UST app event %s enabled successfully for app (pid: %d)",
674 ua_event
->attr
.name
, app
->pid
);
677 health_code_update(&health_thread_cmd
);
682 * Open metadata onto the UST tracer for a UST session.
684 static int open_ust_metadata(struct ust_app
*app
,
685 struct ust_app_session
*ua_sess
)
688 struct lttng_ust_channel_attr uattr
;
690 health_code_update(&health_thread_cmd
);
692 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
693 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
694 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
695 uattr
.switch_timer_interval
=
696 ua_sess
->metadata
->attr
.switch_timer_interval
;
697 uattr
.read_timer_interval
=
698 ua_sess
->metadata
->attr
.read_timer_interval
;
699 uattr
.output
= ua_sess
->metadata
->attr
.output
;
701 /* We are going to receive 2 fds, we need to reserve them. */
702 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
704 ERR("Exhausted number of available FD upon metadata open");
707 /* UST tracer metadata creation */
708 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
709 &ua_sess
->metadata
->obj
);
711 ERR("UST app open metadata failed for app pid:%d with ret %d",
716 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
719 health_code_update(&health_thread_cmd
);
724 * Create stream onto the UST tracer for a UST session.
726 static int create_ust_stream(struct ust_app
*app
,
727 struct ust_app_session
*ua_sess
)
731 health_code_update(&health_thread_cmd
);
733 /* We are going to receive 2 fds, we need to reserve them. */
734 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
736 ERR("Exhausted number of available FD upon metadata stream create");
739 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
740 &ua_sess
->metadata
->stream_obj
);
742 ERR("UST create metadata stream failed");
747 health_code_update(&health_thread_cmd
);
752 * Create the specified channel onto the UST tracer for a UST session.
754 static int create_ust_channel(struct ust_app
*app
,
755 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
759 health_code_update(&health_thread_cmd
);
761 /* TODO: remove cast and use lttng-ust-abi.h */
763 /* We are going to receive 2 fds, we need to reserve them. */
764 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
766 ERR("Exhausted number of available FD upon create channel");
770 health_code_update(&health_thread_cmd
);
772 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
773 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
775 ERR("Creating channel %s for app (pid: %d, sock: %d) "
776 "and session handle %d with ret %d",
777 ua_chan
->name
, app
->pid
, app
->sock
,
778 ua_sess
->handle
, ret
);
779 lttng_fd_put(LTTNG_FD_APPS
, 2);
783 ua_chan
->handle
= ua_chan
->obj
->handle
;
785 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
786 ua_chan
->name
, app
->pid
, app
->sock
);
788 health_code_update(&health_thread_cmd
);
790 /* If channel is not enabled, disable it on the tracer */
791 if (!ua_chan
->enabled
) {
792 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
799 health_code_update(&health_thread_cmd
);
804 * Create the specified event onto the UST tracer for a UST session.
807 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
808 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
812 health_code_update(&health_thread_cmd
);
814 /* Create UST event on tracer */
815 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
818 ERR("Error ustctl create event %s for app pid: %d with ret %d",
819 ua_event
->attr
.name
, app
->pid
, ret
);
823 ua_event
->handle
= ua_event
->obj
->handle
;
825 DBG2("UST app event %s created successfully for pid:%d",
826 ua_event
->attr
.name
, app
->pid
);
828 health_code_update(&health_thread_cmd
);
830 /* Set filter if one is present. */
831 if (ua_event
->filter
) {
832 ret
= set_ust_event_filter(ua_event
, app
);
838 /* If event not enabled, disable it on the tracer */
839 if (ua_event
->enabled
== 0) {
840 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
843 * If we hit an EPERM, something is wrong with our disable call. If
844 * we get an EEXIST, there is a problem on the tracer side since we
848 case -LTTNG_UST_ERR_PERM
:
849 /* Code flow problem */
851 case -LTTNG_UST_ERR_EXIST
:
852 /* It's OK for our use case. */
863 health_code_update(&health_thread_cmd
);
868 * Copy data between an UST app event and a LTT event.
870 static void shadow_copy_event(struct ust_app_event
*ua_event
,
871 struct ltt_ust_event
*uevent
)
873 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
874 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
876 ua_event
->enabled
= uevent
->enabled
;
878 /* Copy event attributes */
879 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
881 /* Copy filter bytecode */
882 if (uevent
->filter
) {
883 ua_event
->filter
= alloc_copy_ust_app_filter(uevent
->filter
);
884 /* Filter might be NULL here in case of ENONEM. */
889 * Copy data between an UST app channel and a LTT channel.
891 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
892 struct ltt_ust_channel
*uchan
)
894 struct lttng_ht_iter iter
;
895 struct ltt_ust_event
*uevent
;
896 struct ltt_ust_context
*uctx
;
897 struct ust_app_event
*ua_event
;
898 struct ust_app_ctx
*ua_ctx
;
900 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
902 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
903 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
904 /* Copy event attributes */
905 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
907 ua_chan
->enabled
= uchan
->enabled
;
909 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
910 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
911 if (ua_ctx
== NULL
) {
914 lttng_ht_node_init_ulong(&ua_ctx
->node
,
915 (unsigned long) ua_ctx
->ctx
.ctx
);
916 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
919 /* Copy all events from ltt ust channel to ust app channel */
920 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
921 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
922 uevent
->filter
, uevent
->attr
.loglevel
);
923 if (ua_event
== NULL
) {
924 DBG2("UST event %s not found on shadow copy channel",
926 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
927 if (ua_event
== NULL
) {
930 shadow_copy_event(ua_event
, uevent
);
931 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
935 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
939 * Copy data between a UST app session and a regular LTT session.
941 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
942 struct ltt_ust_session
*usess
, struct ust_app
*app
)
944 struct lttng_ht_node_str
*ua_chan_node
;
945 struct lttng_ht_iter iter
;
946 struct ltt_ust_channel
*uchan
;
947 struct ust_app_channel
*ua_chan
;
953 /* Get date and time for unique app path */
955 timeinfo
= localtime(&rawtime
);
956 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
958 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
960 ua_sess
->id
= usess
->id
;
961 ua_sess
->uid
= usess
->uid
;
962 ua_sess
->gid
= usess
->gid
;
964 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
967 PERROR("asprintf UST shadow copy session");
968 /* TODO: We cannot return an error from here.. */
972 /* TODO: support all UST domain */
974 /* Iterate over all channels in global domain. */
975 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
977 struct lttng_ht_iter uiter
;
979 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
980 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
981 if (ua_chan_node
!= NULL
) {
982 /* Session exist. Contiuing. */
986 DBG2("Channel %s not found on shadow session copy, creating it",
988 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
989 if (ua_chan
== NULL
) {
990 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
994 shadow_copy_channel(ua_chan
, uchan
);
995 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1000 * Lookup sesison wrapper.
1003 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
1004 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
1006 /* Get right UST app session from app */
1007 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
1011 * Return ust app session from the app session hashtable using the UST session
1014 static struct ust_app_session
*lookup_session_by_app(
1015 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1017 struct lttng_ht_iter iter
;
1018 struct lttng_ht_node_ulong
*node
;
1020 __lookup_session_by_app(usess
, app
, &iter
);
1021 node
= lttng_ht_iter_get_node_ulong(&iter
);
1026 return caa_container_of(node
, struct ust_app_session
, node
);
1033 * Create a UST session onto the tracer of app and add it the session
1036 * Return ust app session or NULL on error.
1038 static struct ust_app_session
*create_ust_app_session(
1039 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1041 struct ust_app_session
*ua_sess
;
1043 health_code_update(&health_thread_cmd
);
1045 ua_sess
= lookup_session_by_app(usess
, app
);
1046 if (ua_sess
== NULL
) {
1047 DBG2("UST app pid: %d session id %d not found, creating it",
1048 app
->pid
, usess
->id
);
1049 ua_sess
= alloc_ust_app_session();
1050 if (ua_sess
== NULL
) {
1051 /* Only malloc can failed so something is really wrong */
1054 shadow_copy_session(ua_sess
, usess
, app
);
1057 health_code_update(&health_thread_cmd
);
1059 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. Set ua_chanp of the
1217 * newly created channel if not NULL.
1219 static int create_ust_app_channel(struct ust_app_session
*ua_sess
,
1220 struct ltt_ust_channel
*uchan
, struct ust_app
*app
,
1221 struct ust_app_channel
**ua_chanp
)
1224 struct lttng_ht_iter iter
;
1225 struct lttng_ht_node_str
*ua_chan_node
;
1226 struct ust_app_channel
*ua_chan
;
1228 /* Lookup channel in the ust app session */
1229 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1230 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1231 if (ua_chan_node
!= NULL
) {
1232 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1236 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1237 if (ua_chan
== NULL
) {
1238 /* Only malloc can fail here */
1242 shadow_copy_channel(ua_chan
, uchan
);
1244 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1246 /* Not found previously means that it does not exist on the tracer */
1247 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1251 /* Only add the channel if successful on the tracer side. */
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
,
1259 *ua_chanp
= ua_chan
;
1262 /* Everything went well. */
1266 delete_ust_app_channel(-1, ua_chan
);
1271 * Create UST app event and create it on the tracer side.
1274 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1275 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1276 struct ust_app
*app
)
1279 struct ust_app_event
*ua_event
;
1281 /* Get event node */
1282 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
1283 uevent
->filter
, uevent
->attr
.loglevel
);
1284 if (ua_event
!= NULL
) {
1289 /* Does not exist so create one */
1290 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1291 if (ua_event
== NULL
) {
1292 /* Only malloc can failed so something is really wrong */
1296 shadow_copy_event(ua_event
, uevent
);
1298 /* Create it on the tracer side */
1299 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1301 /* Not found previously means that it does not exist on the tracer */
1302 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1306 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
1308 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1315 /* Valid. Calling here is already in a read side lock */
1316 delete_ust_app_event(-1, ua_event
);
1321 * Create UST metadata and open it on the tracer side.
1323 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1324 char *pathname
, struct ust_app
*app
)
1328 if (ua_sess
->metadata
== NULL
) {
1329 /* Allocate UST metadata */
1330 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1331 if (ua_sess
->metadata
== NULL
) {
1332 /* malloc() failed */
1336 ret
= open_ust_metadata(app
, ua_sess
);
1338 DBG3("Opening metadata failed. Cleaning up memory");
1340 /* Cleanup failed metadata struct */
1341 free(ua_sess
->metadata
);
1343 * This is very important because delete_ust_app_session check if
1344 * the pointer is null or not in order to delete the metadata.
1346 ua_sess
->metadata
= NULL
;
1350 DBG2("UST metadata opened for app pid %d", app
->pid
);
1353 /* Open UST metadata stream */
1354 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1355 ret
= create_ust_stream(app
, ua_sess
);
1360 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1361 "%s/metadata", ua_sess
->path
);
1363 PERROR("asprintf UST create stream");
1367 DBG2("UST metadata stream object created for app pid %d",
1370 ERR("Attempting to create stream without metadata opened");
1381 * Return pointer to traceable apps list.
1383 struct lttng_ht
*ust_app_get_ht(void)
1389 * Return ust app pointer or NULL if not found.
1391 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1393 struct lttng_ht_node_ulong
*node
;
1394 struct lttng_ht_iter iter
;
1397 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1398 node
= lttng_ht_iter_get_node_ulong(&iter
);
1400 DBG2("UST app no found with pid %d", pid
);
1405 DBG2("Found UST app by pid %d", pid
);
1407 return caa_container_of(node
, struct ust_app
, pid_n
);
1415 * Using pid and uid (of the app), allocate a new ust_app struct and
1416 * add it to the global traceable app list.
1418 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1419 * bitness is not supported.
1421 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1423 struct ust_app
*lta
;
1426 if ((msg
->bits_per_long
== 64 &&
1427 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
1428 || (msg
->bits_per_long
== 32 &&
1429 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
1430 ERR("Registration failed: application \"%s\" (pid: %d) has "
1431 "%d-bit long, but no consumerd for this long size is available.\n",
1432 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1437 lttng_fd_put(LTTNG_FD_APPS
, 1);
1440 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1441 ERR("Registration failed: application \"%s\" (pid: %d) has "
1442 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1443 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1448 lttng_fd_put(LTTNG_FD_APPS
, 1);
1451 lta
= zmalloc(sizeof(struct ust_app
));
1457 lta
->ppid
= msg
->ppid
;
1458 lta
->uid
= msg
->uid
;
1459 lta
->gid
= msg
->gid
;
1460 lta
->compatible
= 0; /* Not compatible until proven */
1461 lta
->bits_per_long
= msg
->bits_per_long
;
1462 lta
->v_major
= msg
->major
;
1463 lta
->v_minor
= msg
->minor
;
1464 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1465 lta
->name
[16] = '\0';
1466 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1468 lta
->pid
= msg
->pid
;
1469 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1471 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1473 CDS_INIT_LIST_HEAD(<a
->teardown_head
);
1478 * On a re-registration, we want to kick out the previous registration of
1481 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1484 * The socket _should_ be unique until _we_ call close. So, a add_unique
1485 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1486 * already in the table.
1488 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1492 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1493 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1494 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1500 * Unregister app by removing it from the global traceable app list and freeing
1503 * The socket is already closed at this point so no close to sock.
1505 void ust_app_unregister(int sock
)
1507 struct ust_app
*lta
;
1508 struct lttng_ht_node_ulong
*node
;
1509 struct lttng_ht_iter iter
;
1510 struct ust_app_session
*ua_sess
;
1515 /* Get the node reference for a call_rcu */
1516 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1517 node
= lttng_ht_iter_get_node_ulong(&iter
);
1519 ERR("Unable to find app by sock %d", sock
);
1523 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1525 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1527 /* Remove application from PID hash table */
1528 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1531 /* Assign second node for deletion */
1532 iter
.iter
.node
= <a
->pid_n
.node
;
1535 * Ignore return value since the node might have been removed before by an
1536 * add replace during app registration because the PID can be reassigned by
1539 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1541 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
1545 /* Remove sessions so they are not visible during deletion.*/
1546 cds_lfht_for_each_entry(lta
->sessions
->ht
, &iter
.iter
, ua_sess
,
1548 ret
= lttng_ht_del(lta
->sessions
, &iter
);
1550 /* The session was already removed so scheduled for teardown. */
1555 * Add session to list for teardown. This is safe since at this point we
1556 * are the only one using this list.
1558 cds_list_add(&ua_sess
->teardown_node
, <a
->teardown_head
);
1562 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1570 * Return traceable_app_count
1572 unsigned long ust_app_list_count(void)
1574 unsigned long count
;
1577 count
= lttng_ht_get_count(ust_app_ht
);
1584 * Fill events array with all events name of all registered apps.
1586 int ust_app_list_events(struct lttng_event
**events
)
1589 size_t nbmem
, count
= 0;
1590 struct lttng_ht_iter iter
;
1591 struct ust_app
*app
;
1592 struct lttng_event
*tmp_event
;
1594 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1595 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1596 if (tmp_event
== NULL
) {
1597 PERROR("zmalloc ust app events");
1604 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1605 struct lttng_ust_tracepoint_iter uiter
;
1607 health_code_update(&health_thread_cmd
);
1609 if (!app
->compatible
) {
1611 * TODO: In time, we should notice the caller of this error by
1612 * telling him that this is a version error.
1616 handle
= ustctl_tracepoint_list(app
->sock
);
1618 ERR("UST app list events getting handle failed for app pid %d",
1623 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1624 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1625 health_code_update(&health_thread_cmd
);
1626 if (count
>= nbmem
) {
1627 /* In case the realloc fails, we free the memory */
1630 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1633 ptr
= realloc(tmp_event
, nbmem
* sizeof(struct lttng_event
));
1635 PERROR("realloc ust app events");
1642 memcpy(tmp_event
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1643 tmp_event
[count
].loglevel
= uiter
.loglevel
;
1644 tmp_event
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1645 tmp_event
[count
].pid
= app
->pid
;
1646 tmp_event
[count
].enabled
= -1;
1652 *events
= tmp_event
;
1654 DBG2("UST app list events done (%zu events)", count
);
1659 health_code_update(&health_thread_cmd
);
1664 * Fill events array with all events name of all registered apps.
1666 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1669 size_t nbmem
, count
= 0;
1670 struct lttng_ht_iter iter
;
1671 struct ust_app
*app
;
1672 struct lttng_event_field
*tmp_event
;
1674 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1675 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1676 if (tmp_event
== NULL
) {
1677 PERROR("zmalloc ust app event fields");
1684 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1685 struct lttng_ust_field_iter uiter
;
1687 health_code_update(&health_thread_cmd
);
1689 if (!app
->compatible
) {
1691 * TODO: In time, we should notice the caller of this error by
1692 * telling him that this is a version error.
1696 handle
= ustctl_tracepoint_field_list(app
->sock
);
1698 ERR("UST app list event fields getting handle failed for app pid %d",
1703 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1704 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1705 health_code_update(&health_thread_cmd
);
1706 if (count
>= nbmem
) {
1707 /* In case the realloc fails, we free the memory */
1710 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1713 ptr
= realloc(tmp_event
, nbmem
* sizeof(struct lttng_event_field
));
1715 PERROR("realloc ust app event fields");
1723 memcpy(tmp_event
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1724 tmp_event
[count
].type
= uiter
.type
;
1725 tmp_event
[count
].nowrite
= uiter
.nowrite
;
1727 memcpy(tmp_event
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1728 tmp_event
[count
].event
.loglevel
= uiter
.loglevel
;
1729 tmp_event
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1730 tmp_event
[count
].event
.pid
= app
->pid
;
1731 tmp_event
[count
].event
.enabled
= -1;
1737 *fields
= tmp_event
;
1739 DBG2("UST app list event fields done (%zu events)", count
);
1744 health_code_update(&health_thread_cmd
);
1749 * Free and clean all traceable apps of the global list.
1751 void ust_app_clean_list(void)
1754 struct ust_app
*app
;
1755 struct lttng_ht_iter iter
;
1757 DBG2("UST app cleaning registered apps hash table");
1761 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1762 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1764 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
1767 /* Cleanup socket hash table */
1768 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
1770 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1774 /* Destroy is done only when the ht is empty */
1775 lttng_ht_destroy(ust_app_ht
);
1776 lttng_ht_destroy(ust_app_ht_by_sock
);
1782 * Init UST app hash table.
1784 void ust_app_ht_alloc(void)
1786 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1787 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1791 * For a specific UST session, disable the channel for all registered apps.
1793 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1794 struct ltt_ust_channel
*uchan
)
1797 struct lttng_ht_iter iter
;
1798 struct lttng_ht_node_str
*ua_chan_node
;
1799 struct ust_app
*app
;
1800 struct ust_app_session
*ua_sess
;
1801 struct ust_app_channel
*ua_chan
;
1803 if (usess
== NULL
|| uchan
== NULL
) {
1804 ERR("Disabling UST global channel with NULL values");
1809 DBG2("UST app disabling channel %s from global domain for session id %d",
1810 uchan
->name
, usess
->id
);
1814 /* For every registered applications */
1815 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1816 struct lttng_ht_iter uiter
;
1817 if (!app
->compatible
) {
1819 * TODO: In time, we should notice the caller of this error by
1820 * telling him that this is a version error.
1824 ua_sess
= lookup_session_by_app(usess
, app
);
1825 if (ua_sess
== NULL
) {
1830 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1831 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1832 /* If the session if found for the app, the channel must be there */
1833 assert(ua_chan_node
);
1835 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1836 /* The channel must not be already disabled */
1837 assert(ua_chan
->enabled
== 1);
1839 /* Disable channel onto application */
1840 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1842 /* XXX: We might want to report this error at some point... */
1854 * For a specific UST session, enable the channel for all registered apps.
1856 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1857 struct ltt_ust_channel
*uchan
)
1860 struct lttng_ht_iter iter
;
1861 struct ust_app
*app
;
1862 struct ust_app_session
*ua_sess
;
1864 if (usess
== NULL
|| uchan
== NULL
) {
1865 ERR("Adding UST global channel to NULL values");
1870 DBG2("UST app enabling channel %s to global domain for session id %d",
1871 uchan
->name
, usess
->id
);
1875 /* For every registered applications */
1876 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1877 if (!app
->compatible
) {
1879 * TODO: In time, we should notice the caller of this error by
1880 * telling him that this is a version error.
1884 ua_sess
= lookup_session_by_app(usess
, app
);
1885 if (ua_sess
== NULL
) {
1889 /* Enable channel onto application */
1890 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1892 /* XXX: We might want to report this error at some point... */
1904 * Disable an event in a channel and for a specific session.
1906 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1907 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1910 struct lttng_ht_iter iter
, uiter
;
1911 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1912 struct ust_app
*app
;
1913 struct ust_app_session
*ua_sess
;
1914 struct ust_app_channel
*ua_chan
;
1915 struct ust_app_event
*ua_event
;
1917 DBG("UST app disabling event %s for all apps in channel "
1918 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1922 /* For all registered applications */
1923 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1924 if (!app
->compatible
) {
1926 * TODO: In time, we should notice the caller of this error by
1927 * telling him that this is a version error.
1931 ua_sess
= lookup_session_by_app(usess
, app
);
1932 if (ua_sess
== NULL
) {
1937 /* Lookup channel in the ust app session */
1938 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1939 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1940 if (ua_chan_node
== NULL
) {
1941 DBG2("Channel %s not found in session id %d for app pid %d."
1942 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1945 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1947 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1948 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1949 if (ua_event_node
== NULL
) {
1950 DBG2("Event %s not found in channel %s for app pid %d."
1951 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1954 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1956 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1958 /* XXX: Report error someday... */
1969 * For a specific UST session and UST channel, the event for all
1972 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1973 struct ltt_ust_channel
*uchan
)
1976 struct lttng_ht_iter iter
, uiter
;
1977 struct lttng_ht_node_str
*ua_chan_node
;
1978 struct ust_app
*app
;
1979 struct ust_app_session
*ua_sess
;
1980 struct ust_app_channel
*ua_chan
;
1981 struct ust_app_event
*ua_event
;
1983 DBG("UST app disabling all event for all apps in channel "
1984 "%s for session id %d", uchan
->name
, usess
->id
);
1988 /* For all registered applications */
1989 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1990 if (!app
->compatible
) {
1992 * TODO: In time, we should notice the caller of this error by
1993 * telling him that this is a version error.
1997 ua_sess
= lookup_session_by_app(usess
, app
);
1999 /* The application has problem or is probably dead. */
2003 /* Lookup channel in the ust app session */
2004 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2005 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2006 /* If the channel is not found, there is a code flow error */
2007 assert(ua_chan_node
);
2009 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2011 /* Disable each events of channel */
2012 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2014 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2016 /* XXX: Report error someday... */
2028 * For a specific UST session, create the channel for all registered apps.
2030 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
2031 struct ltt_ust_channel
*uchan
)
2034 struct lttng_ht_iter iter
;
2035 struct ust_app
*app
;
2036 struct ust_app_session
*ua_sess
;
2038 /* Very wrong code flow */
2042 DBG2("UST app adding channel %s to global domain for session id %d",
2043 uchan
->name
, usess
->id
);
2047 /* For every registered applications */
2048 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2049 if (!app
->compatible
) {
2051 * TODO: In time, we should notice the caller of this error by
2052 * telling him that this is a version error.
2057 * Create session on the tracer side and add it to app session HT. Note
2058 * that if session exist, it will simply return a pointer to the ust
2061 ua_sess
= create_ust_app_session(usess
, app
);
2062 if (ua_sess
== NULL
) {
2063 /* The malloc() failed. */
2065 goto error_rcu_unlock
;
2066 } else if (ua_sess
== (void *) -1UL) {
2068 * The application's socket is not valid. Either a bad socket or a
2069 * timeout on it. We can't inform yet the caller that for a
2070 * specific app, the session failed so we continue here.
2075 /* Create channel onto application. We don't need the chan ref. */
2076 ret
= create_ust_app_channel(ua_sess
, uchan
, app
, NULL
);
2077 if (ret
< 0 && ret
== -ENOMEM
) {
2078 /* No more memory is a fatal error. Stop right now. */
2079 goto error_rcu_unlock
;
2089 * Enable event for a specific session and channel on the tracer.
2091 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
2092 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2095 struct lttng_ht_iter iter
, uiter
;
2096 struct lttng_ht_node_str
*ua_chan_node
;
2097 struct ust_app
*app
;
2098 struct ust_app_session
*ua_sess
;
2099 struct ust_app_channel
*ua_chan
;
2100 struct ust_app_event
*ua_event
;
2102 DBG("UST app enabling event %s for all apps for session id %d",
2103 uevent
->attr
.name
, usess
->id
);
2106 * NOTE: At this point, this function is called only if the session and
2107 * channel passed are already created for all apps. and enabled on the
2113 /* For all registered applications */
2114 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2115 if (!app
->compatible
) {
2117 * TODO: In time, we should notice the caller of this error by
2118 * telling him that this is a version error.
2122 ua_sess
= lookup_session_by_app(usess
, app
);
2124 /* The application has problem or is probably dead. */
2128 /* Lookup channel in the ust app session */
2129 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2130 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2131 /* If the channel is not found, there is a code flow error */
2132 assert(ua_chan_node
);
2134 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2136 /* Get event node */
2137 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2138 uevent
->filter
, uevent
->attr
.loglevel
);
2139 if (ua_event
== NULL
) {
2140 DBG3("UST app enable event %s not found for app PID %d."
2141 "Skipping app", uevent
->attr
.name
, app
->pid
);
2145 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2157 * For a specific existing UST session and UST channel, creates the event for
2158 * all registered apps.
2160 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2161 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2164 struct lttng_ht_iter iter
, uiter
;
2165 struct lttng_ht_node_str
*ua_chan_node
;
2166 struct ust_app
*app
;
2167 struct ust_app_session
*ua_sess
;
2168 struct ust_app_channel
*ua_chan
;
2170 DBG("UST app creating event %s for all apps for session id %d",
2171 uevent
->attr
.name
, usess
->id
);
2175 /* For all registered applications */
2176 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2177 if (!app
->compatible
) {
2179 * TODO: In time, we should notice the caller of this error by
2180 * telling him that this is a version error.
2184 ua_sess
= lookup_session_by_app(usess
, app
);
2186 /* The application has problem or is probably dead. */
2190 /* Lookup channel in the ust app session */
2191 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2192 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2193 /* If the channel is not found, there is a code flow error */
2194 assert(ua_chan_node
);
2196 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2198 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2200 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
2201 /* Possible value at this point: -ENOMEM. If so, we stop! */
2204 DBG2("UST app event %s already exist on app PID %d",
2205 uevent
->attr
.name
, app
->pid
);
2216 * Start tracing for a specific UST session and app.
2218 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2221 struct lttng_ht_iter iter
;
2222 struct ust_app_session
*ua_sess
;
2223 struct ust_app_channel
*ua_chan
;
2224 struct ltt_ust_stream
*ustream
;
2225 struct consumer_socket
*socket
;
2227 DBG("Starting tracing for ust app pid %d", app
->pid
);
2231 if (!app
->compatible
) {
2235 ua_sess
= lookup_session_by_app(usess
, app
);
2236 if (ua_sess
== NULL
) {
2237 /* The session is in teardown process. Ignore and continue. */
2241 /* Upon restart, we skip the setup, already done */
2242 if (ua_sess
->started
) {
2246 /* Create directories if consumer is LOCAL and has a path defined. */
2247 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
2248 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
2249 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
2250 S_IRWXU
| S_IRWXG
, usess
->uid
, usess
->gid
);
2252 if (ret
!= -EEXIST
) {
2253 ERR("Trace directory creation error");
2255 goto error_rcu_unlock
;
2260 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2262 ret
= LTTNG_ERR_UST_META_FAIL
;
2263 goto error_rcu_unlock
;
2266 /* For each channel */
2267 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2269 /* Create all streams */
2271 /* Create UST stream */
2272 ustream
= zmalloc(sizeof(*ustream
));
2273 if (ustream
== NULL
) {
2274 PERROR("zmalloc ust stream");
2275 goto error_rcu_unlock
;
2278 /* We are going to receive 2 fds, we need to reserve them. */
2279 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2281 ERR("Exhausted number of available FD upon stream create");
2283 goto error_rcu_unlock
;
2286 health_code_update(&health_thread_cmd
);
2288 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2291 /* Got all streams */
2292 lttng_fd_put(LTTNG_FD_APPS
, 2);
2294 ret
= LTTNG_ERR_UST_STREAM_FAIL
;
2297 ustream
->handle
= ustream
->obj
->handle
;
2299 health_code_update(&health_thread_cmd
);
2301 /* Order is important */
2302 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2303 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2304 ua_chan
->name
, ua_chan
->streams
.count
);
2305 ua_chan
->streams
.count
++;
2307 PERROR("asprintf UST create stream");
2309 * XXX what should we do here with the
2314 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2318 health_code_update(&health_thread_cmd
);
2321 switch (app
->bits_per_long
) {
2323 socket
= consumer_find_socket(uatomic_read(&ust_consumerd64_fd
),
2325 if (socket
== NULL
) {
2330 socket
= consumer_find_socket(uatomic_read(&ust_consumerd32_fd
),
2332 if (socket
== NULL
) {
2338 goto error_rcu_unlock
;
2341 /* Setup UST consumer socket and send fds to it */
2342 ret
= ust_consumer_send_session(ua_sess
, usess
->consumer
, socket
);
2344 goto error_rcu_unlock
;
2347 health_code_update(&health_thread_cmd
);
2350 /* This start the UST tracing */
2351 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2353 ERR("Error starting tracing for app pid: %d", app
->pid
);
2354 goto error_rcu_unlock
;
2357 /* Indicate that the session has been started once */
2358 ua_sess
->started
= 1;
2360 health_code_update(&health_thread_cmd
);
2362 /* Quiescent wait after starting trace */
2363 ustctl_wait_quiescent(app
->sock
);
2367 health_code_update(&health_thread_cmd
);
2372 health_code_update(&health_thread_cmd
);
2377 * Stop tracing for a specific UST session and app.
2379 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2382 struct lttng_ht_iter iter
;
2383 struct ust_app_session
*ua_sess
;
2384 struct ust_app_channel
*ua_chan
;
2386 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2390 if (!app
->compatible
) {
2394 ua_sess
= lookup_session_by_app(usess
, app
);
2395 if (ua_sess
== NULL
) {
2400 * If started = 0, it means that stop trace has been called for a session
2401 * that was never started. It's possible since we can have a fail start
2402 * from either the application manager thread or the command thread. Simply
2403 * indicate that this is a stop error.
2405 if (ua_sess
->started
== 1) {
2406 goto error_rcu_unlock
;
2409 health_code_update(&health_thread_cmd
);
2411 /* This inhibits UST tracing */
2412 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2414 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2415 goto error_rcu_unlock
;
2418 health_code_update(&health_thread_cmd
);
2420 /* Quiescent wait after stopping trace */
2421 ustctl_wait_quiescent(app
->sock
);
2423 health_code_update(&health_thread_cmd
);
2425 /* Flushing buffers */
2426 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2428 health_code_update(&health_thread_cmd
);
2429 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2431 ERR("UST app PID %d channel %s flush failed with ret %d",
2432 app
->pid
, ua_chan
->name
, ret
);
2433 /* Continuing flushing all buffers */
2438 health_code_update(&health_thread_cmd
);
2440 /* Flush all buffers before stopping */
2441 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2443 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2449 health_code_update(&health_thread_cmd
);
2454 health_code_update(&health_thread_cmd
);
2459 * Destroy a specific UST session in apps.
2461 static int destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2463 struct ust_app_session
*ua_sess
;
2464 struct lttng_ust_object_data obj
;
2465 struct lttng_ht_iter iter
;
2466 struct lttng_ht_node_ulong
*node
;
2469 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2473 if (!app
->compatible
) {
2477 __lookup_session_by_app(usess
, app
, &iter
);
2478 node
= lttng_ht_iter_get_node_ulong(&iter
);
2480 /* Session is being or is deleted. */
2483 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2484 ret
= lttng_ht_del(app
->sessions
, &iter
);
2486 /* Already scheduled for teardown. */
2490 obj
.handle
= ua_sess
->handle
;
2493 obj
.memory_map_size
= 0;
2494 health_code_update(&health_thread_cmd
);
2495 ustctl_release_object(app
->sock
, &obj
);
2497 health_code_update(&health_thread_cmd
);
2498 delete_ust_app_session(app
->sock
, ua_sess
);
2500 /* Quiescent wait after stopping trace */
2501 ustctl_wait_quiescent(app
->sock
);
2505 health_code_update(&health_thread_cmd
);
2510 * Start tracing for the UST session.
2512 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2515 struct lttng_ht_iter iter
;
2516 struct ust_app
*app
;
2518 DBG("Starting all UST traces");
2522 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2523 ret
= ust_app_start_trace(usess
, app
);
2525 /* Continue to next apps even on error */
2536 * Start tracing for the UST session.
2538 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2541 struct lttng_ht_iter iter
;
2542 struct ust_app
*app
;
2544 DBG("Stopping all UST traces");
2548 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2549 ret
= ust_app_stop_trace(usess
, app
);
2551 /* Continue to next apps even on error */
2562 * Destroy app UST session.
2564 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2567 struct lttng_ht_iter iter
;
2568 struct ust_app
*app
;
2570 DBG("Destroy all UST traces");
2574 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2575 ret
= destroy_trace(usess
, app
);
2577 /* Continue to next apps even on error */
2588 * Add channels/events from UST global domain to registered apps at sock.
2590 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2593 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2594 struct ust_app
*app
;
2595 struct ust_app_session
*ua_sess
;
2596 struct ust_app_channel
*ua_chan
;
2597 struct ust_app_event
*ua_event
;
2598 struct ust_app_ctx
*ua_ctx
;
2602 DBG2("UST app global update for app sock %d for session id %d", sock
,
2607 app
= find_app_by_sock(sock
);
2609 ERR("Failed to update app sock %d", sock
);
2613 if (!app
->compatible
) {
2617 ua_sess
= create_ust_app_session(usess
, app
);
2618 if (ua_sess
== NULL
|| ua_sess
== (void *) -1UL) {
2619 /* Tracer is gone for this session and has been freed */
2624 * We can iterate safely here over all UST app session sicne the create ust
2625 * app session above made a shadow copy of the UST global domain from the
2628 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2630 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2632 /* FIXME: Should we quit here or continue... */
2636 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2638 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2640 /* FIXME: Should we quit here or continue... */
2646 /* For each events */
2647 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2649 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2651 /* FIXME: Should we quit here or continue... */
2655 ret
= set_ust_event_filter(ua_event
, app
);
2657 /* FIXME: Should we quit here or continue... */
2663 if (usess
->start_trace
) {
2664 ret
= ust_app_start_trace(usess
, app
);
2669 DBG2("UST trace started for app pid %d", app
->pid
);
2678 * Add context to a specific channel for global UST domain.
2680 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2681 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2684 struct lttng_ht_node_str
*ua_chan_node
;
2685 struct lttng_ht_iter iter
, uiter
;
2686 struct ust_app_channel
*ua_chan
= NULL
;
2687 struct ust_app_session
*ua_sess
;
2688 struct ust_app
*app
;
2692 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2693 if (!app
->compatible
) {
2695 * TODO: In time, we should notice the caller of this error by
2696 * telling him that this is a version error.
2700 ua_sess
= lookup_session_by_app(usess
, app
);
2701 if (ua_sess
== NULL
) {
2705 /* Lookup channel in the ust app session */
2706 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2707 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2708 if (ua_chan_node
== NULL
) {
2711 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2714 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2725 * Enable event for a channel from a UST session for a specific PID.
2727 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2728 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2731 struct lttng_ht_iter iter
;
2732 struct lttng_ht_node_str
*ua_chan_node
;
2733 struct ust_app
*app
;
2734 struct ust_app_session
*ua_sess
;
2735 struct ust_app_channel
*ua_chan
;
2736 struct ust_app_event
*ua_event
;
2738 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2742 app
= ust_app_find_by_pid(pid
);
2744 ERR("UST app enable event per PID %d not found", pid
);
2749 if (!app
->compatible
) {
2754 ua_sess
= lookup_session_by_app(usess
, app
);
2756 /* The application has problem or is probably dead. */
2760 /* Lookup channel in the ust app session */
2761 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2762 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2763 /* If the channel is not found, there is a code flow error */
2764 assert(ua_chan_node
);
2766 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2768 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2769 uevent
->filter
, uevent
->attr
.loglevel
);
2770 if (ua_event
== NULL
) {
2771 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2776 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2788 * Disable event for a channel from a UST session for a specific PID.
2790 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2791 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2794 struct lttng_ht_iter iter
;
2795 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2796 struct ust_app
*app
;
2797 struct ust_app_session
*ua_sess
;
2798 struct ust_app_channel
*ua_chan
;
2799 struct ust_app_event
*ua_event
;
2801 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2805 app
= ust_app_find_by_pid(pid
);
2807 ERR("UST app disable event per PID %d not found", pid
);
2812 if (!app
->compatible
) {
2817 ua_sess
= lookup_session_by_app(usess
, app
);
2819 /* The application has problem or is probably dead. */
2823 /* Lookup channel in the ust app session */
2824 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2825 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2826 if (ua_chan_node
== NULL
) {
2827 /* Channel does not exist, skip disabling */
2830 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2832 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2833 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2834 if (ua_event_node
== NULL
) {
2835 /* Event does not exist, skip disabling */
2838 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2840 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2851 * Validate version of UST apps and set the compatible bit.
2853 int ust_app_validate_version(int sock
)
2856 struct ust_app
*app
;
2860 app
= find_app_by_sock(sock
);
2863 health_code_update(&health_thread_cmd
);
2865 ret
= ustctl_tracer_version(sock
, &app
->version
);
2870 /* Validate version */
2871 if (app
->version
.major
!= UST_APP_MAJOR_VERSION
) {
2875 DBG2("UST app PID %d is compatible with internal major version %d "
2876 "(supporting == %d)", app
->pid
, app
->version
.major
,
2877 UST_APP_MAJOR_VERSION
);
2878 app
->compatible
= 1;
2880 health_code_update(&health_thread_cmd
);
2884 DBG2("UST app PID %d is not compatible with internal major version %d "
2885 "(supporting == %d)", app
->pid
, app
->version
.major
,
2886 UST_APP_MAJOR_VERSION
);
2887 app
->compatible
= 0;
2889 health_code_update(&health_thread_cmd
);
2894 * Calibrate registered applications.
2896 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2899 struct lttng_ht_iter iter
;
2900 struct ust_app
*app
;
2904 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2905 if (!app
->compatible
) {
2907 * TODO: In time, we should notice the caller of this error by
2908 * telling him that this is a version error.
2913 health_code_update(&health_thread_cmd
);
2915 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2919 /* Means that it's not implemented on the tracer side. */
2923 /* TODO: Report error to user */
2924 DBG2("Calibrate app PID %d returned with error %d",
2931 DBG("UST app global domain calibration finished");
2935 health_code_update(&health_thread_cmd
);