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>
32 #include "ust-consumer.h"
35 #include "../../common/sessiond-comm/sessiond-comm.h"
38 * Delete ust context safely. RCU read lock must be held before calling
42 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
)
45 ustctl_release_object(sock
, ua_ctx
->obj
);
52 * Delete ust app event safely. RCU read lock must be held before calling
56 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
59 struct lttng_ht_iter iter
;
60 struct ust_app_ctx
*ua_ctx
;
62 /* Destroy each context of event */
63 cds_lfht_for_each_entry(ua_event
->ctx
->ht
, &iter
.iter
, ua_ctx
,
65 ret
= lttng_ht_del(ua_event
->ctx
, &iter
);
67 delete_ust_app_ctx(sock
, ua_ctx
);
69 free(ua_event
->filter
);
70 lttng_ht_destroy(ua_event
->ctx
);
72 if (ua_event
->obj
!= NULL
) {
73 ustctl_release_object(sock
, ua_event
->obj
);
80 * Delete ust app stream safely. RCU read lock must be held before calling
84 void delete_ust_app_stream(int sock
, struct ltt_ust_stream
*stream
)
87 ustctl_release_object(sock
, stream
->obj
);
88 lttng_fd_put(LTTNG_FD_APPS
, 2);
95 * Delete ust app channel safely. RCU read lock must be held before calling
99 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
)
102 struct lttng_ht_iter iter
;
103 struct ust_app_event
*ua_event
;
104 struct ust_app_ctx
*ua_ctx
;
105 struct ltt_ust_stream
*stream
, *stmp
;
108 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
109 cds_list_del(&stream
->list
);
110 delete_ust_app_stream(sock
, stream
);
114 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
115 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
117 delete_ust_app_ctx(sock
, ua_ctx
);
119 lttng_ht_destroy(ua_chan
->ctx
);
122 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
124 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
126 delete_ust_app_event(sock
, ua_event
);
128 lttng_ht_destroy(ua_chan
->events
);
130 if (ua_chan
->obj
!= NULL
) {
131 ustctl_release_object(sock
, ua_chan
->obj
);
132 lttng_fd_put(LTTNG_FD_APPS
, 2);
139 * Delete ust app session safely. RCU read lock must be held before calling
143 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
)
146 struct lttng_ht_iter iter
;
147 struct ust_app_channel
*ua_chan
;
149 if (ua_sess
->metadata
) {
150 if (ua_sess
->metadata
->stream_obj
) {
151 ustctl_release_object(sock
, ua_sess
->metadata
->stream_obj
);
152 lttng_fd_put(LTTNG_FD_APPS
, 2);
153 free(ua_sess
->metadata
->stream_obj
);
155 if (ua_sess
->metadata
->obj
) {
156 ustctl_release_object(sock
, ua_sess
->metadata
->obj
);
157 lttng_fd_put(LTTNG_FD_APPS
, 2);
158 free(ua_sess
->metadata
->obj
);
160 trace_ust_destroy_metadata(ua_sess
->metadata
);
163 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
165 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
167 delete_ust_app_channel(sock
, ua_chan
);
169 lttng_ht_destroy(ua_sess
->channels
);
171 if (ua_sess
->handle
!= -1) {
172 ustctl_release_handle(sock
, ua_sess
->handle
);
178 * Delete a traceable application structure from the global list. Never call
179 * this function outside of a call_rcu call.
182 void delete_ust_app(struct ust_app
*app
)
185 struct lttng_ht_iter iter
;
186 struct ust_app_session
*ua_sess
;
190 /* Delete ust app sessions info */
195 cds_lfht_for_each_entry(app
->sessions
->ht
, &iter
.iter
, ua_sess
,
197 ret
= lttng_ht_del(app
->sessions
, &iter
);
199 delete_ust_app_session(app
->sock
, ua_sess
);
201 lttng_ht_destroy(app
->sessions
);
204 * Wait until we have deleted the application from the sock hash table
205 * before closing this socket, otherwise an application could re-use the
206 * socket ID and race with the teardown, using the same hash table entry.
208 * It's OK to leave the close in call_rcu. We want it to stay unique for
209 * all RCU readers that could run concurrently with unregister app,
210 * therefore we _need_ to only close that socket after a grace period. So
211 * it should stay in this RCU callback.
213 * This close() is a very important step of the synchronization model so
214 * every modification to this function must be carefully reviewed.
220 lttng_fd_put(LTTNG_FD_APPS
, 1);
222 DBG2("UST app pid %d deleted", app
->pid
);
229 * URCU intermediate call to delete an UST app.
232 void delete_ust_app_rcu(struct rcu_head
*head
)
234 struct lttng_ht_node_ulong
*node
=
235 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
236 struct ust_app
*app
=
237 caa_container_of(node
, struct ust_app
, pid_n
);
239 DBG3("Call RCU deleting app PID %d", app
->pid
);
244 * Alloc new UST app session.
247 struct ust_app_session
*alloc_ust_app_session(void)
249 struct ust_app_session
*ua_sess
;
251 /* Init most of the default value by allocating and zeroing */
252 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
253 if (ua_sess
== NULL
) {
258 ua_sess
->handle
= -1;
259 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
268 * Alloc new UST app channel.
271 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
272 struct lttng_ust_channel
*attr
)
274 struct ust_app_channel
*ua_chan
;
276 /* Init most of the default value by allocating and zeroing */
277 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
278 if (ua_chan
== NULL
) {
283 /* Setup channel name */
284 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
285 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
287 ua_chan
->enabled
= 1;
288 ua_chan
->handle
= -1;
289 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
290 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
291 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
293 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
295 /* Copy attributes */
297 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
300 DBG3("UST app channel %s allocated", ua_chan
->name
);
309 * Alloc new UST app event.
312 struct ust_app_event
*alloc_ust_app_event(char *name
,
313 struct lttng_ust_event
*attr
)
315 struct ust_app_event
*ua_event
;
317 /* Init most of the default value by allocating and zeroing */
318 ua_event
= zmalloc(sizeof(struct ust_app_event
));
319 if (ua_event
== NULL
) {
324 ua_event
->enabled
= 1;
325 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
326 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
327 ua_event
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
328 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
330 /* Copy attributes */
332 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
335 DBG3("UST app event %s allocated", ua_event
->name
);
344 * Alloc new UST app context.
347 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
349 struct ust_app_ctx
*ua_ctx
;
351 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
352 if (ua_ctx
== NULL
) {
357 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
360 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
367 * Find an ust_app using the sock and return it. RCU read side lock must be
368 * held before calling this helper function.
371 struct ust_app
*find_app_by_sock(int sock
)
373 struct lttng_ht_node_ulong
*node
;
374 struct lttng_ht_iter iter
;
376 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
377 node
= lttng_ht_iter_get_node_ulong(&iter
);
379 DBG2("UST app find by sock %d not found", sock
);
383 return caa_container_of(node
, struct ust_app
, sock_n
);
390 * Create the channel context on the tracer.
393 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
394 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
398 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
399 ua_chan
->obj
, &ua_ctx
->obj
);
404 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
406 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
413 * Create the event context on the tracer.
416 int create_ust_event_context(struct ust_app_event
*ua_event
,
417 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
421 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
422 ua_event
->obj
, &ua_ctx
->obj
);
427 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
429 DBG2("UST app context created successfully for event %s", ua_event
->name
);
436 * Set the filter on the tracer.
439 int set_ust_event_filter(struct ust_app_event
*ua_event
,
444 if (!ua_event
->filter
) {
448 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
454 DBG2("UST filter set successfully for event %s", ua_event
->name
);
461 * Disable the specified event on to UST tracer for the UST session.
463 static int disable_ust_event(struct ust_app
*app
,
464 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
468 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
470 ERR("UST app event %s disable failed for app (pid: %d) "
471 "and session handle %d with ret %d",
472 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
476 DBG2("UST app event %s disabled successfully for app (pid: %d)",
477 ua_event
->attr
.name
, app
->pid
);
484 * Disable the specified channel on to UST tracer for the UST session.
486 static int disable_ust_channel(struct ust_app
*app
,
487 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
491 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
493 ERR("UST app channel %s disable failed for app (pid: %d) "
494 "and session handle %d with ret %d",
495 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
499 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
500 ua_chan
->name
, app
->pid
);
507 * Enable the specified channel on to UST tracer for the UST session.
509 static int enable_ust_channel(struct ust_app
*app
,
510 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
514 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
516 ERR("UST app channel %s enable failed for app (pid: %d) "
517 "and session handle %d with ret %d",
518 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
522 ua_chan
->enabled
= 1;
524 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
525 ua_chan
->name
, app
->pid
);
532 * Enable the specified event on to UST tracer for the UST session.
534 static int enable_ust_event(struct ust_app
*app
,
535 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
539 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
541 ERR("UST app event %s enable failed for app (pid: %d) "
542 "and session handle %d with ret %d",
543 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
547 DBG2("UST app event %s enabled successfully for app (pid: %d)",
548 ua_event
->attr
.name
, app
->pid
);
555 * Open metadata onto the UST tracer for a UST session.
557 static int open_ust_metadata(struct ust_app
*app
,
558 struct ust_app_session
*ua_sess
)
561 struct lttng_ust_channel_attr uattr
;
563 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
564 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
565 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
566 uattr
.switch_timer_interval
=
567 ua_sess
->metadata
->attr
.switch_timer_interval
;
568 uattr
.read_timer_interval
=
569 ua_sess
->metadata
->attr
.read_timer_interval
;
570 uattr
.output
= ua_sess
->metadata
->attr
.output
;
572 /* We are going to receive 2 fds, we need to reserve them. */
573 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
575 ERR("Exhausted number of available FD upon metadata open");
578 /* UST tracer metadata creation */
579 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
580 &ua_sess
->metadata
->obj
);
582 ERR("UST app open metadata failed for app pid:%d with ret %d",
587 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
594 * Create stream onto the UST tracer for a UST session.
596 static int create_ust_stream(struct ust_app
*app
,
597 struct ust_app_session
*ua_sess
)
601 /* We are going to receive 2 fds, we need to reserve them. */
602 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
604 ERR("Exhausted number of available FD upon metadata stream create");
607 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
608 &ua_sess
->metadata
->stream_obj
);
610 ERR("UST create metadata stream failed");
619 * Create the specified channel onto the UST tracer for a UST session.
621 static int create_ust_channel(struct ust_app
*app
,
622 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
626 /* TODO: remove cast and use lttng-ust-abi.h */
628 /* We are going to receive 2 fds, we need to reserve them. */
629 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
631 ERR("Exhausted number of available FD upon create channel");
634 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
635 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
637 ERR("Creating channel %s for app (pid: %d, sock: %d) "
638 "and session handle %d with ret %d",
639 ua_chan
->name
, app
->pid
, app
->sock
,
640 ua_sess
->handle
, ret
);
641 lttng_fd_put(LTTNG_FD_APPS
, 2);
645 ua_chan
->handle
= ua_chan
->obj
->handle
;
647 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
648 ua_chan
->name
, app
->pid
, app
->sock
);
650 /* If channel is not enabled, disable it on the tracer */
651 if (!ua_chan
->enabled
) {
652 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
663 * Create the specified event onto the UST tracer for a UST session.
666 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
667 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
671 /* Create UST event on tracer */
672 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
675 if (ret
== -EEXIST
|| ret
== -EPERM
) {
679 ERR("Error ustctl create event %s for app pid: %d with ret %d",
680 ua_event
->attr
.name
, app
->pid
, ret
);
684 ua_event
->handle
= ua_event
->obj
->handle
;
686 DBG2("UST app event %s created successfully for pid:%d",
687 ua_event
->attr
.name
, app
->pid
);
689 /* If event not enabled, disable it on the tracer */
690 if (ua_event
->enabled
== 0) {
691 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
694 * If we hit an EPERM, something is wrong with our disable call. If
695 * we get an EEXIST, there is a problem on the tracer side since we
700 /* Code flow problem */
703 /* It's OK for our use case. */
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 struct lttng_ht_iter iter
;
724 struct ltt_ust_context
*uctx
;
725 struct ust_app_ctx
*ua_ctx
;
727 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
728 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
730 ua_event
->enabled
= uevent
->enabled
;
732 /* Copy event attributes */
733 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
735 /* Copy filter bytecode */
736 if (uevent
->filter
) {
737 ua_event
->filter
= zmalloc(sizeof(*ua_event
->filter
) +
738 uevent
->filter
->len
);
739 if (!ua_event
->filter
) {
742 memcpy(ua_event
->filter
, uevent
->filter
,
743 sizeof(*ua_event
->filter
) + uevent
->filter
->len
);
745 cds_lfht_for_each_entry(uevent
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
746 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
747 if (ua_ctx
== NULL
) {
748 /* malloc() failed. We should simply stop */
752 lttng_ht_node_init_ulong(&ua_ctx
->node
,
753 (unsigned long) ua_ctx
->ctx
.ctx
);
754 lttng_ht_add_unique_ulong(ua_event
->ctx
, &ua_ctx
->node
);
759 * Copy data between an UST app channel and a LTT channel.
761 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
762 struct ltt_ust_channel
*uchan
)
764 struct lttng_ht_iter iter
;
765 struct lttng_ht_node_str
*ua_event_node
;
766 struct ltt_ust_event
*uevent
;
767 struct ltt_ust_context
*uctx
;
768 struct ust_app_event
*ua_event
;
769 struct ust_app_ctx
*ua_ctx
;
771 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
773 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
774 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
775 /* Copy event attributes */
776 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
778 ua_chan
->enabled
= uchan
->enabled
;
780 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
781 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
782 if (ua_ctx
== NULL
) {
785 lttng_ht_node_init_ulong(&ua_ctx
->node
,
786 (unsigned long) ua_ctx
->ctx
.ctx
);
787 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
790 /* Copy all events from ltt ust channel to ust app channel */
791 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
792 struct lttng_ht_iter uiter
;
794 lttng_ht_lookup(ua_chan
->events
, (void *) uevent
->attr
.name
, &uiter
);
795 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
796 if (ua_event_node
== NULL
) {
797 DBG2("UST event %s not found on shadow copy channel",
799 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
800 if (ua_event
== NULL
) {
803 shadow_copy_event(ua_event
, uevent
);
804 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
808 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
812 * Copy data between a UST app session and a regular LTT session.
814 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
815 struct ltt_ust_session
*usess
, struct ust_app
*app
)
817 struct lttng_ht_node_str
*ua_chan_node
;
818 struct lttng_ht_iter iter
;
819 struct ltt_ust_channel
*uchan
;
820 struct ust_app_channel
*ua_chan
;
826 /* Get date and time for unique app path */
828 timeinfo
= localtime(&rawtime
);
829 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
831 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
833 ua_sess
->id
= usess
->id
;
834 ua_sess
->uid
= usess
->uid
;
835 ua_sess
->gid
= usess
->gid
;
837 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
840 PERROR("asprintf UST shadow copy session");
841 /* TODO: We cannot return an error from here.. */
845 /* TODO: support all UST domain */
847 /* Iterate over all channels in global domain. */
848 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
850 struct lttng_ht_iter uiter
;
852 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
853 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
854 if (ua_chan_node
!= NULL
) {
855 /* Session exist. Contiuing. */
859 DBG2("Channel %s not found on shadow session copy, creating it",
861 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
862 if (ua_chan
== NULL
) {
863 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
867 shadow_copy_channel(ua_chan
, uchan
);
868 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
873 * Lookup sesison wrapper.
876 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
877 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
879 /* Get right UST app session from app */
880 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
884 * Return ust app session from the app session hashtable using the UST session
887 static struct ust_app_session
*lookup_session_by_app(
888 struct ltt_ust_session
*usess
, struct ust_app
*app
)
890 struct lttng_ht_iter iter
;
891 struct lttng_ht_node_ulong
*node
;
893 __lookup_session_by_app(usess
, app
, &iter
);
894 node
= lttng_ht_iter_get_node_ulong(&iter
);
899 return caa_container_of(node
, struct ust_app_session
, node
);
906 * Create a UST session onto the tracer of app and add it the session
909 * Return ust app session or NULL on error.
911 static struct ust_app_session
*create_ust_app_session(
912 struct ltt_ust_session
*usess
, struct ust_app
*app
)
915 struct ust_app_session
*ua_sess
;
917 ua_sess
= lookup_session_by_app(usess
, app
);
918 if (ua_sess
== NULL
) {
919 DBG2("UST app pid: %d session id %d not found, creating it",
920 app
->pid
, usess
->id
);
921 ua_sess
= alloc_ust_app_session();
922 if (ua_sess
== NULL
) {
923 /* Only malloc can failed so something is really wrong */
926 shadow_copy_session(ua_sess
, usess
, app
);
929 if (ua_sess
->handle
== -1) {
930 ret
= ustctl_create_session(app
->sock
);
932 ERR("Creating session for app pid %d", app
->pid
);
933 /* This means that the tracer is gone... */
934 ua_sess
= (void*) -1UL;
938 ua_sess
->handle
= ret
;
940 /* Add ust app session to app's HT */
941 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
942 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
944 DBG2("UST app session created successfully with handle %d", ret
);
951 delete_ust_app_session(-1, ua_sess
);
956 * Create a context for the channel on the tracer.
959 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
960 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
964 struct lttng_ht_iter iter
;
965 struct lttng_ht_node_ulong
*node
;
966 struct ust_app_ctx
*ua_ctx
;
968 DBG2("UST app adding context to channel %s", ua_chan
->name
);
970 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
971 node
= lttng_ht_iter_get_node_ulong(&iter
);
977 ua_ctx
= alloc_ust_app_ctx(uctx
);
978 if (ua_ctx
== NULL
) {
984 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
985 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
987 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
997 * Create an UST context and enable it for the event on the tracer.
1000 int create_ust_app_event_context(struct ust_app_session
*ua_sess
,
1001 struct ust_app_event
*ua_event
, struct lttng_ust_context
*uctx
,
1002 struct ust_app
*app
)
1005 struct lttng_ht_iter iter
;
1006 struct lttng_ht_node_ulong
*node
;
1007 struct ust_app_ctx
*ua_ctx
;
1009 DBG2("UST app adding context to event %s", ua_event
->name
);
1011 lttng_ht_lookup(ua_event
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1012 node
= lttng_ht_iter_get_node_ulong(&iter
);
1018 ua_ctx
= alloc_ust_app_ctx(uctx
);
1019 if (ua_ctx
== NULL
) {
1025 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1026 lttng_ht_add_unique_ulong(ua_event
->ctx
, &ua_ctx
->node
);
1028 ret
= create_ust_event_context(ua_event
, ua_ctx
, app
);
1038 * Set UST filter for the event on the tracer.
1041 int set_ust_app_event_filter(struct ust_app_session
*ua_sess
,
1042 struct ust_app_event
*ua_event
,
1043 struct lttng_filter_bytecode
*bytecode
,
1044 struct ust_app
*app
)
1048 DBG2("UST app adding context to event %s", ua_event
->name
);
1050 /* Copy filter bytecode */
1051 ua_event
->filter
= zmalloc(sizeof(*ua_event
->filter
) + bytecode
->len
);
1052 if (!ua_event
->filter
) {
1055 memcpy(ua_event
->filter
, bytecode
,
1056 sizeof(*ua_event
->filter
) + bytecode
->len
);
1057 ret
= set_ust_event_filter(ua_event
, app
);
1067 * Enable on the tracer side a ust app event for the session and channel.
1070 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1071 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1075 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1080 ua_event
->enabled
= 1;
1087 * Disable on the tracer side a ust app event for the session and channel.
1089 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1090 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1094 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1099 ua_event
->enabled
= 0;
1106 * Lookup ust app channel for session and disable it on the tracer side.
1109 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1110 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1114 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1119 ua_chan
->enabled
= 0;
1126 * Lookup ust app channel for session and enable it on the tracer side.
1128 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1129 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1132 struct lttng_ht_iter iter
;
1133 struct lttng_ht_node_str
*ua_chan_node
;
1134 struct ust_app_channel
*ua_chan
;
1136 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1137 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1138 if (ua_chan_node
== NULL
) {
1139 DBG2("Unable to find channel %s in ust session id %u",
1140 uchan
->name
, ua_sess
->id
);
1144 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1146 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1156 * Create UST app channel and create it on the tracer.
1158 static struct ust_app_channel
*create_ust_app_channel(
1159 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
1160 struct ust_app
*app
)
1163 struct lttng_ht_iter iter
;
1164 struct lttng_ht_node_str
*ua_chan_node
;
1165 struct ust_app_channel
*ua_chan
;
1167 /* Lookup channel in the ust app session */
1168 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1169 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1170 if (ua_chan_node
!= NULL
) {
1171 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1175 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1176 if (ua_chan
== NULL
) {
1177 /* Only malloc can fail here */
1180 shadow_copy_channel(ua_chan
, uchan
);
1182 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1184 /* Not found previously means that it does not exist on the tracer */
1185 assert(ret
!= -EEXIST
);
1189 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1191 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1198 delete_ust_app_channel(-1, ua_chan
);
1203 * Create UST app event and create it on the tracer side.
1206 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1207 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1208 struct ust_app
*app
)
1211 struct lttng_ht_iter iter
;
1212 struct lttng_ht_node_str
*ua_event_node
;
1213 struct ust_app_event
*ua_event
;
1215 /* Get event node */
1216 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
1217 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
1218 if (ua_event_node
!= NULL
) {
1223 /* Does not exist so create one */
1224 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1225 if (ua_event
== NULL
) {
1226 /* Only malloc can failed so something is really wrong */
1230 shadow_copy_event(ua_event
, uevent
);
1232 /* Create it on the tracer side */
1233 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1235 /* Not found previously means that it does not exist on the tracer */
1236 assert(ret
!= -EEXIST
);
1240 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
1242 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1249 /* Valid. Calling here is already in a read side lock */
1250 delete_ust_app_event(-1, ua_event
);
1255 * Create UST metadata and open it on the tracer side.
1257 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1258 char *pathname
, struct ust_app
*app
)
1262 if (ua_sess
->metadata
== NULL
) {
1263 /* Allocate UST metadata */
1264 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1265 if (ua_sess
->metadata
== NULL
) {
1266 /* malloc() failed */
1270 ret
= open_ust_metadata(app
, ua_sess
);
1272 DBG3("Opening metadata failed. Cleaning up memory");
1274 /* Cleanup failed metadata struct */
1275 free(ua_sess
->metadata
);
1277 * This is very important because delete_ust_app_session check if
1278 * the pointer is null or not in order to delete the metadata.
1280 ua_sess
->metadata
= NULL
;
1284 DBG2("UST metadata opened for app pid %d", app
->pid
);
1287 /* Open UST metadata stream */
1288 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1289 ret
= create_ust_stream(app
, ua_sess
);
1294 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1295 "%s/metadata", ua_sess
->path
);
1297 PERROR("asprintf UST create stream");
1301 DBG2("UST metadata stream object created for app pid %d",
1304 ERR("Attempting to create stream without metadata opened");
1315 * Return pointer to traceable apps list.
1317 struct lttng_ht
*ust_app_get_ht(void)
1323 * Return ust app pointer or NULL if not found.
1325 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1327 struct lttng_ht_node_ulong
*node
;
1328 struct lttng_ht_iter iter
;
1331 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1332 node
= lttng_ht_iter_get_node_ulong(&iter
);
1334 DBG2("UST app no found with pid %d", pid
);
1339 DBG2("Found UST app by pid %d", pid
);
1341 return caa_container_of(node
, struct ust_app
, pid_n
);
1349 * Using pid and uid (of the app), allocate a new ust_app struct and
1350 * add it to the global traceable app list.
1352 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1353 * bitness is not supported.
1355 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1357 struct ust_app
*lta
;
1360 if ((msg
->bits_per_long
== 64 && ust_consumerd64_fd
== -EINVAL
)
1361 || (msg
->bits_per_long
== 32 && ust_consumerd32_fd
== -EINVAL
)) {
1362 ERR("Registration failed: application \"%s\" (pid: %d) has "
1363 "%d-bit long, but no consumerd for this long size is available.\n",
1364 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1369 lttng_fd_put(LTTNG_FD_APPS
, 1);
1372 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1373 ERR("Registration failed: application \"%s\" (pid: %d) has "
1374 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1375 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1380 lttng_fd_put(LTTNG_FD_APPS
, 1);
1383 lta
= zmalloc(sizeof(struct ust_app
));
1389 lta
->ppid
= msg
->ppid
;
1390 lta
->uid
= msg
->uid
;
1391 lta
->gid
= msg
->gid
;
1392 lta
->compatible
= 0; /* Not compatible until proven */
1393 lta
->bits_per_long
= msg
->bits_per_long
;
1394 lta
->v_major
= msg
->major
;
1395 lta
->v_minor
= msg
->minor
;
1396 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1397 lta
->name
[16] = '\0';
1398 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1400 lta
->pid
= msg
->pid
;
1401 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1403 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1408 * On a re-registration, we want to kick out the previous registration of
1411 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1414 * The socket _should_ be unique until _we_ call close. So, a add_unique
1415 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1416 * already in the table.
1418 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1422 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1423 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1424 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1430 * Unregister app by removing it from the global traceable app list and freeing
1433 * The socket is already closed at this point so no close to sock.
1435 void ust_app_unregister(int sock
)
1437 struct ust_app
*lta
;
1438 struct lttng_ht_node_ulong
*node
;
1439 struct lttng_ht_iter iter
;
1444 /* Get the node reference for a call_rcu */
1445 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1446 node
= lttng_ht_iter_get_node_ulong(&iter
);
1448 ERR("Unable to find app by sock %d", sock
);
1452 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1454 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1456 /* Remove application from PID hash table */
1457 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1460 /* Assign second node for deletion */
1461 iter
.iter
.node
= <a
->pid_n
.node
;
1463 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1467 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1475 * Return traceable_app_count
1477 unsigned long ust_app_list_count(void)
1479 unsigned long count
;
1482 count
= lttng_ht_get_count(ust_app_ht
);
1489 * Fill events array with all events name of all registered apps.
1491 int ust_app_list_events(struct lttng_event
**events
)
1494 size_t nbmem
, count
= 0;
1495 struct lttng_ht_iter iter
;
1496 struct ust_app
*app
;
1497 struct lttng_event
*tmp
;
1499 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1500 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1502 PERROR("zmalloc ust app events");
1509 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1510 struct lttng_ust_tracepoint_iter uiter
;
1512 if (!app
->compatible
) {
1514 * TODO: In time, we should notice the caller of this error by
1515 * telling him that this is a version error.
1519 handle
= ustctl_tracepoint_list(app
->sock
);
1521 ERR("UST app list events getting handle failed for app pid %d",
1526 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1527 &uiter
)) != -ENOENT
) {
1528 if (count
>= nbmem
) {
1529 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1532 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event
));
1534 PERROR("realloc ust app events");
1539 memcpy(tmp
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1540 tmp
[count
].loglevel
= uiter
.loglevel
;
1541 tmp
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1542 tmp
[count
].pid
= app
->pid
;
1543 tmp
[count
].enabled
= -1;
1551 DBG2("UST app list events done (%zu events)", count
);
1560 * Fill events array with all events name of all registered apps.
1562 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1565 size_t nbmem
, count
= 0;
1566 struct lttng_ht_iter iter
;
1567 struct ust_app
*app
;
1568 struct lttng_event_field
*tmp
;
1570 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1571 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1573 PERROR("zmalloc ust app event fields");
1580 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1581 struct lttng_ust_field_iter uiter
;
1583 if (!app
->compatible
) {
1585 * TODO: In time, we should notice the caller of this error by
1586 * telling him that this is a version error.
1590 handle
= ustctl_tracepoint_field_list(app
->sock
);
1592 ERR("UST app list event fields getting handle failed for app pid %d",
1597 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1598 &uiter
)) != -ENOENT
) {
1599 if (count
>= nbmem
) {
1600 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1603 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event_field
));
1605 PERROR("realloc ust app event fields");
1611 memcpy(tmp
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1612 tmp
[count
].type
= uiter
.type
;
1614 memcpy(tmp
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1615 tmp
[count
].event
.loglevel
= uiter
.loglevel
;
1616 tmp
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1617 tmp
[count
].event
.pid
= app
->pid
;
1618 tmp
[count
].event
.enabled
= -1;
1626 DBG2("UST app list event fields done (%zu events)", count
);
1635 * Free and clean all traceable apps of the global list.
1637 void ust_app_clean_list(void)
1640 struct lttng_ht_iter iter
;
1641 struct lttng_ht_node_ulong
*node
;
1643 DBG2("UST app cleaning registered apps hash table");
1647 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, node
, node
) {
1648 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1650 call_rcu(&node
->head
, delete_ust_app_rcu
);
1653 /* Cleanup socket hash table */
1654 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, node
, node
) {
1655 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1659 /* Destroy is done only when the ht is empty */
1660 lttng_ht_destroy(ust_app_ht
);
1661 lttng_ht_destroy(ust_app_ht_by_sock
);
1667 * Init UST app hash table.
1669 void ust_app_ht_alloc(void)
1671 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1672 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1676 * For a specific UST session, disable the channel for all registered apps.
1678 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1679 struct ltt_ust_channel
*uchan
)
1682 struct lttng_ht_iter iter
;
1683 struct lttng_ht_node_str
*ua_chan_node
;
1684 struct ust_app
*app
;
1685 struct ust_app_session
*ua_sess
;
1686 struct ust_app_channel
*ua_chan
;
1688 if (usess
== NULL
|| uchan
== NULL
) {
1689 ERR("Disabling UST global channel with NULL values");
1694 DBG2("UST app disabling channel %s from global domain for session id %d",
1695 uchan
->name
, usess
->id
);
1699 /* For every registered applications */
1700 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1701 struct lttng_ht_iter uiter
;
1702 if (!app
->compatible
) {
1704 * TODO: In time, we should notice the caller of this error by
1705 * telling him that this is a version error.
1709 ua_sess
= lookup_session_by_app(usess
, app
);
1710 if (ua_sess
== NULL
) {
1715 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1716 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1717 /* If the session if found for the app, the channel must be there */
1718 assert(ua_chan_node
);
1720 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1721 /* The channel must not be already disabled */
1722 assert(ua_chan
->enabled
== 1);
1724 /* Disable channel onto application */
1725 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1727 /* XXX: We might want to report this error at some point... */
1739 * For a specific UST session, enable the channel for all registered apps.
1741 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1742 struct ltt_ust_channel
*uchan
)
1745 struct lttng_ht_iter iter
;
1746 struct ust_app
*app
;
1747 struct ust_app_session
*ua_sess
;
1749 if (usess
== NULL
|| uchan
== NULL
) {
1750 ERR("Adding UST global channel to NULL values");
1755 DBG2("UST app enabling channel %s to global domain for session id %d",
1756 uchan
->name
, usess
->id
);
1760 /* For every registered applications */
1761 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1762 if (!app
->compatible
) {
1764 * TODO: In time, we should notice the caller of this error by
1765 * telling him that this is a version error.
1769 ua_sess
= lookup_session_by_app(usess
, app
);
1770 if (ua_sess
== NULL
) {
1774 /* Enable channel onto application */
1775 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1777 /* XXX: We might want to report this error at some point... */
1789 * Disable an event in a channel and for a specific session.
1791 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1792 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1795 struct lttng_ht_iter iter
, uiter
;
1796 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1797 struct ust_app
*app
;
1798 struct ust_app_session
*ua_sess
;
1799 struct ust_app_channel
*ua_chan
;
1800 struct ust_app_event
*ua_event
;
1802 DBG("UST app disabling event %s for all apps in channel "
1803 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1807 /* For all registered applications */
1808 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1809 if (!app
->compatible
) {
1811 * TODO: In time, we should notice the caller of this error by
1812 * telling him that this is a version error.
1816 ua_sess
= lookup_session_by_app(usess
, app
);
1817 if (ua_sess
== NULL
) {
1822 /* Lookup channel in the ust app session */
1823 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1824 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1825 if (ua_chan_node
== NULL
) {
1826 DBG2("Channel %s not found in session id %d for app pid %d."
1827 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1830 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1832 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1833 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1834 if (ua_event_node
== NULL
) {
1835 DBG2("Event %s not found in channel %s for app pid %d."
1836 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1839 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1841 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1843 /* XXX: Report error someday... */
1854 * For a specific UST session and UST channel, the event for all
1857 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1858 struct ltt_ust_channel
*uchan
)
1861 struct lttng_ht_iter iter
, uiter
;
1862 struct lttng_ht_node_str
*ua_chan_node
;
1863 struct ust_app
*app
;
1864 struct ust_app_session
*ua_sess
;
1865 struct ust_app_channel
*ua_chan
;
1866 struct ust_app_event
*ua_event
;
1868 DBG("UST app disabling all event for all apps in channel "
1869 "%s for session id %d", uchan
->name
, usess
->id
);
1873 /* For all registered applications */
1874 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1875 if (!app
->compatible
) {
1877 * TODO: In time, we should notice the caller of this error by
1878 * telling him that this is a version error.
1882 ua_sess
= lookup_session_by_app(usess
, app
);
1883 /* If ua_sess is NULL, there is a code flow error */
1886 /* Lookup channel in the ust app session */
1887 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1888 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1889 /* If the channel is not found, there is a code flow error */
1890 assert(ua_chan_node
);
1892 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1894 /* Disable each events of channel */
1895 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
1897 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1899 /* XXX: Report error someday... */
1911 * For a specific UST session, create the channel for all registered apps.
1913 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
1914 struct ltt_ust_channel
*uchan
)
1916 struct lttng_ht_iter iter
;
1917 struct ust_app
*app
;
1918 struct ust_app_session
*ua_sess
;
1919 struct ust_app_channel
*ua_chan
;
1921 /* Very wrong code flow */
1925 DBG2("UST app adding channel %s to global domain for session id %d",
1926 uchan
->name
, usess
->id
);
1930 /* For every registered applications */
1931 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1932 if (!app
->compatible
) {
1934 * TODO: In time, we should notice the caller of this error by
1935 * telling him that this is a version error.
1940 * Create session on the tracer side and add it to app session HT. Note
1941 * that if session exist, it will simply return a pointer to the ust
1944 ua_sess
= create_ust_app_session(usess
, app
);
1945 if (ua_sess
== NULL
) {
1946 /* The malloc() failed. */
1948 } else if (ua_sess
== (void *) -1UL) {
1949 /* The application's socket is not valid. Contiuing */
1953 /* Create channel onto application */
1954 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
1955 if (ua_chan
== NULL
) {
1956 /* Major problem here and it's maybe the tracer or malloc() */
1970 * Enable event for a specific session and channel on the tracer.
1972 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
1973 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1976 struct lttng_ht_iter iter
, uiter
;
1977 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1978 struct ust_app
*app
;
1979 struct ust_app_session
*ua_sess
;
1980 struct ust_app_channel
*ua_chan
;
1981 struct ust_app_event
*ua_event
;
1983 DBG("UST app enabling event %s for all apps for session id %d",
1984 uevent
->attr
.name
, usess
->id
);
1987 * NOTE: At this point, this function is called only if the session and
1988 * channel passed are already created for all apps. and enabled on the
1994 /* For all registered applications */
1995 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1996 if (!app
->compatible
) {
1998 * TODO: In time, we should notice the caller of this error by
1999 * telling him that this is a version error.
2003 ua_sess
= lookup_session_by_app(usess
, app
);
2004 /* If ua_sess is NULL, there is a code flow error */
2007 /* Lookup channel in the ust app session */
2008 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2009 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2010 /* If the channel is not found, there is a code flow error */
2011 assert(ua_chan_node
);
2013 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2015 lttng_ht_lookup(ua_chan
->events
, (void*)uevent
->attr
.name
, &uiter
);
2016 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2017 if (ua_event_node
== NULL
) {
2018 DBG3("UST app enable event %s not found for app PID %d."
2019 "Skipping app", uevent
->attr
.name
, app
->pid
);
2022 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2024 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2036 * For a specific existing UST session and UST channel, creates the event for
2037 * all registered apps.
2039 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
2040 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
2043 struct lttng_ht_iter iter
, uiter
;
2044 struct lttng_ht_node_str
*ua_chan_node
;
2045 struct ust_app
*app
;
2046 struct ust_app_session
*ua_sess
;
2047 struct ust_app_channel
*ua_chan
;
2049 DBG("UST app creating event %s for all apps for session id %d",
2050 uevent
->attr
.name
, usess
->id
);
2054 /* For all registered applications */
2055 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2056 if (!app
->compatible
) {
2058 * TODO: In time, we should notice the caller of this error by
2059 * telling him that this is a version error.
2063 ua_sess
= lookup_session_by_app(usess
, app
);
2064 /* If ua_sess is NULL, there is a code flow error */
2067 /* Lookup channel in the ust app session */
2068 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2069 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2070 /* If the channel is not found, there is a code flow error */
2071 assert(ua_chan_node
);
2073 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2075 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2077 if (ret
!= -EEXIST
) {
2078 /* Possible value at this point: -ENOMEM. If so, we stop! */
2081 DBG2("UST app event %s already exist on app PID %d",
2082 uevent
->attr
.name
, app
->pid
);
2093 * Start tracing for a specific UST session and app.
2095 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2098 struct lttng_ht_iter iter
;
2099 struct ust_app_session
*ua_sess
;
2100 struct ust_app_channel
*ua_chan
;
2101 struct ltt_ust_stream
*ustream
;
2104 DBG("Starting tracing for ust app pid %d", app
->pid
);
2108 if (!app
->compatible
) {
2112 ua_sess
= lookup_session_by_app(usess
, app
);
2113 if (ua_sess
== NULL
) {
2114 goto error_rcu_unlock
;
2117 /* Upon restart, we skip the setup, already done */
2118 if (ua_sess
->started
) {
2122 /* Indicate that the session has been started once */
2123 ua_sess
->started
= 1;
2125 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2127 goto error_rcu_unlock
;
2130 /* For each channel */
2131 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2133 /* Create all streams */
2135 /* Create UST stream */
2136 ustream
= zmalloc(sizeof(*ustream
));
2137 if (ustream
== NULL
) {
2138 PERROR("zmalloc ust stream");
2139 goto error_rcu_unlock
;
2142 /* We are going to receive 2 fds, we need to reserve them. */
2143 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2145 ERR("Exhausted number of available FD upon stream create");
2147 goto error_rcu_unlock
;
2149 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2152 /* Got all streams */
2153 lttng_fd_put(LTTNG_FD_APPS
, 2);
2157 ustream
->handle
= ustream
->obj
->handle
;
2159 /* Order is important */
2160 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2161 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2162 ua_chan
->name
, ua_chan
->streams
.count
++);
2164 PERROR("asprintf UST create stream");
2166 * XXX what should we do here with the
2171 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2176 switch (app
->bits_per_long
) {
2178 consumerd_fd
= ust_consumerd64_fd
;
2181 consumerd_fd
= ust_consumerd32_fd
;
2185 goto error_rcu_unlock
;
2188 /* Setup UST consumer socket and send fds to it */
2189 ret
= ust_consumer_send_session(consumerd_fd
, ua_sess
, usess
->consumer
);
2191 goto error_rcu_unlock
;
2195 /* This start the UST tracing */
2196 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2198 ERR("Error starting tracing for app pid: %d", app
->pid
);
2199 goto error_rcu_unlock
;
2202 /* Quiescent wait after starting trace */
2203 ustctl_wait_quiescent(app
->sock
);
2215 * Stop tracing for a specific UST session and app.
2217 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2220 struct lttng_ht_iter iter
;
2221 struct ust_app_session
*ua_sess
;
2222 struct ust_app_channel
*ua_chan
;
2224 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2228 if (!app
->compatible
) {
2232 ua_sess
= lookup_session_by_app(usess
, app
);
2233 if (ua_sess
== NULL
) {
2234 /* Only malloc can failed so something is really wrong */
2235 goto error_rcu_unlock
;
2239 * If started = 0, it means that stop trace has been called for a session
2240 * that was never started. This is a code flow error and should never
2243 assert(ua_sess
->started
== 1);
2245 /* This inhibits UST tracing */
2246 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2248 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2249 goto error_rcu_unlock
;
2252 /* Quiescent wait after stopping trace */
2253 ustctl_wait_quiescent(app
->sock
);
2255 /* Flushing buffers */
2256 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2258 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2260 ERR("UST app PID %d channel %s flush failed with ret %d",
2261 app
->pid
, ua_chan
->name
, ret
);
2262 /* Continuing flushing all buffers */
2267 /* Flush all buffers before stopping */
2268 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2270 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2284 * Destroy a specific UST session in apps.
2286 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2288 struct ust_app_session
*ua_sess
;
2289 struct lttng_ust_object_data obj
;
2290 struct lttng_ht_iter iter
;
2291 struct lttng_ht_node_ulong
*node
;
2294 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2298 if (!app
->compatible
) {
2302 __lookup_session_by_app(usess
, app
, &iter
);
2303 node
= lttng_ht_iter_get_node_ulong(&iter
);
2305 /* Only malloc can failed so something is really wrong */
2306 goto error_rcu_unlock
;
2308 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2309 ret
= lttng_ht_del(app
->sessions
, &iter
);
2311 obj
.handle
= ua_sess
->handle
;
2314 obj
.memory_map_size
= 0;
2315 ustctl_release_object(app
->sock
, &obj
);
2317 delete_ust_app_session(app
->sock
, ua_sess
);
2319 /* Quiescent wait after stopping trace */
2320 ustctl_wait_quiescent(app
->sock
);
2332 * Start tracing for the UST session.
2334 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2337 struct lttng_ht_iter iter
;
2338 struct ust_app
*app
;
2340 DBG("Starting all UST traces");
2344 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2345 ret
= ust_app_start_trace(usess
, app
);
2347 /* Continue to next apps even on error */
2358 * Start tracing for the UST session.
2360 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2363 struct lttng_ht_iter iter
;
2364 struct ust_app
*app
;
2366 DBG("Stopping all UST traces");
2370 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2371 ret
= ust_app_stop_trace(usess
, app
);
2373 /* Continue to next apps even on error */
2384 * Destroy app UST session.
2386 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2389 struct lttng_ht_iter iter
;
2390 struct ust_app
*app
;
2392 DBG("Destroy all UST traces");
2396 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2397 ret
= ust_app_destroy_trace(usess
, app
);
2399 /* Continue to next apps even on error */
2410 * Add channels/events from UST global domain to registered apps at sock.
2412 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2415 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2416 struct ust_app
*app
;
2417 struct ust_app_session
*ua_sess
;
2418 struct ust_app_channel
*ua_chan
;
2419 struct ust_app_event
*ua_event
;
2420 struct ust_app_ctx
*ua_ctx
;
2422 if (usess
== NULL
) {
2423 ERR("No UST session on global update. Returning");
2427 DBG2("UST app global update for app sock %d for session id %d", sock
,
2432 app
= find_app_by_sock(sock
);
2434 ERR("Failed to update app sock %d", sock
);
2438 if (!app
->compatible
) {
2442 ua_sess
= create_ust_app_session(usess
, app
);
2443 if (ua_sess
== NULL
) {
2448 * We can iterate safely here over all UST app session sicne the create ust
2449 * app session above made a shadow copy of the UST global domain from the
2452 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2454 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2456 /* FIXME: Should we quit here or continue... */
2460 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2462 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2464 /* FIXME: Should we quit here or continue... */
2470 /* For each events */
2471 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2473 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2475 /* FIXME: Should we quit here or continue... */
2479 /* Add context on events. */
2480 cds_lfht_for_each_entry(ua_event
->ctx
->ht
, &iter_ctx
.iter
,
2481 ua_ctx
, node
.node
) {
2482 ret
= create_ust_event_context(ua_event
, ua_ctx
, app
);
2484 /* FIXME: Should we quit here or continue... */
2488 ret
= set_ust_event_filter(ua_event
, app
);
2490 /* FIXME: Should we quit here or continue... */
2496 if (usess
->start_trace
) {
2497 ret
= ust_app_start_trace(usess
, app
);
2502 DBG2("UST trace started for app pid %d", app
->pid
);
2511 * Add context to a specific channel for global UST domain.
2513 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2514 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2517 struct lttng_ht_node_str
*ua_chan_node
;
2518 struct lttng_ht_iter iter
, uiter
;
2519 struct ust_app_channel
*ua_chan
= NULL
;
2520 struct ust_app_session
*ua_sess
;
2521 struct ust_app
*app
;
2525 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2526 if (!app
->compatible
) {
2528 * TODO: In time, we should notice the caller of this error by
2529 * telling him that this is a version error.
2533 ua_sess
= lookup_session_by_app(usess
, app
);
2534 if (ua_sess
== NULL
) {
2538 /* Lookup channel in the ust app session */
2539 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2540 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2541 if (ua_chan_node
== NULL
) {
2544 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2547 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2558 * Add context to a specific event in a channel for global UST domain.
2560 int ust_app_add_ctx_event_glb(struct ltt_ust_session
*usess
,
2561 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
2562 struct ltt_ust_context
*uctx
)
2565 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2566 struct lttng_ht_iter iter
, uiter
;
2567 struct ust_app_session
*ua_sess
;
2568 struct ust_app_event
*ua_event
;
2569 struct ust_app_channel
*ua_chan
= NULL
;
2570 struct ust_app
*app
;
2574 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2575 if (!app
->compatible
) {
2577 * TODO: In time, we should notice the caller of this error by
2578 * telling him that this is a version error.
2582 ua_sess
= lookup_session_by_app(usess
, app
);
2583 if (ua_sess
== NULL
) {
2587 /* Lookup channel in the ust app session */
2588 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2589 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2590 if (ua_chan_node
== NULL
) {
2593 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2596 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
2597 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2598 if (ua_event_node
== NULL
) {
2601 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
,
2604 ret
= create_ust_app_event_context(ua_sess
, ua_event
, &uctx
->ctx
, app
);
2615 * Add context to a specific event in a channel for global UST domain.
2617 int ust_app_set_filter_event_glb(struct ltt_ust_session
*usess
,
2618 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
2619 struct lttng_filter_bytecode
*bytecode
)
2622 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2623 struct lttng_ht_iter iter
, uiter
;
2624 struct ust_app_session
*ua_sess
;
2625 struct ust_app_event
*ua_event
;
2626 struct ust_app_channel
*ua_chan
= NULL
;
2627 struct ust_app
*app
;
2631 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2632 if (!app
->compatible
) {
2634 * TODO: In time, we should notice the caller of this error by
2635 * telling him that this is a version error.
2639 ua_sess
= lookup_session_by_app(usess
, app
);
2640 if (ua_sess
== NULL
) {
2644 /* Lookup channel in the ust app session */
2645 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2646 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2647 if (ua_chan_node
== NULL
) {
2650 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2653 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
2654 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2655 if (ua_event_node
== NULL
) {
2658 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
,
2661 ret
= set_ust_app_event_filter(ua_sess
, ua_event
, bytecode
, app
);
2672 * Enable event for a channel from a UST session for a specific PID.
2674 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2675 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2678 struct lttng_ht_iter iter
;
2679 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2680 struct ust_app
*app
;
2681 struct ust_app_session
*ua_sess
;
2682 struct ust_app_channel
*ua_chan
;
2683 struct ust_app_event
*ua_event
;
2685 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2689 app
= ust_app_find_by_pid(pid
);
2691 ERR("UST app enable event per PID %d not found", pid
);
2696 if (!app
->compatible
) {
2701 ua_sess
= lookup_session_by_app(usess
, app
);
2702 /* If ua_sess is NULL, there is a code flow error */
2705 /* Lookup channel in the ust app session */
2706 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2707 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2708 /* If the channel is not found, there is a code flow error */
2709 assert(ua_chan_node
);
2711 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2713 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2714 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2715 if (ua_event_node
== NULL
) {
2716 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2721 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2723 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2735 * Disable event for a channel from a UST session for a specific PID.
2737 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2738 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2741 struct lttng_ht_iter iter
;
2742 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2743 struct ust_app
*app
;
2744 struct ust_app_session
*ua_sess
;
2745 struct ust_app_channel
*ua_chan
;
2746 struct ust_app_event
*ua_event
;
2748 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2752 app
= ust_app_find_by_pid(pid
);
2754 ERR("UST app disable event per PID %d not found", pid
);
2759 if (!app
->compatible
) {
2764 ua_sess
= lookup_session_by_app(usess
, app
);
2765 /* If ua_sess is NULL, there is a code flow error */
2768 /* Lookup channel in the ust app session */
2769 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2770 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2771 if (ua_chan_node
== NULL
) {
2772 /* Channel does not exist, skip disabling */
2775 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2777 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2778 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2779 if (ua_event_node
== NULL
) {
2780 /* Event does not exist, skip disabling */
2783 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2785 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2796 * Validate version of UST apps and set the compatible bit.
2798 int ust_app_validate_version(int sock
)
2801 struct ust_app
*app
;
2805 app
= find_app_by_sock(sock
);
2808 ret
= ustctl_tracer_version(sock
, &app
->version
);
2813 /* Validate version */
2814 if (app
->version
.major
> UST_APP_MAJOR_VERSION
) {
2818 DBG2("UST app PID %d is compatible with major version %d "
2819 "(supporting <= %d)", app
->pid
, app
->version
.major
,
2820 UST_APP_MAJOR_VERSION
);
2821 app
->compatible
= 1;
2826 DBG2("UST app PID %d is not compatible with major version %d "
2827 "(supporting <= %d)", app
->pid
, app
->version
.major
,
2828 UST_APP_MAJOR_VERSION
);
2829 app
->compatible
= 0;
2835 * Calibrate registered applications.
2837 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2840 struct lttng_ht_iter iter
;
2841 struct ust_app
*app
;
2845 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2846 if (!app
->compatible
) {
2848 * TODO: In time, we should notice the caller of this error by
2849 * telling him that this is a version error.
2854 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2858 /* Means that it's not implemented on the tracer side. */
2862 /* TODO: Report error to user */
2863 DBG2("Calibrate app PID %d returned with error %d",
2870 DBG("UST app global domain calibration finished");