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>
29 #include <common/common.h>
30 #include <common/sessiond-comm/sessiond-comm.h>
35 #include "ust-consumer.h"
39 * Delete ust context safely. RCU read lock must be held before calling
43 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
)
46 ustctl_release_object(sock
, ua_ctx
->obj
);
53 * Delete ust app event safely. RCU read lock must be held before calling
57 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
60 struct lttng_ht_iter iter
;
61 struct ust_app_ctx
*ua_ctx
;
63 /* Destroy each context of event */
64 cds_lfht_for_each_entry(ua_event
->ctx
->ht
, &iter
.iter
, ua_ctx
,
66 ret
= lttng_ht_del(ua_event
->ctx
, &iter
);
68 delete_ust_app_ctx(sock
, ua_ctx
);
70 free(ua_event
->filter
);
71 lttng_ht_destroy(ua_event
->ctx
);
73 if (ua_event
->obj
!= NULL
) {
74 ustctl_release_object(sock
, ua_event
->obj
);
81 * Delete ust app stream safely. RCU read lock must be held before calling
85 void delete_ust_app_stream(int sock
, struct ltt_ust_stream
*stream
)
88 ustctl_release_object(sock
, stream
->obj
);
89 lttng_fd_put(LTTNG_FD_APPS
, 2);
96 * Delete ust app channel safely. RCU read lock must be held before calling
100 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
)
103 struct lttng_ht_iter iter
;
104 struct ust_app_event
*ua_event
;
105 struct ust_app_ctx
*ua_ctx
;
106 struct ltt_ust_stream
*stream
, *stmp
;
109 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
110 cds_list_del(&stream
->list
);
111 delete_ust_app_stream(sock
, stream
);
115 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
116 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
118 delete_ust_app_ctx(sock
, ua_ctx
);
120 lttng_ht_destroy(ua_chan
->ctx
);
123 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
125 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
127 delete_ust_app_event(sock
, ua_event
);
129 lttng_ht_destroy(ua_chan
->events
);
131 if (ua_chan
->obj
!= NULL
) {
132 ustctl_release_object(sock
, ua_chan
->obj
);
133 lttng_fd_put(LTTNG_FD_APPS
, 2);
140 * Delete ust app session safely. RCU read lock must be held before calling
144 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
)
147 struct lttng_ht_iter iter
;
148 struct ust_app_channel
*ua_chan
;
150 if (ua_sess
->metadata
) {
151 if (ua_sess
->metadata
->stream_obj
) {
152 ustctl_release_object(sock
, ua_sess
->metadata
->stream_obj
);
153 lttng_fd_put(LTTNG_FD_APPS
, 2);
154 free(ua_sess
->metadata
->stream_obj
);
156 if (ua_sess
->metadata
->obj
) {
157 ustctl_release_object(sock
, ua_sess
->metadata
->obj
);
158 lttng_fd_put(LTTNG_FD_APPS
, 2);
159 free(ua_sess
->metadata
->obj
);
161 trace_ust_destroy_metadata(ua_sess
->metadata
);
164 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
166 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
168 delete_ust_app_channel(sock
, ua_chan
);
170 lttng_ht_destroy(ua_sess
->channels
);
172 if (ua_sess
->handle
!= -1) {
173 ustctl_release_handle(sock
, ua_sess
->handle
);
179 * Delete a traceable application structure from the global list. Never call
180 * this function outside of a call_rcu call.
183 void delete_ust_app(struct ust_app
*app
)
186 struct lttng_ht_iter iter
;
187 struct ust_app_session
*ua_sess
;
191 /* Delete ust app sessions info */
196 cds_lfht_for_each_entry(app
->sessions
->ht
, &iter
.iter
, ua_sess
,
198 ret
= lttng_ht_del(app
->sessions
, &iter
);
200 delete_ust_app_session(app
->sock
, ua_sess
);
202 lttng_ht_destroy(app
->sessions
);
205 * Wait until we have deleted the application from the sock hash table
206 * before closing this socket, otherwise an application could re-use the
207 * socket ID and race with the teardown, using the same hash table entry.
209 * It's OK to leave the close in call_rcu. We want it to stay unique for
210 * all RCU readers that could run concurrently with unregister app,
211 * therefore we _need_ to only close that socket after a grace period. So
212 * it should stay in this RCU callback.
214 * This close() is a very important step of the synchronization model so
215 * every modification to this function must be carefully reviewed.
221 lttng_fd_put(LTTNG_FD_APPS
, 1);
223 DBG2("UST app pid %d deleted", app
->pid
);
230 * URCU intermediate call to delete an UST app.
233 void delete_ust_app_rcu(struct rcu_head
*head
)
235 struct lttng_ht_node_ulong
*node
=
236 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
237 struct ust_app
*app
=
238 caa_container_of(node
, struct ust_app
, pid_n
);
240 DBG3("Call RCU deleting app PID %d", app
->pid
);
245 * Alloc new UST app session.
248 struct ust_app_session
*alloc_ust_app_session(void)
250 struct ust_app_session
*ua_sess
;
252 /* Init most of the default value by allocating and zeroing */
253 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
254 if (ua_sess
== NULL
) {
259 ua_sess
->handle
= -1;
260 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
269 * Alloc new UST app channel.
272 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
273 struct lttng_ust_channel
*attr
)
275 struct ust_app_channel
*ua_chan
;
277 /* Init most of the default value by allocating and zeroing */
278 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
279 if (ua_chan
== NULL
) {
284 /* Setup channel name */
285 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
286 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
288 ua_chan
->enabled
= 1;
289 ua_chan
->handle
= -1;
290 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
291 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
292 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
294 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
296 /* Copy attributes */
298 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
301 DBG3("UST app channel %s allocated", ua_chan
->name
);
310 * Alloc new UST app event.
313 struct ust_app_event
*alloc_ust_app_event(char *name
,
314 struct lttng_ust_event
*attr
)
316 struct ust_app_event
*ua_event
;
318 /* Init most of the default value by allocating and zeroing */
319 ua_event
= zmalloc(sizeof(struct ust_app_event
));
320 if (ua_event
== NULL
) {
325 ua_event
->enabled
= 1;
326 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
327 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
328 ua_event
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
329 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
331 /* Copy attributes */
333 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
336 DBG3("UST app event %s allocated", ua_event
->name
);
345 * Alloc new UST app context.
348 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
350 struct ust_app_ctx
*ua_ctx
;
352 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
353 if (ua_ctx
== NULL
) {
358 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
361 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
368 * Find an ust_app using the sock and return it. RCU read side lock must be
369 * held before calling this helper function.
372 struct ust_app
*find_app_by_sock(int sock
)
374 struct lttng_ht_node_ulong
*node
;
375 struct lttng_ht_iter iter
;
377 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
378 node
= lttng_ht_iter_get_node_ulong(&iter
);
380 DBG2("UST app find by sock %d not found", sock
);
384 return caa_container_of(node
, struct ust_app
, sock_n
);
391 * Create the channel context on the tracer.
394 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
395 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
399 health_code_update(&health_thread_cmd
);
401 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
402 ua_chan
->obj
, &ua_ctx
->obj
);
407 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
409 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
412 health_code_update(&health_thread_cmd
);
417 * Create the event context on the tracer.
420 int create_ust_event_context(struct ust_app_event
*ua_event
,
421 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
425 health_code_update(&health_thread_cmd
);
427 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
428 ua_event
->obj
, &ua_ctx
->obj
);
433 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
435 DBG2("UST app context created successfully for event %s", ua_event
->name
);
438 health_code_update(&health_thread_cmd
);
443 * Set the filter on the tracer.
446 int set_ust_event_filter(struct ust_app_event
*ua_event
,
451 health_code_update(&health_thread_cmd
);
453 if (!ua_event
->filter
) {
458 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
464 DBG2("UST filter set successfully for event %s", ua_event
->name
);
467 health_code_update(&health_thread_cmd
);
472 * Disable the specified event on to UST tracer for the UST session.
474 static int disable_ust_event(struct ust_app
*app
,
475 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
479 health_code_update(&health_thread_cmd
);
481 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
483 ERR("UST app event %s disable failed for app (pid: %d) "
484 "and session handle %d with ret %d",
485 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
489 DBG2("UST app event %s disabled successfully for app (pid: %d)",
490 ua_event
->attr
.name
, app
->pid
);
493 health_code_update(&health_thread_cmd
);
498 * Disable the specified channel on to UST tracer for the UST session.
500 static int disable_ust_channel(struct ust_app
*app
,
501 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
505 health_code_update(&health_thread_cmd
);
507 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
509 ERR("UST app channel %s disable failed for app (pid: %d) "
510 "and session handle %d with ret %d",
511 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
515 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
516 ua_chan
->name
, app
->pid
);
519 health_code_update(&health_thread_cmd
);
524 * Enable the specified channel on to UST tracer for the UST session.
526 static int enable_ust_channel(struct ust_app
*app
,
527 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
531 health_code_update(&health_thread_cmd
);
533 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
535 ERR("UST app channel %s enable failed for app (pid: %d) "
536 "and session handle %d with ret %d",
537 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
541 ua_chan
->enabled
= 1;
543 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
544 ua_chan
->name
, app
->pid
);
547 health_code_update(&health_thread_cmd
);
552 * Enable the specified event on to UST tracer for the UST session.
554 static int enable_ust_event(struct ust_app
*app
,
555 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
559 health_code_update(&health_thread_cmd
);
561 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
563 ERR("UST app event %s enable failed for app (pid: %d) "
564 "and session handle %d with ret %d",
565 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
569 DBG2("UST app event %s enabled successfully for app (pid: %d)",
570 ua_event
->attr
.name
, app
->pid
);
573 health_code_update(&health_thread_cmd
);
578 * Open metadata onto the UST tracer for a UST session.
580 static int open_ust_metadata(struct ust_app
*app
,
581 struct ust_app_session
*ua_sess
)
584 struct lttng_ust_channel_attr uattr
;
586 health_code_update(&health_thread_cmd
);
588 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
589 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
590 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
591 uattr
.switch_timer_interval
=
592 ua_sess
->metadata
->attr
.switch_timer_interval
;
593 uattr
.read_timer_interval
=
594 ua_sess
->metadata
->attr
.read_timer_interval
;
595 uattr
.output
= ua_sess
->metadata
->attr
.output
;
597 /* We are going to receive 2 fds, we need to reserve them. */
598 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
600 ERR("Exhausted number of available FD upon metadata open");
603 /* UST tracer metadata creation */
604 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
605 &ua_sess
->metadata
->obj
);
607 ERR("UST app open metadata failed for app pid:%d with ret %d",
612 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
615 health_code_update(&health_thread_cmd
);
620 * Create stream onto the UST tracer for a UST session.
622 static int create_ust_stream(struct ust_app
*app
,
623 struct ust_app_session
*ua_sess
)
627 health_code_update(&health_thread_cmd
);
629 /* We are going to receive 2 fds, we need to reserve them. */
630 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
632 ERR("Exhausted number of available FD upon metadata stream create");
635 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
636 &ua_sess
->metadata
->stream_obj
);
638 ERR("UST create metadata stream failed");
643 health_code_update(&health_thread_cmd
);
648 * Create the specified channel onto the UST tracer for a UST session.
650 static int create_ust_channel(struct ust_app
*app
,
651 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
655 health_code_update(&health_thread_cmd
);
657 /* TODO: remove cast and use lttng-ust-abi.h */
659 /* We are going to receive 2 fds, we need to reserve them. */
660 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
662 ERR("Exhausted number of available FD upon create channel");
666 health_code_update(&health_thread_cmd
);
668 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
669 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
671 ERR("Creating channel %s for app (pid: %d, sock: %d) "
672 "and session handle %d with ret %d",
673 ua_chan
->name
, app
->pid
, app
->sock
,
674 ua_sess
->handle
, ret
);
675 lttng_fd_put(LTTNG_FD_APPS
, 2);
679 ua_chan
->handle
= ua_chan
->obj
->handle
;
681 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
682 ua_chan
->name
, app
->pid
, app
->sock
);
684 health_code_update(&health_thread_cmd
);
686 /* If channel is not enabled, disable it on the tracer */
687 if (!ua_chan
->enabled
) {
688 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
695 health_code_update(&health_thread_cmd
);
700 * Create the specified event onto the UST tracer for a UST session.
703 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
704 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
708 health_code_update(&health_thread_cmd
);
710 /* Create UST event on tracer */
711 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
714 if (ret
== -EEXIST
|| ret
== -EPERM
) {
718 ERR("Error ustctl create event %s for app pid: %d with ret %d",
719 ua_event
->attr
.name
, app
->pid
, ret
);
723 ua_event
->handle
= ua_event
->obj
->handle
;
725 DBG2("UST app event %s created successfully for pid:%d",
726 ua_event
->attr
.name
, app
->pid
);
728 health_code_update(&health_thread_cmd
);
730 /* If event not enabled, disable it on the tracer */
731 if (ua_event
->enabled
== 0) {
732 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
735 * If we hit an EPERM, something is wrong with our disable call. If
736 * we get an EEXIST, there is a problem on the tracer side since we
741 /* Code flow problem */
744 /* It's OK for our use case. */
755 health_code_update(&health_thread_cmd
);
760 * Copy data between an UST app event and a LTT event.
762 static void shadow_copy_event(struct ust_app_event
*ua_event
,
763 struct ltt_ust_event
*uevent
)
765 struct lttng_ht_iter iter
;
766 struct ltt_ust_context
*uctx
;
767 struct ust_app_ctx
*ua_ctx
;
769 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
770 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
772 ua_event
->enabled
= uevent
->enabled
;
774 /* Copy event attributes */
775 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
777 /* Copy filter bytecode */
778 if (uevent
->filter
) {
779 ua_event
->filter
= zmalloc(sizeof(*ua_event
->filter
) +
780 uevent
->filter
->len
);
781 if (!ua_event
->filter
) {
784 memcpy(ua_event
->filter
, uevent
->filter
,
785 sizeof(*ua_event
->filter
) + uevent
->filter
->len
);
787 cds_lfht_for_each_entry(uevent
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
788 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
789 if (ua_ctx
== NULL
) {
790 /* malloc() failed. We should simply stop */
794 lttng_ht_node_init_ulong(&ua_ctx
->node
,
795 (unsigned long) ua_ctx
->ctx
.ctx
);
796 lttng_ht_add_unique_ulong(ua_event
->ctx
, &ua_ctx
->node
);
801 * Copy data between an UST app channel and a LTT channel.
803 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
804 struct ltt_ust_channel
*uchan
)
806 struct lttng_ht_iter iter
;
807 struct lttng_ht_node_str
*ua_event_node
;
808 struct ltt_ust_event
*uevent
;
809 struct ltt_ust_context
*uctx
;
810 struct ust_app_event
*ua_event
;
811 struct ust_app_ctx
*ua_ctx
;
813 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
815 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
816 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
817 /* Copy event attributes */
818 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
820 ua_chan
->enabled
= uchan
->enabled
;
822 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
823 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
824 if (ua_ctx
== NULL
) {
827 lttng_ht_node_init_ulong(&ua_ctx
->node
,
828 (unsigned long) ua_ctx
->ctx
.ctx
);
829 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
832 /* Copy all events from ltt ust channel to ust app channel */
833 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
834 struct lttng_ht_iter uiter
;
836 lttng_ht_lookup(ua_chan
->events
, (void *) uevent
->attr
.name
, &uiter
);
837 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
838 if (ua_event_node
== NULL
) {
839 DBG2("UST event %s not found on shadow copy channel",
841 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
842 if (ua_event
== NULL
) {
845 shadow_copy_event(ua_event
, uevent
);
846 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
850 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
854 * Copy data between a UST app session and a regular LTT session.
856 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
857 struct ltt_ust_session
*usess
, struct ust_app
*app
)
859 struct lttng_ht_node_str
*ua_chan_node
;
860 struct lttng_ht_iter iter
;
861 struct ltt_ust_channel
*uchan
;
862 struct ust_app_channel
*ua_chan
;
868 /* Get date and time for unique app path */
870 timeinfo
= localtime(&rawtime
);
871 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
873 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
875 ua_sess
->id
= usess
->id
;
876 ua_sess
->uid
= usess
->uid
;
877 ua_sess
->gid
= usess
->gid
;
879 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
882 PERROR("asprintf UST shadow copy session");
883 /* TODO: We cannot return an error from here.. */
887 /* TODO: support all UST domain */
889 /* Iterate over all channels in global domain. */
890 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
892 struct lttng_ht_iter uiter
;
894 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
895 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
896 if (ua_chan_node
!= NULL
) {
897 /* Session exist. Contiuing. */
901 DBG2("Channel %s not found on shadow session copy, creating it",
903 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
904 if (ua_chan
== NULL
) {
905 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
909 shadow_copy_channel(ua_chan
, uchan
);
910 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
915 * Lookup sesison wrapper.
918 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
919 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
921 /* Get right UST app session from app */
922 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
926 * Return ust app session from the app session hashtable using the UST session
929 static struct ust_app_session
*lookup_session_by_app(
930 struct ltt_ust_session
*usess
, struct ust_app
*app
)
932 struct lttng_ht_iter iter
;
933 struct lttng_ht_node_ulong
*node
;
935 __lookup_session_by_app(usess
, app
, &iter
);
936 node
= lttng_ht_iter_get_node_ulong(&iter
);
941 return caa_container_of(node
, struct ust_app_session
, node
);
948 * Create a UST session onto the tracer of app and add it the session
951 * Return ust app session or NULL on error.
953 static struct ust_app_session
*create_ust_app_session(
954 struct ltt_ust_session
*usess
, struct ust_app
*app
)
957 struct ust_app_session
*ua_sess
;
959 health_code_update(&health_thread_cmd
);
961 ua_sess
= lookup_session_by_app(usess
, app
);
962 if (ua_sess
== NULL
) {
963 DBG2("UST app pid: %d session id %d not found, creating it",
964 app
->pid
, usess
->id
);
965 ua_sess
= alloc_ust_app_session();
966 if (ua_sess
== NULL
) {
967 /* Only malloc can failed so something is really wrong */
970 shadow_copy_session(ua_sess
, usess
, app
);
973 health_code_update(&health_thread_cmd
);
975 if (ua_sess
->handle
== -1) {
976 ret
= ustctl_create_session(app
->sock
);
978 ERR("Creating session for app pid %d", app
->pid
);
979 /* This means that the tracer is gone... */
980 ua_sess
= (void*) -1UL;
984 ua_sess
->handle
= ret
;
986 /* Add ust app session to app's HT */
987 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
988 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
990 DBG2("UST app session created successfully with handle %d", ret
);
994 health_code_update(&health_thread_cmd
);
998 delete_ust_app_session(-1, ua_sess
);
999 health_code_update(&health_thread_cmd
);
1004 * Create a context for the channel on the tracer.
1007 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
1008 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
1009 struct ust_app
*app
)
1012 struct lttng_ht_iter iter
;
1013 struct lttng_ht_node_ulong
*node
;
1014 struct ust_app_ctx
*ua_ctx
;
1016 DBG2("UST app adding context to channel %s", ua_chan
->name
);
1018 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1019 node
= lttng_ht_iter_get_node_ulong(&iter
);
1025 ua_ctx
= alloc_ust_app_ctx(uctx
);
1026 if (ua_ctx
== NULL
) {
1032 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1033 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1035 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
1045 * Create an UST context and enable it for the event on the tracer.
1048 int create_ust_app_event_context(struct ust_app_session
*ua_sess
,
1049 struct ust_app_event
*ua_event
, struct lttng_ust_context
*uctx
,
1050 struct ust_app
*app
)
1053 struct lttng_ht_iter iter
;
1054 struct lttng_ht_node_ulong
*node
;
1055 struct ust_app_ctx
*ua_ctx
;
1057 DBG2("UST app adding context to event %s", ua_event
->name
);
1059 lttng_ht_lookup(ua_event
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1060 node
= lttng_ht_iter_get_node_ulong(&iter
);
1066 ua_ctx
= alloc_ust_app_ctx(uctx
);
1067 if (ua_ctx
== NULL
) {
1073 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1074 lttng_ht_add_unique_ulong(ua_event
->ctx
, &ua_ctx
->node
);
1076 ret
= create_ust_event_context(ua_event
, ua_ctx
, app
);
1086 * Set UST filter for the event on the tracer.
1089 int set_ust_app_event_filter(struct ust_app_session
*ua_sess
,
1090 struct ust_app_event
*ua_event
,
1091 struct lttng_filter_bytecode
*bytecode
,
1092 struct ust_app
*app
)
1096 DBG2("UST app adding context to event %s", ua_event
->name
);
1098 /* Copy filter bytecode */
1099 ua_event
->filter
= zmalloc(sizeof(*ua_event
->filter
) + bytecode
->len
);
1100 if (!ua_event
->filter
) {
1103 memcpy(ua_event
->filter
, bytecode
,
1104 sizeof(*ua_event
->filter
) + bytecode
->len
);
1105 ret
= set_ust_event_filter(ua_event
, app
);
1115 * Enable on the tracer side a ust app event for the session and channel.
1118 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1119 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1123 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1128 ua_event
->enabled
= 1;
1135 * Disable on the tracer side a ust app event for the session and channel.
1137 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1138 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1142 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1147 ua_event
->enabled
= 0;
1154 * Lookup ust app channel for session and disable it on the tracer side.
1157 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1158 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1162 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1167 ua_chan
->enabled
= 0;
1174 * Lookup ust app channel for session and enable it on the tracer side.
1176 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1177 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1180 struct lttng_ht_iter iter
;
1181 struct lttng_ht_node_str
*ua_chan_node
;
1182 struct ust_app_channel
*ua_chan
;
1184 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1185 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1186 if (ua_chan_node
== NULL
) {
1187 DBG2("Unable to find channel %s in ust session id %u",
1188 uchan
->name
, ua_sess
->id
);
1192 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1194 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1204 * Create UST app channel and create it on the tracer.
1206 static struct ust_app_channel
*create_ust_app_channel(
1207 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
1208 struct ust_app
*app
)
1211 struct lttng_ht_iter iter
;
1212 struct lttng_ht_node_str
*ua_chan_node
;
1213 struct ust_app_channel
*ua_chan
;
1215 /* Lookup channel in the ust app session */
1216 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1217 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1218 if (ua_chan_node
!= NULL
) {
1219 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1223 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1224 if (ua_chan
== NULL
) {
1225 /* Only malloc can fail here */
1228 shadow_copy_channel(ua_chan
, uchan
);
1230 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1232 /* Not found previously means that it does not exist on the tracer */
1233 assert(ret
!= -EEXIST
);
1237 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1239 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1246 delete_ust_app_channel(-1, ua_chan
);
1251 * Create UST app event and create it on the tracer side.
1254 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1255 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1256 struct ust_app
*app
)
1259 struct lttng_ht_iter iter
;
1260 struct lttng_ht_node_str
*ua_event_node
;
1261 struct ust_app_event
*ua_event
;
1263 /* Get event node */
1264 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
1265 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
1266 if (ua_event_node
!= NULL
) {
1271 /* Does not exist so create one */
1272 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1273 if (ua_event
== NULL
) {
1274 /* Only malloc can failed so something is really wrong */
1278 shadow_copy_event(ua_event
, uevent
);
1280 /* Create it on the tracer side */
1281 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1283 /* Not found previously means that it does not exist on the tracer */
1284 assert(ret
!= -EEXIST
);
1288 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
1290 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1297 /* Valid. Calling here is already in a read side lock */
1298 delete_ust_app_event(-1, ua_event
);
1303 * Create UST metadata and open it on the tracer side.
1305 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1306 char *pathname
, struct ust_app
*app
)
1310 if (ua_sess
->metadata
== NULL
) {
1311 /* Allocate UST metadata */
1312 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1313 if (ua_sess
->metadata
== NULL
) {
1314 /* malloc() failed */
1318 ret
= open_ust_metadata(app
, ua_sess
);
1320 DBG3("Opening metadata failed. Cleaning up memory");
1322 /* Cleanup failed metadata struct */
1323 free(ua_sess
->metadata
);
1325 * This is very important because delete_ust_app_session check if
1326 * the pointer is null or not in order to delete the metadata.
1328 ua_sess
->metadata
= NULL
;
1332 DBG2("UST metadata opened for app pid %d", app
->pid
);
1335 /* Open UST metadata stream */
1336 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1337 ret
= create_ust_stream(app
, ua_sess
);
1342 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1343 "%s/metadata", ua_sess
->path
);
1345 PERROR("asprintf UST create stream");
1349 DBG2("UST metadata stream object created for app pid %d",
1352 ERR("Attempting to create stream without metadata opened");
1363 * Return pointer to traceable apps list.
1365 struct lttng_ht
*ust_app_get_ht(void)
1371 * Return ust app pointer or NULL if not found.
1373 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1375 struct lttng_ht_node_ulong
*node
;
1376 struct lttng_ht_iter iter
;
1379 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1380 node
= lttng_ht_iter_get_node_ulong(&iter
);
1382 DBG2("UST app no found with pid %d", pid
);
1387 DBG2("Found UST app by pid %d", pid
);
1389 return caa_container_of(node
, struct ust_app
, pid_n
);
1397 * Using pid and uid (of the app), allocate a new ust_app struct and
1398 * add it to the global traceable app list.
1400 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1401 * bitness is not supported.
1403 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1405 struct ust_app
*lta
;
1408 if ((msg
->bits_per_long
== 64 && ust_consumerd64_fd
== -EINVAL
)
1409 || (msg
->bits_per_long
== 32 && ust_consumerd32_fd
== -EINVAL
)) {
1410 ERR("Registration failed: application \"%s\" (pid: %d) has "
1411 "%d-bit long, but no consumerd for this long size is available.\n",
1412 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1417 lttng_fd_put(LTTNG_FD_APPS
, 1);
1420 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1421 ERR("Registration failed: application \"%s\" (pid: %d) has "
1422 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1423 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1428 lttng_fd_put(LTTNG_FD_APPS
, 1);
1431 lta
= zmalloc(sizeof(struct ust_app
));
1437 lta
->ppid
= msg
->ppid
;
1438 lta
->uid
= msg
->uid
;
1439 lta
->gid
= msg
->gid
;
1440 lta
->compatible
= 0; /* Not compatible until proven */
1441 lta
->bits_per_long
= msg
->bits_per_long
;
1442 lta
->v_major
= msg
->major
;
1443 lta
->v_minor
= msg
->minor
;
1444 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1445 lta
->name
[16] = '\0';
1446 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1448 lta
->pid
= msg
->pid
;
1449 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1451 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1456 * On a re-registration, we want to kick out the previous registration of
1459 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1462 * The socket _should_ be unique until _we_ call close. So, a add_unique
1463 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1464 * already in the table.
1466 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1470 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1471 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1472 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1478 * Unregister app by removing it from the global traceable app list and freeing
1481 * The socket is already closed at this point so no close to sock.
1483 void ust_app_unregister(int sock
)
1485 struct ust_app
*lta
;
1486 struct lttng_ht_node_ulong
*node
;
1487 struct lttng_ht_iter iter
;
1492 /* Get the node reference for a call_rcu */
1493 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1494 node
= lttng_ht_iter_get_node_ulong(&iter
);
1496 ERR("Unable to find app by sock %d", sock
);
1500 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1502 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1504 /* Remove application from PID hash table */
1505 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1508 /* Assign second node for deletion */
1509 iter
.iter
.node
= <a
->pid_n
.node
;
1511 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1515 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1523 * Return traceable_app_count
1525 unsigned long ust_app_list_count(void)
1527 unsigned long count
;
1530 count
= lttng_ht_get_count(ust_app_ht
);
1537 * Fill events array with all events name of all registered apps.
1539 int ust_app_list_events(struct lttng_event
**events
)
1542 size_t nbmem
, count
= 0;
1543 struct lttng_ht_iter iter
;
1544 struct ust_app
*app
;
1545 struct lttng_event
*tmp
;
1547 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1548 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1550 PERROR("zmalloc ust app events");
1557 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1558 struct lttng_ust_tracepoint_iter uiter
;
1560 health_code_update(&health_thread_cmd
);
1562 if (!app
->compatible
) {
1564 * TODO: In time, we should notice the caller of this error by
1565 * telling him that this is a version error.
1569 handle
= ustctl_tracepoint_list(app
->sock
);
1571 ERR("UST app list events getting handle failed for app pid %d",
1576 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1577 &uiter
)) != -ENOENT
) {
1578 health_code_update(&health_thread_cmd
);
1579 if (count
>= nbmem
) {
1580 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1583 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event
));
1585 PERROR("realloc ust app events");
1590 memcpy(tmp
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1591 tmp
[count
].loglevel
= uiter
.loglevel
;
1592 tmp
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1593 tmp
[count
].pid
= app
->pid
;
1594 tmp
[count
].enabled
= -1;
1602 DBG2("UST app list events done (%zu events)", count
);
1607 health_code_update(&health_thread_cmd
);
1612 * Fill events array with all events name of all registered apps.
1614 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1617 size_t nbmem
, count
= 0;
1618 struct lttng_ht_iter iter
;
1619 struct ust_app
*app
;
1620 struct lttng_event_field
*tmp
;
1622 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1623 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1625 PERROR("zmalloc ust app event fields");
1632 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1633 struct lttng_ust_field_iter uiter
;
1635 health_code_update(&health_thread_cmd
);
1637 if (!app
->compatible
) {
1639 * TODO: In time, we should notice the caller of this error by
1640 * telling him that this is a version error.
1644 handle
= ustctl_tracepoint_field_list(app
->sock
);
1646 ERR("UST app list event fields getting handle failed for app pid %d",
1651 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1652 &uiter
)) != -ENOENT
) {
1653 health_code_update(&health_thread_cmd
);
1654 if (count
>= nbmem
) {
1655 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1658 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event_field
));
1660 PERROR("realloc ust app event fields");
1666 memcpy(tmp
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1667 tmp
[count
].type
= uiter
.type
;
1669 memcpy(tmp
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1670 tmp
[count
].event
.loglevel
= uiter
.loglevel
;
1671 tmp
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1672 tmp
[count
].event
.pid
= app
->pid
;
1673 tmp
[count
].event
.enabled
= -1;
1681 DBG2("UST app list event fields done (%zu events)", count
);
1686 health_code_update(&health_thread_cmd
);
1691 * Free and clean all traceable apps of the global list.
1693 void ust_app_clean_list(void)
1696 struct lttng_ht_iter iter
;
1697 struct lttng_ht_node_ulong
*node
;
1699 DBG2("UST app cleaning registered apps hash table");
1703 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, node
, node
) {
1704 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1706 call_rcu(&node
->head
, delete_ust_app_rcu
);
1709 /* Cleanup socket hash table */
1710 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, node
, node
) {
1711 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1715 /* Destroy is done only when the ht is empty */
1716 lttng_ht_destroy(ust_app_ht
);
1717 lttng_ht_destroy(ust_app_ht_by_sock
);
1723 * Init UST app hash table.
1725 void ust_app_ht_alloc(void)
1727 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1728 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1732 * For a specific UST session, disable the channel for all registered apps.
1734 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1735 struct ltt_ust_channel
*uchan
)
1738 struct lttng_ht_iter iter
;
1739 struct lttng_ht_node_str
*ua_chan_node
;
1740 struct ust_app
*app
;
1741 struct ust_app_session
*ua_sess
;
1742 struct ust_app_channel
*ua_chan
;
1744 if (usess
== NULL
|| uchan
== NULL
) {
1745 ERR("Disabling UST global channel with NULL values");
1750 DBG2("UST app disabling channel %s from global domain for session id %d",
1751 uchan
->name
, usess
->id
);
1755 /* For every registered applications */
1756 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1757 struct lttng_ht_iter uiter
;
1758 if (!app
->compatible
) {
1760 * TODO: In time, we should notice the caller of this error by
1761 * telling him that this is a version error.
1765 ua_sess
= lookup_session_by_app(usess
, app
);
1766 if (ua_sess
== NULL
) {
1771 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1772 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1773 /* If the session if found for the app, the channel must be there */
1774 assert(ua_chan_node
);
1776 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1777 /* The channel must not be already disabled */
1778 assert(ua_chan
->enabled
== 1);
1780 /* Disable channel onto application */
1781 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1783 /* XXX: We might want to report this error at some point... */
1795 * For a specific UST session, enable the channel for all registered apps.
1797 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1798 struct ltt_ust_channel
*uchan
)
1801 struct lttng_ht_iter iter
;
1802 struct ust_app
*app
;
1803 struct ust_app_session
*ua_sess
;
1805 if (usess
== NULL
|| uchan
== NULL
) {
1806 ERR("Adding UST global channel to NULL values");
1811 DBG2("UST app enabling channel %s to global domain for session id %d",
1812 uchan
->name
, usess
->id
);
1816 /* For every registered applications */
1817 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
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
) {
1830 /* Enable channel onto application */
1831 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1833 /* XXX: We might want to report this error at some point... */
1845 * Disable an event in a channel and for a specific session.
1847 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1848 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1851 struct lttng_ht_iter iter
, uiter
;
1852 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1853 struct ust_app
*app
;
1854 struct ust_app_session
*ua_sess
;
1855 struct ust_app_channel
*ua_chan
;
1856 struct ust_app_event
*ua_event
;
1858 DBG("UST app disabling event %s for all apps in channel "
1859 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1863 /* For all registered applications */
1864 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1865 if (!app
->compatible
) {
1867 * TODO: In time, we should notice the caller of this error by
1868 * telling him that this is a version error.
1872 ua_sess
= lookup_session_by_app(usess
, app
);
1873 if (ua_sess
== NULL
) {
1878 /* Lookup channel in the ust app session */
1879 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1880 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1881 if (ua_chan_node
== NULL
) {
1882 DBG2("Channel %s not found in session id %d for app pid %d."
1883 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1886 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1888 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1889 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1890 if (ua_event_node
== NULL
) {
1891 DBG2("Event %s not found in channel %s for app pid %d."
1892 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1895 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1897 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1899 /* XXX: Report error someday... */
1910 * For a specific UST session and UST channel, the event for all
1913 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1914 struct ltt_ust_channel
*uchan
)
1917 struct lttng_ht_iter iter
, uiter
;
1918 struct lttng_ht_node_str
*ua_chan_node
;
1919 struct ust_app
*app
;
1920 struct ust_app_session
*ua_sess
;
1921 struct ust_app_channel
*ua_chan
;
1922 struct ust_app_event
*ua_event
;
1924 DBG("UST app disabling all event for all apps in channel "
1925 "%s for session id %d", uchan
->name
, usess
->id
);
1929 /* For all registered applications */
1930 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1931 if (!app
->compatible
) {
1933 * TODO: In time, we should notice the caller of this error by
1934 * telling him that this is a version error.
1938 ua_sess
= lookup_session_by_app(usess
, app
);
1939 /* If ua_sess is NULL, there is a code flow error */
1942 /* Lookup channel in the ust app session */
1943 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1944 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1945 /* If the channel is not found, there is a code flow error */
1946 assert(ua_chan_node
);
1948 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1950 /* Disable each events of channel */
1951 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
1953 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1955 /* XXX: Report error someday... */
1967 * For a specific UST session, create the channel for all registered apps.
1969 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
1970 struct ltt_ust_channel
*uchan
)
1972 struct lttng_ht_iter iter
;
1973 struct ust_app
*app
;
1974 struct ust_app_session
*ua_sess
;
1975 struct ust_app_channel
*ua_chan
;
1977 /* Very wrong code flow */
1981 DBG2("UST app adding channel %s to global domain for session id %d",
1982 uchan
->name
, usess
->id
);
1986 /* For every registered applications */
1987 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1988 if (!app
->compatible
) {
1990 * TODO: In time, we should notice the caller of this error by
1991 * telling him that this is a version error.
1996 * Create session on the tracer side and add it to app session HT. Note
1997 * that if session exist, it will simply return a pointer to the ust
2000 ua_sess
= create_ust_app_session(usess
, app
);
2001 if (ua_sess
== NULL
) {
2002 /* The malloc() failed. */
2004 } else if (ua_sess
== (void *) -1UL) {
2005 /* The application's socket is not valid. Contiuing */
2009 /* Create channel onto application */
2010 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
2011 if (ua_chan
== NULL
) {
2012 /* Major problem here and it's maybe the tracer or malloc() */
2026 * Enable event for a specific session and channel on the tracer.
2028 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
2029 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2032 struct lttng_ht_iter iter
, uiter
;
2033 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2034 struct ust_app
*app
;
2035 struct ust_app_session
*ua_sess
;
2036 struct ust_app_channel
*ua_chan
;
2037 struct ust_app_event
*ua_event
;
2039 DBG("UST app enabling event %s for all apps for session id %d",
2040 uevent
->attr
.name
, usess
->id
);
2043 * NOTE: At this point, this function is called only if the session and
2044 * channel passed are already created for all apps. and enabled on the
2050 /* For all registered applications */
2051 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2052 if (!app
->compatible
) {
2054 * TODO: In time, we should notice the caller of this error by
2055 * telling him that this is a version error.
2059 ua_sess
= lookup_session_by_app(usess
, app
);
2060 /* If ua_sess is NULL, there is a code flow error */
2063 /* Lookup channel in the ust app session */
2064 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2065 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2066 /* If the channel is not found, there is a code flow error */
2067 assert(ua_chan_node
);
2069 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2071 lttng_ht_lookup(ua_chan
->events
, (void*)uevent
->attr
.name
, &uiter
);
2072 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2073 if (ua_event_node
== NULL
) {
2074 DBG3("UST app enable event %s not found for app PID %d."
2075 "Skipping app", uevent
->attr
.name
, app
->pid
);
2078 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2080 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2092 * For a specific existing UST session and UST channel, creates the event for
2093 * all registered apps.
2095 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2096 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2099 struct lttng_ht_iter iter
, uiter
;
2100 struct lttng_ht_node_str
*ua_chan_node
;
2101 struct ust_app
*app
;
2102 struct ust_app_session
*ua_sess
;
2103 struct ust_app_channel
*ua_chan
;
2105 DBG("UST app creating event %s for all apps for session id %d",
2106 uevent
->attr
.name
, usess
->id
);
2110 /* For all registered applications */
2111 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2112 if (!app
->compatible
) {
2114 * TODO: In time, we should notice the caller of this error by
2115 * telling him that this is a version error.
2119 ua_sess
= lookup_session_by_app(usess
, app
);
2120 /* If ua_sess is NULL, there is a code flow error */
2123 /* Lookup channel in the ust app session */
2124 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2125 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2126 /* If the channel is not found, there is a code flow error */
2127 assert(ua_chan_node
);
2129 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2131 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2133 if (ret
!= -EEXIST
) {
2134 /* Possible value at this point: -ENOMEM. If so, we stop! */
2137 DBG2("UST app event %s already exist on app PID %d",
2138 uevent
->attr
.name
, app
->pid
);
2149 * Start tracing for a specific UST session and app.
2151 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2154 struct lttng_ht_iter iter
;
2155 struct ust_app_session
*ua_sess
;
2156 struct ust_app_channel
*ua_chan
;
2157 struct ltt_ust_stream
*ustream
;
2160 DBG("Starting tracing for ust app pid %d", app
->pid
);
2164 if (!app
->compatible
) {
2168 ua_sess
= lookup_session_by_app(usess
, app
);
2169 if (ua_sess
== NULL
) {
2170 goto error_rcu_unlock
;
2173 /* Upon restart, we skip the setup, already done */
2174 if (ua_sess
->started
) {
2178 /* Indicate that the session has been started once */
2179 ua_sess
->started
= 1;
2181 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2183 goto error_rcu_unlock
;
2186 /* For each channel */
2187 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2189 /* Create all streams */
2191 /* Create UST stream */
2192 ustream
= zmalloc(sizeof(*ustream
));
2193 if (ustream
== NULL
) {
2194 PERROR("zmalloc ust stream");
2195 goto error_rcu_unlock
;
2198 /* We are going to receive 2 fds, we need to reserve them. */
2199 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2201 ERR("Exhausted number of available FD upon stream create");
2203 goto error_rcu_unlock
;
2206 health_code_update(&health_thread_cmd
);
2208 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2211 /* Got all streams */
2212 lttng_fd_put(LTTNG_FD_APPS
, 2);
2216 ustream
->handle
= ustream
->obj
->handle
;
2218 health_code_update(&health_thread_cmd
);
2220 /* Order is important */
2221 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2222 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2223 ua_chan
->name
, ua_chan
->streams
.count
++);
2225 PERROR("asprintf UST create stream");
2227 * XXX what should we do here with the
2232 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2236 health_code_update(&health_thread_cmd
);
2239 switch (app
->bits_per_long
) {
2241 consumerd_fd
= ust_consumerd64_fd
;
2244 consumerd_fd
= ust_consumerd32_fd
;
2248 goto error_rcu_unlock
;
2251 /* Setup UST consumer socket and send fds to it */
2252 ret
= ust_consumer_send_session(consumerd_fd
, ua_sess
, usess
->consumer
);
2254 goto error_rcu_unlock
;
2257 health_code_update(&health_thread_cmd
);
2260 /* This start the UST tracing */
2261 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2263 ERR("Error starting tracing for app pid: %d", app
->pid
);
2264 goto error_rcu_unlock
;
2267 health_code_update(&health_thread_cmd
);
2269 /* Quiescent wait after starting trace */
2270 ustctl_wait_quiescent(app
->sock
);
2274 health_code_update(&health_thread_cmd
);
2279 health_code_update(&health_thread_cmd
);
2284 * Stop tracing for a specific UST session and app.
2286 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2289 struct lttng_ht_iter iter
;
2290 struct ust_app_session
*ua_sess
;
2291 struct ust_app_channel
*ua_chan
;
2293 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2297 if (!app
->compatible
) {
2301 ua_sess
= lookup_session_by_app(usess
, app
);
2302 if (ua_sess
== NULL
) {
2303 /* Only malloc can failed so something is really wrong */
2304 goto error_rcu_unlock
;
2308 * If started = 0, it means that stop trace has been called for a session
2309 * that was never started. This is a code flow error and should never
2312 assert(ua_sess
->started
== 1);
2314 health_code_update(&health_thread_cmd
);
2316 /* This inhibits UST tracing */
2317 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2319 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2320 goto error_rcu_unlock
;
2323 health_code_update(&health_thread_cmd
);
2325 /* Quiescent wait after stopping trace */
2326 ustctl_wait_quiescent(app
->sock
);
2328 health_code_update(&health_thread_cmd
);
2330 /* Flushing buffers */
2331 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2333 health_code_update(&health_thread_cmd
);
2334 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2336 ERR("UST app PID %d channel %s flush failed with ret %d",
2337 app
->pid
, ua_chan
->name
, ret
);
2338 /* Continuing flushing all buffers */
2343 health_code_update(&health_thread_cmd
);
2345 /* Flush all buffers before stopping */
2346 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2348 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2354 health_code_update(&health_thread_cmd
);
2359 health_code_update(&health_thread_cmd
);
2364 * Destroy a specific UST session in apps.
2366 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2368 struct ust_app_session
*ua_sess
;
2369 struct lttng_ust_object_data obj
;
2370 struct lttng_ht_iter iter
;
2371 struct lttng_ht_node_ulong
*node
;
2374 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2378 if (!app
->compatible
) {
2382 __lookup_session_by_app(usess
, app
, &iter
);
2383 node
= lttng_ht_iter_get_node_ulong(&iter
);
2385 /* Only malloc can failed so something is really wrong */
2386 goto error_rcu_unlock
;
2388 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2389 ret
= lttng_ht_del(app
->sessions
, &iter
);
2391 obj
.handle
= ua_sess
->handle
;
2394 obj
.memory_map_size
= 0;
2395 health_code_update(&health_thread_cmd
);
2396 ustctl_release_object(app
->sock
, &obj
);
2398 health_code_update(&health_thread_cmd
);
2399 delete_ust_app_session(app
->sock
, ua_sess
);
2401 /* Quiescent wait after stopping trace */
2402 ustctl_wait_quiescent(app
->sock
);
2406 health_code_update(&health_thread_cmd
);
2411 health_code_update(&health_thread_cmd
);
2416 * Start tracing for the UST session.
2418 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2421 struct lttng_ht_iter iter
;
2422 struct ust_app
*app
;
2424 DBG("Starting all UST traces");
2428 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2429 ret
= ust_app_start_trace(usess
, app
);
2431 /* Continue to next apps even on error */
2442 * Start tracing for the UST session.
2444 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2447 struct lttng_ht_iter iter
;
2448 struct ust_app
*app
;
2450 DBG("Stopping all UST traces");
2454 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2455 ret
= ust_app_stop_trace(usess
, app
);
2457 /* Continue to next apps even on error */
2468 * Destroy app UST session.
2470 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2473 struct lttng_ht_iter iter
;
2474 struct ust_app
*app
;
2476 DBG("Destroy all UST traces");
2480 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2481 ret
= ust_app_destroy_trace(usess
, app
);
2483 /* Continue to next apps even on error */
2494 * Add channels/events from UST global domain to registered apps at sock.
2496 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2499 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2500 struct ust_app
*app
;
2501 struct ust_app_session
*ua_sess
;
2502 struct ust_app_channel
*ua_chan
;
2503 struct ust_app_event
*ua_event
;
2504 struct ust_app_ctx
*ua_ctx
;
2506 if (usess
== NULL
) {
2507 ERR("No UST session on global update. Returning");
2511 DBG2("UST app global update for app sock %d for session id %d", sock
,
2516 app
= find_app_by_sock(sock
);
2518 ERR("Failed to update app sock %d", sock
);
2522 if (!app
->compatible
) {
2526 ua_sess
= create_ust_app_session(usess
, app
);
2527 if (ua_sess
== NULL
) {
2532 * We can iterate safely here over all UST app session sicne the create ust
2533 * app session above made a shadow copy of the UST global domain from the
2536 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2538 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2540 /* FIXME: Should we quit here or continue... */
2544 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2546 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2548 /* FIXME: Should we quit here or continue... */
2554 /* For each events */
2555 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2557 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2559 /* FIXME: Should we quit here or continue... */
2563 /* Add context on events. */
2564 cds_lfht_for_each_entry(ua_event
->ctx
->ht
, &iter_ctx
.iter
,
2565 ua_ctx
, node
.node
) {
2566 ret
= create_ust_event_context(ua_event
, ua_ctx
, app
);
2568 /* FIXME: Should we quit here or continue... */
2572 ret
= set_ust_event_filter(ua_event
, app
);
2574 /* FIXME: Should we quit here or continue... */
2580 if (usess
->start_trace
) {
2581 ret
= ust_app_start_trace(usess
, app
);
2586 DBG2("UST trace started for app pid %d", app
->pid
);
2595 * Add context to a specific channel for global UST domain.
2597 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2598 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2601 struct lttng_ht_node_str
*ua_chan_node
;
2602 struct lttng_ht_iter iter
, uiter
;
2603 struct ust_app_channel
*ua_chan
= NULL
;
2604 struct ust_app_session
*ua_sess
;
2605 struct ust_app
*app
;
2609 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2610 if (!app
->compatible
) {
2612 * TODO: In time, we should notice the caller of this error by
2613 * telling him that this is a version error.
2617 ua_sess
= lookup_session_by_app(usess
, app
);
2618 if (ua_sess
== NULL
) {
2622 /* Lookup channel in the ust app session */
2623 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2624 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2625 if (ua_chan_node
== NULL
) {
2628 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2631 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2642 * Add context to a specific event in a channel for global UST domain.
2644 int ust_app_add_ctx_event_glb(struct ltt_ust_session
*usess
,
2645 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
2646 struct ltt_ust_context
*uctx
)
2649 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2650 struct lttng_ht_iter iter
, uiter
;
2651 struct ust_app_session
*ua_sess
;
2652 struct ust_app_event
*ua_event
;
2653 struct ust_app_channel
*ua_chan
= NULL
;
2654 struct ust_app
*app
;
2658 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2659 if (!app
->compatible
) {
2661 * TODO: In time, we should notice the caller of this error by
2662 * telling him that this is a version error.
2666 ua_sess
= lookup_session_by_app(usess
, app
);
2667 if (ua_sess
== NULL
) {
2671 /* Lookup channel in the ust app session */
2672 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2673 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2674 if (ua_chan_node
== NULL
) {
2677 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2680 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
2681 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2682 if (ua_event_node
== NULL
) {
2685 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
,
2688 ret
= create_ust_app_event_context(ua_sess
, ua_event
, &uctx
->ctx
, app
);
2699 * Add context to a specific event in a channel for global UST domain.
2701 int ust_app_set_filter_event_glb(struct ltt_ust_session
*usess
,
2702 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
2703 struct lttng_filter_bytecode
*bytecode
)
2706 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2707 struct lttng_ht_iter iter
, uiter
;
2708 struct ust_app_session
*ua_sess
;
2709 struct ust_app_event
*ua_event
;
2710 struct ust_app_channel
*ua_chan
= NULL
;
2711 struct ust_app
*app
;
2715 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2716 if (!app
->compatible
) {
2718 * TODO: In time, we should notice the caller of this error by
2719 * telling him that this is a version error.
2723 ua_sess
= lookup_session_by_app(usess
, app
);
2724 if (ua_sess
== NULL
) {
2728 /* Lookup channel in the ust app session */
2729 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2730 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2731 if (ua_chan_node
== NULL
) {
2734 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2737 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
2738 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2739 if (ua_event_node
== NULL
) {
2742 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
,
2745 ret
= set_ust_app_event_filter(ua_sess
, ua_event
, bytecode
, app
);
2756 * Enable event for a channel from a UST session for a specific PID.
2758 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2759 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2762 struct lttng_ht_iter iter
;
2763 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2764 struct ust_app
*app
;
2765 struct ust_app_session
*ua_sess
;
2766 struct ust_app_channel
*ua_chan
;
2767 struct ust_app_event
*ua_event
;
2769 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2773 app
= ust_app_find_by_pid(pid
);
2775 ERR("UST app enable event per PID %d not found", pid
);
2780 if (!app
->compatible
) {
2785 ua_sess
= lookup_session_by_app(usess
, app
);
2786 /* If ua_sess is NULL, there is a code flow error */
2789 /* Lookup channel in the ust app session */
2790 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2791 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2792 /* If the channel is not found, there is a code flow error */
2793 assert(ua_chan_node
);
2795 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2797 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2798 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2799 if (ua_event_node
== NULL
) {
2800 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2805 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2807 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2819 * Disable event for a channel from a UST session for a specific PID.
2821 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2822 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2825 struct lttng_ht_iter iter
;
2826 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2827 struct ust_app
*app
;
2828 struct ust_app_session
*ua_sess
;
2829 struct ust_app_channel
*ua_chan
;
2830 struct ust_app_event
*ua_event
;
2832 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2836 app
= ust_app_find_by_pid(pid
);
2838 ERR("UST app disable event per PID %d not found", pid
);
2843 if (!app
->compatible
) {
2848 ua_sess
= lookup_session_by_app(usess
, app
);
2849 /* If ua_sess is NULL, there is a code flow error */
2852 /* Lookup channel in the ust app session */
2853 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2854 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2855 if (ua_chan_node
== NULL
) {
2856 /* Channel does not exist, skip disabling */
2859 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2861 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2862 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2863 if (ua_event_node
== NULL
) {
2864 /* Event does not exist, skip disabling */
2867 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2869 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2880 * Validate version of UST apps and set the compatible bit.
2882 int ust_app_validate_version(int sock
)
2885 struct ust_app
*app
;
2889 app
= find_app_by_sock(sock
);
2892 health_code_update(&health_thread_cmd
);
2894 ret
= ustctl_tracer_version(sock
, &app
->version
);
2899 /* Validate version */
2900 if (app
->version
.major
> UST_APP_MAJOR_VERSION
) {
2904 DBG2("UST app PID %d is compatible with major version %d "
2905 "(supporting <= %d)", app
->pid
, app
->version
.major
,
2906 UST_APP_MAJOR_VERSION
);
2907 app
->compatible
= 1;
2909 health_code_update(&health_thread_cmd
);
2913 DBG2("UST app PID %d is not compatible with major version %d "
2914 "(supporting <= %d)", app
->pid
, app
->version
.major
,
2915 UST_APP_MAJOR_VERSION
);
2916 app
->compatible
= 0;
2918 health_code_update(&health_thread_cmd
);
2923 * Calibrate registered applications.
2925 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2928 struct lttng_ht_iter iter
;
2929 struct ust_app
*app
;
2933 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2934 if (!app
->compatible
) {
2936 * TODO: In time, we should notice the caller of this error by
2937 * telling him that this is a version error.
2942 health_code_update(&health_thread_cmd
);
2944 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2948 /* Means that it's not implemented on the tracer side. */
2952 /* TODO: Report error to user */
2953 DBG2("Calibrate app PID %d returned with error %d",
2960 DBG("UST app global domain calibration finished");
2964 health_code_update(&health_thread_cmd
);