2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/types.h>
29 #include <urcu/compiler.h>
30 #include <lttng/ust-error.h>
33 #include <common/common.h>
34 #include <common/sessiond-comm/sessiond-comm.h>
36 #include "buffer-registry.h"
38 #include "health-sessiond.h"
40 #include "ust-consumer.h"
44 #include "lttng-sessiond.h"
45 #include "notification-thread-commands.h"
48 int ust_app_flush_app_session(struct ust_app
*app
, struct ust_app_session
*ua_sess
);
50 /* Next available channel key. Access under next_channel_key_lock. */
51 static uint64_t _next_channel_key
;
52 static pthread_mutex_t next_channel_key_lock
= PTHREAD_MUTEX_INITIALIZER
;
54 /* Next available session ID. Access under next_session_id_lock. */
55 static uint64_t _next_session_id
;
56 static pthread_mutex_t next_session_id_lock
= PTHREAD_MUTEX_INITIALIZER
;
59 * Return the incremented value of next_channel_key.
61 static uint64_t get_next_channel_key(void)
65 pthread_mutex_lock(&next_channel_key_lock
);
66 ret
= ++_next_channel_key
;
67 pthread_mutex_unlock(&next_channel_key_lock
);
72 * Return the atomically incremented value of next_session_id.
74 static uint64_t get_next_session_id(void)
78 pthread_mutex_lock(&next_session_id_lock
);
79 ret
= ++_next_session_id
;
80 pthread_mutex_unlock(&next_session_id_lock
);
84 static void copy_channel_attr_to_ustctl(
85 struct ustctl_consumer_channel_attr
*attr
,
86 struct lttng_ust_channel_attr
*uattr
)
88 /* Copy event attributes since the layout is different. */
89 attr
->subbuf_size
= uattr
->subbuf_size
;
90 attr
->num_subbuf
= uattr
->num_subbuf
;
91 attr
->overwrite
= uattr
->overwrite
;
92 attr
->switch_timer_interval
= uattr
->switch_timer_interval
;
93 attr
->read_timer_interval
= uattr
->read_timer_interval
;
94 attr
->output
= uattr
->output
;
98 * Match function for the hash table lookup.
100 * It matches an ust app event based on three attributes which are the event
101 * name, the filter bytecode and the loglevel.
103 static int ht_match_ust_app_event(struct cds_lfht_node
*node
, const void *_key
)
105 struct ust_app_event
*event
;
106 const struct ust_app_ht_key
*key
;
107 int ev_loglevel_value
;
112 event
= caa_container_of(node
, struct ust_app_event
, node
.node
);
114 ev_loglevel_value
= event
->attr
.loglevel
;
116 /* Match the 4 elements of the key: name, filter, loglevel, exclusions */
119 if (strncmp(event
->attr
.name
, key
->name
, sizeof(event
->attr
.name
)) != 0) {
123 /* Event loglevel. */
124 if (ev_loglevel_value
!= key
->loglevel_type
) {
125 if (event
->attr
.loglevel_type
== LTTNG_UST_LOGLEVEL_ALL
126 && key
->loglevel_type
== 0 &&
127 ev_loglevel_value
== -1) {
129 * Match is accepted. This is because on event creation, the
130 * loglevel is set to -1 if the event loglevel type is ALL so 0 and
131 * -1 are accepted for this loglevel type since 0 is the one set by
132 * the API when receiving an enable event.
139 /* One of the filters is NULL, fail. */
140 if ((key
->filter
&& !event
->filter
) || (!key
->filter
&& event
->filter
)) {
144 if (key
->filter
&& event
->filter
) {
145 /* Both filters exists, check length followed by the bytecode. */
146 if (event
->filter
->len
!= key
->filter
->len
||
147 memcmp(event
->filter
->data
, key
->filter
->data
,
148 event
->filter
->len
) != 0) {
153 /* One of the exclusions is NULL, fail. */
154 if ((key
->exclusion
&& !event
->exclusion
) || (!key
->exclusion
&& event
->exclusion
)) {
158 if (key
->exclusion
&& event
->exclusion
) {
159 /* Both exclusions exists, check count followed by the names. */
160 if (event
->exclusion
->count
!= key
->exclusion
->count
||
161 memcmp(event
->exclusion
->names
, key
->exclusion
->names
,
162 event
->exclusion
->count
* LTTNG_UST_SYM_NAME_LEN
) != 0) {
176 * Unique add of an ust app event in the given ht. This uses the custom
177 * ht_match_ust_app_event match function and the event name as hash.
179 static void add_unique_ust_app_event(struct ust_app_channel
*ua_chan
,
180 struct ust_app_event
*event
)
182 struct cds_lfht_node
*node_ptr
;
183 struct ust_app_ht_key key
;
187 assert(ua_chan
->events
);
190 ht
= ua_chan
->events
;
191 key
.name
= event
->attr
.name
;
192 key
.filter
= event
->filter
;
193 key
.loglevel_type
= event
->attr
.loglevel
;
194 key
.exclusion
= event
->exclusion
;
196 node_ptr
= cds_lfht_add_unique(ht
->ht
,
197 ht
->hash_fct(event
->node
.key
, lttng_ht_seed
),
198 ht_match_ust_app_event
, &key
, &event
->node
.node
);
199 assert(node_ptr
== &event
->node
.node
);
203 * Close the notify socket from the given RCU head object. This MUST be called
204 * through a call_rcu().
206 static void close_notify_sock_rcu(struct rcu_head
*head
)
209 struct ust_app_notify_sock_obj
*obj
=
210 caa_container_of(head
, struct ust_app_notify_sock_obj
, head
);
212 /* Must have a valid fd here. */
213 assert(obj
->fd
>= 0);
215 ret
= close(obj
->fd
);
217 ERR("close notify sock %d RCU", obj
->fd
);
219 lttng_fd_put(LTTNG_FD_APPS
, 1);
225 * Return the session registry according to the buffer type of the given
228 * A registry per UID object MUST exists before calling this function or else
229 * it assert() if not found. RCU read side lock must be acquired.
231 static struct ust_registry_session
*get_session_registry(
232 struct ust_app_session
*ua_sess
)
234 struct ust_registry_session
*registry
= NULL
;
238 switch (ua_sess
->buffer_type
) {
239 case LTTNG_BUFFER_PER_PID
:
241 struct buffer_reg_pid
*reg_pid
= buffer_reg_pid_find(ua_sess
->id
);
245 registry
= reg_pid
->registry
->reg
.ust
;
248 case LTTNG_BUFFER_PER_UID
:
250 struct buffer_reg_uid
*reg_uid
= buffer_reg_uid_find(
251 ua_sess
->tracing_id
, ua_sess
->bits_per_long
, ua_sess
->uid
);
255 registry
= reg_uid
->registry
->reg
.ust
;
267 * Delete ust context safely. RCU read lock must be held before calling
271 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
,
279 pthread_mutex_lock(&app
->sock_lock
);
280 ret
= ustctl_release_object(sock
, ua_ctx
->obj
);
281 pthread_mutex_unlock(&app
->sock_lock
);
282 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
283 ERR("UST app sock %d release ctx obj handle %d failed with ret %d",
284 sock
, ua_ctx
->obj
->handle
, ret
);
292 * Delete ust app event safely. RCU read lock must be held before calling
296 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
,
303 free(ua_event
->filter
);
304 if (ua_event
->exclusion
!= NULL
)
305 free(ua_event
->exclusion
);
306 if (ua_event
->obj
!= NULL
) {
307 pthread_mutex_lock(&app
->sock_lock
);
308 ret
= ustctl_release_object(sock
, ua_event
->obj
);
309 pthread_mutex_unlock(&app
->sock_lock
);
310 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
311 ERR("UST app sock %d release event obj failed with ret %d",
320 * Release ust data object of the given stream.
322 * Return 0 on success or else a negative value.
324 static int release_ust_app_stream(int sock
, struct ust_app_stream
*stream
,
332 pthread_mutex_lock(&app
->sock_lock
);
333 ret
= ustctl_release_object(sock
, stream
->obj
);
334 pthread_mutex_unlock(&app
->sock_lock
);
335 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
336 ERR("UST app sock %d release stream obj failed with ret %d",
339 lttng_fd_put(LTTNG_FD_APPS
, 2);
347 * Delete ust app stream safely. RCU read lock must be held before calling
351 void delete_ust_app_stream(int sock
, struct ust_app_stream
*stream
,
356 (void) release_ust_app_stream(sock
, stream
, app
);
361 * We need to execute ht_destroy outside of RCU read-side critical
362 * section and outside of call_rcu thread, so we postpone its execution
363 * using ht_cleanup_push. It is simpler than to change the semantic of
364 * the many callers of delete_ust_app_session().
367 void delete_ust_app_channel_rcu(struct rcu_head
*head
)
369 struct ust_app_channel
*ua_chan
=
370 caa_container_of(head
, struct ust_app_channel
, rcu_head
);
372 ht_cleanup_push(ua_chan
->ctx
);
373 ht_cleanup_push(ua_chan
->events
);
378 * Extract the lost packet or discarded events counter when the channel is
379 * being deleted and store the value in the parent channel so we can
380 * access it from lttng list and at stop/destroy.
382 * The session list lock must be held by the caller.
385 void save_per_pid_lost_discarded_counters(struct ust_app_channel
*ua_chan
)
387 uint64_t discarded
= 0, lost
= 0;
388 struct ltt_session
*session
;
389 struct ltt_ust_channel
*uchan
;
391 if (ua_chan
->attr
.type
!= LTTNG_UST_CHAN_PER_CPU
) {
396 session
= session_find_by_id(ua_chan
->session
->tracing_id
);
397 if (!session
|| !session
->ust_session
) {
399 * Not finding the session is not an error because there are
400 * multiple ways the channels can be torn down.
402 * 1) The session daemon can initiate the destruction of the
403 * ust app session after receiving a destroy command or
404 * during its shutdown/teardown.
405 * 2) The application, since we are in per-pid tracing, is
406 * unregistering and tearing down its ust app session.
408 * Both paths are protected by the session list lock which
409 * ensures that the accounting of lost packets and discarded
410 * events is done exactly once. The session is then unpublished
411 * from the session list, resulting in this condition.
416 if (ua_chan
->attr
.overwrite
) {
417 consumer_get_lost_packets(ua_chan
->session
->tracing_id
,
418 ua_chan
->key
, session
->ust_session
->consumer
,
421 consumer_get_discarded_events(ua_chan
->session
->tracing_id
,
422 ua_chan
->key
, session
->ust_session
->consumer
,
425 uchan
= trace_ust_find_channel_by_name(
426 session
->ust_session
->domain_global
.channels
,
429 ERR("Missing UST channel to store discarded counters");
433 uchan
->per_pid_closed_app_discarded
+= discarded
;
434 uchan
->per_pid_closed_app_lost
+= lost
;
441 * Delete ust app channel safely. RCU read lock must be held before calling
444 * The session list lock must be held by the caller.
447 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
,
451 struct lttng_ht_iter iter
;
452 struct ust_app_event
*ua_event
;
453 struct ust_app_ctx
*ua_ctx
;
454 struct ust_app_stream
*stream
, *stmp
;
455 struct ust_registry_session
*registry
;
459 DBG3("UST app deleting channel %s", ua_chan
->name
);
462 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
463 cds_list_del(&stream
->list
);
464 delete_ust_app_stream(sock
, stream
, app
);
468 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
469 cds_list_del(&ua_ctx
->list
);
470 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
472 delete_ust_app_ctx(sock
, ua_ctx
, app
);
476 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
478 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
480 delete_ust_app_event(sock
, ua_event
, app
);
483 if (ua_chan
->session
->buffer_type
== LTTNG_BUFFER_PER_PID
) {
484 /* Wipe and free registry from session registry. */
485 registry
= get_session_registry(ua_chan
->session
);
487 ust_registry_channel_del_free(registry
, ua_chan
->key
,
490 save_per_pid_lost_discarded_counters(ua_chan
);
493 if (ua_chan
->obj
!= NULL
) {
494 /* Remove channel from application UST object descriptor. */
495 iter
.iter
.node
= &ua_chan
->ust_objd_node
.node
;
496 ret
= lttng_ht_del(app
->ust_objd
, &iter
);
498 pthread_mutex_lock(&app
->sock_lock
);
499 ret
= ustctl_release_object(sock
, ua_chan
->obj
);
500 pthread_mutex_unlock(&app
->sock_lock
);
501 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
502 ERR("UST app sock %d release channel obj failed with ret %d",
505 lttng_fd_put(LTTNG_FD_APPS
, 1);
508 call_rcu(&ua_chan
->rcu_head
, delete_ust_app_channel_rcu
);
511 int ust_app_register_done(struct ust_app
*app
)
515 pthread_mutex_lock(&app
->sock_lock
);
516 ret
= ustctl_register_done(app
->sock
);
517 pthread_mutex_unlock(&app
->sock_lock
);
521 int ust_app_release_object(struct ust_app
*app
, struct lttng_ust_object_data
*data
)
526 pthread_mutex_lock(&app
->sock_lock
);
531 ret
= ustctl_release_object(sock
, data
);
533 pthread_mutex_unlock(&app
->sock_lock
);
539 * Push metadata to consumer socket.
541 * RCU read-side lock must be held to guarantee existance of socket.
542 * Must be called with the ust app session lock held.
543 * Must be called with the registry lock held.
545 * On success, return the len of metadata pushed or else a negative value.
546 * Returning a -EPIPE return value means we could not send the metadata,
547 * but it can be caused by recoverable errors (e.g. the application has
548 * terminated concurrently).
550 ssize_t
ust_app_push_metadata(struct ust_registry_session
*registry
,
551 struct consumer_socket
*socket
, int send_zero_data
)
554 char *metadata_str
= NULL
;
555 size_t len
, offset
, new_metadata_len_sent
;
557 uint64_t metadata_key
, metadata_version
;
562 metadata_key
= registry
->metadata_key
;
565 * Means that no metadata was assigned to the session. This can
566 * happens if no start has been done previously.
572 offset
= registry
->metadata_len_sent
;
573 len
= registry
->metadata_len
- registry
->metadata_len_sent
;
574 new_metadata_len_sent
= registry
->metadata_len
;
575 metadata_version
= registry
->metadata_version
;
577 DBG3("No metadata to push for metadata key %" PRIu64
,
578 registry
->metadata_key
);
580 if (send_zero_data
) {
581 DBG("No metadata to push");
587 /* Allocate only what we have to send. */
588 metadata_str
= zmalloc(len
);
590 PERROR("zmalloc ust app metadata string");
594 /* Copy what we haven't sent out. */
595 memcpy(metadata_str
, registry
->metadata
+ offset
, len
);
598 pthread_mutex_unlock(®istry
->lock
);
600 * We need to unlock the registry while we push metadata to
601 * break a circular dependency between the consumerd metadata
602 * lock and the sessiond registry lock. Indeed, pushing metadata
603 * to the consumerd awaits that it gets pushed all the way to
604 * relayd, but doing so requires grabbing the metadata lock. If
605 * a concurrent metadata request is being performed by
606 * consumerd, this can try to grab the registry lock on the
607 * sessiond while holding the metadata lock on the consumer
608 * daemon. Those push and pull schemes are performed on two
609 * different bidirectionnal communication sockets.
611 ret
= consumer_push_metadata(socket
, metadata_key
,
612 metadata_str
, len
, offset
, metadata_version
);
613 pthread_mutex_lock(®istry
->lock
);
616 * There is an acceptable race here between the registry
617 * metadata key assignment and the creation on the
618 * consumer. The session daemon can concurrently push
619 * metadata for this registry while being created on the
620 * consumer since the metadata key of the registry is
621 * assigned *before* it is setup to avoid the consumer
622 * to ask for metadata that could possibly be not found
623 * in the session daemon.
625 * The metadata will get pushed either by the session
626 * being stopped or the consumer requesting metadata if
627 * that race is triggered.
629 if (ret
== -LTTCOMM_CONSUMERD_CHANNEL_FAIL
) {
632 ERR("Error pushing metadata to consumer");
638 * Metadata may have been concurrently pushed, since
639 * we're not holding the registry lock while pushing to
640 * consumer. This is handled by the fact that we send
641 * the metadata content, size, and the offset at which
642 * that metadata belongs. This may arrive out of order
643 * on the consumer side, and the consumer is able to
644 * deal with overlapping fragments. The consumer
645 * supports overlapping fragments, which must be
646 * contiguous starting from offset 0. We keep the
647 * largest metadata_len_sent value of the concurrent
650 registry
->metadata_len_sent
=
651 max_t(size_t, registry
->metadata_len_sent
,
652 new_metadata_len_sent
);
661 * On error, flag the registry that the metadata is
662 * closed. We were unable to push anything and this
663 * means that either the consumer is not responding or
664 * the metadata cache has been destroyed on the
667 registry
->metadata_closed
= 1;
675 * For a given application and session, push metadata to consumer.
676 * Either sock or consumer is required : if sock is NULL, the default
677 * socket to send the metadata is retrieved from consumer, if sock
678 * is not NULL we use it to send the metadata.
679 * RCU read-side lock must be held while calling this function,
680 * therefore ensuring existance of registry. It also ensures existance
681 * of socket throughout this function.
683 * Return 0 on success else a negative error.
684 * Returning a -EPIPE return value means we could not send the metadata,
685 * but it can be caused by recoverable errors (e.g. the application has
686 * terminated concurrently).
688 static int push_metadata(struct ust_registry_session
*registry
,
689 struct consumer_output
*consumer
)
693 struct consumer_socket
*socket
;
698 pthread_mutex_lock(®istry
->lock
);
699 if (registry
->metadata_closed
) {
704 /* Get consumer socket to use to push the metadata.*/
705 socket
= consumer_find_socket_by_bitness(registry
->bits_per_long
,
712 ret
= ust_app_push_metadata(registry
, socket
, 0);
717 pthread_mutex_unlock(®istry
->lock
);
721 pthread_mutex_unlock(®istry
->lock
);
726 * Send to the consumer a close metadata command for the given session. Once
727 * done, the metadata channel is deleted and the session metadata pointer is
728 * nullified. The session lock MUST be held unless the application is
729 * in the destroy path.
731 * Return 0 on success else a negative value.
733 static int close_metadata(struct ust_registry_session
*registry
,
734 struct consumer_output
*consumer
)
737 struct consumer_socket
*socket
;
744 pthread_mutex_lock(®istry
->lock
);
746 if (!registry
->metadata_key
|| registry
->metadata_closed
) {
751 /* Get consumer socket to use to push the metadata.*/
752 socket
= consumer_find_socket_by_bitness(registry
->bits_per_long
,
759 ret
= consumer_close_metadata(socket
, registry
->metadata_key
);
766 * Metadata closed. Even on error this means that the consumer is not
767 * responding or not found so either way a second close should NOT be emit
770 registry
->metadata_closed
= 1;
772 pthread_mutex_unlock(®istry
->lock
);
778 * We need to execute ht_destroy outside of RCU read-side critical
779 * section and outside of call_rcu thread, so we postpone its execution
780 * using ht_cleanup_push. It is simpler than to change the semantic of
781 * the many callers of delete_ust_app_session().
784 void delete_ust_app_session_rcu(struct rcu_head
*head
)
786 struct ust_app_session
*ua_sess
=
787 caa_container_of(head
, struct ust_app_session
, rcu_head
);
789 ht_cleanup_push(ua_sess
->channels
);
794 * Delete ust app session safely. RCU read lock must be held before calling
797 * The session list lock must be held by the caller.
800 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
,
804 struct lttng_ht_iter iter
;
805 struct ust_app_channel
*ua_chan
;
806 struct ust_registry_session
*registry
;
810 pthread_mutex_lock(&ua_sess
->lock
);
812 assert(!ua_sess
->deleted
);
813 ua_sess
->deleted
= true;
815 registry
= get_session_registry(ua_sess
);
817 /* Push metadata for application before freeing the application. */
818 (void) push_metadata(registry
, ua_sess
->consumer
);
821 * Don't ask to close metadata for global per UID buffers. Close
822 * metadata only on destroy trace session in this case. Also, the
823 * previous push metadata could have flag the metadata registry to
824 * close so don't send a close command if closed.
826 if (ua_sess
->buffer_type
!= LTTNG_BUFFER_PER_UID
) {
827 /* And ask to close it for this session registry. */
828 (void) close_metadata(registry
, ua_sess
->consumer
);
832 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
834 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
836 delete_ust_app_channel(sock
, ua_chan
, app
);
839 /* In case of per PID, the registry is kept in the session. */
840 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_PID
) {
841 struct buffer_reg_pid
*reg_pid
= buffer_reg_pid_find(ua_sess
->id
);
843 buffer_reg_pid_remove(reg_pid
);
844 buffer_reg_pid_destroy(reg_pid
);
848 if (ua_sess
->handle
!= -1) {
849 pthread_mutex_lock(&app
->sock_lock
);
850 ret
= ustctl_release_handle(sock
, ua_sess
->handle
);
851 pthread_mutex_unlock(&app
->sock_lock
);
852 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
853 ERR("UST app sock %d release session handle failed with ret %d",
856 /* Remove session from application UST object descriptor. */
857 iter
.iter
.node
= &ua_sess
->ust_objd_node
.node
;
858 ret
= lttng_ht_del(app
->ust_sessions_objd
, &iter
);
862 pthread_mutex_unlock(&ua_sess
->lock
);
864 consumer_output_put(ua_sess
->consumer
);
866 call_rcu(&ua_sess
->rcu_head
, delete_ust_app_session_rcu
);
870 * Delete a traceable application structure from the global list. Never call
871 * this function outside of a call_rcu call.
873 * RCU read side lock should _NOT_ be held when calling this function.
876 void delete_ust_app(struct ust_app
*app
)
879 struct ust_app_session
*ua_sess
, *tmp_ua_sess
;
882 * The session list lock must be held during this function to guarantee
883 * the existence of ua_sess.
886 /* Delete ust app sessions info */
891 cds_list_for_each_entry_safe(ua_sess
, tmp_ua_sess
, &app
->teardown_head
,
893 /* Free every object in the session and the session. */
895 delete_ust_app_session(sock
, ua_sess
, app
);
899 ht_cleanup_push(app
->sessions
);
900 ht_cleanup_push(app
->ust_sessions_objd
);
901 ht_cleanup_push(app
->ust_objd
);
904 * Wait until we have deleted the application from the sock hash table
905 * before closing this socket, otherwise an application could re-use the
906 * socket ID and race with the teardown, using the same hash table entry.
908 * It's OK to leave the close in call_rcu. We want it to stay unique for
909 * all RCU readers that could run concurrently with unregister app,
910 * therefore we _need_ to only close that socket after a grace period. So
911 * it should stay in this RCU callback.
913 * This close() is a very important step of the synchronization model so
914 * every modification to this function must be carefully reviewed.
920 lttng_fd_put(LTTNG_FD_APPS
, 1);
922 DBG2("UST app pid %d deleted", app
->pid
);
924 session_unlock_list();
928 * URCU intermediate call to delete an UST app.
931 void delete_ust_app_rcu(struct rcu_head
*head
)
933 struct lttng_ht_node_ulong
*node
=
934 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
935 struct ust_app
*app
=
936 caa_container_of(node
, struct ust_app
, pid_n
);
938 DBG3("Call RCU deleting app PID %d", app
->pid
);
943 * Delete the session from the application ht and delete the data structure by
944 * freeing every object inside and releasing them.
946 * The session list lock must be held by the caller.
948 static void destroy_app_session(struct ust_app
*app
,
949 struct ust_app_session
*ua_sess
)
952 struct lttng_ht_iter iter
;
957 iter
.iter
.node
= &ua_sess
->node
.node
;
958 ret
= lttng_ht_del(app
->sessions
, &iter
);
960 /* Already scheduled for teardown. */
964 /* Once deleted, free the data structure. */
965 delete_ust_app_session(app
->sock
, ua_sess
, app
);
972 * Alloc new UST app session.
975 struct ust_app_session
*alloc_ust_app_session(struct ust_app
*app
)
977 struct ust_app_session
*ua_sess
;
979 /* Init most of the default value by allocating and zeroing */
980 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
981 if (ua_sess
== NULL
) {
986 ua_sess
->handle
= -1;
987 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
988 ua_sess
->metadata_attr
.type
= LTTNG_UST_CHAN_METADATA
;
989 pthread_mutex_init(&ua_sess
->lock
, NULL
);
998 * Alloc new UST app channel.
1001 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
1002 struct ust_app_session
*ua_sess
,
1003 struct lttng_ust_channel_attr
*attr
)
1005 struct ust_app_channel
*ua_chan
;
1007 /* Init most of the default value by allocating and zeroing */
1008 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
1009 if (ua_chan
== NULL
) {
1014 /* Setup channel name */
1015 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
1016 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
1018 ua_chan
->enabled
= 1;
1019 ua_chan
->handle
= -1;
1020 ua_chan
->session
= ua_sess
;
1021 ua_chan
->key
= get_next_channel_key();
1022 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1023 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
1024 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
1026 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
1027 CDS_INIT_LIST_HEAD(&ua_chan
->ctx_list
);
1029 /* Copy attributes */
1031 /* Translate from lttng_ust_channel to ustctl_consumer_channel_attr. */
1032 ua_chan
->attr
.subbuf_size
= attr
->subbuf_size
;
1033 ua_chan
->attr
.num_subbuf
= attr
->num_subbuf
;
1034 ua_chan
->attr
.overwrite
= attr
->overwrite
;
1035 ua_chan
->attr
.switch_timer_interval
= attr
->switch_timer_interval
;
1036 ua_chan
->attr
.read_timer_interval
= attr
->read_timer_interval
;
1037 ua_chan
->attr
.output
= attr
->output
;
1039 /* By default, the channel is a per cpu channel. */
1040 ua_chan
->attr
.type
= LTTNG_UST_CHAN_PER_CPU
;
1042 DBG3("UST app channel %s allocated", ua_chan
->name
);
1051 * Allocate and initialize a UST app stream.
1053 * Return newly allocated stream pointer or NULL on error.
1055 struct ust_app_stream
*ust_app_alloc_stream(void)
1057 struct ust_app_stream
*stream
= NULL
;
1059 stream
= zmalloc(sizeof(*stream
));
1060 if (stream
== NULL
) {
1061 PERROR("zmalloc ust app stream");
1065 /* Zero could be a valid value for a handle so flag it to -1. */
1066 stream
->handle
= -1;
1073 * Alloc new UST app event.
1076 struct ust_app_event
*alloc_ust_app_event(char *name
,
1077 struct lttng_ust_event
*attr
)
1079 struct ust_app_event
*ua_event
;
1081 /* Init most of the default value by allocating and zeroing */
1082 ua_event
= zmalloc(sizeof(struct ust_app_event
));
1083 if (ua_event
== NULL
) {
1088 ua_event
->enabled
= 1;
1089 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
1090 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
1091 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
1093 /* Copy attributes */
1095 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
1098 DBG3("UST app event %s allocated", ua_event
->name
);
1107 * Alloc new UST app context.
1110 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context_attr
*uctx
)
1112 struct ust_app_ctx
*ua_ctx
;
1114 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
1115 if (ua_ctx
== NULL
) {
1119 CDS_INIT_LIST_HEAD(&ua_ctx
->list
);
1122 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
1123 if (uctx
->ctx
== LTTNG_UST_CONTEXT_APP_CONTEXT
) {
1124 char *provider_name
= NULL
, *ctx_name
= NULL
;
1126 provider_name
= strdup(uctx
->u
.app_ctx
.provider_name
);
1127 ctx_name
= strdup(uctx
->u
.app_ctx
.ctx_name
);
1128 if (!provider_name
|| !ctx_name
) {
1129 free(provider_name
);
1134 ua_ctx
->ctx
.u
.app_ctx
.provider_name
= provider_name
;
1135 ua_ctx
->ctx
.u
.app_ctx
.ctx_name
= ctx_name
;
1139 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
1147 * Allocate a filter and copy the given original filter.
1149 * Return allocated filter or NULL on error.
1151 static struct lttng_filter_bytecode
*copy_filter_bytecode(
1152 struct lttng_filter_bytecode
*orig_f
)
1154 struct lttng_filter_bytecode
*filter
= NULL
;
1156 /* Copy filter bytecode */
1157 filter
= zmalloc(sizeof(*filter
) + orig_f
->len
);
1159 PERROR("zmalloc alloc filter bytecode");
1163 memcpy(filter
, orig_f
, sizeof(*filter
) + orig_f
->len
);
1170 * Create a liblttng-ust filter bytecode from given bytecode.
1172 * Return allocated filter or NULL on error.
1174 static struct lttng_ust_filter_bytecode
*create_ust_bytecode_from_bytecode(
1175 struct lttng_filter_bytecode
*orig_f
)
1177 struct lttng_ust_filter_bytecode
*filter
= NULL
;
1179 /* Copy filter bytecode */
1180 filter
= zmalloc(sizeof(*filter
) + orig_f
->len
);
1182 PERROR("zmalloc alloc ust filter bytecode");
1186 assert(sizeof(struct lttng_filter_bytecode
) ==
1187 sizeof(struct lttng_ust_filter_bytecode
));
1188 memcpy(filter
, orig_f
, sizeof(*filter
) + orig_f
->len
);
1194 * Find an ust_app using the sock and return it. RCU read side lock must be
1195 * held before calling this helper function.
1197 struct ust_app
*ust_app_find_by_sock(int sock
)
1199 struct lttng_ht_node_ulong
*node
;
1200 struct lttng_ht_iter iter
;
1202 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1203 node
= lttng_ht_iter_get_node_ulong(&iter
);
1205 DBG2("UST app find by sock %d not found", sock
);
1209 return caa_container_of(node
, struct ust_app
, sock_n
);
1216 * Find an ust_app using the notify sock and return it. RCU read side lock must
1217 * be held before calling this helper function.
1219 static struct ust_app
*find_app_by_notify_sock(int sock
)
1221 struct lttng_ht_node_ulong
*node
;
1222 struct lttng_ht_iter iter
;
1224 lttng_ht_lookup(ust_app_ht_by_notify_sock
, (void *)((unsigned long) sock
),
1226 node
= lttng_ht_iter_get_node_ulong(&iter
);
1228 DBG2("UST app find by notify sock %d not found", sock
);
1232 return caa_container_of(node
, struct ust_app
, notify_sock_n
);
1239 * Lookup for an ust app event based on event name, filter bytecode and the
1242 * Return an ust_app_event object or NULL on error.
1244 static struct ust_app_event
*find_ust_app_event(struct lttng_ht
*ht
,
1245 char *name
, struct lttng_filter_bytecode
*filter
,
1247 const struct lttng_event_exclusion
*exclusion
)
1249 struct lttng_ht_iter iter
;
1250 struct lttng_ht_node_str
*node
;
1251 struct ust_app_event
*event
= NULL
;
1252 struct ust_app_ht_key key
;
1257 /* Setup key for event lookup. */
1259 key
.filter
= filter
;
1260 key
.loglevel_type
= loglevel_value
;
1261 /* lttng_event_exclusion and lttng_ust_event_exclusion structures are similar */
1262 key
.exclusion
= exclusion
;
1264 /* Lookup using the event name as hash and a custom match fct. */
1265 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
1266 ht_match_ust_app_event
, &key
, &iter
.iter
);
1267 node
= lttng_ht_iter_get_node_str(&iter
);
1272 event
= caa_container_of(node
, struct ust_app_event
, node
);
1279 * Create the channel context on the tracer.
1281 * Called with UST app session lock held.
1284 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
1285 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
1289 health_code_update();
1291 pthread_mutex_lock(&app
->sock_lock
);
1292 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
1293 ua_chan
->obj
, &ua_ctx
->obj
);
1294 pthread_mutex_unlock(&app
->sock_lock
);
1296 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1297 ERR("UST app create channel context failed for app (pid: %d) "
1298 "with ret %d", app
->pid
, ret
);
1301 * This is normal behavior, an application can die during the
1302 * creation process. Don't report an error so the execution can
1303 * continue normally.
1306 DBG3("UST app disable event failed. Application is dead.");
1311 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
1313 DBG2("UST app context handle %d created successfully for channel %s",
1314 ua_ctx
->handle
, ua_chan
->name
);
1317 health_code_update();
1322 * Set the filter on the tracer.
1325 int set_ust_event_filter(struct ust_app_event
*ua_event
,
1326 struct ust_app
*app
)
1329 struct lttng_ust_filter_bytecode
*ust_bytecode
= NULL
;
1331 health_code_update();
1333 if (!ua_event
->filter
) {
1338 ust_bytecode
= create_ust_bytecode_from_bytecode(ua_event
->filter
);
1339 if (!ust_bytecode
) {
1340 ret
= -LTTNG_ERR_NOMEM
;
1343 pthread_mutex_lock(&app
->sock_lock
);
1344 ret
= ustctl_set_filter(app
->sock
, ust_bytecode
,
1346 pthread_mutex_unlock(&app
->sock_lock
);
1348 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1349 ERR("UST app event %s filter failed for app (pid: %d) "
1350 "with ret %d", ua_event
->attr
.name
, app
->pid
, ret
);
1353 * This is normal behavior, an application can die during the
1354 * creation process. Don't report an error so the execution can
1355 * continue normally.
1358 DBG3("UST app filter event failed. Application is dead.");
1363 DBG2("UST filter set successfully for event %s", ua_event
->name
);
1366 health_code_update();
1372 struct lttng_ust_event_exclusion
*create_ust_exclusion_from_exclusion(
1373 struct lttng_event_exclusion
*exclusion
)
1375 struct lttng_ust_event_exclusion
*ust_exclusion
= NULL
;
1376 size_t exclusion_alloc_size
= sizeof(struct lttng_ust_event_exclusion
) +
1377 LTTNG_UST_SYM_NAME_LEN
* exclusion
->count
;
1379 ust_exclusion
= zmalloc(exclusion_alloc_size
);
1380 if (!ust_exclusion
) {
1385 assert(sizeof(struct lttng_event_exclusion
) ==
1386 sizeof(struct lttng_ust_event_exclusion
));
1387 memcpy(ust_exclusion
, exclusion
, exclusion_alloc_size
);
1389 return ust_exclusion
;
1393 * Set event exclusions on the tracer.
1396 int set_ust_event_exclusion(struct ust_app_event
*ua_event
,
1397 struct ust_app
*app
)
1400 struct lttng_ust_event_exclusion
*ust_exclusion
= NULL
;
1402 health_code_update();
1404 if (!ua_event
->exclusion
|| !ua_event
->exclusion
->count
) {
1409 ust_exclusion
= create_ust_exclusion_from_exclusion(
1410 ua_event
->exclusion
);
1411 if (!ust_exclusion
) {
1412 ret
= -LTTNG_ERR_NOMEM
;
1415 pthread_mutex_lock(&app
->sock_lock
);
1416 ret
= ustctl_set_exclusion(app
->sock
, ust_exclusion
, ua_event
->obj
);
1417 pthread_mutex_unlock(&app
->sock_lock
);
1419 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1420 ERR("UST app event %s exclusions failed for app (pid: %d) "
1421 "with ret %d", ua_event
->attr
.name
, app
->pid
, ret
);
1424 * This is normal behavior, an application can die during the
1425 * creation process. Don't report an error so the execution can
1426 * continue normally.
1429 DBG3("UST app event exclusion failed. Application is dead.");
1434 DBG2("UST exclusion set successfully for event %s", ua_event
->name
);
1437 health_code_update();
1438 free(ust_exclusion
);
1443 * Disable the specified event on to UST tracer for the UST session.
1445 static int disable_ust_event(struct ust_app
*app
,
1446 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
1450 health_code_update();
1452 pthread_mutex_lock(&app
->sock_lock
);
1453 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
1454 pthread_mutex_unlock(&app
->sock_lock
);
1456 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1457 ERR("UST app event %s disable failed for app (pid: %d) "
1458 "and session handle %d with ret %d",
1459 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
1462 * This is normal behavior, an application can die during the
1463 * creation process. Don't report an error so the execution can
1464 * continue normally.
1467 DBG3("UST app disable event failed. Application is dead.");
1472 DBG2("UST app event %s disabled successfully for app (pid: %d)",
1473 ua_event
->attr
.name
, app
->pid
);
1476 health_code_update();
1481 * Disable the specified channel on to UST tracer for the UST session.
1483 static int disable_ust_channel(struct ust_app
*app
,
1484 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
1488 health_code_update();
1490 pthread_mutex_lock(&app
->sock_lock
);
1491 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
1492 pthread_mutex_unlock(&app
->sock_lock
);
1494 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1495 ERR("UST app channel %s disable failed for app (pid: %d) "
1496 "and session handle %d with ret %d",
1497 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
1500 * This is normal behavior, an application can die during the
1501 * creation process. Don't report an error so the execution can
1502 * continue normally.
1505 DBG3("UST app disable channel failed. Application is dead.");
1510 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
1511 ua_chan
->name
, app
->pid
);
1514 health_code_update();
1519 * Enable the specified channel on to UST tracer for the UST session.
1521 static int enable_ust_channel(struct ust_app
*app
,
1522 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
1526 health_code_update();
1528 pthread_mutex_lock(&app
->sock_lock
);
1529 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
1530 pthread_mutex_unlock(&app
->sock_lock
);
1532 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1533 ERR("UST app channel %s enable failed for app (pid: %d) "
1534 "and session handle %d with ret %d",
1535 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
1538 * This is normal behavior, an application can die during the
1539 * creation process. Don't report an error so the execution can
1540 * continue normally.
1543 DBG3("UST app enable channel failed. Application is dead.");
1548 ua_chan
->enabled
= 1;
1550 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
1551 ua_chan
->name
, app
->pid
);
1554 health_code_update();
1559 * Enable the specified event on to UST tracer for the UST session.
1561 static int enable_ust_event(struct ust_app
*app
,
1562 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
1566 health_code_update();
1568 pthread_mutex_lock(&app
->sock_lock
);
1569 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
1570 pthread_mutex_unlock(&app
->sock_lock
);
1572 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1573 ERR("UST app event %s enable failed for app (pid: %d) "
1574 "and session handle %d with ret %d",
1575 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
1578 * This is normal behavior, an application can die during the
1579 * creation process. Don't report an error so the execution can
1580 * continue normally.
1583 DBG3("UST app enable event failed. Application is dead.");
1588 DBG2("UST app event %s enabled successfully for app (pid: %d)",
1589 ua_event
->attr
.name
, app
->pid
);
1592 health_code_update();
1597 * Send channel and stream buffer to application.
1599 * Return 0 on success. On error, a negative value is returned.
1601 static int send_channel_pid_to_ust(struct ust_app
*app
,
1602 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
1605 struct ust_app_stream
*stream
, *stmp
;
1611 health_code_update();
1613 DBG("UST app sending channel %s to UST app sock %d", ua_chan
->name
,
1616 /* Send channel to the application. */
1617 ret
= ust_consumer_send_channel_to_ust(app
, ua_sess
, ua_chan
);
1618 if (ret
== -EPIPE
|| ret
== -LTTNG_UST_ERR_EXITING
) {
1619 ret
= -ENOTCONN
; /* Caused by app exiting. */
1621 } else if (ret
< 0) {
1625 health_code_update();
1627 /* Send all streams to application. */
1628 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
1629 ret
= ust_consumer_send_stream_to_ust(app
, ua_chan
, stream
);
1630 if (ret
== -EPIPE
|| ret
== -LTTNG_UST_ERR_EXITING
) {
1631 ret
= -ENOTCONN
; /* Caused by app exiting. */
1633 } else if (ret
< 0) {
1636 /* We don't need the stream anymore once sent to the tracer. */
1637 cds_list_del(&stream
->list
);
1638 delete_ust_app_stream(-1, stream
, app
);
1640 /* Flag the channel that it is sent to the application. */
1641 ua_chan
->is_sent
= 1;
1644 health_code_update();
1649 * Create the specified event onto the UST tracer for a UST session.
1651 * Should be called with session mutex held.
1654 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
1655 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
1659 health_code_update();
1661 /* Create UST event on tracer */
1662 pthread_mutex_lock(&app
->sock_lock
);
1663 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
1665 pthread_mutex_unlock(&app
->sock_lock
);
1667 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1668 ERR("Error ustctl create event %s for app pid: %d with ret %d",
1669 ua_event
->attr
.name
, app
->pid
, ret
);
1672 * This is normal behavior, an application can die during the
1673 * creation process. Don't report an error so the execution can
1674 * continue normally.
1677 DBG3("UST app create event failed. Application is dead.");
1682 ua_event
->handle
= ua_event
->obj
->handle
;
1684 DBG2("UST app event %s created successfully for pid:%d",
1685 ua_event
->attr
.name
, app
->pid
);
1687 health_code_update();
1689 /* Set filter if one is present. */
1690 if (ua_event
->filter
) {
1691 ret
= set_ust_event_filter(ua_event
, app
);
1697 /* Set exclusions for the event */
1698 if (ua_event
->exclusion
) {
1699 ret
= set_ust_event_exclusion(ua_event
, app
);
1705 /* If event not enabled, disable it on the tracer */
1706 if (ua_event
->enabled
) {
1708 * We now need to explicitly enable the event, since it
1709 * is now disabled at creation.
1711 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1714 * If we hit an EPERM, something is wrong with our enable call. If
1715 * we get an EEXIST, there is a problem on the tracer side since we
1719 case -LTTNG_UST_ERR_PERM
:
1720 /* Code flow problem */
1722 case -LTTNG_UST_ERR_EXIST
:
1723 /* It's OK for our use case. */
1734 health_code_update();
1739 * Copy data between an UST app event and a LTT event.
1741 static void shadow_copy_event(struct ust_app_event
*ua_event
,
1742 struct ltt_ust_event
*uevent
)
1744 size_t exclusion_alloc_size
;
1746 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
1747 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
1749 ua_event
->enabled
= uevent
->enabled
;
1751 /* Copy event attributes */
1752 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
1754 /* Copy filter bytecode */
1755 if (uevent
->filter
) {
1756 ua_event
->filter
= copy_filter_bytecode(uevent
->filter
);
1757 /* Filter might be NULL here in case of ENONEM. */
1760 /* Copy exclusion data */
1761 if (uevent
->exclusion
) {
1762 exclusion_alloc_size
= sizeof(struct lttng_event_exclusion
) +
1763 LTTNG_UST_SYM_NAME_LEN
* uevent
->exclusion
->count
;
1764 ua_event
->exclusion
= zmalloc(exclusion_alloc_size
);
1765 if (ua_event
->exclusion
== NULL
) {
1768 memcpy(ua_event
->exclusion
, uevent
->exclusion
,
1769 exclusion_alloc_size
);
1775 * Copy data between an UST app channel and a LTT channel.
1777 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
1778 struct ltt_ust_channel
*uchan
)
1780 struct lttng_ht_iter iter
;
1781 struct ltt_ust_event
*uevent
;
1782 struct ltt_ust_context
*uctx
;
1783 struct ust_app_event
*ua_event
;
1785 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
1787 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
1788 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
1790 ua_chan
->tracefile_size
= uchan
->tracefile_size
;
1791 ua_chan
->tracefile_count
= uchan
->tracefile_count
;
1793 /* Copy event attributes since the layout is different. */
1794 ua_chan
->attr
.subbuf_size
= uchan
->attr
.subbuf_size
;
1795 ua_chan
->attr
.num_subbuf
= uchan
->attr
.num_subbuf
;
1796 ua_chan
->attr
.overwrite
= uchan
->attr
.overwrite
;
1797 ua_chan
->attr
.switch_timer_interval
= uchan
->attr
.switch_timer_interval
;
1798 ua_chan
->attr
.read_timer_interval
= uchan
->attr
.read_timer_interval
;
1799 ua_chan
->monitor_timer_interval
= uchan
->monitor_timer_interval
;
1800 ua_chan
->attr
.output
= uchan
->attr
.output
;
1802 * Note that the attribute channel type is not set since the channel on the
1803 * tracing registry side does not have this information.
1806 ua_chan
->enabled
= uchan
->enabled
;
1807 ua_chan
->tracing_channel_id
= uchan
->id
;
1809 cds_list_for_each_entry(uctx
, &uchan
->ctx_list
, list
) {
1810 struct ust_app_ctx
*ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
1812 if (ua_ctx
== NULL
) {
1815 lttng_ht_node_init_ulong(&ua_ctx
->node
,
1816 (unsigned long) ua_ctx
->ctx
.ctx
);
1817 lttng_ht_add_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1818 cds_list_add_tail(&ua_ctx
->list
, &ua_chan
->ctx_list
);
1821 /* Copy all events from ltt ust channel to ust app channel */
1822 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
1823 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
1824 uevent
->filter
, uevent
->attr
.loglevel
, uevent
->exclusion
);
1825 if (ua_event
== NULL
) {
1826 DBG2("UST event %s not found on shadow copy channel",
1828 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1829 if (ua_event
== NULL
) {
1832 shadow_copy_event(ua_event
, uevent
);
1833 add_unique_ust_app_event(ua_chan
, ua_event
);
1837 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
1841 * Copy data between a UST app session and a regular LTT session.
1843 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
1844 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1846 struct lttng_ht_node_str
*ua_chan_node
;
1847 struct lttng_ht_iter iter
;
1848 struct ltt_ust_channel
*uchan
;
1849 struct ust_app_channel
*ua_chan
;
1851 struct tm
*timeinfo
;
1854 char tmp_shm_path
[PATH_MAX
];
1856 /* Get date and time for unique app path */
1858 timeinfo
= localtime(&rawtime
);
1859 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
1861 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
1863 ua_sess
->tracing_id
= usess
->id
;
1864 ua_sess
->id
= get_next_session_id();
1865 ua_sess
->uid
= app
->uid
;
1866 ua_sess
->gid
= app
->gid
;
1867 ua_sess
->euid
= usess
->uid
;
1868 ua_sess
->egid
= usess
->gid
;
1869 ua_sess
->buffer_type
= usess
->buffer_type
;
1870 ua_sess
->bits_per_long
= app
->bits_per_long
;
1872 /* There is only one consumer object per session possible. */
1873 consumer_output_get(usess
->consumer
);
1874 ua_sess
->consumer
= usess
->consumer
;
1876 ua_sess
->output_traces
= usess
->output_traces
;
1877 ua_sess
->live_timer_interval
= usess
->live_timer_interval
;
1878 copy_channel_attr_to_ustctl(&ua_sess
->metadata_attr
,
1879 &usess
->metadata_attr
);
1881 switch (ua_sess
->buffer_type
) {
1882 case LTTNG_BUFFER_PER_PID
:
1883 ret
= snprintf(ua_sess
->path
, sizeof(ua_sess
->path
),
1884 DEFAULT_UST_TRACE_PID_PATH
"/%s-%d-%s", app
->name
, app
->pid
,
1887 case LTTNG_BUFFER_PER_UID
:
1888 ret
= snprintf(ua_sess
->path
, sizeof(ua_sess
->path
),
1889 DEFAULT_UST_TRACE_UID_PATH
, ua_sess
->uid
, app
->bits_per_long
);
1896 PERROR("asprintf UST shadow copy session");
1901 strncpy(ua_sess
->root_shm_path
, usess
->root_shm_path
,
1902 sizeof(ua_sess
->root_shm_path
));
1903 ua_sess
->root_shm_path
[sizeof(ua_sess
->root_shm_path
) - 1] = '\0';
1904 strncpy(ua_sess
->shm_path
, usess
->shm_path
,
1905 sizeof(ua_sess
->shm_path
));
1906 ua_sess
->shm_path
[sizeof(ua_sess
->shm_path
) - 1] = '\0';
1907 if (ua_sess
->shm_path
[0]) {
1908 switch (ua_sess
->buffer_type
) {
1909 case LTTNG_BUFFER_PER_PID
:
1910 ret
= snprintf(tmp_shm_path
, sizeof(tmp_shm_path
),
1911 DEFAULT_UST_TRACE_PID_PATH
"/%s-%d-%s",
1912 app
->name
, app
->pid
, datetime
);
1914 case LTTNG_BUFFER_PER_UID
:
1915 ret
= snprintf(tmp_shm_path
, sizeof(tmp_shm_path
),
1916 DEFAULT_UST_TRACE_UID_PATH
,
1917 app
->uid
, app
->bits_per_long
);
1924 PERROR("sprintf UST shadow copy session");
1928 strncat(ua_sess
->shm_path
, tmp_shm_path
,
1929 sizeof(ua_sess
->shm_path
) - strlen(ua_sess
->shm_path
) - 1);
1930 ua_sess
->shm_path
[sizeof(ua_sess
->shm_path
) - 1] = '\0';
1933 /* Iterate over all channels in global domain. */
1934 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
1936 struct lttng_ht_iter uiter
;
1938 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1939 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1940 if (ua_chan_node
!= NULL
) {
1941 /* Session exist. Contiuing. */
1945 DBG2("Channel %s not found on shadow session copy, creating it",
1947 ua_chan
= alloc_ust_app_channel(uchan
->name
, ua_sess
,
1949 if (ua_chan
== NULL
) {
1950 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
1953 shadow_copy_channel(ua_chan
, uchan
);
1955 * The concept of metadata channel does not exist on the tracing
1956 * registry side of the session daemon so this can only be a per CPU
1957 * channel and not metadata.
1959 ua_chan
->attr
.type
= LTTNG_UST_CHAN_PER_CPU
;
1961 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1966 consumer_output_put(ua_sess
->consumer
);
1970 * Lookup sesison wrapper.
1973 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
1974 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
1976 /* Get right UST app session from app */
1977 lttng_ht_lookup(app
->sessions
, &usess
->id
, iter
);
1981 * Return ust app session from the app session hashtable using the UST session
1984 static struct ust_app_session
*lookup_session_by_app(
1985 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1987 struct lttng_ht_iter iter
;
1988 struct lttng_ht_node_u64
*node
;
1990 __lookup_session_by_app(usess
, app
, &iter
);
1991 node
= lttng_ht_iter_get_node_u64(&iter
);
1996 return caa_container_of(node
, struct ust_app_session
, node
);
2003 * Setup buffer registry per PID for the given session and application. If none
2004 * is found, a new one is created, added to the global registry and
2005 * initialized. If regp is valid, it's set with the newly created object.
2007 * Return 0 on success or else a negative value.
2009 static int setup_buffer_reg_pid(struct ust_app_session
*ua_sess
,
2010 struct ust_app
*app
, struct buffer_reg_pid
**regp
)
2013 struct buffer_reg_pid
*reg_pid
;
2020 reg_pid
= buffer_reg_pid_find(ua_sess
->id
);
2023 * This is the create channel path meaning that if there is NO
2024 * registry available, we have to create one for this session.
2026 ret
= buffer_reg_pid_create(ua_sess
->id
, ®_pid
,
2027 ua_sess
->root_shm_path
, ua_sess
->shm_path
);
2035 /* Initialize registry. */
2036 ret
= ust_registry_session_init(®_pid
->registry
->reg
.ust
, app
,
2037 app
->bits_per_long
, app
->uint8_t_alignment
,
2038 app
->uint16_t_alignment
, app
->uint32_t_alignment
,
2039 app
->uint64_t_alignment
, app
->long_alignment
,
2040 app
->byte_order
, app
->version
.major
,
2041 app
->version
.minor
, reg_pid
->root_shm_path
,
2043 ua_sess
->euid
, ua_sess
->egid
);
2046 * reg_pid->registry->reg.ust is NULL upon error, so we need to
2047 * destroy the buffer registry, because it is always expected
2048 * that if the buffer registry can be found, its ust registry is
2051 buffer_reg_pid_destroy(reg_pid
);
2055 buffer_reg_pid_add(reg_pid
);
2057 DBG3("UST app buffer registry per PID created successfully");
2069 * Setup buffer registry per UID for the given session and application. If none
2070 * is found, a new one is created, added to the global registry and
2071 * initialized. If regp is valid, it's set with the newly created object.
2073 * Return 0 on success or else a negative value.
2075 static int setup_buffer_reg_uid(struct ltt_ust_session
*usess
,
2076 struct ust_app_session
*ua_sess
,
2077 struct ust_app
*app
, struct buffer_reg_uid
**regp
)
2080 struct buffer_reg_uid
*reg_uid
;
2087 reg_uid
= buffer_reg_uid_find(usess
->id
, app
->bits_per_long
, app
->uid
);
2090 * This is the create channel path meaning that if there is NO
2091 * registry available, we have to create one for this session.
2093 ret
= buffer_reg_uid_create(usess
->id
, app
->bits_per_long
, app
->uid
,
2094 LTTNG_DOMAIN_UST
, ®_uid
,
2095 ua_sess
->root_shm_path
, ua_sess
->shm_path
);
2103 /* Initialize registry. */
2104 ret
= ust_registry_session_init(®_uid
->registry
->reg
.ust
, NULL
,
2105 app
->bits_per_long
, app
->uint8_t_alignment
,
2106 app
->uint16_t_alignment
, app
->uint32_t_alignment
,
2107 app
->uint64_t_alignment
, app
->long_alignment
,
2108 app
->byte_order
, app
->version
.major
,
2109 app
->version
.minor
, reg_uid
->root_shm_path
,
2110 reg_uid
->shm_path
, usess
->uid
, usess
->gid
);
2113 * reg_uid->registry->reg.ust is NULL upon error, so we need to
2114 * destroy the buffer registry, because it is always expected
2115 * that if the buffer registry can be found, its ust registry is
2118 buffer_reg_uid_destroy(reg_uid
, NULL
);
2121 /* Add node to teardown list of the session. */
2122 cds_list_add(®_uid
->lnode
, &usess
->buffer_reg_uid_list
);
2124 buffer_reg_uid_add(reg_uid
);
2126 DBG3("UST app buffer registry per UID created successfully");
2137 * Create a session on the tracer side for the given app.
2139 * On success, ua_sess_ptr is populated with the session pointer or else left
2140 * untouched. If the session was created, is_created is set to 1. On error,
2141 * it's left untouched. Note that ua_sess_ptr is mandatory but is_created can
2144 * Returns 0 on success or else a negative code which is either -ENOMEM or
2145 * -ENOTCONN which is the default code if the ustctl_create_session fails.
2147 static int create_ust_app_session(struct ltt_ust_session
*usess
,
2148 struct ust_app
*app
, struct ust_app_session
**ua_sess_ptr
,
2151 int ret
, created
= 0;
2152 struct ust_app_session
*ua_sess
;
2156 assert(ua_sess_ptr
);
2158 health_code_update();
2160 ua_sess
= lookup_session_by_app(usess
, app
);
2161 if (ua_sess
== NULL
) {
2162 DBG2("UST app pid: %d session id %" PRIu64
" not found, creating it",
2163 app
->pid
, usess
->id
);
2164 ua_sess
= alloc_ust_app_session(app
);
2165 if (ua_sess
== NULL
) {
2166 /* Only malloc can failed so something is really wrong */
2170 shadow_copy_session(ua_sess
, usess
, app
);
2174 switch (usess
->buffer_type
) {
2175 case LTTNG_BUFFER_PER_PID
:
2176 /* Init local registry. */
2177 ret
= setup_buffer_reg_pid(ua_sess
, app
, NULL
);
2179 delete_ust_app_session(-1, ua_sess
, app
);
2183 case LTTNG_BUFFER_PER_UID
:
2184 /* Look for a global registry. If none exists, create one. */
2185 ret
= setup_buffer_reg_uid(usess
, ua_sess
, app
, NULL
);
2187 delete_ust_app_session(-1, ua_sess
, app
);
2197 health_code_update();
2199 if (ua_sess
->handle
== -1) {
2200 pthread_mutex_lock(&app
->sock_lock
);
2201 ret
= ustctl_create_session(app
->sock
);
2202 pthread_mutex_unlock(&app
->sock_lock
);
2204 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
2205 ERR("Creating session for app pid %d with ret %d",
2208 DBG("UST app creating session failed. Application is dead");
2210 * This is normal behavior, an application can die during the
2211 * creation process. Don't report an error so the execution can
2212 * continue normally. This will get flagged ENOTCONN and the
2213 * caller will handle it.
2217 delete_ust_app_session(-1, ua_sess
, app
);
2218 if (ret
!= -ENOMEM
) {
2220 * Tracer is probably gone or got an internal error so let's
2221 * behave like it will soon unregister or not usable.
2228 ua_sess
->handle
= ret
;
2230 /* Add ust app session to app's HT */
2231 lttng_ht_node_init_u64(&ua_sess
->node
,
2232 ua_sess
->tracing_id
);
2233 lttng_ht_add_unique_u64(app
->sessions
, &ua_sess
->node
);
2234 lttng_ht_node_init_ulong(&ua_sess
->ust_objd_node
, ua_sess
->handle
);
2235 lttng_ht_add_unique_ulong(app
->ust_sessions_objd
,
2236 &ua_sess
->ust_objd_node
);
2238 DBG2("UST app session created successfully with handle %d", ret
);
2241 *ua_sess_ptr
= ua_sess
;
2243 *is_created
= created
;
2246 /* Everything went well. */
2250 health_code_update();
2255 * Match function for a hash table lookup of ust_app_ctx.
2257 * It matches an ust app context based on the context type and, in the case
2258 * of perf counters, their name.
2260 static int ht_match_ust_app_ctx(struct cds_lfht_node
*node
, const void *_key
)
2262 struct ust_app_ctx
*ctx
;
2263 const struct lttng_ust_context_attr
*key
;
2268 ctx
= caa_container_of(node
, struct ust_app_ctx
, node
.node
);
2272 if (ctx
->ctx
.ctx
!= key
->ctx
) {
2277 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
2278 if (strncmp(key
->u
.perf_counter
.name
,
2279 ctx
->ctx
.u
.perf_counter
.name
,
2280 sizeof(key
->u
.perf_counter
.name
))) {
2284 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
2285 if (strcmp(key
->u
.app_ctx
.provider_name
,
2286 ctx
->ctx
.u
.app_ctx
.provider_name
) ||
2287 strcmp(key
->u
.app_ctx
.ctx_name
,
2288 ctx
->ctx
.u
.app_ctx
.ctx_name
)) {
2304 * Lookup for an ust app context from an lttng_ust_context.
2306 * Must be called while holding RCU read side lock.
2307 * Return an ust_app_ctx object or NULL on error.
2310 struct ust_app_ctx
*find_ust_app_context(struct lttng_ht
*ht
,
2311 struct lttng_ust_context_attr
*uctx
)
2313 struct lttng_ht_iter iter
;
2314 struct lttng_ht_node_ulong
*node
;
2315 struct ust_app_ctx
*app_ctx
= NULL
;
2320 /* Lookup using the lttng_ust_context_type and a custom match fct. */
2321 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) uctx
->ctx
, lttng_ht_seed
),
2322 ht_match_ust_app_ctx
, uctx
, &iter
.iter
);
2323 node
= lttng_ht_iter_get_node_ulong(&iter
);
2328 app_ctx
= caa_container_of(node
, struct ust_app_ctx
, node
);
2335 * Create a context for the channel on the tracer.
2337 * Called with UST app session lock held and a RCU read side lock.
2340 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
2341 struct ust_app_channel
*ua_chan
,
2342 struct lttng_ust_context_attr
*uctx
,
2343 struct ust_app
*app
)
2346 struct ust_app_ctx
*ua_ctx
;
2348 DBG2("UST app adding context to channel %s", ua_chan
->name
);
2350 ua_ctx
= find_ust_app_context(ua_chan
->ctx
, uctx
);
2356 ua_ctx
= alloc_ust_app_ctx(uctx
);
2357 if (ua_ctx
== NULL
) {
2363 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
2364 lttng_ht_add_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
2365 cds_list_add_tail(&ua_ctx
->list
, &ua_chan
->ctx_list
);
2367 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2377 * Enable on the tracer side a ust app event for the session and channel.
2379 * Called with UST app session lock held.
2382 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
2383 struct ust_app_event
*ua_event
, struct ust_app
*app
)
2387 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
2392 ua_event
->enabled
= 1;
2399 * Disable on the tracer side a ust app event for the session and channel.
2401 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
2402 struct ust_app_event
*ua_event
, struct ust_app
*app
)
2406 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
2411 ua_event
->enabled
= 0;
2418 * Lookup ust app channel for session and disable it on the tracer side.
2421 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
2422 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
2426 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
2431 ua_chan
->enabled
= 0;
2438 * Lookup ust app channel for session and enable it on the tracer side. This
2439 * MUST be called with a RCU read side lock acquired.
2441 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
2442 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
2445 struct lttng_ht_iter iter
;
2446 struct lttng_ht_node_str
*ua_chan_node
;
2447 struct ust_app_channel
*ua_chan
;
2449 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2450 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2451 if (ua_chan_node
== NULL
) {
2452 DBG2("Unable to find channel %s in ust session id %" PRIu64
,
2453 uchan
->name
, ua_sess
->tracing_id
);
2457 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2459 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
2469 * Ask the consumer to create a channel and get it if successful.
2471 * Return 0 on success or else a negative value.
2473 static int do_consumer_create_channel(struct ltt_ust_session
*usess
,
2474 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
,
2475 int bitness
, struct ust_registry_session
*registry
)
2478 unsigned int nb_fd
= 0;
2479 struct consumer_socket
*socket
;
2487 health_code_update();
2489 /* Get the right consumer socket for the application. */
2490 socket
= consumer_find_socket_by_bitness(bitness
, usess
->consumer
);
2496 health_code_update();
2498 /* Need one fd for the channel. */
2499 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
2501 ERR("Exhausted number of available FD upon create channel");
2506 * Ask consumer to create channel. The consumer will return the number of
2507 * stream we have to expect.
2509 ret
= ust_consumer_ask_channel(ua_sess
, ua_chan
, usess
->consumer
, socket
,
2516 * Compute the number of fd needed before receiving them. It must be 2 per
2517 * stream (2 being the default value here).
2519 nb_fd
= DEFAULT_UST_STREAM_FD_NUM
* ua_chan
->expected_stream_count
;
2521 /* Reserve the amount of file descriptor we need. */
2522 ret
= lttng_fd_get(LTTNG_FD_APPS
, nb_fd
);
2524 ERR("Exhausted number of available FD upon create channel");
2525 goto error_fd_get_stream
;
2528 health_code_update();
2531 * Now get the channel from the consumer. This call wil populate the stream
2532 * list of that channel and set the ust objects.
2534 if (usess
->consumer
->enabled
) {
2535 ret
= ust_consumer_get_channel(socket
, ua_chan
);
2545 lttng_fd_put(LTTNG_FD_APPS
, nb_fd
);
2546 error_fd_get_stream
:
2548 * Initiate a destroy channel on the consumer since we had an error
2549 * handling it on our side. The return value is of no importance since we
2550 * already have a ret value set by the previous error that we need to
2553 (void) ust_consumer_destroy_channel(socket
, ua_chan
);
2555 lttng_fd_put(LTTNG_FD_APPS
, 1);
2557 health_code_update();
2563 * Duplicate the ust data object of the ust app stream and save it in the
2564 * buffer registry stream.
2566 * Return 0 on success or else a negative value.
2568 static int duplicate_stream_object(struct buffer_reg_stream
*reg_stream
,
2569 struct ust_app_stream
*stream
)
2576 /* Reserve the amount of file descriptor we need. */
2577 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2579 ERR("Exhausted number of available FD upon duplicate stream");
2583 /* Duplicate object for stream once the original is in the registry. */
2584 ret
= ustctl_duplicate_ust_object_data(&stream
->obj
,
2585 reg_stream
->obj
.ust
);
2587 ERR("Duplicate stream obj from %p to %p failed with ret %d",
2588 reg_stream
->obj
.ust
, stream
->obj
, ret
);
2589 lttng_fd_put(LTTNG_FD_APPS
, 2);
2592 stream
->handle
= stream
->obj
->handle
;
2599 * Duplicate the ust data object of the ust app. channel and save it in the
2600 * buffer registry channel.
2602 * Return 0 on success or else a negative value.
2604 static int duplicate_channel_object(struct buffer_reg_channel
*reg_chan
,
2605 struct ust_app_channel
*ua_chan
)
2612 /* Need two fds for the channel. */
2613 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
2615 ERR("Exhausted number of available FD upon duplicate channel");
2619 /* Duplicate object for stream once the original is in the registry. */
2620 ret
= ustctl_duplicate_ust_object_data(&ua_chan
->obj
, reg_chan
->obj
.ust
);
2622 ERR("Duplicate channel obj from %p to %p failed with ret: %d",
2623 reg_chan
->obj
.ust
, ua_chan
->obj
, ret
);
2626 ua_chan
->handle
= ua_chan
->obj
->handle
;
2631 lttng_fd_put(LTTNG_FD_APPS
, 1);
2637 * For a given channel buffer registry, setup all streams of the given ust
2638 * application channel.
2640 * Return 0 on success or else a negative value.
2642 static int setup_buffer_reg_streams(struct buffer_reg_channel
*reg_chan
,
2643 struct ust_app_channel
*ua_chan
,
2644 struct ust_app
*app
)
2647 struct ust_app_stream
*stream
, *stmp
;
2652 DBG2("UST app setup buffer registry stream");
2654 /* Send all streams to application. */
2655 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
2656 struct buffer_reg_stream
*reg_stream
;
2658 ret
= buffer_reg_stream_create(®_stream
);
2664 * Keep original pointer and nullify it in the stream so the delete
2665 * stream call does not release the object.
2667 reg_stream
->obj
.ust
= stream
->obj
;
2669 buffer_reg_stream_add(reg_stream
, reg_chan
);
2671 /* We don't need the streams anymore. */
2672 cds_list_del(&stream
->list
);
2673 delete_ust_app_stream(-1, stream
, app
);
2681 * Create a buffer registry channel for the given session registry and
2682 * application channel object. If regp pointer is valid, it's set with the
2683 * created object. Important, the created object is NOT added to the session
2684 * registry hash table.
2686 * Return 0 on success else a negative value.
2688 static int create_buffer_reg_channel(struct buffer_reg_session
*reg_sess
,
2689 struct ust_app_channel
*ua_chan
, struct buffer_reg_channel
**regp
)
2692 struct buffer_reg_channel
*reg_chan
= NULL
;
2697 DBG2("UST app creating buffer registry channel for %s", ua_chan
->name
);
2699 /* Create buffer registry channel. */
2700 ret
= buffer_reg_channel_create(ua_chan
->tracing_channel_id
, ®_chan
);
2705 reg_chan
->consumer_key
= ua_chan
->key
;
2706 reg_chan
->subbuf_size
= ua_chan
->attr
.subbuf_size
;
2707 reg_chan
->num_subbuf
= ua_chan
->attr
.num_subbuf
;
2709 /* Create and add a channel registry to session. */
2710 ret
= ust_registry_channel_add(reg_sess
->reg
.ust
,
2711 ua_chan
->tracing_channel_id
);
2715 buffer_reg_channel_add(reg_sess
, reg_chan
);
2724 /* Safe because the registry channel object was not added to any HT. */
2725 buffer_reg_channel_destroy(reg_chan
, LTTNG_DOMAIN_UST
);
2731 * Setup buffer registry channel for the given session registry and application
2732 * channel object. If regp pointer is valid, it's set with the created object.
2734 * Return 0 on success else a negative value.
2736 static int setup_buffer_reg_channel(struct buffer_reg_session
*reg_sess
,
2737 struct ust_app_channel
*ua_chan
, struct buffer_reg_channel
*reg_chan
,
2738 struct ust_app
*app
)
2745 assert(ua_chan
->obj
);
2747 DBG2("UST app setup buffer registry channel for %s", ua_chan
->name
);
2749 /* Setup all streams for the registry. */
2750 ret
= setup_buffer_reg_streams(reg_chan
, ua_chan
, app
);
2755 reg_chan
->obj
.ust
= ua_chan
->obj
;
2756 ua_chan
->obj
= NULL
;
2761 buffer_reg_channel_remove(reg_sess
, reg_chan
);
2762 buffer_reg_channel_destroy(reg_chan
, LTTNG_DOMAIN_UST
);
2767 * Send buffer registry channel to the application.
2769 * Return 0 on success else a negative value.
2771 static int send_channel_uid_to_ust(struct buffer_reg_channel
*reg_chan
,
2772 struct ust_app
*app
, struct ust_app_session
*ua_sess
,
2773 struct ust_app_channel
*ua_chan
)
2776 struct buffer_reg_stream
*reg_stream
;
2783 DBG("UST app sending buffer registry channel to ust sock %d", app
->sock
);
2785 ret
= duplicate_channel_object(reg_chan
, ua_chan
);
2790 /* Send channel to the application. */
2791 ret
= ust_consumer_send_channel_to_ust(app
, ua_sess
, ua_chan
);
2792 if (ret
== -EPIPE
|| ret
== -LTTNG_UST_ERR_EXITING
) {
2793 ret
= -ENOTCONN
; /* Caused by app exiting. */
2795 } else if (ret
< 0) {
2799 health_code_update();
2801 /* Send all streams to application. */
2802 pthread_mutex_lock(®_chan
->stream_list_lock
);
2803 cds_list_for_each_entry(reg_stream
, ®_chan
->streams
, lnode
) {
2804 struct ust_app_stream stream
;
2806 ret
= duplicate_stream_object(reg_stream
, &stream
);
2808 goto error_stream_unlock
;
2811 ret
= ust_consumer_send_stream_to_ust(app
, ua_chan
, &stream
);
2813 (void) release_ust_app_stream(-1, &stream
, app
);
2814 if (ret
== -EPIPE
|| ret
== -LTTNG_UST_ERR_EXITING
) {
2815 ret
= -ENOTCONN
; /* Caused by app exiting. */
2817 goto error_stream_unlock
;
2821 * The return value is not important here. This function will output an
2824 (void) release_ust_app_stream(-1, &stream
, app
);
2826 ua_chan
->is_sent
= 1;
2828 error_stream_unlock
:
2829 pthread_mutex_unlock(®_chan
->stream_list_lock
);
2835 * Create and send to the application the created buffers with per UID buffers.
2837 * Return 0 on success else a negative value.
2839 static int create_channel_per_uid(struct ust_app
*app
,
2840 struct ltt_ust_session
*usess
, struct ust_app_session
*ua_sess
,
2841 struct ust_app_channel
*ua_chan
)
2844 struct buffer_reg_uid
*reg_uid
;
2845 struct buffer_reg_channel
*reg_chan
;
2846 bool created
= false;
2853 DBG("UST app creating channel %s with per UID buffers", ua_chan
->name
);
2855 reg_uid
= buffer_reg_uid_find(usess
->id
, app
->bits_per_long
, app
->uid
);
2857 * The session creation handles the creation of this global registry
2858 * object. If none can be find, there is a code flow problem or a
2863 reg_chan
= buffer_reg_channel_find(ua_chan
->tracing_channel_id
,
2866 /* Create the buffer registry channel object. */
2867 ret
= create_buffer_reg_channel(reg_uid
->registry
, ua_chan
, ®_chan
);
2869 ERR("Error creating the UST channel \"%s\" registry instance",
2876 * Create the buffers on the consumer side. This call populates the
2877 * ust app channel object with all streams and data object.
2879 ret
= do_consumer_create_channel(usess
, ua_sess
, ua_chan
,
2880 app
->bits_per_long
, reg_uid
->registry
->reg
.ust
);
2882 ERR("Error creating UST channel \"%s\" on the consumer daemon",
2886 * Let's remove the previously created buffer registry channel so
2887 * it's not visible anymore in the session registry.
2889 ust_registry_channel_del_free(reg_uid
->registry
->reg
.ust
,
2890 ua_chan
->tracing_channel_id
, false);
2891 buffer_reg_channel_remove(reg_uid
->registry
, reg_chan
);
2892 buffer_reg_channel_destroy(reg_chan
, LTTNG_DOMAIN_UST
);
2897 * Setup the streams and add it to the session registry.
2899 ret
= setup_buffer_reg_channel(reg_uid
->registry
,
2900 ua_chan
, reg_chan
, app
);
2902 ERR("Error setting up UST channel \"%s\"",
2909 /* Send buffers to the application. */
2910 ret
= send_channel_uid_to_ust(reg_chan
, app
, ua_sess
, ua_chan
);
2912 if (ret
!= -ENOTCONN
) {
2913 ERR("Error sending channel to application");
2919 enum lttng_error_code cmd_ret
;
2920 struct ltt_session
*session
;
2921 uint64_t chan_reg_key
;
2922 struct ust_registry_channel
*chan_reg
;
2925 chan_reg_key
= ua_chan
->tracing_channel_id
;
2927 pthread_mutex_lock(®_uid
->registry
->reg
.ust
->lock
);
2928 chan_reg
= ust_registry_channel_find(reg_uid
->registry
->reg
.ust
,
2931 chan_reg
->consumer_key
= ua_chan
->key
;
2933 pthread_mutex_unlock(®_uid
->registry
->reg
.ust
->lock
);
2935 session
= session_find_by_id(ua_sess
->tracing_id
);
2938 cmd_ret
= notification_thread_command_add_channel(
2939 notification_thread_handle
, session
->name
,
2940 ua_sess
->euid
, ua_sess
->egid
,
2944 ua_chan
->attr
.subbuf_size
* ua_chan
->attr
.num_subbuf
);
2946 if (cmd_ret
!= LTTNG_OK
) {
2947 ret
= - (int) cmd_ret
;
2948 ERR("Failed to add channel to notification thread");
2958 * Create and send to the application the created buffers with per PID buffers.
2960 * Return 0 on success else a negative value.
2962 static int create_channel_per_pid(struct ust_app
*app
,
2963 struct ltt_ust_session
*usess
, struct ust_app_session
*ua_sess
,
2964 struct ust_app_channel
*ua_chan
)
2967 struct ust_registry_session
*registry
;
2968 enum lttng_error_code cmd_ret
;
2969 struct ltt_session
*session
;
2970 uint64_t chan_reg_key
;
2971 struct ust_registry_channel
*chan_reg
;
2978 DBG("UST app creating channel %s with per PID buffers", ua_chan
->name
);
2982 registry
= get_session_registry(ua_sess
);
2985 /* Create and add a new channel registry to session. */
2986 ret
= ust_registry_channel_add(registry
, ua_chan
->key
);
2988 ERR("Error creating the UST channel \"%s\" registry instance",
2993 /* Create and get channel on the consumer side. */
2994 ret
= do_consumer_create_channel(usess
, ua_sess
, ua_chan
,
2995 app
->bits_per_long
, registry
);
2997 ERR("Error creating UST channel \"%s\" on the consumer daemon",
3002 ret
= send_channel_pid_to_ust(app
, ua_sess
, ua_chan
);
3004 if (ret
!= -ENOTCONN
) {
3005 ERR("Error sending channel to application");
3010 session
= session_find_by_id(ua_sess
->tracing_id
);
3013 chan_reg_key
= ua_chan
->key
;
3014 pthread_mutex_lock(®istry
->lock
);
3015 chan_reg
= ust_registry_channel_find(registry
, chan_reg_key
);
3017 chan_reg
->consumer_key
= ua_chan
->key
;
3018 pthread_mutex_unlock(®istry
->lock
);
3020 cmd_ret
= notification_thread_command_add_channel(
3021 notification_thread_handle
, session
->name
,
3022 ua_sess
->euid
, ua_sess
->egid
,
3026 ua_chan
->attr
.subbuf_size
* ua_chan
->attr
.num_subbuf
);
3027 if (cmd_ret
!= LTTNG_OK
) {
3028 ret
= - (int) cmd_ret
;
3029 ERR("Failed to add channel to notification thread");
3039 * From an already allocated ust app channel, create the channel buffers if
3040 * need and send it to the application. This MUST be called with a RCU read
3041 * side lock acquired.
3043 * Return 0 on success or else a negative value. Returns -ENOTCONN if
3044 * the application exited concurrently.
3046 static int do_create_channel(struct ust_app
*app
,
3047 struct ltt_ust_session
*usess
, struct ust_app_session
*ua_sess
,
3048 struct ust_app_channel
*ua_chan
)
3057 /* Handle buffer type before sending the channel to the application. */
3058 switch (usess
->buffer_type
) {
3059 case LTTNG_BUFFER_PER_UID
:
3061 ret
= create_channel_per_uid(app
, usess
, ua_sess
, ua_chan
);
3067 case LTTNG_BUFFER_PER_PID
:
3069 ret
= create_channel_per_pid(app
, usess
, ua_sess
, ua_chan
);
3081 /* Initialize ust objd object using the received handle and add it. */
3082 lttng_ht_node_init_ulong(&ua_chan
->ust_objd_node
, ua_chan
->handle
);
3083 lttng_ht_add_unique_ulong(app
->ust_objd
, &ua_chan
->ust_objd_node
);
3085 /* If channel is not enabled, disable it on the tracer */
3086 if (!ua_chan
->enabled
) {
3087 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
3098 * Create UST app channel and create it on the tracer. Set ua_chanp of the
3099 * newly created channel if not NULL.
3101 * Called with UST app session lock and RCU read-side lock held.
3103 * Return 0 on success or else a negative value. Returns -ENOTCONN if
3104 * the application exited concurrently.
3106 static int create_ust_app_channel(struct ust_app_session
*ua_sess
,
3107 struct ltt_ust_channel
*uchan
, struct ust_app
*app
,
3108 enum lttng_ust_chan_type type
, struct ltt_ust_session
*usess
,
3109 struct ust_app_channel
**ua_chanp
)
3112 struct lttng_ht_iter iter
;
3113 struct lttng_ht_node_str
*ua_chan_node
;
3114 struct ust_app_channel
*ua_chan
;
3116 /* Lookup channel in the ust app session */
3117 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
3118 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
3119 if (ua_chan_node
!= NULL
) {
3120 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3124 ua_chan
= alloc_ust_app_channel(uchan
->name
, ua_sess
, &uchan
->attr
);
3125 if (ua_chan
== NULL
) {
3126 /* Only malloc can fail here */
3130 shadow_copy_channel(ua_chan
, uchan
);
3132 /* Set channel type. */
3133 ua_chan
->attr
.type
= type
;
3135 ret
= do_create_channel(app
, usess
, ua_sess
, ua_chan
);
3140 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
3143 /* Only add the channel if successful on the tracer side. */
3144 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
3147 *ua_chanp
= ua_chan
;
3150 /* Everything went well. */
3154 delete_ust_app_channel(ua_chan
->is_sent
? app
->sock
: -1, ua_chan
, app
);
3160 * Create UST app event and create it on the tracer side.
3162 * Called with ust app session mutex held.
3165 int create_ust_app_event(struct ust_app_session
*ua_sess
,
3166 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
3167 struct ust_app
*app
)
3170 struct ust_app_event
*ua_event
;
3172 /* Get event node */
3173 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
3174 uevent
->filter
, uevent
->attr
.loglevel
, uevent
->exclusion
);
3175 if (ua_event
!= NULL
) {
3180 /* Does not exist so create one */
3181 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
3182 if (ua_event
== NULL
) {
3183 /* Only malloc can failed so something is really wrong */
3187 shadow_copy_event(ua_event
, uevent
);
3189 /* Create it on the tracer side */
3190 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
3192 /* Not found previously means that it does not exist on the tracer */
3193 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
3197 add_unique_ust_app_event(ua_chan
, ua_event
);
3199 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
3206 /* Valid. Calling here is already in a read side lock */
3207 delete_ust_app_event(-1, ua_event
, app
);
3212 * Create UST metadata and open it on the tracer side.
3214 * Called with UST app session lock held and RCU read side lock.
3216 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
3217 struct ust_app
*app
, struct consumer_output
*consumer
)
3220 struct ust_app_channel
*metadata
;
3221 struct consumer_socket
*socket
;
3222 struct ust_registry_session
*registry
;
3228 registry
= get_session_registry(ua_sess
);
3231 pthread_mutex_lock(®istry
->lock
);
3233 /* Metadata already exists for this registry or it was closed previously */
3234 if (registry
->metadata_key
|| registry
->metadata_closed
) {
3239 /* Allocate UST metadata */
3240 metadata
= alloc_ust_app_channel(DEFAULT_METADATA_NAME
, ua_sess
, NULL
);
3242 /* malloc() failed */
3247 memcpy(&metadata
->attr
, &ua_sess
->metadata_attr
, sizeof(metadata
->attr
));
3249 /* Need one fd for the channel. */
3250 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
3252 ERR("Exhausted number of available FD upon create metadata");
3256 /* Get the right consumer socket for the application. */
3257 socket
= consumer_find_socket_by_bitness(app
->bits_per_long
, consumer
);
3260 goto error_consumer
;
3264 * Keep metadata key so we can identify it on the consumer side. Assign it
3265 * to the registry *before* we ask the consumer so we avoid the race of the
3266 * consumer requesting the metadata and the ask_channel call on our side
3267 * did not returned yet.
3269 registry
->metadata_key
= metadata
->key
;
3272 * Ask the metadata channel creation to the consumer. The metadata object
3273 * will be created by the consumer and kept their. However, the stream is
3274 * never added or monitored until we do a first push metadata to the
3277 ret
= ust_consumer_ask_channel(ua_sess
, metadata
, consumer
, socket
,
3280 /* Nullify the metadata key so we don't try to close it later on. */
3281 registry
->metadata_key
= 0;
3282 goto error_consumer
;
3286 * The setup command will make the metadata stream be sent to the relayd,
3287 * if applicable, and the thread managing the metadatas. This is important
3288 * because after this point, if an error occurs, the only way the stream
3289 * can be deleted is to be monitored in the consumer.
3291 ret
= consumer_setup_metadata(socket
, metadata
->key
);
3293 /* Nullify the metadata key so we don't try to close it later on. */
3294 registry
->metadata_key
= 0;
3295 goto error_consumer
;
3298 DBG2("UST metadata with key %" PRIu64
" created for app pid %d",
3299 metadata
->key
, app
->pid
);
3302 lttng_fd_put(LTTNG_FD_APPS
, 1);
3303 delete_ust_app_channel(-1, metadata
, app
);
3305 pthread_mutex_unlock(®istry
->lock
);
3310 * Return ust app pointer or NULL if not found. RCU read side lock MUST be
3311 * acquired before calling this function.
3313 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
3315 struct ust_app
*app
= NULL
;
3316 struct lttng_ht_node_ulong
*node
;
3317 struct lttng_ht_iter iter
;
3319 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
3320 node
= lttng_ht_iter_get_node_ulong(&iter
);
3322 DBG2("UST app no found with pid %d", pid
);
3326 DBG2("Found UST app by pid %d", pid
);
3328 app
= caa_container_of(node
, struct ust_app
, pid_n
);
3335 * Allocate and init an UST app object using the registration information and
3336 * the command socket. This is called when the command socket connects to the
3339 * The object is returned on success or else NULL.
3341 struct ust_app
*ust_app_create(struct ust_register_msg
*msg
, int sock
)
3343 struct ust_app
*lta
= NULL
;
3348 DBG3("UST app creating application for socket %d", sock
);
3350 if ((msg
->bits_per_long
== 64 &&
3351 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
3352 || (msg
->bits_per_long
== 32 &&
3353 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
3354 ERR("Registration failed: application \"%s\" (pid: %d) has "
3355 "%d-bit long, but no consumerd for this size is available.\n",
3356 msg
->name
, msg
->pid
, msg
->bits_per_long
);
3360 lta
= zmalloc(sizeof(struct ust_app
));
3366 lta
->ppid
= msg
->ppid
;
3367 lta
->uid
= msg
->uid
;
3368 lta
->gid
= msg
->gid
;
3370 lta
->bits_per_long
= msg
->bits_per_long
;
3371 lta
->uint8_t_alignment
= msg
->uint8_t_alignment
;
3372 lta
->uint16_t_alignment
= msg
->uint16_t_alignment
;
3373 lta
->uint32_t_alignment
= msg
->uint32_t_alignment
;
3374 lta
->uint64_t_alignment
= msg
->uint64_t_alignment
;
3375 lta
->long_alignment
= msg
->long_alignment
;
3376 lta
->byte_order
= msg
->byte_order
;
3378 lta
->v_major
= msg
->major
;
3379 lta
->v_minor
= msg
->minor
;
3380 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
3381 lta
->ust_objd
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3382 lta
->ust_sessions_objd
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3383 lta
->notify_sock
= -1;
3385 /* Copy name and make sure it's NULL terminated. */
3386 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
3387 lta
->name
[UST_APP_PROCNAME_LEN
] = '\0';
3390 * Before this can be called, when receiving the registration information,
3391 * the application compatibility is checked. So, at this point, the
3392 * application can work with this session daemon.
3394 lta
->compatible
= 1;
3396 lta
->pid
= msg
->pid
;
3397 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long) lta
->pid
);
3399 pthread_mutex_init(<a
->sock_lock
, NULL
);
3400 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long) lta
->sock
);
3402 CDS_INIT_LIST_HEAD(<a
->teardown_head
);
3408 * For a given application object, add it to every hash table.
3410 void ust_app_add(struct ust_app
*app
)
3413 assert(app
->notify_sock
>= 0);
3418 * On a re-registration, we want to kick out the previous registration of
3421 lttng_ht_add_replace_ulong(ust_app_ht
, &app
->pid_n
);
3424 * The socket _should_ be unique until _we_ call close. So, a add_unique
3425 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
3426 * already in the table.
3428 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, &app
->sock_n
);
3430 /* Add application to the notify socket hash table. */
3431 lttng_ht_node_init_ulong(&app
->notify_sock_n
, app
->notify_sock
);
3432 lttng_ht_add_unique_ulong(ust_app_ht_by_notify_sock
, &app
->notify_sock_n
);
3434 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s "
3435 "notify_sock:%d (version %d.%d)", app
->pid
, app
->ppid
, app
->uid
,
3436 app
->gid
, app
->sock
, app
->name
, app
->notify_sock
, app
->v_major
,
3443 * Set the application version into the object.
3445 * Return 0 on success else a negative value either an errno code or a
3446 * LTTng-UST error code.
3448 int ust_app_version(struct ust_app
*app
)
3454 pthread_mutex_lock(&app
->sock_lock
);
3455 ret
= ustctl_tracer_version(app
->sock
, &app
->version
);
3456 pthread_mutex_unlock(&app
->sock_lock
);
3458 if (ret
!= -LTTNG_UST_ERR_EXITING
&& ret
!= -EPIPE
) {
3459 ERR("UST app %d version failed with ret %d", app
->sock
, ret
);
3461 DBG3("UST app %d version failed. Application is dead", app
->sock
);
3469 * Unregister app by removing it from the global traceable app list and freeing
3472 * The socket is already closed at this point so no close to sock.
3474 void ust_app_unregister(int sock
)
3476 struct ust_app
*lta
;
3477 struct lttng_ht_node_ulong
*node
;
3478 struct lttng_ht_iter ust_app_sock_iter
;
3479 struct lttng_ht_iter iter
;
3480 struct ust_app_session
*ua_sess
;
3485 /* Get the node reference for a call_rcu */
3486 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &ust_app_sock_iter
);
3487 node
= lttng_ht_iter_get_node_ulong(&ust_app_sock_iter
);
3490 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
3491 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
3494 * For per-PID buffers, perform "push metadata" and flush all
3495 * application streams before removing app from hash tables,
3496 * ensuring proper behavior of data_pending check.
3497 * Remove sessions so they are not visible during deletion.
3499 cds_lfht_for_each_entry(lta
->sessions
->ht
, &iter
.iter
, ua_sess
,
3501 struct ust_registry_session
*registry
;
3503 ret
= lttng_ht_del(lta
->sessions
, &iter
);
3505 /* The session was already removed so scheduled for teardown. */
3509 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_PID
) {
3510 (void) ust_app_flush_app_session(lta
, ua_sess
);
3514 * Add session to list for teardown. This is safe since at this point we
3515 * are the only one using this list.
3517 pthread_mutex_lock(&ua_sess
->lock
);
3519 if (ua_sess
->deleted
) {
3520 pthread_mutex_unlock(&ua_sess
->lock
);
3525 * Normally, this is done in the delete session process which is
3526 * executed in the call rcu below. However, upon registration we can't
3527 * afford to wait for the grace period before pushing data or else the
3528 * data pending feature can race between the unregistration and stop
3529 * command where the data pending command is sent *before* the grace
3532 * The close metadata below nullifies the metadata pointer in the
3533 * session so the delete session will NOT push/close a second time.
3535 registry
= get_session_registry(ua_sess
);
3537 /* Push metadata for application before freeing the application. */
3538 (void) push_metadata(registry
, ua_sess
->consumer
);
3541 * Don't ask to close metadata for global per UID buffers. Close
3542 * metadata only on destroy trace session in this case. Also, the
3543 * previous push metadata could have flag the metadata registry to
3544 * close so don't send a close command if closed.
3546 if (ua_sess
->buffer_type
!= LTTNG_BUFFER_PER_UID
) {
3547 /* And ask to close it for this session registry. */
3548 (void) close_metadata(registry
, ua_sess
->consumer
);
3551 cds_list_add(&ua_sess
->teardown_node
, <a
->teardown_head
);
3553 pthread_mutex_unlock(&ua_sess
->lock
);
3556 /* Remove application from PID hash table */
3557 ret
= lttng_ht_del(ust_app_ht_by_sock
, &ust_app_sock_iter
);
3561 * Remove application from notify hash table. The thread handling the
3562 * notify socket could have deleted the node so ignore on error because
3563 * either way it's valid. The close of that socket is handled by the other
3566 iter
.iter
.node
= <a
->notify_sock_n
.node
;
3567 (void) lttng_ht_del(ust_app_ht_by_notify_sock
, &iter
);
3570 * Ignore return value since the node might have been removed before by an
3571 * add replace during app registration because the PID can be reassigned by
3574 iter
.iter
.node
= <a
->pid_n
.node
;
3575 ret
= lttng_ht_del(ust_app_ht
, &iter
);
3577 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
3582 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
3589 * Fill events array with all events name of all registered apps.
3591 int ust_app_list_events(struct lttng_event
**events
)
3594 size_t nbmem
, count
= 0;
3595 struct lttng_ht_iter iter
;
3596 struct ust_app
*app
;
3597 struct lttng_event
*tmp_event
;
3599 nbmem
= UST_APP_EVENT_LIST_SIZE
;
3600 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event
));
3601 if (tmp_event
== NULL
) {
3602 PERROR("zmalloc ust app events");
3609 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3610 struct lttng_ust_tracepoint_iter uiter
;
3612 health_code_update();
3614 if (!app
->compatible
) {
3616 * TODO: In time, we should notice the caller of this error by
3617 * telling him that this is a version error.
3621 pthread_mutex_lock(&app
->sock_lock
);
3622 handle
= ustctl_tracepoint_list(app
->sock
);
3624 if (handle
!= -EPIPE
&& handle
!= -LTTNG_UST_ERR_EXITING
) {
3625 ERR("UST app list events getting handle failed for app pid %d",
3628 pthread_mutex_unlock(&app
->sock_lock
);
3632 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
3633 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
3634 /* Handle ustctl error. */
3638 if (ret
!= -LTTNG_UST_ERR_EXITING
&& ret
!= -EPIPE
) {
3639 ERR("UST app tp list get failed for app %d with ret %d",
3642 DBG3("UST app tp list get failed. Application is dead");
3644 * This is normal behavior, an application can die during the
3645 * creation process. Don't report an error so the execution can
3646 * continue normally. Continue normal execution.
3651 release_ret
= ustctl_release_handle(app
->sock
, handle
);
3652 if (release_ret
< 0 &&
3653 release_ret
!= -LTTNG_UST_ERR_EXITING
&&
3654 release_ret
!= -EPIPE
) {
3655 ERR("Error releasing app handle for app %d with ret %d", app
->sock
, release_ret
);
3657 pthread_mutex_unlock(&app
->sock_lock
);
3661 health_code_update();
3662 if (count
>= nbmem
) {
3663 /* In case the realloc fails, we free the memory */
3664 struct lttng_event
*new_tmp_event
;
3667 new_nbmem
= nbmem
<< 1;
3668 DBG2("Reallocating event list from %zu to %zu entries",
3670 new_tmp_event
= realloc(tmp_event
,
3671 new_nbmem
* sizeof(struct lttng_event
));
3672 if (new_tmp_event
== NULL
) {
3675 PERROR("realloc ust app events");
3678 release_ret
= ustctl_release_handle(app
->sock
, handle
);
3679 if (release_ret
< 0 &&
3680 release_ret
!= -LTTNG_UST_ERR_EXITING
&&
3681 release_ret
!= -EPIPE
) {
3682 ERR("Error releasing app handle for app %d with ret %d", app
->sock
, release_ret
);
3684 pthread_mutex_unlock(&app
->sock_lock
);
3687 /* Zero the new memory */
3688 memset(new_tmp_event
+ nbmem
, 0,
3689 (new_nbmem
- nbmem
) * sizeof(struct lttng_event
));
3691 tmp_event
= new_tmp_event
;
3693 memcpy(tmp_event
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
3694 tmp_event
[count
].loglevel
= uiter
.loglevel
;
3695 tmp_event
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
3696 tmp_event
[count
].pid
= app
->pid
;
3697 tmp_event
[count
].enabled
= -1;
3700 ret
= ustctl_release_handle(app
->sock
, handle
);
3701 pthread_mutex_unlock(&app
->sock_lock
);
3702 if (ret
< 0 && ret
!= -LTTNG_UST_ERR_EXITING
&& ret
!= -EPIPE
) {
3703 ERR("Error releasing app handle for app %d with ret %d", app
->sock
, ret
);
3708 *events
= tmp_event
;
3710 DBG2("UST app list events done (%zu events)", count
);
3715 health_code_update();
3720 * Fill events array with all events name of all registered apps.
3722 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
3725 size_t nbmem
, count
= 0;
3726 struct lttng_ht_iter iter
;
3727 struct ust_app
*app
;
3728 struct lttng_event_field
*tmp_event
;
3730 nbmem
= UST_APP_EVENT_LIST_SIZE
;
3731 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
3732 if (tmp_event
== NULL
) {
3733 PERROR("zmalloc ust app event fields");
3740 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3741 struct lttng_ust_field_iter uiter
;
3743 health_code_update();
3745 if (!app
->compatible
) {
3747 * TODO: In time, we should notice the caller of this error by
3748 * telling him that this is a version error.
3752 pthread_mutex_lock(&app
->sock_lock
);
3753 handle
= ustctl_tracepoint_field_list(app
->sock
);
3755 if (handle
!= -EPIPE
&& handle
!= -LTTNG_UST_ERR_EXITING
) {
3756 ERR("UST app list field getting handle failed for app pid %d",
3759 pthread_mutex_unlock(&app
->sock_lock
);
3763 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
3764 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
3765 /* Handle ustctl error. */
3769 if (ret
!= -LTTNG_UST_ERR_EXITING
&& ret
!= -EPIPE
) {
3770 ERR("UST app tp list field failed for app %d with ret %d",
3773 DBG3("UST app tp list field failed. Application is dead");
3775 * This is normal behavior, an application can die during the
3776 * creation process. Don't report an error so the execution can
3777 * continue normally. Reset list and count for next app.
3782 release_ret
= ustctl_release_handle(app
->sock
, handle
);
3783 pthread_mutex_unlock(&app
->sock_lock
);
3784 if (release_ret
< 0 &&
3785 release_ret
!= -LTTNG_UST_ERR_EXITING
&&
3786 release_ret
!= -EPIPE
) {
3787 ERR("Error releasing app handle for app %d with ret %d", app
->sock
, release_ret
);
3792 health_code_update();
3793 if (count
>= nbmem
) {
3794 /* In case the realloc fails, we free the memory */
3795 struct lttng_event_field
*new_tmp_event
;
3798 new_nbmem
= nbmem
<< 1;
3799 DBG2("Reallocating event field list from %zu to %zu entries",
3801 new_tmp_event
= realloc(tmp_event
,
3802 new_nbmem
* sizeof(struct lttng_event_field
));
3803 if (new_tmp_event
== NULL
) {
3806 PERROR("realloc ust app event fields");
3809 release_ret
= ustctl_release_handle(app
->sock
, handle
);
3810 pthread_mutex_unlock(&app
->sock_lock
);
3812 release_ret
!= -LTTNG_UST_ERR_EXITING
&&
3813 release_ret
!= -EPIPE
) {
3814 ERR("Error releasing app handle for app %d with ret %d", app
->sock
, release_ret
);
3818 /* Zero the new memory */
3819 memset(new_tmp_event
+ nbmem
, 0,
3820 (new_nbmem
- nbmem
) * sizeof(struct lttng_event_field
));
3822 tmp_event
= new_tmp_event
;
3825 memcpy(tmp_event
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
3826 /* Mapping between these enums matches 1 to 1. */
3827 tmp_event
[count
].type
= (enum lttng_event_field_type
) uiter
.type
;
3828 tmp_event
[count
].nowrite
= uiter
.nowrite
;
3830 memcpy(tmp_event
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
3831 tmp_event
[count
].event
.loglevel
= uiter
.loglevel
;
3832 tmp_event
[count
].event
.type
= LTTNG_EVENT_TRACEPOINT
;
3833 tmp_event
[count
].event
.pid
= app
->pid
;
3834 tmp_event
[count
].event
.enabled
= -1;
3837 ret
= ustctl_release_handle(app
->sock
, handle
);
3838 pthread_mutex_unlock(&app
->sock_lock
);
3840 ret
!= -LTTNG_UST_ERR_EXITING
&&
3842 ERR("Error releasing app handle for app %d with ret %d", app
->sock
, ret
);
3847 *fields
= tmp_event
;
3849 DBG2("UST app list event fields done (%zu events)", count
);
3854 health_code_update();
3859 * Free and clean all traceable apps of the global list.
3861 * Should _NOT_ be called with RCU read-side lock held.
3863 void ust_app_clean_list(void)
3866 struct ust_app
*app
;
3867 struct lttng_ht_iter iter
;
3869 DBG2("UST app cleaning registered apps hash table");
3874 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3875 ret
= lttng_ht_del(ust_app_ht
, &iter
);
3877 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
3881 /* Cleanup socket hash table */
3882 if (ust_app_ht_by_sock
) {
3883 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
3885 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
3890 /* Cleanup notify socket hash table */
3891 if (ust_app_ht_by_notify_sock
) {
3892 cds_lfht_for_each_entry(ust_app_ht_by_notify_sock
->ht
, &iter
.iter
, app
,
3893 notify_sock_n
.node
) {
3894 ret
= lttng_ht_del(ust_app_ht_by_notify_sock
, &iter
);
3900 /* Destroy is done only when the ht is empty */
3902 ht_cleanup_push(ust_app_ht
);
3904 if (ust_app_ht_by_sock
) {
3905 ht_cleanup_push(ust_app_ht_by_sock
);
3907 if (ust_app_ht_by_notify_sock
) {
3908 ht_cleanup_push(ust_app_ht_by_notify_sock
);
3913 * Init UST app hash table.
3915 int ust_app_ht_alloc(void)
3917 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3921 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3922 if (!ust_app_ht_by_sock
) {
3925 ust_app_ht_by_notify_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3926 if (!ust_app_ht_by_notify_sock
) {
3933 * For a specific UST session, disable the channel for all registered apps.
3935 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
3936 struct ltt_ust_channel
*uchan
)
3939 struct lttng_ht_iter iter
;
3940 struct lttng_ht_node_str
*ua_chan_node
;
3941 struct ust_app
*app
;
3942 struct ust_app_session
*ua_sess
;
3943 struct ust_app_channel
*ua_chan
;
3945 if (usess
== NULL
|| uchan
== NULL
) {
3946 ERR("Disabling UST global channel with NULL values");
3951 DBG2("UST app disabling channel %s from global domain for session id %" PRIu64
,
3952 uchan
->name
, usess
->id
);
3956 /* For every registered applications */
3957 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3958 struct lttng_ht_iter uiter
;
3959 if (!app
->compatible
) {
3961 * TODO: In time, we should notice the caller of this error by
3962 * telling him that this is a version error.
3966 ua_sess
= lookup_session_by_app(usess
, app
);
3967 if (ua_sess
== NULL
) {
3972 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3973 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3974 /* If the session if found for the app, the channel must be there */
3975 assert(ua_chan_node
);
3977 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3978 /* The channel must not be already disabled */
3979 assert(ua_chan
->enabled
== 1);
3981 /* Disable channel onto application */
3982 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
3984 /* XXX: We might want to report this error at some point... */
3996 * For a specific UST session, enable the channel for all registered apps.
3998 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
3999 struct ltt_ust_channel
*uchan
)
4002 struct lttng_ht_iter iter
;
4003 struct ust_app
*app
;
4004 struct ust_app_session
*ua_sess
;
4006 if (usess
== NULL
|| uchan
== NULL
) {
4007 ERR("Adding UST global channel to NULL values");
4012 DBG2("UST app enabling channel %s to global domain for session id %" PRIu64
,
4013 uchan
->name
, usess
->id
);
4017 /* For every registered applications */
4018 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4019 if (!app
->compatible
) {
4021 * TODO: In time, we should notice the caller of this error by
4022 * telling him that this is a version error.
4026 ua_sess
= lookup_session_by_app(usess
, app
);
4027 if (ua_sess
== NULL
) {
4031 /* Enable channel onto application */
4032 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
4034 /* XXX: We might want to report this error at some point... */
4046 * Disable an event in a channel and for a specific session.
4048 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
4049 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
4052 struct lttng_ht_iter iter
, uiter
;
4053 struct lttng_ht_node_str
*ua_chan_node
;
4054 struct ust_app
*app
;
4055 struct ust_app_session
*ua_sess
;
4056 struct ust_app_channel
*ua_chan
;
4057 struct ust_app_event
*ua_event
;
4059 DBG("UST app disabling event %s for all apps in channel "
4060 "%s for session id %" PRIu64
,
4061 uevent
->attr
.name
, uchan
->name
, usess
->id
);
4065 /* For all registered applications */
4066 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4067 if (!app
->compatible
) {
4069 * TODO: In time, we should notice the caller of this error by
4070 * telling him that this is a version error.
4074 ua_sess
= lookup_session_by_app(usess
, app
);
4075 if (ua_sess
== NULL
) {
4080 /* Lookup channel in the ust app session */
4081 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
4082 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
4083 if (ua_chan_node
== NULL
) {
4084 DBG2("Channel %s not found in session id %" PRIu64
" for app pid %d."
4085 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
4088 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
4090 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
4091 uevent
->filter
, uevent
->attr
.loglevel
,
4093 if (ua_event
== NULL
) {
4094 DBG2("Event %s not found in channel %s for app pid %d."
4095 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
4099 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
4101 /* XXX: Report error someday... */
4112 * For a specific UST session, create the channel for all registered apps.
4114 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
4115 struct ltt_ust_channel
*uchan
)
4117 int ret
= 0, created
;
4118 struct lttng_ht_iter iter
;
4119 struct ust_app
*app
;
4120 struct ust_app_session
*ua_sess
= NULL
;
4122 /* Very wrong code flow */
4126 DBG2("UST app adding channel %s to UST domain for session id %" PRIu64
,
4127 uchan
->name
, usess
->id
);
4131 /* For every registered applications */
4132 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4133 if (!app
->compatible
) {
4135 * TODO: In time, we should notice the caller of this error by
4136 * telling him that this is a version error.
4140 if (!trace_ust_pid_tracker_lookup(usess
, app
->pid
)) {
4146 * Create session on the tracer side and add it to app session HT. Note
4147 * that if session exist, it will simply return a pointer to the ust
4150 ret
= create_ust_app_session(usess
, app
, &ua_sess
, &created
);
4155 * The application's socket is not valid. Either a bad socket
4156 * or a timeout on it. We can't inform the caller that for a
4157 * specific app, the session failed so lets continue here.
4159 ret
= 0; /* Not an error. */
4163 goto error_rcu_unlock
;
4168 pthread_mutex_lock(&ua_sess
->lock
);
4170 if (ua_sess
->deleted
) {
4171 pthread_mutex_unlock(&ua_sess
->lock
);
4175 if (!strncmp(uchan
->name
, DEFAULT_METADATA_NAME
,
4176 sizeof(uchan
->name
))) {
4177 copy_channel_attr_to_ustctl(&ua_sess
->metadata_attr
, &uchan
->attr
);
4180 /* Create channel onto application. We don't need the chan ref. */
4181 ret
= create_ust_app_channel(ua_sess
, uchan
, app
,
4182 LTTNG_UST_CHAN_PER_CPU
, usess
, NULL
);
4184 pthread_mutex_unlock(&ua_sess
->lock
);
4186 /* Cleanup the created session if it's the case. */
4188 destroy_app_session(app
, ua_sess
);
4193 * The application's socket is not valid. Either a bad socket
4194 * or a timeout on it. We can't inform the caller that for a
4195 * specific app, the session failed so lets continue here.
4197 ret
= 0; /* Not an error. */
4201 goto error_rcu_unlock
;
4212 * Enable event for a specific session and channel on the tracer.
4214 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
4215 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
4218 struct lttng_ht_iter iter
, uiter
;
4219 struct lttng_ht_node_str
*ua_chan_node
;
4220 struct ust_app
*app
;
4221 struct ust_app_session
*ua_sess
;
4222 struct ust_app_channel
*ua_chan
;
4223 struct ust_app_event
*ua_event
;
4225 DBG("UST app enabling event %s for all apps for session id %" PRIu64
,
4226 uevent
->attr
.name
, usess
->id
);
4229 * NOTE: At this point, this function is called only if the session and
4230 * channel passed are already created for all apps. and enabled on the
4236 /* For all registered applications */
4237 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4238 if (!app
->compatible
) {
4240 * TODO: In time, we should notice the caller of this error by
4241 * telling him that this is a version error.
4245 ua_sess
= lookup_session_by_app(usess
, app
);
4247 /* The application has problem or is probably dead. */
4251 pthread_mutex_lock(&ua_sess
->lock
);
4253 if (ua_sess
->deleted
) {
4254 pthread_mutex_unlock(&ua_sess
->lock
);
4258 /* Lookup channel in the ust app session */
4259 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
4260 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
4262 * It is possible that the channel cannot be found is
4263 * the channel/event creation occurs concurrently with
4264 * an application exit.
4266 if (!ua_chan_node
) {
4267 pthread_mutex_unlock(&ua_sess
->lock
);
4271 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
4273 /* Get event node */
4274 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
4275 uevent
->filter
, uevent
->attr
.loglevel
, uevent
->exclusion
);
4276 if (ua_event
== NULL
) {
4277 DBG3("UST app enable event %s not found for app PID %d."
4278 "Skipping app", uevent
->attr
.name
, app
->pid
);
4282 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
4284 pthread_mutex_unlock(&ua_sess
->lock
);
4288 pthread_mutex_unlock(&ua_sess
->lock
);
4297 * For a specific existing UST session and UST channel, creates the event for
4298 * all registered apps.
4300 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
4301 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
4304 struct lttng_ht_iter iter
, uiter
;
4305 struct lttng_ht_node_str
*ua_chan_node
;
4306 struct ust_app
*app
;
4307 struct ust_app_session
*ua_sess
;
4308 struct ust_app_channel
*ua_chan
;
4310 DBG("UST app creating event %s for all apps for session id %" PRIu64
,
4311 uevent
->attr
.name
, usess
->id
);
4315 /* For all registered applications */
4316 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4317 if (!app
->compatible
) {
4319 * TODO: In time, we should notice the caller of this error by
4320 * telling him that this is a version error.
4324 ua_sess
= lookup_session_by_app(usess
, app
);
4326 /* The application has problem or is probably dead. */
4330 pthread_mutex_lock(&ua_sess
->lock
);
4332 if (ua_sess
->deleted
) {
4333 pthread_mutex_unlock(&ua_sess
->lock
);
4337 /* Lookup channel in the ust app session */
4338 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
4339 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
4340 /* If the channel is not found, there is a code flow error */
4341 assert(ua_chan_node
);
4343 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
4345 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
4346 pthread_mutex_unlock(&ua_sess
->lock
);
4348 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
4349 /* Possible value at this point: -ENOMEM. If so, we stop! */
4352 DBG2("UST app event %s already exist on app PID %d",
4353 uevent
->attr
.name
, app
->pid
);
4364 * Start tracing for a specific UST session and app.
4367 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
4370 struct ust_app_session
*ua_sess
;
4372 DBG("Starting tracing for ust app pid %d", app
->pid
);
4376 if (!app
->compatible
) {
4380 ua_sess
= lookup_session_by_app(usess
, app
);
4381 if (ua_sess
== NULL
) {
4382 /* The session is in teardown process. Ignore and continue. */
4386 pthread_mutex_lock(&ua_sess
->lock
);
4388 if (ua_sess
->deleted
) {
4389 pthread_mutex_unlock(&ua_sess
->lock
);
4393 /* Upon restart, we skip the setup, already done */
4394 if (ua_sess
->started
) {
4398 /* Create directories if consumer is LOCAL and has a path defined. */
4399 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
4400 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
4401 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
4402 S_IRWXU
| S_IRWXG
, ua_sess
->euid
, ua_sess
->egid
);
4404 if (errno
!= EEXIST
) {
4405 ERR("Trace directory creation error");
4412 * Create the metadata for the application. This returns gracefully if a
4413 * metadata was already set for the session.
4415 ret
= create_ust_app_metadata(ua_sess
, app
, usess
->consumer
);
4420 health_code_update();
4423 /* This start the UST tracing */
4424 pthread_mutex_lock(&app
->sock_lock
);
4425 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
4426 pthread_mutex_unlock(&app
->sock_lock
);
4428 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4429 ERR("Error starting tracing for app pid: %d (ret: %d)",
4432 DBG("UST app start session failed. Application is dead.");
4434 * This is normal behavior, an application can die during the
4435 * creation process. Don't report an error so the execution can
4436 * continue normally.
4438 pthread_mutex_unlock(&ua_sess
->lock
);
4444 /* Indicate that the session has been started once */
4445 ua_sess
->started
= 1;
4447 pthread_mutex_unlock(&ua_sess
->lock
);
4449 health_code_update();
4451 /* Quiescent wait after starting trace */
4452 pthread_mutex_lock(&app
->sock_lock
);
4453 ret
= ustctl_wait_quiescent(app
->sock
);
4454 pthread_mutex_unlock(&app
->sock_lock
);
4455 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4456 ERR("UST app wait quiescent failed for app pid %d ret %d",
4462 health_code_update();
4466 pthread_mutex_unlock(&ua_sess
->lock
);
4468 health_code_update();
4473 * Stop tracing for a specific UST session and app.
4476 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
4479 struct ust_app_session
*ua_sess
;
4480 struct ust_registry_session
*registry
;
4482 DBG("Stopping tracing for ust app pid %d", app
->pid
);
4486 if (!app
->compatible
) {
4487 goto end_no_session
;
4490 ua_sess
= lookup_session_by_app(usess
, app
);
4491 if (ua_sess
== NULL
) {
4492 goto end_no_session
;
4495 pthread_mutex_lock(&ua_sess
->lock
);
4497 if (ua_sess
->deleted
) {
4498 pthread_mutex_unlock(&ua_sess
->lock
);
4499 goto end_no_session
;
4503 * If started = 0, it means that stop trace has been called for a session
4504 * that was never started. It's possible since we can have a fail start
4505 * from either the application manager thread or the command thread. Simply
4506 * indicate that this is a stop error.
4508 if (!ua_sess
->started
) {
4509 goto error_rcu_unlock
;
4512 health_code_update();
4514 /* This inhibits UST tracing */
4515 pthread_mutex_lock(&app
->sock_lock
);
4516 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
4517 pthread_mutex_unlock(&app
->sock_lock
);
4519 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4520 ERR("Error stopping tracing for app pid: %d (ret: %d)",
4523 DBG("UST app stop session failed. Application is dead.");
4525 * This is normal behavior, an application can die during the
4526 * creation process. Don't report an error so the execution can
4527 * continue normally.
4531 goto error_rcu_unlock
;
4534 health_code_update();
4536 /* Quiescent wait after stopping trace */
4537 pthread_mutex_lock(&app
->sock_lock
);
4538 ret
= ustctl_wait_quiescent(app
->sock
);
4539 pthread_mutex_unlock(&app
->sock_lock
);
4540 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4541 ERR("UST app wait quiescent failed for app pid %d ret %d",
4545 health_code_update();
4547 registry
= get_session_registry(ua_sess
);
4550 /* Push metadata for application before freeing the application. */
4551 (void) push_metadata(registry
, ua_sess
->consumer
);
4554 pthread_mutex_unlock(&ua_sess
->lock
);
4557 health_code_update();
4561 pthread_mutex_unlock(&ua_sess
->lock
);
4563 health_code_update();
4568 int ust_app_flush_app_session(struct ust_app
*app
,
4569 struct ust_app_session
*ua_sess
)
4571 int ret
, retval
= 0;
4572 struct lttng_ht_iter iter
;
4573 struct ust_app_channel
*ua_chan
;
4574 struct consumer_socket
*socket
;
4576 DBG("Flushing app session buffers for ust app pid %d", app
->pid
);
4580 if (!app
->compatible
) {
4581 goto end_not_compatible
;
4584 pthread_mutex_lock(&ua_sess
->lock
);
4586 if (ua_sess
->deleted
) {
4590 health_code_update();
4592 /* Flushing buffers */
4593 socket
= consumer_find_socket_by_bitness(app
->bits_per_long
,
4596 /* Flush buffers and push metadata. */
4597 switch (ua_sess
->buffer_type
) {
4598 case LTTNG_BUFFER_PER_PID
:
4599 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
4601 health_code_update();
4602 ret
= consumer_flush_channel(socket
, ua_chan
->key
);
4604 ERR("Error flushing consumer channel");
4610 case LTTNG_BUFFER_PER_UID
:
4616 health_code_update();
4619 pthread_mutex_unlock(&ua_sess
->lock
);
4623 health_code_update();
4628 * Flush buffers for all applications for a specific UST session.
4629 * Called with UST session lock held.
4632 int ust_app_flush_session(struct ltt_ust_session
*usess
)
4637 DBG("Flushing session buffers for all ust apps");
4641 /* Flush buffers and push metadata. */
4642 switch (usess
->buffer_type
) {
4643 case LTTNG_BUFFER_PER_UID
:
4645 struct buffer_reg_uid
*reg
;
4646 struct lttng_ht_iter iter
;
4648 /* Flush all per UID buffers associated to that session. */
4649 cds_list_for_each_entry(reg
, &usess
->buffer_reg_uid_list
, lnode
) {
4650 struct ust_registry_session
*ust_session_reg
;
4651 struct buffer_reg_channel
*reg_chan
;
4652 struct consumer_socket
*socket
;
4654 /* Get consumer socket to use to push the metadata.*/
4655 socket
= consumer_find_socket_by_bitness(reg
->bits_per_long
,
4658 /* Ignore request if no consumer is found for the session. */
4662 cds_lfht_for_each_entry(reg
->registry
->channels
->ht
, &iter
.iter
,
4663 reg_chan
, node
.node
) {
4665 * The following call will print error values so the return
4666 * code is of little importance because whatever happens, we
4667 * have to try them all.
4669 (void) consumer_flush_channel(socket
, reg_chan
->consumer_key
);
4672 ust_session_reg
= reg
->registry
->reg
.ust
;
4673 /* Push metadata. */
4674 (void) push_metadata(ust_session_reg
, usess
->consumer
);
4678 case LTTNG_BUFFER_PER_PID
:
4680 struct ust_app_session
*ua_sess
;
4681 struct lttng_ht_iter iter
;
4682 struct ust_app
*app
;
4684 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4685 ua_sess
= lookup_session_by_app(usess
, app
);
4686 if (ua_sess
== NULL
) {
4689 (void) ust_app_flush_app_session(app
, ua_sess
);
4700 health_code_update();
4705 int ust_app_clear_quiescent_app_session(struct ust_app
*app
,
4706 struct ust_app_session
*ua_sess
)
4709 struct lttng_ht_iter iter
;
4710 struct ust_app_channel
*ua_chan
;
4711 struct consumer_socket
*socket
;
4713 DBG("Clearing stream quiescent state for ust app pid %d", app
->pid
);
4717 if (!app
->compatible
) {
4718 goto end_not_compatible
;
4721 pthread_mutex_lock(&ua_sess
->lock
);
4723 if (ua_sess
->deleted
) {
4727 health_code_update();
4729 socket
= consumer_find_socket_by_bitness(app
->bits_per_long
,
4732 ERR("Failed to find consumer (%" PRIu32
") socket",
4733 app
->bits_per_long
);
4738 /* Clear quiescent state. */
4739 switch (ua_sess
->buffer_type
) {
4740 case LTTNG_BUFFER_PER_PID
:
4741 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
,
4742 ua_chan
, node
.node
) {
4743 health_code_update();
4744 ret
= consumer_clear_quiescent_channel(socket
,
4747 ERR("Error clearing quiescent state for consumer channel");
4753 case LTTNG_BUFFER_PER_UID
:
4760 health_code_update();
4763 pthread_mutex_unlock(&ua_sess
->lock
);
4767 health_code_update();
4772 * Clear quiescent state in each stream for all applications for a
4773 * specific UST session.
4774 * Called with UST session lock held.
4777 int ust_app_clear_quiescent_session(struct ltt_ust_session
*usess
)
4782 DBG("Clearing stream quiescent state for all ust apps");
4786 switch (usess
->buffer_type
) {
4787 case LTTNG_BUFFER_PER_UID
:
4789 struct lttng_ht_iter iter
;
4790 struct buffer_reg_uid
*reg
;
4793 * Clear quiescent for all per UID buffers associated to
4796 cds_list_for_each_entry(reg
, &usess
->buffer_reg_uid_list
, lnode
) {
4797 struct consumer_socket
*socket
;
4798 struct buffer_reg_channel
*reg_chan
;
4800 /* Get associated consumer socket.*/
4801 socket
= consumer_find_socket_by_bitness(
4802 reg
->bits_per_long
, usess
->consumer
);
4805 * Ignore request if no consumer is found for
4811 cds_lfht_for_each_entry(reg
->registry
->channels
->ht
,
4812 &iter
.iter
, reg_chan
, node
.node
) {
4814 * The following call will print error values so
4815 * the return code is of little importance
4816 * because whatever happens, we have to try them
4819 (void) consumer_clear_quiescent_channel(socket
,
4820 reg_chan
->consumer_key
);
4825 case LTTNG_BUFFER_PER_PID
:
4827 struct ust_app_session
*ua_sess
;
4828 struct lttng_ht_iter iter
;
4829 struct ust_app
*app
;
4831 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
,
4833 ua_sess
= lookup_session_by_app(usess
, app
);
4834 if (ua_sess
== NULL
) {
4837 (void) ust_app_clear_quiescent_app_session(app
,
4849 health_code_update();
4854 * Destroy a specific UST session in apps.
4856 static int destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
4859 struct ust_app_session
*ua_sess
;
4860 struct lttng_ht_iter iter
;
4861 struct lttng_ht_node_u64
*node
;
4863 DBG("Destroy tracing for ust app pid %d", app
->pid
);
4867 if (!app
->compatible
) {
4871 __lookup_session_by_app(usess
, app
, &iter
);
4872 node
= lttng_ht_iter_get_node_u64(&iter
);
4874 /* Session is being or is deleted. */
4877 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
4879 health_code_update();
4880 destroy_app_session(app
, ua_sess
);
4882 health_code_update();
4884 /* Quiescent wait after stopping trace */
4885 pthread_mutex_lock(&app
->sock_lock
);
4886 ret
= ustctl_wait_quiescent(app
->sock
);
4887 pthread_mutex_unlock(&app
->sock_lock
);
4888 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4889 ERR("UST app wait quiescent failed for app pid %d ret %d",
4894 health_code_update();
4899 * Start tracing for the UST session.
4901 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
4904 struct lttng_ht_iter iter
;
4905 struct ust_app
*app
;
4907 DBG("Starting all UST traces");
4912 * In a start-stop-start use-case, we need to clear the quiescent state
4913 * of each channel set by the prior stop command, thus ensuring that a
4914 * following stop or destroy is sure to grab a timestamp_end near those
4915 * operations, even if the packet is empty.
4917 (void) ust_app_clear_quiescent_session(usess
);
4919 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4920 ret
= ust_app_start_trace(usess
, app
);
4922 /* Continue to next apps even on error */
4933 * Start tracing for the UST session.
4934 * Called with UST session lock held.
4936 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
4939 struct lttng_ht_iter iter
;
4940 struct ust_app
*app
;
4942 DBG("Stopping all UST traces");
4946 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4947 ret
= ust_app_stop_trace(usess
, app
);
4949 /* Continue to next apps even on error */
4954 (void) ust_app_flush_session(usess
);
4962 * Destroy app UST session.
4964 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
4967 struct lttng_ht_iter iter
;
4968 struct ust_app
*app
;
4970 DBG("Destroy all UST traces");
4974 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4975 ret
= destroy_trace(usess
, app
);
4977 /* Continue to next apps even on error */
4988 void ust_app_global_create(struct ltt_ust_session
*usess
, struct ust_app
*app
)
4991 struct lttng_ht_iter iter
, uiter
;
4992 struct ust_app_session
*ua_sess
= NULL
;
4993 struct ust_app_channel
*ua_chan
;
4994 struct ust_app_event
*ua_event
;
4995 struct ust_app_ctx
*ua_ctx
;
4998 ret
= create_ust_app_session(usess
, app
, &ua_sess
, &is_created
);
5000 /* Tracer is probably gone or ENOMEM. */
5004 /* App session already created. */
5009 pthread_mutex_lock(&ua_sess
->lock
);
5011 if (ua_sess
->deleted
) {
5012 pthread_mutex_unlock(&ua_sess
->lock
);
5017 * We can iterate safely here over all UST app session since the create ust
5018 * app session above made a shadow copy of the UST global domain from the
5021 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
5023 ret
= do_create_channel(app
, usess
, ua_sess
, ua_chan
);
5024 if (ret
< 0 && ret
!= -ENOTCONN
) {
5026 * Stop everything. On error, the application
5027 * failed, no more file descriptor are available
5028 * or ENOMEM so stopping here is the only thing
5029 * we can do for now. The only exception is
5030 * -ENOTCONN, which indicates that the application
5037 * Add context using the list so they are enabled in the same order the
5040 cds_list_for_each_entry(ua_ctx
, &ua_chan
->ctx_list
, list
) {
5041 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
5048 /* For each events */
5049 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
5051 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
5058 pthread_mutex_unlock(&ua_sess
->lock
);
5060 if (usess
->active
) {
5061 ret
= ust_app_start_trace(usess
, app
);
5066 DBG2("UST trace started for app pid %d", app
->pid
);
5069 /* Everything went well at this point. */
5073 pthread_mutex_unlock(&ua_sess
->lock
);
5076 destroy_app_session(app
, ua_sess
);
5082 void ust_app_global_destroy(struct ltt_ust_session
*usess
, struct ust_app
*app
)
5084 struct ust_app_session
*ua_sess
;
5086 ua_sess
= lookup_session_by_app(usess
, app
);
5087 if (ua_sess
== NULL
) {
5090 destroy_app_session(app
, ua_sess
);
5094 * Add channels/events from UST global domain to registered apps at sock.
5096 * Called with session lock held.
5097 * Called with RCU read-side lock held.
5099 void ust_app_global_update(struct ltt_ust_session
*usess
, struct ust_app
*app
)
5103 DBG2("UST app global update for app sock %d for session id %" PRIu64
,
5104 app
->sock
, usess
->id
);
5106 if (!app
->compatible
) {
5110 if (trace_ust_pid_tracker_lookup(usess
, app
->pid
)) {
5111 ust_app_global_create(usess
, app
);
5113 ust_app_global_destroy(usess
, app
);
5118 * Called with session lock held.
5120 void ust_app_global_update_all(struct ltt_ust_session
*usess
)
5122 struct lttng_ht_iter iter
;
5123 struct ust_app
*app
;
5126 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
5127 ust_app_global_update(usess
, app
);
5133 * Add context to a specific channel for global UST domain.
5135 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
5136 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
5139 struct lttng_ht_node_str
*ua_chan_node
;
5140 struct lttng_ht_iter iter
, uiter
;
5141 struct ust_app_channel
*ua_chan
= NULL
;
5142 struct ust_app_session
*ua_sess
;
5143 struct ust_app
*app
;
5147 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
5148 if (!app
->compatible
) {
5150 * TODO: In time, we should notice the caller of this error by
5151 * telling him that this is a version error.
5155 ua_sess
= lookup_session_by_app(usess
, app
);
5156 if (ua_sess
== NULL
) {
5160 pthread_mutex_lock(&ua_sess
->lock
);
5162 if (ua_sess
->deleted
) {
5163 pthread_mutex_unlock(&ua_sess
->lock
);
5167 /* Lookup channel in the ust app session */
5168 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
5169 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
5170 if (ua_chan_node
== NULL
) {
5173 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
5175 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
5180 pthread_mutex_unlock(&ua_sess
->lock
);
5188 * Enable event for a channel from a UST session for a specific PID.
5190 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
5191 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
5194 struct lttng_ht_iter iter
;
5195 struct lttng_ht_node_str
*ua_chan_node
;
5196 struct ust_app
*app
;
5197 struct ust_app_session
*ua_sess
;
5198 struct ust_app_channel
*ua_chan
;
5199 struct ust_app_event
*ua_event
;
5201 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
5205 app
= ust_app_find_by_pid(pid
);
5207 ERR("UST app enable event per PID %d not found", pid
);
5212 if (!app
->compatible
) {
5217 ua_sess
= lookup_session_by_app(usess
, app
);
5219 /* The application has problem or is probably dead. */
5224 pthread_mutex_lock(&ua_sess
->lock
);
5226 if (ua_sess
->deleted
) {
5231 /* Lookup channel in the ust app session */
5232 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
5233 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
5234 /* If the channel is not found, there is a code flow error */
5235 assert(ua_chan_node
);
5237 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
5239 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
5240 uevent
->filter
, uevent
->attr
.loglevel
, uevent
->exclusion
);
5241 if (ua_event
== NULL
) {
5242 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
5247 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
5254 pthread_mutex_unlock(&ua_sess
->lock
);
5261 * Receive registration and populate the given msg structure.
5263 * On success return 0 else a negative value returned by the ustctl call.
5265 int ust_app_recv_registration(int sock
, struct ust_register_msg
*msg
)
5268 uint32_t pid
, ppid
, uid
, gid
;
5272 ret
= ustctl_recv_reg_msg(sock
, &msg
->type
, &msg
->major
, &msg
->minor
,
5273 &pid
, &ppid
, &uid
, &gid
,
5274 &msg
->bits_per_long
,
5275 &msg
->uint8_t_alignment
,
5276 &msg
->uint16_t_alignment
,
5277 &msg
->uint32_t_alignment
,
5278 &msg
->uint64_t_alignment
,
5279 &msg
->long_alignment
,
5286 case LTTNG_UST_ERR_EXITING
:
5287 DBG3("UST app recv reg message failed. Application died");
5289 case LTTNG_UST_ERR_UNSUP_MAJOR
:
5290 ERR("UST app recv reg unsupported version %d.%d. Supporting %d.%d",
5291 msg
->major
, msg
->minor
, LTTNG_UST_ABI_MAJOR_VERSION
,
5292 LTTNG_UST_ABI_MINOR_VERSION
);
5295 ERR("UST app recv reg message failed with ret %d", ret
);
5300 msg
->pid
= (pid_t
) pid
;
5301 msg
->ppid
= (pid_t
) ppid
;
5302 msg
->uid
= (uid_t
) uid
;
5303 msg
->gid
= (gid_t
) gid
;
5310 * Return a ust app session object using the application object and the
5311 * session object descriptor has a key. If not found, NULL is returned.
5312 * A RCU read side lock MUST be acquired when calling this function.
5314 static struct ust_app_session
*find_session_by_objd(struct ust_app
*app
,
5317 struct lttng_ht_node_ulong
*node
;
5318 struct lttng_ht_iter iter
;
5319 struct ust_app_session
*ua_sess
= NULL
;
5323 lttng_ht_lookup(app
->ust_sessions_objd
, (void *)((unsigned long) objd
), &iter
);
5324 node
= lttng_ht_iter_get_node_ulong(&iter
);
5326 DBG2("UST app session find by objd %d not found", objd
);
5330 ua_sess
= caa_container_of(node
, struct ust_app_session
, ust_objd_node
);
5337 * Return a ust app channel object using the application object and the channel
5338 * object descriptor has a key. If not found, NULL is returned. A RCU read side
5339 * lock MUST be acquired before calling this function.
5341 static struct ust_app_channel
*find_channel_by_objd(struct ust_app
*app
,
5344 struct lttng_ht_node_ulong
*node
;
5345 struct lttng_ht_iter iter
;
5346 struct ust_app_channel
*ua_chan
= NULL
;
5350 lttng_ht_lookup(app
->ust_objd
, (void *)((unsigned long) objd
), &iter
);
5351 node
= lttng_ht_iter_get_node_ulong(&iter
);
5353 DBG2("UST app channel find by objd %d not found", objd
);
5357 ua_chan
= caa_container_of(node
, struct ust_app_channel
, ust_objd_node
);
5364 * Reply to a register channel notification from an application on the notify
5365 * socket. The channel metadata is also created.
5367 * The session UST registry lock is acquired in this function.
5369 * On success 0 is returned else a negative value.
5371 static int reply_ust_register_channel(int sock
, int sobjd
, int cobjd
,
5372 size_t nr_fields
, struct ustctl_field
*fields
)
5374 int ret
, ret_code
= 0;
5375 uint32_t chan_id
, reg_count
;
5376 uint64_t chan_reg_key
;
5377 enum ustctl_channel_header type
;
5378 struct ust_app
*app
;
5379 struct ust_app_channel
*ua_chan
;
5380 struct ust_app_session
*ua_sess
;
5381 struct ust_registry_session
*registry
;
5382 struct ust_registry_channel
*chan_reg
;
5386 /* Lookup application. If not found, there is a code flow error. */
5387 app
= find_app_by_notify_sock(sock
);
5389 DBG("Application socket %d is being teardown. Abort event notify",
5393 goto error_rcu_unlock
;
5396 /* Lookup channel by UST object descriptor. */
5397 ua_chan
= find_channel_by_objd(app
, cobjd
);
5399 DBG("Application channel is being teardown. Abort event notify");
5402 goto error_rcu_unlock
;
5405 assert(ua_chan
->session
);
5406 ua_sess
= ua_chan
->session
;
5408 /* Get right session registry depending on the session buffer type. */
5409 registry
= get_session_registry(ua_sess
);
5412 /* Depending on the buffer type, a different channel key is used. */
5413 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
5414 chan_reg_key
= ua_chan
->tracing_channel_id
;
5416 chan_reg_key
= ua_chan
->key
;
5419 pthread_mutex_lock(®istry
->lock
);
5421 chan_reg
= ust_registry_channel_find(registry
, chan_reg_key
);
5424 if (!chan_reg
->register_done
) {
5425 reg_count
= ust_registry_get_event_count(chan_reg
);
5426 if (reg_count
< 31) {
5427 type
= USTCTL_CHANNEL_HEADER_COMPACT
;
5429 type
= USTCTL_CHANNEL_HEADER_LARGE
;
5432 chan_reg
->nr_ctx_fields
= nr_fields
;
5433 chan_reg
->ctx_fields
= fields
;
5434 chan_reg
->header_type
= type
;
5436 /* Get current already assigned values. */
5437 type
= chan_reg
->header_type
;
5439 /* Set to NULL so the error path does not do a double free. */
5442 /* Channel id is set during the object creation. */
5443 chan_id
= chan_reg
->chan_id
;
5445 /* Append to metadata */
5446 if (!chan_reg
->metadata_dumped
) {
5447 ret_code
= ust_metadata_channel_statedump(registry
, chan_reg
);
5449 ERR("Error appending channel metadata (errno = %d)", ret_code
);
5455 DBG3("UST app replying to register channel key %" PRIu64
5456 " with id %u, type: %d, ret: %d", chan_reg_key
, chan_id
, type
,
5459 ret
= ustctl_reply_register_channel(sock
, chan_id
, type
, ret_code
);
5461 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5462 ERR("UST app reply channel failed with ret %d", ret
);
5464 DBG3("UST app reply channel failed. Application died");
5469 /* This channel registry registration is completed. */
5470 chan_reg
->register_done
= 1;
5473 pthread_mutex_unlock(®istry
->lock
);
5483 * Add event to the UST channel registry. When the event is added to the
5484 * registry, the metadata is also created. Once done, this replies to the
5485 * application with the appropriate error code.
5487 * The session UST registry lock is acquired in the function.
5489 * On success 0 is returned else a negative value.
5491 static int add_event_ust_registry(int sock
, int sobjd
, int cobjd
, char *name
,
5492 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
,
5493 int loglevel_value
, char *model_emf_uri
)
5496 uint32_t event_id
= 0;
5497 uint64_t chan_reg_key
;
5498 struct ust_app
*app
;
5499 struct ust_app_channel
*ua_chan
;
5500 struct ust_app_session
*ua_sess
;
5501 struct ust_registry_session
*registry
;
5505 /* Lookup application. If not found, there is a code flow error. */
5506 app
= find_app_by_notify_sock(sock
);
5508 DBG("Application socket %d is being teardown. Abort event notify",
5513 free(model_emf_uri
);
5514 goto error_rcu_unlock
;
5517 /* Lookup channel by UST object descriptor. */
5518 ua_chan
= find_channel_by_objd(app
, cobjd
);
5520 DBG("Application channel is being teardown. Abort event notify");
5524 free(model_emf_uri
);
5525 goto error_rcu_unlock
;
5528 assert(ua_chan
->session
);
5529 ua_sess
= ua_chan
->session
;
5531 registry
= get_session_registry(ua_sess
);
5534 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
5535 chan_reg_key
= ua_chan
->tracing_channel_id
;
5537 chan_reg_key
= ua_chan
->key
;
5540 pthread_mutex_lock(®istry
->lock
);
5543 * From this point on, this call acquires the ownership of the sig, fields
5544 * and model_emf_uri meaning any free are done inside it if needed. These
5545 * three variables MUST NOT be read/write after this.
5547 ret_code
= ust_registry_create_event(registry
, chan_reg_key
,
5548 sobjd
, cobjd
, name
, sig
, nr_fields
, fields
,
5549 loglevel_value
, model_emf_uri
, ua_sess
->buffer_type
,
5553 * The return value is returned to ustctl so in case of an error, the
5554 * application can be notified. In case of an error, it's important not to
5555 * return a negative error or else the application will get closed.
5557 ret
= ustctl_reply_register_event(sock
, event_id
, ret_code
);
5559 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5560 ERR("UST app reply event failed with ret %d", ret
);
5562 DBG3("UST app reply event failed. Application died");
5565 * No need to wipe the create event since the application socket will
5566 * get close on error hence cleaning up everything by itself.
5571 DBG3("UST registry event %s with id %" PRId32
" added successfully",
5575 pthread_mutex_unlock(®istry
->lock
);
5582 * Add enum to the UST session registry. Once done, this replies to the
5583 * application with the appropriate error code.
5585 * The session UST registry lock is acquired within this function.
5587 * On success 0 is returned else a negative value.
5589 static int add_enum_ust_registry(int sock
, int sobjd
, char *name
,
5590 struct ustctl_enum_entry
*entries
, size_t nr_entries
)
5592 int ret
= 0, ret_code
;
5593 struct ust_app
*app
;
5594 struct ust_app_session
*ua_sess
;
5595 struct ust_registry_session
*registry
;
5596 uint64_t enum_id
= -1ULL;
5600 /* Lookup application. If not found, there is a code flow error. */
5601 app
= find_app_by_notify_sock(sock
);
5603 /* Return an error since this is not an error */
5604 DBG("Application socket %d is being torn down. Aborting enum registration",
5607 goto error_rcu_unlock
;
5610 /* Lookup session by UST object descriptor. */
5611 ua_sess
= find_session_by_objd(app
, sobjd
);
5613 /* Return an error since this is not an error */
5614 DBG("Application session is being torn down. Aborting enum registration.");
5616 goto error_rcu_unlock
;
5619 registry
= get_session_registry(ua_sess
);
5622 pthread_mutex_lock(®istry
->lock
);
5625 * From this point on, the callee acquires the ownership of
5626 * entries. The variable entries MUST NOT be read/written after
5629 ret_code
= ust_registry_create_or_find_enum(registry
, sobjd
, name
,
5630 entries
, nr_entries
, &enum_id
);
5634 * The return value is returned to ustctl so in case of an error, the
5635 * application can be notified. In case of an error, it's important not to
5636 * return a negative error or else the application will get closed.
5638 ret
= ustctl_reply_register_enum(sock
, enum_id
, ret_code
);
5640 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5641 ERR("UST app reply enum failed with ret %d", ret
);
5643 DBG3("UST app reply enum failed. Application died");
5646 * No need to wipe the create enum since the application socket will
5647 * get close on error hence cleaning up everything by itself.
5652 DBG3("UST registry enum %s added successfully or already found", name
);
5655 pthread_mutex_unlock(®istry
->lock
);
5662 * Handle application notification through the given notify socket.
5664 * Return 0 on success or else a negative value.
5666 int ust_app_recv_notify(int sock
)
5669 enum ustctl_notify_cmd cmd
;
5671 DBG3("UST app receiving notify from sock %d", sock
);
5673 ret
= ustctl_recv_notify(sock
, &cmd
);
5675 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5676 ERR("UST app recv notify failed with ret %d", ret
);
5678 DBG3("UST app recv notify failed. Application died");
5684 case USTCTL_NOTIFY_CMD_EVENT
:
5686 int sobjd
, cobjd
, loglevel_value
;
5687 char name
[LTTNG_UST_SYM_NAME_LEN
], *sig
, *model_emf_uri
;
5689 struct ustctl_field
*fields
;
5691 DBG2("UST app ustctl register event received");
5693 ret
= ustctl_recv_register_event(sock
, &sobjd
, &cobjd
, name
,
5694 &loglevel_value
, &sig
, &nr_fields
, &fields
,
5697 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5698 ERR("UST app recv event failed with ret %d", ret
);
5700 DBG3("UST app recv event failed. Application died");
5706 * Add event to the UST registry coming from the notify socket. This
5707 * call will free if needed the sig, fields and model_emf_uri. This
5708 * code path loses the ownsership of these variables and transfer them
5709 * to the this function.
5711 ret
= add_event_ust_registry(sock
, sobjd
, cobjd
, name
, sig
, nr_fields
,
5712 fields
, loglevel_value
, model_emf_uri
);
5719 case USTCTL_NOTIFY_CMD_CHANNEL
:
5723 struct ustctl_field
*fields
;
5725 DBG2("UST app ustctl register channel received");
5727 ret
= ustctl_recv_register_channel(sock
, &sobjd
, &cobjd
, &nr_fields
,
5730 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5731 ERR("UST app recv channel failed with ret %d", ret
);
5733 DBG3("UST app recv channel failed. Application died");
5739 * The fields ownership are transfered to this function call meaning
5740 * that if needed it will be freed. After this, it's invalid to access
5741 * fields or clean it up.
5743 ret
= reply_ust_register_channel(sock
, sobjd
, cobjd
, nr_fields
,
5751 case USTCTL_NOTIFY_CMD_ENUM
:
5754 char name
[LTTNG_UST_SYM_NAME_LEN
];
5756 struct ustctl_enum_entry
*entries
;
5758 DBG2("UST app ustctl register enum received");
5760 ret
= ustctl_recv_register_enum(sock
, &sobjd
, name
,
5761 &entries
, &nr_entries
);
5763 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
5764 ERR("UST app recv enum failed with ret %d", ret
);
5766 DBG3("UST app recv enum failed. Application died");
5771 /* Callee assumes ownership of entries */
5772 ret
= add_enum_ust_registry(sock
, sobjd
, name
,
5773 entries
, nr_entries
);
5781 /* Should NEVER happen. */
5790 * Once the notify socket hangs up, this is called. First, it tries to find the
5791 * corresponding application. On failure, the call_rcu to close the socket is
5792 * executed. If an application is found, it tries to delete it from the notify
5793 * socket hash table. Whathever the result, it proceeds to the call_rcu.
5795 * Note that an object needs to be allocated here so on ENOMEM failure, the
5796 * call RCU is not done but the rest of the cleanup is.
5798 void ust_app_notify_sock_unregister(int sock
)
5801 struct lttng_ht_iter iter
;
5802 struct ust_app
*app
;
5803 struct ust_app_notify_sock_obj
*obj
;
5809 obj
= zmalloc(sizeof(*obj
));
5812 * An ENOMEM is kind of uncool. If this strikes we continue the
5813 * procedure but the call_rcu will not be called. In this case, we
5814 * accept the fd leak rather than possibly creating an unsynchronized
5815 * state between threads.
5817 * TODO: The notify object should be created once the notify socket is
5818 * registered and stored independantely from the ust app object. The
5819 * tricky part is to synchronize the teardown of the application and
5820 * this notify object. Let's keep that in mind so we can avoid this
5821 * kind of shenanigans with ENOMEM in the teardown path.
5828 DBG("UST app notify socket unregister %d", sock
);
5831 * Lookup application by notify socket. If this fails, this means that the
5832 * hash table delete has already been done by the application
5833 * unregistration process so we can safely close the notify socket in a
5836 app
= find_app_by_notify_sock(sock
);
5841 iter
.iter
.node
= &app
->notify_sock_n
.node
;
5844 * Whatever happens here either we fail or succeed, in both cases we have
5845 * to close the socket after a grace period to continue to the call RCU
5846 * here. If the deletion is successful, the application is not visible
5847 * anymore by other threads and is it fails it means that it was already
5848 * deleted from the hash table so either way we just have to close the
5851 (void) lttng_ht_del(ust_app_ht_by_notify_sock
, &iter
);
5857 * Close socket after a grace period to avoid for the socket to be reused
5858 * before the application object is freed creating potential race between
5859 * threads trying to add unique in the global hash table.
5862 call_rcu(&obj
->head
, close_notify_sock_rcu
);
5867 * Destroy a ust app data structure and free its memory.
5869 void ust_app_destroy(struct ust_app
*app
)
5875 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
5879 * Take a snapshot for a given UST session. The snapshot is sent to the given
5882 * Return 0 on success or else a negative value.
5884 int ust_app_snapshot_record(struct ltt_ust_session
*usess
,
5885 struct snapshot_output
*output
, int wait
,
5886 uint64_t nb_packets_per_stream
)
5889 struct lttng_ht_iter iter
;
5890 struct ust_app
*app
;
5891 char pathname
[PATH_MAX
];
5898 switch (usess
->buffer_type
) {
5899 case LTTNG_BUFFER_PER_UID
:
5901 struct buffer_reg_uid
*reg
;
5903 cds_list_for_each_entry(reg
, &usess
->buffer_reg_uid_list
, lnode
) {
5904 struct buffer_reg_channel
*reg_chan
;
5905 struct consumer_socket
*socket
;
5907 /* Get consumer socket to use to push the metadata.*/
5908 socket
= consumer_find_socket_by_bitness(reg
->bits_per_long
,
5915 memset(pathname
, 0, sizeof(pathname
));
5916 ret
= snprintf(pathname
, sizeof(pathname
),
5917 DEFAULT_UST_TRACE_DIR
"/" DEFAULT_UST_TRACE_UID_PATH
,
5918 reg
->uid
, reg
->bits_per_long
);
5920 PERROR("snprintf snapshot path");
5924 /* Add the UST default trace dir to path. */
5925 cds_lfht_for_each_entry(reg
->registry
->channels
->ht
, &iter
.iter
,
5926 reg_chan
, node
.node
) {
5927 ret
= consumer_snapshot_channel(socket
, reg_chan
->consumer_key
,
5928 output
, 0, usess
->uid
, usess
->gid
, pathname
, wait
,
5929 nb_packets_per_stream
);
5934 ret
= consumer_snapshot_channel(socket
,
5935 reg
->registry
->reg
.ust
->metadata_key
, output
, 1,
5936 usess
->uid
, usess
->gid
, pathname
, wait
, 0);
5943 case LTTNG_BUFFER_PER_PID
:
5945 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
5946 struct consumer_socket
*socket
;
5947 struct lttng_ht_iter chan_iter
;
5948 struct ust_app_channel
*ua_chan
;
5949 struct ust_app_session
*ua_sess
;
5950 struct ust_registry_session
*registry
;
5952 ua_sess
= lookup_session_by_app(usess
, app
);
5954 /* Session not associated with this app. */
5958 /* Get the right consumer socket for the application. */
5959 socket
= consumer_find_socket_by_bitness(app
->bits_per_long
,
5966 /* Add the UST default trace dir to path. */
5967 memset(pathname
, 0, sizeof(pathname
));
5968 ret
= snprintf(pathname
, sizeof(pathname
), DEFAULT_UST_TRACE_DIR
"/%s",
5971 PERROR("snprintf snapshot path");
5975 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &chan_iter
.iter
,
5976 ua_chan
, node
.node
) {
5977 ret
= consumer_snapshot_channel(socket
, ua_chan
->key
, output
,
5978 0, ua_sess
->euid
, ua_sess
->egid
, pathname
, wait
,
5979 nb_packets_per_stream
);
5985 registry
= get_session_registry(ua_sess
);
5987 ret
= consumer_snapshot_channel(socket
, registry
->metadata_key
, output
,
5988 1, ua_sess
->euid
, ua_sess
->egid
, pathname
, wait
, 0);
6006 * Return the size taken by one more packet per stream.
6008 uint64_t ust_app_get_size_one_more_packet_per_stream(struct ltt_ust_session
*usess
,
6009 uint64_t cur_nr_packets
)
6011 uint64_t tot_size
= 0;
6012 struct ust_app
*app
;
6013 struct lttng_ht_iter iter
;
6017 switch (usess
->buffer_type
) {
6018 case LTTNG_BUFFER_PER_UID
:
6020 struct buffer_reg_uid
*reg
;
6022 cds_list_for_each_entry(reg
, &usess
->buffer_reg_uid_list
, lnode
) {
6023 struct buffer_reg_channel
*reg_chan
;
6026 cds_lfht_for_each_entry(reg
->registry
->channels
->ht
, &iter
.iter
,
6027 reg_chan
, node
.node
) {
6028 if (cur_nr_packets
>= reg_chan
->num_subbuf
) {
6030 * Don't take channel into account if we
6031 * already grab all its packets.
6035 tot_size
+= reg_chan
->subbuf_size
* reg_chan
->stream_count
;
6041 case LTTNG_BUFFER_PER_PID
:
6044 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
6045 struct ust_app_channel
*ua_chan
;
6046 struct ust_app_session
*ua_sess
;
6047 struct lttng_ht_iter chan_iter
;
6049 ua_sess
= lookup_session_by_app(usess
, app
);
6051 /* Session not associated with this app. */
6055 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &chan_iter
.iter
,
6056 ua_chan
, node
.node
) {
6057 if (cur_nr_packets
>= ua_chan
->attr
.num_subbuf
) {
6059 * Don't take channel into account if we
6060 * already grab all its packets.
6064 tot_size
+= ua_chan
->attr
.subbuf_size
* ua_chan
->streams
.count
;
6078 int ust_app_uid_get_channel_runtime_stats(uint64_t ust_session_id
,
6079 struct cds_list_head
*buffer_reg_uid_list
,
6080 struct consumer_output
*consumer
, uint64_t uchan_id
,
6081 int overwrite
, uint64_t *discarded
, uint64_t *lost
)
6084 uint64_t consumer_chan_key
;
6086 ret
= buffer_reg_uid_consumer_channel_key(
6087 buffer_reg_uid_list
, ust_session_id
,
6088 uchan_id
, &consumer_chan_key
);
6094 ret
= consumer_get_lost_packets(ust_session_id
,
6095 consumer_chan_key
, consumer
, lost
);
6098 ret
= consumer_get_discarded_events(ust_session_id
,
6099 consumer_chan_key
, consumer
, discarded
);
6107 int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session
*usess
,
6108 struct ltt_ust_channel
*uchan
,
6109 struct consumer_output
*consumer
, int overwrite
,
6110 uint64_t *discarded
, uint64_t *lost
)
6113 struct lttng_ht_iter iter
;
6114 struct lttng_ht_node_str
*ua_chan_node
;
6115 struct ust_app
*app
;
6116 struct ust_app_session
*ua_sess
;
6117 struct ust_app_channel
*ua_chan
;
6121 * Iterate over every registered applications, return when we
6122 * found one in the right session and channel.
6124 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
6125 struct lttng_ht_iter uiter
;
6127 ua_sess
= lookup_session_by_app(usess
, app
);
6128 if (ua_sess
== NULL
) {
6133 lttng_ht_lookup(ua_sess
->channels
, (void *) uchan
->name
, &uiter
);
6134 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
6135 /* If the session is found for the app, the channel must be there */
6136 assert(ua_chan_node
);
6138 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
6141 ret
= consumer_get_lost_packets(usess
->id
, ua_chan
->key
,
6146 ret
= consumer_get_discarded_events(usess
->id
,
6147 ua_chan
->key
, consumer
, discarded
);
6159 int ust_app_regenerate_statedump(struct ltt_ust_session
*usess
,
6160 struct ust_app
*app
)
6163 struct ust_app_session
*ua_sess
;
6165 DBG("Regenerating the metadata for ust app pid %d", app
->pid
);
6169 ua_sess
= lookup_session_by_app(usess
, app
);
6170 if (ua_sess
== NULL
) {
6171 /* The session is in teardown process. Ignore and continue. */
6175 pthread_mutex_lock(&ua_sess
->lock
);
6177 if (ua_sess
->deleted
) {
6181 pthread_mutex_lock(&app
->sock_lock
);
6182 ret
= ustctl_regenerate_statedump(app
->sock
, ua_sess
->handle
);
6183 pthread_mutex_unlock(&app
->sock_lock
);
6186 pthread_mutex_unlock(&ua_sess
->lock
);
6190 health_code_update();
6195 * Regenerate the statedump for each app in the session.
6197 int ust_app_regenerate_statedump_all(struct ltt_ust_session
*usess
)
6200 struct lttng_ht_iter iter
;
6201 struct ust_app
*app
;
6203 DBG("Regenerating the metadata for all UST apps");
6207 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
6208 if (!app
->compatible
) {
6212 ret
= ust_app_regenerate_statedump(usess
, app
);
6214 /* Continue to the next app even on error */