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 * Delete ust context safely. RCU read lock must be held before calling
44 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
)
47 ustctl_release_object(sock
, ua_ctx
->obj
);
54 * Delete ust app event safely. RCU read lock must be held before calling
58 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
60 free(ua_event
->filter
);
62 if (ua_event
->obj
!= NULL
) {
63 ustctl_release_object(sock
, ua_event
->obj
);
70 * Delete ust app stream safely. RCU read lock must be held before calling
74 void delete_ust_app_stream(int sock
, struct ltt_ust_stream
*stream
)
77 ustctl_release_object(sock
, stream
->obj
);
78 lttng_fd_put(LTTNG_FD_APPS
, 2);
85 * Delete ust app channel safely. RCU read lock must be held before calling
89 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
)
92 struct lttng_ht_iter iter
;
93 struct ust_app_event
*ua_event
;
94 struct ust_app_ctx
*ua_ctx
;
95 struct ltt_ust_stream
*stream
, *stmp
;
98 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
99 cds_list_del(&stream
->list
);
100 delete_ust_app_stream(sock
, stream
);
104 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
105 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
107 delete_ust_app_ctx(sock
, ua_ctx
);
109 lttng_ht_destroy(ua_chan
->ctx
);
112 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
114 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
116 delete_ust_app_event(sock
, ua_event
);
118 lttng_ht_destroy(ua_chan
->events
);
120 if (ua_chan
->obj
!= NULL
) {
121 ustctl_release_object(sock
, ua_chan
->obj
);
122 lttng_fd_put(LTTNG_FD_APPS
, 2);
129 * Delete ust app session safely. RCU read lock must be held before calling
133 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
)
136 struct lttng_ht_iter iter
;
137 struct ust_app_channel
*ua_chan
;
139 if (ua_sess
->metadata
) {
140 if (ua_sess
->metadata
->stream_obj
) {
141 ustctl_release_object(sock
, ua_sess
->metadata
->stream_obj
);
142 lttng_fd_put(LTTNG_FD_APPS
, 2);
143 free(ua_sess
->metadata
->stream_obj
);
145 if (ua_sess
->metadata
->obj
) {
146 ustctl_release_object(sock
, ua_sess
->metadata
->obj
);
147 lttng_fd_put(LTTNG_FD_APPS
, 2);
148 free(ua_sess
->metadata
->obj
);
150 trace_ust_destroy_metadata(ua_sess
->metadata
);
153 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
155 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
157 delete_ust_app_channel(sock
, ua_chan
);
159 lttng_ht_destroy(ua_sess
->channels
);
161 if (ua_sess
->handle
!= -1) {
162 ustctl_release_handle(sock
, ua_sess
->handle
);
168 * Delete a traceable application structure from the global list. Never call
169 * this function outside of a call_rcu call.
172 void delete_ust_app(struct ust_app
*app
)
175 struct lttng_ht_iter iter
;
176 struct ust_app_session
*ua_sess
;
180 /* Delete ust app sessions info */
185 cds_lfht_for_each_entry(app
->sessions
->ht
, &iter
.iter
, ua_sess
,
187 ret
= lttng_ht_del(app
->sessions
, &iter
);
189 delete_ust_app_session(app
->sock
, ua_sess
);
191 lttng_ht_destroy(app
->sessions
);
194 * Wait until we have deleted the application from the sock hash table
195 * before closing this socket, otherwise an application could re-use the
196 * socket ID and race with the teardown, using the same hash table entry.
198 * It's OK to leave the close in call_rcu. We want it to stay unique for
199 * all RCU readers that could run concurrently with unregister app,
200 * therefore we _need_ to only close that socket after a grace period. So
201 * it should stay in this RCU callback.
203 * This close() is a very important step of the synchronization model so
204 * every modification to this function must be carefully reviewed.
210 lttng_fd_put(LTTNG_FD_APPS
, 1);
212 DBG2("UST app pid %d deleted", app
->pid
);
219 * URCU intermediate call to delete an UST app.
222 void delete_ust_app_rcu(struct rcu_head
*head
)
224 struct lttng_ht_node_ulong
*node
=
225 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
226 struct ust_app
*app
=
227 caa_container_of(node
, struct ust_app
, pid_n
);
229 DBG3("Call RCU deleting app PID %d", app
->pid
);
234 * Alloc new UST app session.
237 struct ust_app_session
*alloc_ust_app_session(void)
239 struct ust_app_session
*ua_sess
;
241 /* Init most of the default value by allocating and zeroing */
242 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
243 if (ua_sess
== NULL
) {
248 ua_sess
->handle
= -1;
249 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
258 * Alloc new UST app channel.
261 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
262 struct lttng_ust_channel
*attr
)
264 struct ust_app_channel
*ua_chan
;
266 /* Init most of the default value by allocating and zeroing */
267 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
268 if (ua_chan
== NULL
) {
273 /* Setup channel name */
274 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
275 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
277 ua_chan
->enabled
= 1;
278 ua_chan
->handle
= -1;
279 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
280 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
281 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
283 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
285 /* Copy attributes */
287 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
290 DBG3("UST app channel %s allocated", ua_chan
->name
);
299 * Alloc new UST app event.
302 struct ust_app_event
*alloc_ust_app_event(char *name
,
303 struct lttng_ust_event
*attr
)
305 struct ust_app_event
*ua_event
;
307 /* Init most of the default value by allocating and zeroing */
308 ua_event
= zmalloc(sizeof(struct ust_app_event
));
309 if (ua_event
== NULL
) {
314 ua_event
->enabled
= 1;
315 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
316 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
317 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
319 /* Copy attributes */
321 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
324 DBG3("UST app event %s allocated", ua_event
->name
);
333 * Alloc new UST app context.
336 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
338 struct ust_app_ctx
*ua_ctx
;
340 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
341 if (ua_ctx
== NULL
) {
346 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
349 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
356 * Find an ust_app using the sock and return it. RCU read side lock must be
357 * held before calling this helper function.
360 struct ust_app
*find_app_by_sock(int sock
)
362 struct lttng_ht_node_ulong
*node
;
363 struct lttng_ht_iter iter
;
365 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
366 node
= lttng_ht_iter_get_node_ulong(&iter
);
368 DBG2("UST app find by sock %d not found", sock
);
372 return caa_container_of(node
, struct ust_app
, sock_n
);
379 * Create the channel context on the tracer.
382 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
383 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
387 health_code_update(&health_thread_cmd
);
389 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
390 ua_chan
->obj
, &ua_ctx
->obj
);
395 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
397 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
400 health_code_update(&health_thread_cmd
);
405 * Set the filter on the tracer.
408 int set_ust_event_filter(struct ust_app_event
*ua_event
,
413 health_code_update(&health_thread_cmd
);
415 if (!ua_event
->filter
) {
420 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
426 DBG2("UST filter set successfully for event %s", ua_event
->name
);
429 health_code_update(&health_thread_cmd
);
434 * Disable the specified event on to UST tracer for the UST session.
436 static int disable_ust_event(struct ust_app
*app
,
437 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
441 health_code_update(&health_thread_cmd
);
443 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
445 ERR("UST app event %s disable failed for app (pid: %d) "
446 "and session handle %d with ret %d",
447 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
451 DBG2("UST app event %s disabled successfully for app (pid: %d)",
452 ua_event
->attr
.name
, app
->pid
);
455 health_code_update(&health_thread_cmd
);
460 * Disable the specified channel on to UST tracer for the UST session.
462 static int disable_ust_channel(struct ust_app
*app
,
463 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
467 health_code_update(&health_thread_cmd
);
469 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
471 ERR("UST app channel %s disable failed for app (pid: %d) "
472 "and session handle %d with ret %d",
473 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
477 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
478 ua_chan
->name
, app
->pid
);
481 health_code_update(&health_thread_cmd
);
486 * Enable the specified channel on to UST tracer for the UST session.
488 static int enable_ust_channel(struct ust_app
*app
,
489 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
493 health_code_update(&health_thread_cmd
);
495 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
497 ERR("UST app channel %s enable failed for app (pid: %d) "
498 "and session handle %d with ret %d",
499 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
503 ua_chan
->enabled
= 1;
505 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
506 ua_chan
->name
, app
->pid
);
509 health_code_update(&health_thread_cmd
);
514 * Enable the specified event on to UST tracer for the UST session.
516 static int enable_ust_event(struct ust_app
*app
,
517 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
521 health_code_update(&health_thread_cmd
);
523 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
525 ERR("UST app event %s enable failed for app (pid: %d) "
526 "and session handle %d with ret %d",
527 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
531 DBG2("UST app event %s enabled successfully for app (pid: %d)",
532 ua_event
->attr
.name
, app
->pid
);
535 health_code_update(&health_thread_cmd
);
540 * Open metadata onto the UST tracer for a UST session.
542 static int open_ust_metadata(struct ust_app
*app
,
543 struct ust_app_session
*ua_sess
)
546 struct lttng_ust_channel_attr uattr
;
548 health_code_update(&health_thread_cmd
);
550 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
551 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
552 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
553 uattr
.switch_timer_interval
=
554 ua_sess
->metadata
->attr
.switch_timer_interval
;
555 uattr
.read_timer_interval
=
556 ua_sess
->metadata
->attr
.read_timer_interval
;
557 uattr
.output
= ua_sess
->metadata
->attr
.output
;
559 /* We are going to receive 2 fds, we need to reserve them. */
560 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
562 ERR("Exhausted number of available FD upon metadata open");
565 /* UST tracer metadata creation */
566 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
567 &ua_sess
->metadata
->obj
);
569 ERR("UST app open metadata failed for app pid:%d with ret %d",
574 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
577 health_code_update(&health_thread_cmd
);
582 * Create stream onto the UST tracer for a UST session.
584 static int create_ust_stream(struct ust_app
*app
,
585 struct ust_app_session
*ua_sess
)
589 health_code_update(&health_thread_cmd
);
591 /* We are going to receive 2 fds, we need to reserve them. */
592 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
594 ERR("Exhausted number of available FD upon metadata stream create");
597 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
598 &ua_sess
->metadata
->stream_obj
);
600 ERR("UST create metadata stream failed");
605 health_code_update(&health_thread_cmd
);
610 * Create the specified channel onto the UST tracer for a UST session.
612 static int create_ust_channel(struct ust_app
*app
,
613 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
617 health_code_update(&health_thread_cmd
);
619 /* TODO: remove cast and use lttng-ust-abi.h */
621 /* We are going to receive 2 fds, we need to reserve them. */
622 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
624 ERR("Exhausted number of available FD upon create channel");
628 health_code_update(&health_thread_cmd
);
630 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
631 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
633 ERR("Creating channel %s for app (pid: %d, sock: %d) "
634 "and session handle %d with ret %d",
635 ua_chan
->name
, app
->pid
, app
->sock
,
636 ua_sess
->handle
, ret
);
637 lttng_fd_put(LTTNG_FD_APPS
, 2);
641 ua_chan
->handle
= ua_chan
->obj
->handle
;
643 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
644 ua_chan
->name
, app
->pid
, app
->sock
);
646 health_code_update(&health_thread_cmd
);
648 /* If channel is not enabled, disable it on the tracer */
649 if (!ua_chan
->enabled
) {
650 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
657 health_code_update(&health_thread_cmd
);
662 * Create the specified event onto the UST tracer for a UST session.
665 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
666 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
670 health_code_update(&health_thread_cmd
);
672 /* Create UST event on tracer */
673 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
676 ERR("Error ustctl create event %s for app pid: %d with ret %d",
677 ua_event
->attr
.name
, app
->pid
, ret
);
681 ua_event
->handle
= ua_event
->obj
->handle
;
683 DBG2("UST app event %s created successfully for pid:%d",
684 ua_event
->attr
.name
, app
->pid
);
686 health_code_update(&health_thread_cmd
);
688 /* If event not enabled, disable it on the tracer */
689 if (ua_event
->enabled
== 0) {
690 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
693 * If we hit an EPERM, something is wrong with our disable call. If
694 * we get an EEXIST, there is a problem on the tracer side since we
698 case -LTTNG_UST_ERR_PERM
:
699 /* Code flow problem */
701 case -LTTNG_UST_ERR_EXIST
:
702 /* It's OK for our use case. */
713 health_code_update(&health_thread_cmd
);
718 * Copy data between an UST app event and a LTT event.
720 static void shadow_copy_event(struct ust_app_event
*ua_event
,
721 struct ltt_ust_event
*uevent
)
723 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
724 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
726 ua_event
->enabled
= uevent
->enabled
;
728 /* Copy event attributes */
729 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
731 /* Copy filter bytecode */
732 if (uevent
->filter
) {
733 ua_event
->filter
= zmalloc(sizeof(*ua_event
->filter
) +
734 uevent
->filter
->len
);
735 if (!ua_event
->filter
) {
738 memcpy(ua_event
->filter
, uevent
->filter
,
739 sizeof(*ua_event
->filter
) + uevent
->filter
->len
);
744 * Copy data between an UST app channel and a LTT channel.
746 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
747 struct ltt_ust_channel
*uchan
)
749 struct lttng_ht_iter iter
;
750 struct lttng_ht_node_str
*ua_event_node
;
751 struct ltt_ust_event
*uevent
;
752 struct ltt_ust_context
*uctx
;
753 struct ust_app_event
*ua_event
;
754 struct ust_app_ctx
*ua_ctx
;
756 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
758 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
759 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
760 /* Copy event attributes */
761 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
763 ua_chan
->enabled
= uchan
->enabled
;
765 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
766 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
767 if (ua_ctx
== NULL
) {
770 lttng_ht_node_init_ulong(&ua_ctx
->node
,
771 (unsigned long) ua_ctx
->ctx
.ctx
);
772 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
775 /* Copy all events from ltt ust channel to ust app channel */
776 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
777 struct lttng_ht_iter uiter
;
779 lttng_ht_lookup(ua_chan
->events
, (void *) uevent
->attr
.name
, &uiter
);
780 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
781 if (ua_event_node
== NULL
) {
782 DBG2("UST event %s not found on shadow copy channel",
784 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
785 if (ua_event
== NULL
) {
788 shadow_copy_event(ua_event
, uevent
);
789 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
793 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
797 * Copy data between a UST app session and a regular LTT session.
799 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
800 struct ltt_ust_session
*usess
, struct ust_app
*app
)
802 struct lttng_ht_node_str
*ua_chan_node
;
803 struct lttng_ht_iter iter
;
804 struct ltt_ust_channel
*uchan
;
805 struct ust_app_channel
*ua_chan
;
811 /* Get date and time for unique app path */
813 timeinfo
= localtime(&rawtime
);
814 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
816 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
818 ua_sess
->id
= usess
->id
;
819 ua_sess
->uid
= usess
->uid
;
820 ua_sess
->gid
= usess
->gid
;
822 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
825 PERROR("asprintf UST shadow copy session");
826 /* TODO: We cannot return an error from here.. */
830 /* TODO: support all UST domain */
832 /* Iterate over all channels in global domain. */
833 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
835 struct lttng_ht_iter uiter
;
837 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
838 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
839 if (ua_chan_node
!= NULL
) {
840 /* Session exist. Contiuing. */
844 DBG2("Channel %s not found on shadow session copy, creating it",
846 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
847 if (ua_chan
== NULL
) {
848 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
852 shadow_copy_channel(ua_chan
, uchan
);
853 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
858 * Lookup sesison wrapper.
861 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
862 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
864 /* Get right UST app session from app */
865 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
869 * Return ust app session from the app session hashtable using the UST session
872 static struct ust_app_session
*lookup_session_by_app(
873 struct ltt_ust_session
*usess
, struct ust_app
*app
)
875 struct lttng_ht_iter iter
;
876 struct lttng_ht_node_ulong
*node
;
878 __lookup_session_by_app(usess
, app
, &iter
);
879 node
= lttng_ht_iter_get_node_ulong(&iter
);
884 return caa_container_of(node
, struct ust_app_session
, node
);
891 * Create a UST session onto the tracer of app and add it the session
894 * Return ust app session or NULL on error.
896 static struct ust_app_session
*create_ust_app_session(
897 struct ltt_ust_session
*usess
, struct ust_app
*app
)
900 struct ust_app_session
*ua_sess
;
902 health_code_update(&health_thread_cmd
);
904 ua_sess
= lookup_session_by_app(usess
, app
);
905 if (ua_sess
== NULL
) {
906 DBG2("UST app pid: %d session id %d not found, creating it",
907 app
->pid
, usess
->id
);
908 ua_sess
= alloc_ust_app_session();
909 if (ua_sess
== NULL
) {
910 /* Only malloc can failed so something is really wrong */
913 shadow_copy_session(ua_sess
, usess
, app
);
916 health_code_update(&health_thread_cmd
);
918 if (ua_sess
->handle
== -1) {
919 ret
= ustctl_create_session(app
->sock
);
921 ERR("Creating session for app pid %d", app
->pid
);
922 delete_ust_app_session(-1, ua_sess
);
923 /* This means that the tracer is gone... */
924 ua_sess
= (void*) -1UL;
928 ua_sess
->handle
= ret
;
930 /* Add ust app session to app's HT */
931 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
932 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
934 DBG2("UST app session created successfully with handle %d", ret
);
938 health_code_update(&health_thread_cmd
);
943 * Create a context for the channel on the tracer.
946 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
947 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
951 struct lttng_ht_iter iter
;
952 struct lttng_ht_node_ulong
*node
;
953 struct ust_app_ctx
*ua_ctx
;
955 DBG2("UST app adding context to channel %s", ua_chan
->name
);
957 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
958 node
= lttng_ht_iter_get_node_ulong(&iter
);
964 ua_ctx
= alloc_ust_app_ctx(uctx
);
965 if (ua_ctx
== NULL
) {
971 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
972 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
974 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
984 * Set UST filter for the event on the tracer.
987 int set_ust_app_event_filter(struct ust_app_session
*ua_sess
,
988 struct ust_app_event
*ua_event
,
989 struct lttng_filter_bytecode
*bytecode
,
994 DBG2("UST app adding context to event %s", ua_event
->name
);
996 /* Copy filter bytecode */
997 ua_event
->filter
= zmalloc(sizeof(*ua_event
->filter
) + bytecode
->len
);
998 if (!ua_event
->filter
) {
1001 memcpy(ua_event
->filter
, bytecode
,
1002 sizeof(*ua_event
->filter
) + bytecode
->len
);
1003 ret
= set_ust_event_filter(ua_event
, app
);
1013 * Enable on the tracer side a ust app event for the session and channel.
1016 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1017 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1021 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1026 ua_event
->enabled
= 1;
1033 * Disable on the tracer side a ust app event for the session and channel.
1035 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1036 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1040 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1045 ua_event
->enabled
= 0;
1052 * Lookup ust app channel for session and disable it on the tracer side.
1055 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1056 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1060 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1065 ua_chan
->enabled
= 0;
1072 * Lookup ust app channel for session and enable it on the tracer side.
1074 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1075 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1078 struct lttng_ht_iter iter
;
1079 struct lttng_ht_node_str
*ua_chan_node
;
1080 struct ust_app_channel
*ua_chan
;
1082 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1083 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1084 if (ua_chan_node
== NULL
) {
1085 DBG2("Unable to find channel %s in ust session id %u",
1086 uchan
->name
, ua_sess
->id
);
1090 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1092 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1102 * Create UST app channel and create it on the tracer.
1104 static struct ust_app_channel
*create_ust_app_channel(
1105 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
1106 struct ust_app
*app
)
1109 struct lttng_ht_iter iter
;
1110 struct lttng_ht_node_str
*ua_chan_node
;
1111 struct ust_app_channel
*ua_chan
;
1113 /* Lookup channel in the ust app session */
1114 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1115 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1116 if (ua_chan_node
!= NULL
) {
1117 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1121 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1122 if (ua_chan
== NULL
) {
1123 /* Only malloc can fail here */
1126 shadow_copy_channel(ua_chan
, uchan
);
1128 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1130 /* Not found previously means that it does not exist on the tracer */
1131 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1135 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1137 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1144 delete_ust_app_channel(-1, ua_chan
);
1149 * Create UST app event and create it on the tracer side.
1152 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1153 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1154 struct ust_app
*app
)
1157 struct lttng_ht_iter iter
;
1158 struct lttng_ht_node_str
*ua_event_node
;
1159 struct ust_app_event
*ua_event
;
1161 /* Get event node */
1162 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
1163 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
1164 if (ua_event_node
!= NULL
) {
1169 /* Does not exist so create one */
1170 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1171 if (ua_event
== NULL
) {
1172 /* Only malloc can failed so something is really wrong */
1176 shadow_copy_event(ua_event
, uevent
);
1178 /* Create it on the tracer side */
1179 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1181 /* Not found previously means that it does not exist on the tracer */
1182 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
1186 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
1188 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1195 /* Valid. Calling here is already in a read side lock */
1196 delete_ust_app_event(-1, ua_event
);
1201 * Create UST metadata and open it on the tracer side.
1203 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1204 char *pathname
, struct ust_app
*app
)
1208 if (ua_sess
->metadata
== NULL
) {
1209 /* Allocate UST metadata */
1210 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1211 if (ua_sess
->metadata
== NULL
) {
1212 /* malloc() failed */
1216 ret
= open_ust_metadata(app
, ua_sess
);
1218 DBG3("Opening metadata failed. Cleaning up memory");
1220 /* Cleanup failed metadata struct */
1221 free(ua_sess
->metadata
);
1223 * This is very important because delete_ust_app_session check if
1224 * the pointer is null or not in order to delete the metadata.
1226 ua_sess
->metadata
= NULL
;
1230 DBG2("UST metadata opened for app pid %d", app
->pid
);
1233 /* Open UST metadata stream */
1234 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1235 ret
= create_ust_stream(app
, ua_sess
);
1240 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1241 "%s/metadata", ua_sess
->path
);
1243 PERROR("asprintf UST create stream");
1247 DBG2("UST metadata stream object created for app pid %d",
1250 ERR("Attempting to create stream without metadata opened");
1261 * Return pointer to traceable apps list.
1263 struct lttng_ht
*ust_app_get_ht(void)
1269 * Return ust app pointer or NULL if not found.
1271 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1273 struct lttng_ht_node_ulong
*node
;
1274 struct lttng_ht_iter iter
;
1277 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1278 node
= lttng_ht_iter_get_node_ulong(&iter
);
1280 DBG2("UST app no found with pid %d", pid
);
1285 DBG2("Found UST app by pid %d", pid
);
1287 return caa_container_of(node
, struct ust_app
, pid_n
);
1295 * Using pid and uid (of the app), allocate a new ust_app struct and
1296 * add it to the global traceable app list.
1298 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1299 * bitness is not supported.
1301 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1303 struct ust_app
*lta
;
1306 if ((msg
->bits_per_long
== 64 &&
1307 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
1308 || (msg
->bits_per_long
== 32 &&
1309 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
1310 ERR("Registration failed: application \"%s\" (pid: %d) has "
1311 "%d-bit long, but no consumerd for this long size is available.\n",
1312 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1317 lttng_fd_put(LTTNG_FD_APPS
, 1);
1320 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1321 ERR("Registration failed: application \"%s\" (pid: %d) has "
1322 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1323 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1328 lttng_fd_put(LTTNG_FD_APPS
, 1);
1331 lta
= zmalloc(sizeof(struct ust_app
));
1337 lta
->ppid
= msg
->ppid
;
1338 lta
->uid
= msg
->uid
;
1339 lta
->gid
= msg
->gid
;
1340 lta
->compatible
= 0; /* Not compatible until proven */
1341 lta
->bits_per_long
= msg
->bits_per_long
;
1342 lta
->v_major
= msg
->major
;
1343 lta
->v_minor
= msg
->minor
;
1344 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1345 lta
->name
[16] = '\0';
1346 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1348 lta
->pid
= msg
->pid
;
1349 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1351 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1356 * On a re-registration, we want to kick out the previous registration of
1359 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1362 * The socket _should_ be unique until _we_ call close. So, a add_unique
1363 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1364 * already in the table.
1366 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1370 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1371 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1372 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1378 * Unregister app by removing it from the global traceable app list and freeing
1381 * The socket is already closed at this point so no close to sock.
1383 void ust_app_unregister(int sock
)
1385 struct ust_app
*lta
;
1386 struct lttng_ht_node_ulong
*node
;
1387 struct lttng_ht_iter iter
;
1392 /* Get the node reference for a call_rcu */
1393 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1394 node
= lttng_ht_iter_get_node_ulong(&iter
);
1396 ERR("Unable to find app by sock %d", sock
);
1400 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1402 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1404 /* Remove application from PID hash table */
1405 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1408 /* Assign second node for deletion */
1409 iter
.iter
.node
= <a
->pid_n
.node
;
1412 * Ignore return value since the node might have been removed before by an
1413 * add replace during app registration because the PID can be reassigned by
1416 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1418 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
1423 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1431 * Return traceable_app_count
1433 unsigned long ust_app_list_count(void)
1435 unsigned long count
;
1438 count
= lttng_ht_get_count(ust_app_ht
);
1445 * Fill events array with all events name of all registered apps.
1447 int ust_app_list_events(struct lttng_event
**events
)
1450 size_t nbmem
, count
= 0;
1451 struct lttng_ht_iter iter
;
1452 struct ust_app
*app
;
1453 struct lttng_event
*tmp
;
1455 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1456 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1458 PERROR("zmalloc ust app events");
1465 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1466 struct lttng_ust_tracepoint_iter uiter
;
1468 health_code_update(&health_thread_cmd
);
1470 if (!app
->compatible
) {
1472 * TODO: In time, we should notice the caller of this error by
1473 * telling him that this is a version error.
1477 handle
= ustctl_tracepoint_list(app
->sock
);
1479 ERR("UST app list events getting handle failed for app pid %d",
1484 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1485 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1486 health_code_update(&health_thread_cmd
);
1487 if (count
>= nbmem
) {
1488 /* In case the realloc fails, we free the memory */
1489 void *tmp_ptr
= (void *) tmp
;
1490 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1493 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event
));
1495 PERROR("realloc ust app events");
1501 memcpy(tmp
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1502 tmp
[count
].loglevel
= uiter
.loglevel
;
1503 tmp
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1504 tmp
[count
].pid
= app
->pid
;
1505 tmp
[count
].enabled
= -1;
1513 DBG2("UST app list events done (%zu events)", count
);
1518 health_code_update(&health_thread_cmd
);
1523 * Fill events array with all events name of all registered apps.
1525 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1528 size_t nbmem
, count
= 0;
1529 struct lttng_ht_iter iter
;
1530 struct ust_app
*app
;
1531 struct lttng_event_field
*tmp
;
1533 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1534 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1536 PERROR("zmalloc ust app event fields");
1543 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1544 struct lttng_ust_field_iter uiter
;
1546 health_code_update(&health_thread_cmd
);
1548 if (!app
->compatible
) {
1550 * TODO: In time, we should notice the caller of this error by
1551 * telling him that this is a version error.
1555 handle
= ustctl_tracepoint_field_list(app
->sock
);
1557 ERR("UST app list event fields getting handle failed for app pid %d",
1562 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1563 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
1564 health_code_update(&health_thread_cmd
);
1565 if (count
>= nbmem
) {
1566 /* In case the realloc fails, we free the memory */
1567 void *tmp_ptr
= (void *) tmp
;
1568 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1571 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event_field
));
1573 PERROR("realloc ust app event fields");
1580 memcpy(tmp
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1581 tmp
[count
].type
= uiter
.type
;
1582 tmp
[count
].nowrite
= uiter
.nowrite
;
1584 memcpy(tmp
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1585 tmp
[count
].event
.loglevel
= uiter
.loglevel
;
1586 tmp
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1587 tmp
[count
].event
.pid
= app
->pid
;
1588 tmp
[count
].event
.enabled
= -1;
1596 DBG2("UST app list event fields done (%zu events)", count
);
1601 health_code_update(&health_thread_cmd
);
1606 * Free and clean all traceable apps of the global list.
1608 void ust_app_clean_list(void)
1611 struct ust_app
*app
;
1612 struct lttng_ht_iter iter
;
1614 DBG2("UST app cleaning registered apps hash table");
1618 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1619 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1621 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
1624 /* Cleanup socket hash table */
1625 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
1627 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1631 /* Destroy is done only when the ht is empty */
1632 lttng_ht_destroy(ust_app_ht
);
1633 lttng_ht_destroy(ust_app_ht_by_sock
);
1639 * Init UST app hash table.
1641 void ust_app_ht_alloc(void)
1643 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1644 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1648 * For a specific UST session, disable the channel for all registered apps.
1650 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1651 struct ltt_ust_channel
*uchan
)
1654 struct lttng_ht_iter iter
;
1655 struct lttng_ht_node_str
*ua_chan_node
;
1656 struct ust_app
*app
;
1657 struct ust_app_session
*ua_sess
;
1658 struct ust_app_channel
*ua_chan
;
1660 if (usess
== NULL
|| uchan
== NULL
) {
1661 ERR("Disabling UST global channel with NULL values");
1666 DBG2("UST app disabling channel %s from global domain for session id %d",
1667 uchan
->name
, usess
->id
);
1671 /* For every registered applications */
1672 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1673 struct lttng_ht_iter uiter
;
1674 if (!app
->compatible
) {
1676 * TODO: In time, we should notice the caller of this error by
1677 * telling him that this is a version error.
1681 ua_sess
= lookup_session_by_app(usess
, app
);
1682 if (ua_sess
== NULL
) {
1687 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1688 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1689 /* If the session if found for the app, the channel must be there */
1690 assert(ua_chan_node
);
1692 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1693 /* The channel must not be already disabled */
1694 assert(ua_chan
->enabled
== 1);
1696 /* Disable channel onto application */
1697 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1699 /* XXX: We might want to report this error at some point... */
1711 * For a specific UST session, enable the channel for all registered apps.
1713 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1714 struct ltt_ust_channel
*uchan
)
1717 struct lttng_ht_iter iter
;
1718 struct ust_app
*app
;
1719 struct ust_app_session
*ua_sess
;
1721 if (usess
== NULL
|| uchan
== NULL
) {
1722 ERR("Adding UST global channel to NULL values");
1727 DBG2("UST app enabling channel %s to global domain for session id %d",
1728 uchan
->name
, usess
->id
);
1732 /* For every registered applications */
1733 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1734 if (!app
->compatible
) {
1736 * TODO: In time, we should notice the caller of this error by
1737 * telling him that this is a version error.
1741 ua_sess
= lookup_session_by_app(usess
, app
);
1742 if (ua_sess
== NULL
) {
1746 /* Enable channel onto application */
1747 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1749 /* XXX: We might want to report this error at some point... */
1761 * Disable an event in a channel and for a specific session.
1763 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1764 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1767 struct lttng_ht_iter iter
, uiter
;
1768 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1769 struct ust_app
*app
;
1770 struct ust_app_session
*ua_sess
;
1771 struct ust_app_channel
*ua_chan
;
1772 struct ust_app_event
*ua_event
;
1774 DBG("UST app disabling event %s for all apps in channel "
1775 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1779 /* For all registered applications */
1780 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1781 if (!app
->compatible
) {
1783 * TODO: In time, we should notice the caller of this error by
1784 * telling him that this is a version error.
1788 ua_sess
= lookup_session_by_app(usess
, app
);
1789 if (ua_sess
== NULL
) {
1794 /* Lookup channel in the ust app session */
1795 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1796 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1797 if (ua_chan_node
== NULL
) {
1798 DBG2("Channel %s not found in session id %d for app pid %d."
1799 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1802 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1804 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1805 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1806 if (ua_event_node
== NULL
) {
1807 DBG2("Event %s not found in channel %s for app pid %d."
1808 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1811 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1813 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1815 /* XXX: Report error someday... */
1826 * For a specific UST session and UST channel, the event for all
1829 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1830 struct ltt_ust_channel
*uchan
)
1833 struct lttng_ht_iter iter
, uiter
;
1834 struct lttng_ht_node_str
*ua_chan_node
;
1835 struct ust_app
*app
;
1836 struct ust_app_session
*ua_sess
;
1837 struct ust_app_channel
*ua_chan
;
1838 struct ust_app_event
*ua_event
;
1840 DBG("UST app disabling all event for all apps in channel "
1841 "%s for session id %d", uchan
->name
, usess
->id
);
1845 /* For all registered applications */
1846 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1847 if (!app
->compatible
) {
1849 * TODO: In time, we should notice the caller of this error by
1850 * telling him that this is a version error.
1854 ua_sess
= lookup_session_by_app(usess
, app
);
1855 /* If ua_sess is NULL, there is a code flow error */
1858 /* Lookup channel in the ust app session */
1859 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1860 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1861 /* If the channel is not found, there is a code flow error */
1862 assert(ua_chan_node
);
1864 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1866 /* Disable each events of channel */
1867 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
1869 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1871 /* XXX: Report error someday... */
1883 * For a specific UST session, create the channel for all registered apps.
1885 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
1886 struct ltt_ust_channel
*uchan
)
1889 struct lttng_ht_iter iter
;
1890 struct ust_app
*app
;
1891 struct ust_app_session
*ua_sess
;
1892 struct ust_app_channel
*ua_chan
;
1894 /* Very wrong code flow */
1898 DBG2("UST app adding channel %s to global domain for session id %d",
1899 uchan
->name
, usess
->id
);
1903 /* For every registered applications */
1904 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1905 if (!app
->compatible
) {
1907 * TODO: In time, we should notice the caller of this error by
1908 * telling him that this is a version error.
1913 * Create session on the tracer side and add it to app session HT. Note
1914 * that if session exist, it will simply return a pointer to the ust
1917 ua_sess
= create_ust_app_session(usess
, app
);
1918 if (ua_sess
== NULL
) {
1919 /* The malloc() failed. */
1922 } else if (ua_sess
== (void *) -1UL) {
1923 /* The application's socket is not valid. Contiuing */
1928 /* Create channel onto application */
1929 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
1930 if (ua_chan
== NULL
) {
1931 /* Major problem here and it's maybe the tracer or malloc() */
1944 * Enable event for a specific session and channel on the tracer.
1946 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
1947 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1950 struct lttng_ht_iter iter
, uiter
;
1951 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1952 struct ust_app
*app
;
1953 struct ust_app_session
*ua_sess
;
1954 struct ust_app_channel
*ua_chan
;
1955 struct ust_app_event
*ua_event
;
1957 DBG("UST app enabling event %s for all apps for session id %d",
1958 uevent
->attr
.name
, usess
->id
);
1961 * NOTE: At this point, this function is called only if the session and
1962 * channel passed are already created for all apps. and enabled on the
1968 /* For all registered applications */
1969 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1970 if (!app
->compatible
) {
1972 * TODO: In time, we should notice the caller of this error by
1973 * telling him that this is a version error.
1977 ua_sess
= lookup_session_by_app(usess
, app
);
1978 /* If ua_sess is NULL, there is a code flow error */
1981 /* Lookup channel in the ust app session */
1982 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1983 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1984 /* If the channel is not found, there is a code flow error */
1985 assert(ua_chan_node
);
1987 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1989 lttng_ht_lookup(ua_chan
->events
, (void*)uevent
->attr
.name
, &uiter
);
1990 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1991 if (ua_event_node
== NULL
) {
1992 DBG3("UST app enable event %s not found for app PID %d."
1993 "Skipping app", uevent
->attr
.name
, app
->pid
);
1996 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1998 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2010 * For a specific existing UST session and UST channel, creates the event for
2011 * all registered apps.
2013 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2014 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2017 struct lttng_ht_iter iter
, uiter
;
2018 struct lttng_ht_node_str
*ua_chan_node
;
2019 struct ust_app
*app
;
2020 struct ust_app_session
*ua_sess
;
2021 struct ust_app_channel
*ua_chan
;
2023 DBG("UST app creating event %s for all apps for session id %d",
2024 uevent
->attr
.name
, usess
->id
);
2028 /* For all registered applications */
2029 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2030 if (!app
->compatible
) {
2032 * TODO: In time, we should notice the caller of this error by
2033 * telling him that this is a version error.
2037 ua_sess
= lookup_session_by_app(usess
, app
);
2038 /* If ua_sess is NULL, there is a code flow error */
2041 /* Lookup channel in the ust app session */
2042 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2043 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2044 /* If the channel is not found, there is a code flow error */
2045 assert(ua_chan_node
);
2047 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2049 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2051 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
2052 /* Possible value at this point: -ENOMEM. If so, we stop! */
2055 DBG2("UST app event %s already exist on app PID %d",
2056 uevent
->attr
.name
, app
->pid
);
2067 * Start tracing for a specific UST session and app.
2069 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2072 struct lttng_ht_iter iter
;
2073 struct ust_app_session
*ua_sess
;
2074 struct ust_app_channel
*ua_chan
;
2075 struct ltt_ust_stream
*ustream
;
2076 struct consumer_socket
*socket
;
2078 DBG("Starting tracing for ust app pid %d", app
->pid
);
2082 if (!app
->compatible
) {
2086 ua_sess
= lookup_session_by_app(usess
, app
);
2087 if (ua_sess
== NULL
) {
2088 goto error_rcu_unlock
;
2091 /* Upon restart, we skip the setup, already done */
2092 if (ua_sess
->started
) {
2096 /* Create directories if consumer is LOCAL and has a path defined. */
2097 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
2098 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
2099 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
2100 S_IRWXU
| S_IRWXG
, usess
->uid
, usess
->gid
);
2102 if (ret
!= -EEXIST
) {
2103 ERR("Trace directory creation error");
2105 goto error_rcu_unlock
;
2110 /* Indicate that the session has been started once */
2111 ua_sess
->started
= 1;
2113 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2115 ret
= LTTNG_ERR_UST_META_FAIL
;
2116 goto error_rcu_unlock
;
2119 /* For each channel */
2120 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2122 /* Create all streams */
2124 /* Create UST stream */
2125 ustream
= zmalloc(sizeof(*ustream
));
2126 if (ustream
== NULL
) {
2127 PERROR("zmalloc ust stream");
2128 goto error_rcu_unlock
;
2131 /* We are going to receive 2 fds, we need to reserve them. */
2132 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2134 ERR("Exhausted number of available FD upon stream create");
2136 goto error_rcu_unlock
;
2139 health_code_update(&health_thread_cmd
);
2141 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2144 /* Got all streams */
2145 lttng_fd_put(LTTNG_FD_APPS
, 2);
2147 ret
= LTTNG_ERR_UST_STREAM_FAIL
;
2150 ustream
->handle
= ustream
->obj
->handle
;
2152 health_code_update(&health_thread_cmd
);
2154 /* Order is important */
2155 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2156 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2157 ua_chan
->name
, ua_chan
->streams
.count
);
2158 ua_chan
->streams
.count
++;
2160 PERROR("asprintf UST create stream");
2162 * XXX what should we do here with the
2167 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2171 health_code_update(&health_thread_cmd
);
2174 switch (app
->bits_per_long
) {
2176 socket
= consumer_find_socket(uatomic_read(&ust_consumerd64_fd
),
2178 if (socket
== NULL
) {
2183 socket
= consumer_find_socket(uatomic_read(&ust_consumerd32_fd
),
2185 if (socket
== NULL
) {
2191 goto error_rcu_unlock
;
2194 /* Setup UST consumer socket and send fds to it */
2195 ret
= ust_consumer_send_session(ua_sess
, usess
->consumer
, socket
);
2197 goto error_rcu_unlock
;
2200 health_code_update(&health_thread_cmd
);
2203 /* This start the UST tracing */
2204 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2206 ERR("Error starting tracing for app pid: %d", app
->pid
);
2207 goto error_rcu_unlock
;
2210 health_code_update(&health_thread_cmd
);
2212 /* Quiescent wait after starting trace */
2213 ustctl_wait_quiescent(app
->sock
);
2217 health_code_update(&health_thread_cmd
);
2222 health_code_update(&health_thread_cmd
);
2227 * Stop tracing for a specific UST session and app.
2229 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2232 struct lttng_ht_iter iter
;
2233 struct ust_app_session
*ua_sess
;
2234 struct ust_app_channel
*ua_chan
;
2236 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2240 if (!app
->compatible
) {
2244 ua_sess
= lookup_session_by_app(usess
, app
);
2245 if (ua_sess
== NULL
) {
2246 /* Only malloc can failed so something is really wrong */
2247 goto error_rcu_unlock
;
2251 * If started = 0, it means that stop trace has been called for a session
2252 * that was never started. This is a code flow error and should never
2255 assert(ua_sess
->started
== 1);
2257 health_code_update(&health_thread_cmd
);
2259 /* This inhibits UST tracing */
2260 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2262 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2263 goto error_rcu_unlock
;
2266 health_code_update(&health_thread_cmd
);
2268 /* Quiescent wait after stopping trace */
2269 ustctl_wait_quiescent(app
->sock
);
2271 health_code_update(&health_thread_cmd
);
2273 /* Flushing buffers */
2274 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2276 health_code_update(&health_thread_cmd
);
2277 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2279 ERR("UST app PID %d channel %s flush failed with ret %d",
2280 app
->pid
, ua_chan
->name
, ret
);
2281 /* Continuing flushing all buffers */
2286 health_code_update(&health_thread_cmd
);
2288 /* Flush all buffers before stopping */
2289 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2291 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2297 health_code_update(&health_thread_cmd
);
2302 health_code_update(&health_thread_cmd
);
2307 * Destroy a specific UST session in apps.
2309 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2311 struct ust_app_session
*ua_sess
;
2312 struct lttng_ust_object_data obj
;
2313 struct lttng_ht_iter iter
;
2314 struct lttng_ht_node_ulong
*node
;
2317 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2321 if (!app
->compatible
) {
2325 __lookup_session_by_app(usess
, app
, &iter
);
2326 node
= lttng_ht_iter_get_node_ulong(&iter
);
2328 /* Only malloc can failed so something is really wrong */
2329 goto error_rcu_unlock
;
2331 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2332 ret
= lttng_ht_del(app
->sessions
, &iter
);
2334 obj
.handle
= ua_sess
->handle
;
2337 obj
.memory_map_size
= 0;
2338 health_code_update(&health_thread_cmd
);
2339 ustctl_release_object(app
->sock
, &obj
);
2341 health_code_update(&health_thread_cmd
);
2342 delete_ust_app_session(app
->sock
, ua_sess
);
2344 /* Quiescent wait after stopping trace */
2345 ustctl_wait_quiescent(app
->sock
);
2349 health_code_update(&health_thread_cmd
);
2354 health_code_update(&health_thread_cmd
);
2359 * Start tracing for the UST session.
2361 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2364 struct lttng_ht_iter iter
;
2365 struct ust_app
*app
;
2367 DBG("Starting all UST traces");
2371 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2372 ret
= ust_app_start_trace(usess
, app
);
2374 /* Continue to next apps even on error */
2385 * Start tracing for the UST session.
2387 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2390 struct lttng_ht_iter iter
;
2391 struct ust_app
*app
;
2393 DBG("Stopping all UST traces");
2397 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2398 ret
= ust_app_stop_trace(usess
, app
);
2400 /* Continue to next apps even on error */
2411 * Destroy app UST session.
2413 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2416 struct lttng_ht_iter iter
;
2417 struct ust_app
*app
;
2419 DBG("Destroy all UST traces");
2423 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2424 ret
= ust_app_destroy_trace(usess
, app
);
2426 /* Continue to next apps even on error */
2437 * Add channels/events from UST global domain to registered apps at sock.
2439 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2442 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2443 struct ust_app
*app
;
2444 struct ust_app_session
*ua_sess
;
2445 struct ust_app_channel
*ua_chan
;
2446 struct ust_app_event
*ua_event
;
2447 struct ust_app_ctx
*ua_ctx
;
2449 if (usess
== NULL
) {
2450 ERR("No UST session on global update. Returning");
2454 DBG2("UST app global update for app sock %d for session id %d", sock
,
2459 app
= find_app_by_sock(sock
);
2461 ERR("Failed to update app sock %d", sock
);
2465 if (!app
->compatible
) {
2469 ua_sess
= create_ust_app_session(usess
, app
);
2470 if (ua_sess
== NULL
|| ua_sess
== (void *) -1UL) {
2471 /* Tracer is gone for this session and has been freed */
2476 * We can iterate safely here over all UST app session sicne the create ust
2477 * app session above made a shadow copy of the UST global domain from the
2480 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2482 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2484 /* FIXME: Should we quit here or continue... */
2488 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2490 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2492 /* FIXME: Should we quit here or continue... */
2498 /* For each events */
2499 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2501 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2503 /* FIXME: Should we quit here or continue... */
2507 ret
= set_ust_event_filter(ua_event
, app
);
2509 /* FIXME: Should we quit here or continue... */
2515 if (usess
->start_trace
) {
2516 ret
= ust_app_start_trace(usess
, app
);
2521 DBG2("UST trace started for app pid %d", app
->pid
);
2530 * Add context to a specific channel for global UST domain.
2532 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2533 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2536 struct lttng_ht_node_str
*ua_chan_node
;
2537 struct lttng_ht_iter iter
, uiter
;
2538 struct ust_app_channel
*ua_chan
= NULL
;
2539 struct ust_app_session
*ua_sess
;
2540 struct ust_app
*app
;
2544 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2545 if (!app
->compatible
) {
2547 * TODO: In time, we should notice the caller of this error by
2548 * telling him that this is a version error.
2552 ua_sess
= lookup_session_by_app(usess
, app
);
2553 if (ua_sess
== NULL
) {
2557 /* Lookup channel in the ust app session */
2558 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2559 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2560 if (ua_chan_node
== NULL
) {
2563 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2566 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2577 * Add context to a specific event in a channel for global UST domain.
2579 int ust_app_set_filter_event_glb(struct ltt_ust_session
*usess
,
2580 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
2581 struct lttng_filter_bytecode
*bytecode
)
2584 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2585 struct lttng_ht_iter iter
, uiter
;
2586 struct ust_app_session
*ua_sess
;
2587 struct ust_app_event
*ua_event
;
2588 struct ust_app_channel
*ua_chan
= NULL
;
2589 struct ust_app
*app
;
2593 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2594 if (!app
->compatible
) {
2596 * TODO: In time, we should notice the caller of this error by
2597 * telling him that this is a version error.
2601 ua_sess
= lookup_session_by_app(usess
, app
);
2602 if (ua_sess
== NULL
) {
2606 /* Lookup channel in the ust app session */
2607 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2608 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2609 if (ua_chan_node
== NULL
) {
2612 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2615 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
2616 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2617 if (ua_event_node
== NULL
) {
2620 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
,
2623 ret
= set_ust_app_event_filter(ua_sess
, ua_event
, bytecode
, app
);
2634 * Enable event for a channel from a UST session for a specific PID.
2636 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2637 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2640 struct lttng_ht_iter iter
;
2641 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2642 struct ust_app
*app
;
2643 struct ust_app_session
*ua_sess
;
2644 struct ust_app_channel
*ua_chan
;
2645 struct ust_app_event
*ua_event
;
2647 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2651 app
= ust_app_find_by_pid(pid
);
2653 ERR("UST app enable event per PID %d not found", pid
);
2658 if (!app
->compatible
) {
2663 ua_sess
= lookup_session_by_app(usess
, app
);
2664 /* If ua_sess is NULL, there is a code flow error */
2667 /* Lookup channel in the ust app session */
2668 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2669 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2670 /* If the channel is not found, there is a code flow error */
2671 assert(ua_chan_node
);
2673 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2675 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2676 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2677 if (ua_event_node
== NULL
) {
2678 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2683 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2685 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2697 * Disable event for a channel from a UST session for a specific PID.
2699 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2700 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2703 struct lttng_ht_iter iter
;
2704 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2705 struct ust_app
*app
;
2706 struct ust_app_session
*ua_sess
;
2707 struct ust_app_channel
*ua_chan
;
2708 struct ust_app_event
*ua_event
;
2710 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2714 app
= ust_app_find_by_pid(pid
);
2716 ERR("UST app disable event per PID %d not found", pid
);
2721 if (!app
->compatible
) {
2726 ua_sess
= lookup_session_by_app(usess
, app
);
2727 /* If ua_sess is NULL, there is a code flow error */
2730 /* Lookup channel in the ust app session */
2731 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2732 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2733 if (ua_chan_node
== NULL
) {
2734 /* Channel does not exist, skip disabling */
2737 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2739 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2740 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2741 if (ua_event_node
== NULL
) {
2742 /* Event does not exist, skip disabling */
2745 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2747 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2758 * Validate version of UST apps and set the compatible bit.
2760 int ust_app_validate_version(int sock
)
2763 struct ust_app
*app
;
2767 app
= find_app_by_sock(sock
);
2770 health_code_update(&health_thread_cmd
);
2772 ret
= ustctl_tracer_version(sock
, &app
->version
);
2777 /* Validate version */
2778 if (app
->version
.major
!= UST_APP_MAJOR_VERSION
) {
2782 DBG2("UST app PID %d is compatible with internal major version %d "
2783 "(supporting == %d)", app
->pid
, app
->version
.major
,
2784 UST_APP_MAJOR_VERSION
);
2785 app
->compatible
= 1;
2787 health_code_update(&health_thread_cmd
);
2791 DBG2("UST app PID %d is not compatible with internal major version %d "
2792 "(supporting == %d)", app
->pid
, app
->version
.major
,
2793 UST_APP_MAJOR_VERSION
);
2794 app
->compatible
= 0;
2796 health_code_update(&health_thread_cmd
);
2801 * Calibrate registered applications.
2803 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2806 struct lttng_ht_iter iter
;
2807 struct ust_app
*app
;
2811 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2812 if (!app
->compatible
) {
2814 * TODO: In time, we should notice the caller of this error by
2815 * telling him that this is a version error.
2820 health_code_update(&health_thread_cmd
);
2822 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2826 /* Means that it's not implemented on the tracer side. */
2830 /* TODO: Report error to user */
2831 DBG2("Calibrate app PID %d returned with error %d",
2838 DBG("UST app global domain calibration finished");
2842 health_code_update(&health_thread_cmd
);