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();
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();
547 * Set the filter on the tracer.
550 int set_ust_event_filter(struct ust_app_event
*ua_event
,
555 health_code_update();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
724 * Create metadata stream onto the UST tracer for a given session.
726 static int create_ust_metadata_stream(struct ust_app
*app
,
727 struct ust_app_session
*ua_sess
)
731 health_code_update();
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 lttng_fd_put(LTTNG_FD_APPS
, 2);
743 ERR("UST create metadata stream failed");
748 health_code_update();
753 * Create the specified channel onto the UST tracer for a UST session.
755 static int create_ust_channel(struct ust_app
*app
,
756 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
760 health_code_update();
762 /* TODO: remove cast and use lttng-ust-abi.h */
764 /* We are going to receive 2 fds, we need to reserve them. */
765 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
767 ERR("Exhausted number of available FD upon create channel");
771 health_code_update();
773 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
774 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
776 ERR("Creating channel %s for app (pid: %d, sock: %d) "
777 "and session handle %d with ret %d",
778 ua_chan
->name
, app
->pid
, app
->sock
,
779 ua_sess
->handle
, ret
);
780 lttng_fd_put(LTTNG_FD_APPS
, 2);
784 ua_chan
->handle
= ua_chan
->obj
->handle
;
786 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
787 ua_chan
->name
, app
->pid
, app
->sock
);
789 health_code_update();
791 /* If channel is not enabled, disable it on the tracer */
792 if (!ua_chan
->enabled
) {
793 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
800 health_code_update();
805 * Create the specified event onto the UST tracer for a UST session.
808 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
809 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
813 health_code_update();
815 /* Create UST event on tracer */
816 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
819 ERR("Error ustctl create event %s for app pid: %d with ret %d",
820 ua_event
->attr
.name
, app
->pid
, ret
);
824 ua_event
->handle
= ua_event
->obj
->handle
;
826 DBG2("UST app event %s created successfully for pid:%d",
827 ua_event
->attr
.name
, app
->pid
);
829 health_code_update();
831 /* Set filter if one is present. */
832 if (ua_event
->filter
) {
833 ret
= set_ust_event_filter(ua_event
, app
);
839 /* If event not enabled, disable it on the tracer */
840 if (ua_event
->enabled
== 0) {
841 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
844 * If we hit an EPERM, something is wrong with our disable call. If
845 * we get an EEXIST, there is a problem on the tracer side since we
849 case -LTTNG_UST_ERR_PERM
:
850 /* Code flow problem */
852 case -LTTNG_UST_ERR_EXIST
:
853 /* It's OK for our use case. */
864 health_code_update();
869 * Copy data between an UST app event and a LTT event.
871 static void shadow_copy_event(struct ust_app_event
*ua_event
,
872 struct ltt_ust_event
*uevent
)
874 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
875 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
877 ua_event
->enabled
= uevent
->enabled
;
879 /* Copy event attributes */
880 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
882 /* Copy filter bytecode */
883 if (uevent
->filter
) {
884 ua_event
->filter
= alloc_copy_ust_app_filter(uevent
->filter
);
885 /* Filter might be NULL here in case of ENONEM. */
890 * Copy data between an UST app channel and a LTT channel.
892 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
893 struct ltt_ust_channel
*uchan
)
895 struct lttng_ht_iter iter
;
896 struct ltt_ust_event
*uevent
;
897 struct ltt_ust_context
*uctx
;
898 struct ust_app_event
*ua_event
;
899 struct ust_app_ctx
*ua_ctx
;
901 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
903 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
904 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
905 /* Copy event attributes */
906 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
908 ua_chan
->enabled
= uchan
->enabled
;
910 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
911 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
912 if (ua_ctx
== NULL
) {
915 lttng_ht_node_init_ulong(&ua_ctx
->node
,
916 (unsigned long) ua_ctx
->ctx
.ctx
);
917 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
920 /* Copy all events from ltt ust channel to ust app channel */
921 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
922 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
923 uevent
->filter
, uevent
->attr
.loglevel
);
924 if (ua_event
== NULL
) {
925 DBG2("UST event %s not found on shadow copy channel",
927 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
928 if (ua_event
== NULL
) {
931 shadow_copy_event(ua_event
, uevent
);
932 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
936 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
940 * Copy data between a UST app session and a regular LTT session.
942 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
943 struct ltt_ust_session
*usess
, struct ust_app
*app
)
945 struct lttng_ht_node_str
*ua_chan_node
;
946 struct lttng_ht_iter iter
;
947 struct ltt_ust_channel
*uchan
;
948 struct ust_app_channel
*ua_chan
;
954 /* Get date and time for unique app path */
956 timeinfo
= localtime(&rawtime
);
957 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
959 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
961 ua_sess
->id
= usess
->id
;
962 ua_sess
->uid
= usess
->uid
;
963 ua_sess
->gid
= usess
->gid
;
965 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
968 PERROR("asprintf UST shadow copy session");
969 /* TODO: We cannot return an error from here.. */
973 /* TODO: support all UST domain */
975 /* Iterate over all channels in global domain. */
976 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
978 struct lttng_ht_iter uiter
;
980 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
981 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
982 if (ua_chan_node
!= NULL
) {
983 /* Session exist. Contiuing. */
987 DBG2("Channel %s not found on shadow session copy, creating it",
989 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
990 if (ua_chan
== NULL
) {
991 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
995 shadow_copy_channel(ua_chan
, uchan
);
996 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1001 * Lookup sesison wrapper.
1004 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
1005 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
1007 /* Get right UST app session from app */
1008 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
1012 * Return ust app session from the app session hashtable using the UST session
1015 static struct ust_app_session
*lookup_session_by_app(
1016 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1018 struct lttng_ht_iter iter
;
1019 struct lttng_ht_node_ulong
*node
;
1021 __lookup_session_by_app(usess
, app
, &iter
);
1022 node
= lttng_ht_iter_get_node_ulong(&iter
);
1027 return caa_container_of(node
, struct ust_app_session
, node
);
1034 * Create a UST session onto the tracer of app and add it the session
1037 * Return ust app session or NULL on error.
1039 static struct ust_app_session
*create_ust_app_session(
1040 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1042 struct ust_app_session
*ua_sess
;
1044 health_code_update();
1046 ua_sess
= lookup_session_by_app(usess
, app
);
1047 if (ua_sess
== NULL
) {
1048 DBG2("UST app pid: %d session id %d not found, creating it",
1049 app
->pid
, usess
->id
);
1050 ua_sess
= alloc_ust_app_session();
1051 if (ua_sess
== NULL
) {
1052 /* Only malloc can failed so something is really wrong */
1055 shadow_copy_session(ua_sess
, usess
, app
);
1058 health_code_update();
1060 if (ua_sess
->handle
== -1) {
1063 ret
= ustctl_create_session(app
->sock
);
1065 ERR("Creating session for app pid %d", app
->pid
);
1066 delete_ust_app_session(-1, ua_sess
);
1067 /* This means that the tracer is gone... */
1068 ua_sess
= (void*) -1UL;
1072 ua_sess
->handle
= ret
;
1074 /* Add ust app session to app's HT */
1075 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
1076 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
1078 DBG2("UST app session created successfully with handle %d", ret
);
1082 health_code_update();
1087 * Create a context for the channel on the tracer.
1090 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
1091 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
1092 struct ust_app
*app
)
1095 struct lttng_ht_iter iter
;
1096 struct lttng_ht_node_ulong
*node
;
1097 struct ust_app_ctx
*ua_ctx
;
1099 DBG2("UST app adding context to channel %s", ua_chan
->name
);
1101 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1102 node
= lttng_ht_iter_get_node_ulong(&iter
);
1108 ua_ctx
= alloc_ust_app_ctx(uctx
);
1109 if (ua_ctx
== NULL
) {
1115 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1116 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1118 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
1128 * Enable on the tracer side a ust app event for the session and channel.
1131 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1132 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1136 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1141 ua_event
->enabled
= 1;
1148 * Disable on the tracer side a ust app event for the session and channel.
1150 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1151 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1155 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1160 ua_event
->enabled
= 0;
1167 * Lookup ust app channel for session and disable it on the tracer side.
1170 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1171 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1175 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1180 ua_chan
->enabled
= 0;
1187 * Lookup ust app channel for session and enable it on the tracer side.
1189 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1190 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1193 struct lttng_ht_iter iter
;
1194 struct lttng_ht_node_str
*ua_chan_node
;
1195 struct ust_app_channel
*ua_chan
;
1197 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1198 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1199 if (ua_chan_node
== NULL
) {
1200 DBG2("Unable to find channel %s in ust session id %u",
1201 uchan
->name
, ua_sess
->id
);
1205 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1207 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1217 * Create UST app channel and create it on the tracer. Set ua_chanp of the
1218 * newly created channel if not NULL.
1220 static int create_ust_app_channel(struct ust_app_session
*ua_sess
,
1221 struct ltt_ust_channel
*uchan
, struct ust_app
*app
,
1222 struct ust_app_channel
**ua_chanp
)
1225 struct lttng_ht_iter iter
;
1226 struct lttng_ht_node_str
*ua_chan_node
;
1227 struct ust_app_channel
*ua_chan
;
1229 /* Lookup channel in the ust app session */
1230 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1231 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1232 if (ua_chan_node
!= NULL
) {
1233 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1237 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1238 if (ua_chan
== NULL
) {
1239 /* 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 /* Only add the channel if successful on the tracer side. */
1253 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1255 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1260 *ua_chanp
= ua_chan
;
1263 /* Everything went well. */
1267 delete_ust_app_channel(-1, ua_chan
);
1272 * Create UST app event and create it on the tracer side.
1275 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1276 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1277 struct ust_app
*app
)
1280 struct ust_app_event
*ua_event
;
1282 /* Get event node */
1283 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
1284 uevent
->filter
, uevent
->attr
.loglevel
);
1285 if (ua_event
!= NULL
) {
1290 /* Does not exist so create one */
1291 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1292 if (ua_event
== NULL
) {
1293 /* Only malloc can failed so something is really wrong */
1297 shadow_copy_event(ua_event
, uevent
);
1299 /* Create it on the tracer side */
1300 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1302 /* Not found previously means that it does not exist on the tracer */
1303 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1307 add_unique_ust_app_event(ua_chan
->events
, ua_event
);
1309 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1316 /* Valid. Calling here is already in a read side lock */
1317 delete_ust_app_event(-1, ua_event
);
1322 * Create UST metadata and open it on the tracer side.
1324 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1325 char *pathname
, struct ust_app
*app
)
1329 if (ua_sess
->metadata
== NULL
) {
1330 /* Allocate UST metadata */
1331 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1332 if (ua_sess
->metadata
== NULL
) {
1333 /* malloc() failed */
1337 ret
= open_ust_metadata(app
, ua_sess
);
1339 DBG3("Opening metadata failed. Cleaning up memory");
1341 /* Cleanup failed metadata struct */
1342 free(ua_sess
->metadata
);
1344 * This is very important because delete_ust_app_session check if
1345 * the pointer is null or not in order to delete the metadata.
1347 ua_sess
->metadata
= NULL
;
1351 DBG2("UST metadata opened for app pid %d", app
->pid
);
1354 /* Open UST metadata stream */
1355 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1356 ret
= create_ust_metadata_stream(app
, ua_sess
);
1361 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1362 "%s/metadata", ua_sess
->path
);
1364 PERROR("asprintf UST create stream");
1368 DBG2("UST metadata stream object created for app pid %d",
1371 ERR("Attempting to create stream without metadata opened");
1382 * Return pointer to traceable apps list.
1384 struct lttng_ht
*ust_app_get_ht(void)
1390 * Return ust app pointer or NULL if not found.
1392 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1394 struct lttng_ht_node_ulong
*node
;
1395 struct lttng_ht_iter iter
;
1398 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1399 node
= lttng_ht_iter_get_node_ulong(&iter
);
1401 DBG2("UST app no found with pid %d", pid
);
1406 DBG2("Found UST app by pid %d", pid
);
1408 return caa_container_of(node
, struct ust_app
, pid_n
);
1416 * Using pid and uid (of the app), allocate a new ust_app struct and
1417 * add it to the global traceable app list.
1419 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1420 * bitness is not supported.
1422 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1424 struct ust_app
*lta
;
1427 if ((msg
->bits_per_long
== 64 &&
1428 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
1429 || (msg
->bits_per_long
== 32 &&
1430 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
1431 ERR("Registration failed: application \"%s\" (pid: %d) has "
1432 "%d-bit long, but no consumerd for this long size is available.\n",
1433 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1438 lttng_fd_put(LTTNG_FD_APPS
, 1);
1441 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1442 ERR("Registration failed: application \"%s\" (pid: %d) has "
1443 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1444 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1449 lttng_fd_put(LTTNG_FD_APPS
, 1);
1452 lta
= zmalloc(sizeof(struct ust_app
));
1458 lta
->ppid
= msg
->ppid
;
1459 lta
->uid
= msg
->uid
;
1460 lta
->gid
= msg
->gid
;
1461 lta
->compatible
= 0; /* Not compatible until proven */
1462 lta
->bits_per_long
= msg
->bits_per_long
;
1463 lta
->v_major
= msg
->major
;
1464 lta
->v_minor
= msg
->minor
;
1465 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1466 lta
->name
[16] = '\0';
1467 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1469 lta
->pid
= msg
->pid
;
1470 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1472 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1474 CDS_INIT_LIST_HEAD(<a
->teardown_head
);
1479 * On a re-registration, we want to kick out the previous registration of
1482 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1485 * The socket _should_ be unique until _we_ call close. So, a add_unique
1486 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1487 * already in the table.
1489 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1493 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1494 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1495 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1501 * Unregister app by removing it from the global traceable app list and freeing
1504 * The socket is already closed at this point so no close to sock.
1506 void ust_app_unregister(int sock
)
1508 struct ust_app
*lta
;
1509 struct lttng_ht_node_ulong
*node
;
1510 struct lttng_ht_iter iter
;
1511 struct ust_app_session
*ua_sess
;
1516 /* Get the node reference for a call_rcu */
1517 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1518 node
= lttng_ht_iter_get_node_ulong(&iter
);
1520 ERR("Unable to find app by sock %d", sock
);
1524 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1526 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1528 /* Remove application from PID hash table */
1529 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1532 /* Assign second node for deletion */
1533 iter
.iter
.node
= <a
->pid_n
.node
;
1536 * Ignore return value since the node might have been removed before by an
1537 * add replace during app registration because the PID can be reassigned by
1540 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1542 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
1546 /* Remove sessions so they are not visible during deletion.*/
1547 cds_lfht_for_each_entry(lta
->sessions
->ht
, &iter
.iter
, ua_sess
,
1549 ret
= lttng_ht_del(lta
->sessions
, &iter
);
1551 /* The session was already removed so scheduled for teardown. */
1556 * Add session to list for teardown. This is safe since at this point we
1557 * are the only one using this list.
1559 cds_list_add(&ua_sess
->teardown_node
, <a
->teardown_head
);
1563 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1571 * Return traceable_app_count
1573 unsigned long ust_app_list_count(void)
1575 unsigned long count
;
1578 count
= lttng_ht_get_count(ust_app_ht
);
1585 * Fill events array with all events name of all registered apps.
1587 int ust_app_list_events(struct lttng_event
**events
)
1590 size_t nbmem
, count
= 0;
1591 struct lttng_ht_iter iter
;
1592 struct ust_app
*app
;
1593 struct lttng_event
*tmp_event
;
1595 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1596 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1597 if (tmp_event
== NULL
) {
1598 PERROR("zmalloc ust app events");
1605 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1606 struct lttng_ust_tracepoint_iter uiter
;
1608 health_code_update();
1610 if (!app
->compatible
) {
1612 * TODO: In time, we should notice the caller of this error by
1613 * telling him that this is a version error.
1617 handle
= ustctl_tracepoint_list(app
->sock
);
1619 ERR("UST app list events getting handle failed for app pid %d",
1624 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1625 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1626 health_code_update();
1627 if (count
>= nbmem
) {
1628 /* In case the realloc fails, we free the memory */
1631 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1634 ptr
= realloc(tmp_event
, nbmem
* sizeof(struct lttng_event
));
1636 PERROR("realloc ust app events");
1643 memcpy(tmp_event
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1644 tmp_event
[count
].loglevel
= uiter
.loglevel
;
1645 tmp_event
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1646 tmp_event
[count
].pid
= app
->pid
;
1647 tmp_event
[count
].enabled
= -1;
1653 *events
= tmp_event
;
1655 DBG2("UST app list events done (%zu events)", count
);
1660 health_code_update();
1665 * Fill events array with all events name of all registered apps.
1667 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1670 size_t nbmem
, count
= 0;
1671 struct lttng_ht_iter iter
;
1672 struct ust_app
*app
;
1673 struct lttng_event_field
*tmp_event
;
1675 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1676 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1677 if (tmp_event
== NULL
) {
1678 PERROR("zmalloc ust app event fields");
1685 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1686 struct lttng_ust_field_iter uiter
;
1688 health_code_update();
1690 if (!app
->compatible
) {
1692 * TODO: In time, we should notice the caller of this error by
1693 * telling him that this is a version error.
1697 handle
= ustctl_tracepoint_field_list(app
->sock
);
1699 ERR("UST app list event fields getting handle failed for app pid %d",
1704 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1705 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1706 health_code_update();
1707 if (count
>= nbmem
) {
1708 /* In case the realloc fails, we free the memory */
1711 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1714 ptr
= realloc(tmp_event
, nbmem
* sizeof(struct lttng_event_field
));
1716 PERROR("realloc ust app event fields");
1724 memcpy(tmp_event
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1725 tmp_event
[count
].type
= uiter
.type
;
1726 tmp_event
[count
].nowrite
= uiter
.nowrite
;
1728 memcpy(tmp_event
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1729 tmp_event
[count
].event
.loglevel
= uiter
.loglevel
;
1730 tmp_event
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1731 tmp_event
[count
].event
.pid
= app
->pid
;
1732 tmp_event
[count
].event
.enabled
= -1;
1738 *fields
= tmp_event
;
1740 DBG2("UST app list event fields done (%zu events)", count
);
1745 health_code_update();
1750 * Free and clean all traceable apps of the global list.
1752 void ust_app_clean_list(void)
1755 struct ust_app
*app
;
1756 struct lttng_ht_iter iter
;
1758 DBG2("UST app cleaning registered apps hash table");
1762 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1763 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1765 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
1768 /* Cleanup socket hash table */
1769 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
1771 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1775 /* Destroy is done only when the ht is empty */
1776 lttng_ht_destroy(ust_app_ht
);
1777 lttng_ht_destroy(ust_app_ht_by_sock
);
1783 * Init UST app hash table.
1785 void ust_app_ht_alloc(void)
1787 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1788 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1792 * For a specific UST session, disable the channel for all registered apps.
1794 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1795 struct ltt_ust_channel
*uchan
)
1798 struct lttng_ht_iter iter
;
1799 struct lttng_ht_node_str
*ua_chan_node
;
1800 struct ust_app
*app
;
1801 struct ust_app_session
*ua_sess
;
1802 struct ust_app_channel
*ua_chan
;
1804 if (usess
== NULL
|| uchan
== NULL
) {
1805 ERR("Disabling UST global channel with NULL values");
1810 DBG2("UST app disabling channel %s from global domain for session id %d",
1811 uchan
->name
, usess
->id
);
1815 /* For every registered applications */
1816 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1817 struct lttng_ht_iter uiter
;
1818 if (!app
->compatible
) {
1820 * TODO: In time, we should notice the caller of this error by
1821 * telling him that this is a version error.
1825 ua_sess
= lookup_session_by_app(usess
, app
);
1826 if (ua_sess
== NULL
) {
1831 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1832 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1833 /* If the session if found for the app, the channel must be there */
1834 assert(ua_chan_node
);
1836 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1837 /* The channel must not be already disabled */
1838 assert(ua_chan
->enabled
== 1);
1840 /* Disable channel onto application */
1841 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1843 /* XXX: We might want to report this error at some point... */
1855 * For a specific UST session, enable the channel for all registered apps.
1857 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1858 struct ltt_ust_channel
*uchan
)
1861 struct lttng_ht_iter iter
;
1862 struct ust_app
*app
;
1863 struct ust_app_session
*ua_sess
;
1865 if (usess
== NULL
|| uchan
== NULL
) {
1866 ERR("Adding UST global channel to NULL values");
1871 DBG2("UST app enabling channel %s to global domain for session id %d",
1872 uchan
->name
, usess
->id
);
1876 /* For every registered applications */
1877 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1878 if (!app
->compatible
) {
1880 * TODO: In time, we should notice the caller of this error by
1881 * telling him that this is a version error.
1885 ua_sess
= lookup_session_by_app(usess
, app
);
1886 if (ua_sess
== NULL
) {
1890 /* Enable channel onto application */
1891 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1893 /* XXX: We might want to report this error at some point... */
1905 * Disable an event in a channel and for a specific session.
1907 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1908 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1911 struct lttng_ht_iter iter
, uiter
;
1912 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1913 struct ust_app
*app
;
1914 struct ust_app_session
*ua_sess
;
1915 struct ust_app_channel
*ua_chan
;
1916 struct ust_app_event
*ua_event
;
1918 DBG("UST app disabling event %s for all apps in channel "
1919 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1923 /* For all registered applications */
1924 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1925 if (!app
->compatible
) {
1927 * TODO: In time, we should notice the caller of this error by
1928 * telling him that this is a version error.
1932 ua_sess
= lookup_session_by_app(usess
, app
);
1933 if (ua_sess
== NULL
) {
1938 /* Lookup channel in the ust app session */
1939 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1940 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1941 if (ua_chan_node
== NULL
) {
1942 DBG2("Channel %s not found in session id %d for app pid %d."
1943 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1946 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1948 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1949 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1950 if (ua_event_node
== NULL
) {
1951 DBG2("Event %s not found in channel %s for app pid %d."
1952 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1955 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1957 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1959 /* XXX: Report error someday... */
1970 * For a specific UST session and UST channel, the event for all
1973 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1974 struct ltt_ust_channel
*uchan
)
1977 struct lttng_ht_iter iter
, uiter
;
1978 struct lttng_ht_node_str
*ua_chan_node
;
1979 struct ust_app
*app
;
1980 struct ust_app_session
*ua_sess
;
1981 struct ust_app_channel
*ua_chan
;
1982 struct ust_app_event
*ua_event
;
1984 DBG("UST app disabling all event for all apps in channel "
1985 "%s for session id %d", uchan
->name
, usess
->id
);
1989 /* For all registered applications */
1990 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1991 if (!app
->compatible
) {
1993 * TODO: In time, we should notice the caller of this error by
1994 * telling him that this is a version error.
1998 ua_sess
= lookup_session_by_app(usess
, app
);
2000 /* The application has problem or is probably dead. */
2004 /* Lookup channel in the ust app session */
2005 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2006 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2007 /* If the channel is not found, there is a code flow error */
2008 assert(ua_chan_node
);
2010 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2012 /* Disable each events of channel */
2013 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2015 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2017 /* XXX: Report error someday... */
2029 * For a specific UST session, create the channel for all registered apps.
2031 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
2032 struct ltt_ust_channel
*uchan
)
2035 struct lttng_ht_iter iter
;
2036 struct ust_app
*app
;
2037 struct ust_app_session
*ua_sess
;
2039 /* Very wrong code flow */
2043 DBG2("UST app adding channel %s to global domain for session id %d",
2044 uchan
->name
, usess
->id
);
2048 /* For every registered applications */
2049 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2050 if (!app
->compatible
) {
2052 * TODO: In time, we should notice the caller of this error by
2053 * telling him that this is a version error.
2058 * Create session on the tracer side and add it to app session HT. Note
2059 * that if session exist, it will simply return a pointer to the ust
2062 ua_sess
= create_ust_app_session(usess
, app
);
2063 if (ua_sess
== NULL
) {
2064 /* The malloc() failed. */
2066 goto error_rcu_unlock
;
2067 } else if (ua_sess
== (void *) -1UL) {
2069 * The application's socket is not valid. Either a bad socket or a
2070 * timeout on it. We can't inform yet the caller that for a
2071 * specific app, the session failed so we continue here.
2076 /* Create channel onto application. We don't need the chan ref. */
2077 ret
= create_ust_app_channel(ua_sess
, uchan
, app
, NULL
);
2078 if (ret
< 0 && ret
== -ENOMEM
) {
2079 /* No more memory is a fatal error. Stop right now. */
2080 goto error_rcu_unlock
;
2090 * Enable event for a specific session and channel on the tracer.
2092 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
2093 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2096 struct lttng_ht_iter iter
, uiter
;
2097 struct lttng_ht_node_str
*ua_chan_node
;
2098 struct ust_app
*app
;
2099 struct ust_app_session
*ua_sess
;
2100 struct ust_app_channel
*ua_chan
;
2101 struct ust_app_event
*ua_event
;
2103 DBG("UST app enabling event %s for all apps for session id %d",
2104 uevent
->attr
.name
, usess
->id
);
2107 * NOTE: At this point, this function is called only if the session and
2108 * channel passed are already created for all apps. and enabled on the
2114 /* For all registered applications */
2115 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2116 if (!app
->compatible
) {
2118 * TODO: In time, we should notice the caller of this error by
2119 * telling him that this is a version error.
2123 ua_sess
= lookup_session_by_app(usess
, app
);
2125 /* The application has problem or is probably dead. */
2129 /* Lookup channel in the ust app session */
2130 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2131 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2132 /* If the channel is not found, there is a code flow error */
2133 assert(ua_chan_node
);
2135 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2137 /* Get event node */
2138 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2139 uevent
->filter
, uevent
->attr
.loglevel
);
2140 if (ua_event
== NULL
) {
2141 DBG3("UST app enable event %s not found for app PID %d."
2142 "Skipping app", uevent
->attr
.name
, app
->pid
);
2146 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2158 * For a specific existing UST session and UST channel, creates the event for
2159 * all registered apps.
2161 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2162 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2165 struct lttng_ht_iter iter
, uiter
;
2166 struct lttng_ht_node_str
*ua_chan_node
;
2167 struct ust_app
*app
;
2168 struct ust_app_session
*ua_sess
;
2169 struct ust_app_channel
*ua_chan
;
2171 DBG("UST app creating event %s for all apps for session id %d",
2172 uevent
->attr
.name
, usess
->id
);
2176 /* For all registered applications */
2177 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2178 if (!app
->compatible
) {
2180 * TODO: In time, we should notice the caller of this error by
2181 * telling him that this is a version error.
2185 ua_sess
= lookup_session_by_app(usess
, app
);
2187 /* The application has problem or is probably dead. */
2191 /* Lookup channel in the ust app session */
2192 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2193 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2194 /* If the channel is not found, there is a code flow error */
2195 assert(ua_chan_node
);
2197 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2199 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2201 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
2202 /* Possible value at this point: -ENOMEM. If so, we stop! */
2205 DBG2("UST app event %s already exist on app PID %d",
2206 uevent
->attr
.name
, app
->pid
);
2217 * Start tracing for a specific UST session and app.
2219 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2222 struct lttng_ht_iter iter
;
2223 struct ust_app_session
*ua_sess
;
2224 struct ust_app_channel
*ua_chan
;
2225 struct ltt_ust_stream
*ustream
;
2226 struct consumer_socket
*socket
;
2228 DBG("Starting tracing for ust app pid %d", app
->pid
);
2232 if (!app
->compatible
) {
2236 ua_sess
= lookup_session_by_app(usess
, app
);
2237 if (ua_sess
== NULL
) {
2238 /* The session is in teardown process. Ignore and continue. */
2242 /* Upon restart, we skip the setup, already done */
2243 if (ua_sess
->started
) {
2247 /* Create directories if consumer is LOCAL and has a path defined. */
2248 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
2249 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
2250 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
2251 S_IRWXU
| S_IRWXG
, usess
->uid
, usess
->gid
);
2253 if (ret
!= -EEXIST
) {
2254 ERR("Trace directory creation error");
2256 goto error_rcu_unlock
;
2261 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2263 ret
= LTTNG_ERR_UST_META_FAIL
;
2264 goto error_rcu_unlock
;
2267 /* For each channel */
2268 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2270 /* Create all streams */
2272 /* Create UST stream */
2273 ustream
= zmalloc(sizeof(*ustream
));
2274 if (ustream
== NULL
) {
2275 PERROR("zmalloc ust stream");
2276 goto error_rcu_unlock
;
2279 /* We are going to receive 2 fds, we need to reserve them. */
2280 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2282 ERR("Exhausted number of available FD upon stream create");
2284 goto error_rcu_unlock
;
2287 health_code_update();
2289 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2292 /* Free unused memory and reset FD states. */
2294 lttng_fd_put(LTTNG_FD_APPS
, 2);
2295 if (ret
== -LTTNG_UST_ERR_NOENT
) {
2296 /* Got all streams. Continue normal execution. */
2299 /* Error at this point. Stop everything. */
2300 ret
= LTTNG_ERR_UST_STREAM_FAIL
;
2301 goto error_rcu_unlock
;
2303 ustream
->handle
= ustream
->obj
->handle
;
2305 health_code_update();
2307 /* Order is important */
2308 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2309 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2310 ua_chan
->name
, ua_chan
->streams
.count
);
2311 ua_chan
->streams
.count
++;
2313 PERROR("asprintf UST create stream");
2315 * XXX what should we do here with the
2320 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2324 health_code_update();
2327 switch (app
->bits_per_long
) {
2329 socket
= consumer_find_socket(uatomic_read(&ust_consumerd64_fd
),
2331 if (socket
== NULL
) {
2336 socket
= consumer_find_socket(uatomic_read(&ust_consumerd32_fd
),
2338 if (socket
== NULL
) {
2344 goto error_rcu_unlock
;
2347 /* Setup UST consumer socket and send fds to it */
2348 ret
= ust_consumer_send_session(ua_sess
, usess
->consumer
, socket
);
2350 goto error_rcu_unlock
;
2353 health_code_update();
2356 /* This start the UST tracing */
2357 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2359 ERR("Error starting tracing for app pid: %d (ret: %d)", app
->pid
, ret
);
2360 goto error_rcu_unlock
;
2363 /* Indicate that the session has been started once */
2364 ua_sess
->started
= 1;
2366 health_code_update();
2368 /* Quiescent wait after starting trace */
2369 ustctl_wait_quiescent(app
->sock
);
2373 health_code_update();
2378 health_code_update();
2383 * Stop tracing for a specific UST session and app.
2385 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2388 struct lttng_ht_iter iter
;
2389 struct ust_app_session
*ua_sess
;
2390 struct ust_app_channel
*ua_chan
;
2392 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2396 if (!app
->compatible
) {
2400 ua_sess
= lookup_session_by_app(usess
, app
);
2401 if (ua_sess
== NULL
) {
2406 * If started = 0, it means that stop trace has been called for a session
2407 * that was never started. It's possible since we can have a fail start
2408 * from either the application manager thread or the command thread. Simply
2409 * indicate that this is a stop error.
2411 if (!ua_sess
->started
) {
2412 goto error_rcu_unlock
;
2415 health_code_update();
2417 /* This inhibits UST tracing */
2418 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2420 ERR("Error stopping tracing for app pid: %d (ret: %d)", app
->pid
, ret
);
2421 goto error_rcu_unlock
;
2424 health_code_update();
2426 /* Quiescent wait after stopping trace */
2427 ustctl_wait_quiescent(app
->sock
);
2429 health_code_update();
2431 /* Flushing buffers */
2432 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2434 health_code_update();
2435 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2437 ERR("UST app PID %d channel %s flush failed with ret %d",
2438 app
->pid
, ua_chan
->name
, ret
);
2439 /* Continuing flushing all buffers */
2444 health_code_update();
2446 /* Flush all buffers before stopping */
2447 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2449 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2455 health_code_update();
2460 health_code_update();
2465 * Destroy a specific UST session in apps.
2467 static int destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2469 struct ust_app_session
*ua_sess
;
2470 struct lttng_ust_object_data obj
;
2471 struct lttng_ht_iter iter
;
2472 struct lttng_ht_node_ulong
*node
;
2475 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2479 if (!app
->compatible
) {
2483 __lookup_session_by_app(usess
, app
, &iter
);
2484 node
= lttng_ht_iter_get_node_ulong(&iter
);
2486 /* Session is being or is deleted. */
2489 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2490 ret
= lttng_ht_del(app
->sessions
, &iter
);
2492 /* Already scheduled for teardown. */
2496 obj
.handle
= ua_sess
->handle
;
2499 obj
.memory_map_size
= 0;
2500 health_code_update();
2501 ustctl_release_object(app
->sock
, &obj
);
2503 health_code_update();
2504 delete_ust_app_session(app
->sock
, ua_sess
);
2506 /* Quiescent wait after stopping trace */
2507 ustctl_wait_quiescent(app
->sock
);
2511 health_code_update();
2516 * Start tracing for the UST session.
2518 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2521 struct lttng_ht_iter iter
;
2522 struct ust_app
*app
;
2524 DBG("Starting all UST traces");
2528 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2529 ret
= ust_app_start_trace(usess
, app
);
2531 /* Continue to next apps even on error */
2542 * Start tracing for the UST session.
2544 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2547 struct lttng_ht_iter iter
;
2548 struct ust_app
*app
;
2550 DBG("Stopping all UST traces");
2554 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2555 ret
= ust_app_stop_trace(usess
, app
);
2557 /* Continue to next apps even on error */
2568 * Destroy app UST session.
2570 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2573 struct lttng_ht_iter iter
;
2574 struct ust_app
*app
;
2576 DBG("Destroy all UST traces");
2580 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2581 ret
= destroy_trace(usess
, app
);
2583 /* Continue to next apps even on error */
2594 * Add channels/events from UST global domain to registered apps at sock.
2596 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2599 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2600 struct ust_app
*app
;
2601 struct ust_app_session
*ua_sess
;
2602 struct ust_app_channel
*ua_chan
;
2603 struct ust_app_event
*ua_event
;
2604 struct ust_app_ctx
*ua_ctx
;
2608 DBG2("UST app global update for app sock %d for session id %d", sock
,
2613 app
= find_app_by_sock(sock
);
2615 ERR("Failed to update app sock %d", sock
);
2619 if (!app
->compatible
) {
2623 ua_sess
= create_ust_app_session(usess
, app
);
2624 if (ua_sess
== NULL
|| ua_sess
== (void *) -1UL) {
2625 /* Tracer is gone for this session and has been freed */
2630 * We can iterate safely here over all UST app session sicne the create ust
2631 * app session above made a shadow copy of the UST global domain from the
2634 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2636 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2638 /* FIXME: Should we quit here or continue... */
2642 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2644 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2646 /* FIXME: Should we quit here or continue... */
2652 /* For each events */
2653 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2655 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
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();
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();
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();
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();
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();