2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <sys/types.h>
28 #include <urcu/compiler.h>
29 #include <lttng/ust-error.h>
31 #include <common/common.h>
32 #include <common/sessiond-comm/sessiond-comm.h>
34 #include "buffer-registry.h"
38 #include "ust-consumer.h"
41 /* Next available channel key. */
42 static unsigned long next_channel_key
;
43 static unsigned long next_session_id
;
46 * Return the atomically incremented value of next_channel_key.
48 static inline unsigned long get_next_channel_key(void)
50 return uatomic_add_return(&next_channel_key
, 1);
54 * Return the atomically incremented value of next_session_id.
56 static inline unsigned long get_next_session_id(void)
58 return uatomic_add_return(&next_session_id
, 1);
62 * Match function for the hash table lookup.
64 * It matches an ust app event based on three attributes which are the event
65 * name, the filter bytecode and the loglevel.
67 static int ht_match_ust_app_event(struct cds_lfht_node
*node
, const void *_key
)
69 struct ust_app_event
*event
;
70 const struct ust_app_ht_key
*key
;
75 event
= caa_container_of(node
, struct ust_app_event
, node
.node
);
78 /* Match the 3 elements of the key: name, filter and loglevel. */
81 if (strncmp(event
->attr
.name
, key
->name
, sizeof(event
->attr
.name
)) != 0) {
86 if (event
->attr
.loglevel
!= key
->loglevel
) {
87 if (event
->attr
.loglevel_type
== LTTNG_UST_LOGLEVEL_ALL
88 && key
->loglevel
== 0 && event
->attr
.loglevel
== -1) {
90 * Match is accepted. This is because on event creation, the
91 * loglevel is set to -1 if the event loglevel type is ALL so 0 and
92 * -1 are accepted for this loglevel type since 0 is the one set by
93 * the API when receiving an enable event.
100 /* One of the filters is NULL, fail. */
101 if ((key
->filter
&& !event
->filter
) || (!key
->filter
&& event
->filter
)) {
105 if (key
->filter
&& event
->filter
) {
106 /* Both filters exists, check length followed by the bytecode. */
107 if (event
->filter
->len
!= key
->filter
->len
||
108 memcmp(event
->filter
->data
, key
->filter
->data
,
109 event
->filter
->len
) != 0) {
122 * Unique add of an ust app event in the given ht. This uses the custom
123 * ht_match_ust_app_event match function and the event name as hash.
125 static void add_unique_ust_app_event(struct ust_app_channel
*ua_chan
,
126 struct ust_app_event
*event
)
128 struct cds_lfht_node
*node_ptr
;
129 struct ust_app_ht_key key
;
133 assert(ua_chan
->events
);
136 ht
= ua_chan
->events
;
137 key
.name
= event
->attr
.name
;
138 key
.filter
= event
->filter
;
139 key
.loglevel
= event
->attr
.loglevel
;
141 node_ptr
= cds_lfht_add_unique(ht
->ht
,
142 ht
->hash_fct(event
->node
.key
, lttng_ht_seed
),
143 ht_match_ust_app_event
, &key
, &event
->node
.node
);
144 assert(node_ptr
== &event
->node
.node
);
148 * Close the notify socket from the given RCU head object. This MUST be called
149 * through a call_rcu().
151 static void close_notify_sock_rcu(struct rcu_head
*head
)
154 struct ust_app_notify_sock_obj
*obj
=
155 caa_container_of(head
, struct ust_app_notify_sock_obj
, head
);
157 /* Must have a valid fd here. */
158 assert(obj
->fd
>= 0);
160 ret
= close(obj
->fd
);
162 ERR("close notify sock %d RCU", obj
->fd
);
164 lttng_fd_put(LTTNG_FD_APPS
, 1);
170 * Return the session registry according to the buffer type of the given
173 * A registry per UID object MUST exists before calling this function or else
174 * it assert() if not found. RCU read side lock must be acquired.
176 static struct ust_registry_session
*get_session_registry(
177 struct ust_app_session
*ua_sess
)
179 struct ust_registry_session
*registry
= NULL
;
183 switch (ua_sess
->buffer_type
) {
184 case LTTNG_BUFFER_PER_PID
:
186 struct buffer_reg_pid
*reg_pid
= buffer_reg_pid_find(ua_sess
->id
);
190 registry
= reg_pid
->registry
->reg
.ust
;
193 case LTTNG_BUFFER_PER_UID
:
195 struct buffer_reg_uid
*reg_uid
= buffer_reg_uid_find(
196 ua_sess
->tracing_id
, ua_sess
->bits_per_long
, ua_sess
->uid
);
200 registry
= reg_uid
->registry
->reg
.ust
;
212 * Delete ust context safely. RCU read lock must be held before calling
216 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
)
223 ret
= ustctl_release_object(sock
, ua_ctx
->obj
);
224 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
225 ERR("UST app sock %d release ctx obj handle %d failed with ret %d",
226 sock
, ua_ctx
->obj
->handle
, ret
);
234 * Delete ust app event safely. RCU read lock must be held before calling
238 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
244 free(ua_event
->filter
);
246 if (ua_event
->obj
!= NULL
) {
247 ret
= ustctl_release_object(sock
, ua_event
->obj
);
248 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
249 ERR("UST app sock %d release event obj failed with ret %d",
258 * Release ust data object of the given stream.
260 * Return 0 on success or else a negative value.
262 static int release_ust_app_stream(int sock
, struct ust_app_stream
*stream
)
269 ret
= ustctl_release_object(sock
, stream
->obj
);
270 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
271 ERR("UST app sock %d release stream obj failed with ret %d",
274 lttng_fd_put(LTTNG_FD_APPS
, 2);
282 * Delete ust app stream safely. RCU read lock must be held before calling
286 void delete_ust_app_stream(int sock
, struct ust_app_stream
*stream
)
290 (void) release_ust_app_stream(sock
, stream
);
295 * Delete ust app channel safely. RCU read lock must be held before calling
299 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
,
303 struct lttng_ht_iter iter
;
304 struct ust_app_event
*ua_event
;
305 struct ust_app_ctx
*ua_ctx
;
306 struct ust_app_stream
*stream
, *stmp
;
307 struct ust_registry_session
*registry
;
311 DBG3("UST app deleting channel %s", ua_chan
->name
);
314 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
315 cds_list_del(&stream
->list
);
316 delete_ust_app_stream(sock
, stream
);
320 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
321 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
323 delete_ust_app_ctx(sock
, ua_ctx
);
325 lttng_ht_destroy(ua_chan
->ctx
);
328 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
330 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
332 delete_ust_app_event(sock
, ua_event
);
334 lttng_ht_destroy(ua_chan
->events
);
336 /* Wipe and free registry from session registry. */
337 registry
= get_session_registry(ua_chan
->session
);
339 ust_registry_channel_del_free(registry
, ua_chan
->key
);
342 if (ua_chan
->obj
!= NULL
) {
343 /* Remove channel from application UST object descriptor. */
344 iter
.iter
.node
= &ua_chan
->ust_objd_node
.node
;
345 lttng_ht_del(app
->ust_objd
, &iter
);
346 ret
= ustctl_release_object(sock
, ua_chan
->obj
);
347 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
348 ERR("UST app sock %d release channel obj failed with ret %d",
351 lttng_fd_put(LTTNG_FD_APPS
, 1);
358 * For a given application and session, push metadata to consumer. The session
359 * lock MUST be acquired here before calling this.
361 * Return 0 on success else a negative error.
363 static int push_metadata(struct ust_registry_session
*registry
,
364 struct consumer_output
*consumer
)
367 char *metadata_str
= NULL
;
369 struct consumer_socket
*socket
;
377 * Means that no metadata was assigned to the session. This can happens if
378 * no start has been done previously.
380 if (!registry
->metadata_key
) {
382 goto error_rcu_unlock
;
385 /* Get consumer socket to use to push the metadata.*/
386 socket
= consumer_find_socket_by_bitness(registry
->bits_per_long
,
390 goto error_rcu_unlock
;
394 * TODO: Currently, we hold the socket lock around sampling of the next
395 * metadata segment to ensure we send metadata over the consumer socket in
396 * the correct order. This makes the registry lock nest inside the socket
399 * Please note that this is a temporary measure: we should move this lock
400 * back into ust_consumer_push_metadata() when the consumer gets the
401 * ability to reorder the metadata it receives.
403 pthread_mutex_lock(socket
->lock
);
404 pthread_mutex_lock(®istry
->lock
);
406 offset
= registry
->metadata_len_sent
;
407 len
= registry
->metadata_len
- registry
->metadata_len_sent
;
409 DBG3("No metadata to push for metadata key %" PRIu64
,
410 registry
->metadata_key
);
412 goto error_reg_unlock
;
416 /* Allocate only what we have to send. */
417 metadata_str
= zmalloc(len
);
419 PERROR("zmalloc ust app metadata string");
421 goto error_reg_unlock
;
423 /* Copy what we haven't send out. */
424 memcpy(metadata_str
, registry
->metadata
+ offset
, len
);
426 pthread_mutex_unlock(®istry
->lock
);
428 ret
= consumer_push_metadata(socket
, registry
->metadata_key
,
429 metadata_str
, len
, offset
);
431 pthread_mutex_unlock(socket
->lock
);
432 goto error_rcu_unlock
;
435 /* Update len sent of the registry. */
436 pthread_mutex_lock(®istry
->lock
);
437 registry
->metadata_len_sent
+= len
;
438 pthread_mutex_unlock(®istry
->lock
);
439 pthread_mutex_unlock(socket
->lock
);
446 pthread_mutex_unlock(®istry
->lock
);
447 pthread_mutex_unlock(socket
->lock
);
455 * Send to the consumer a close metadata command for the given session. Once
456 * done, the metadata channel is deleted and the session metadata pointer is
457 * nullified. The session lock MUST be acquired here unless the application is
458 * in the destroy path.
460 * Return 0 on success else a negative value.
462 static int close_metadata(struct ust_registry_session
*registry
,
463 struct consumer_output
*consumer
)
466 struct consumer_socket
*socket
;
473 if (!registry
->metadata_key
|| registry
->metadata_closed
) {
478 /* Get consumer socket to use to push the metadata.*/
479 socket
= consumer_find_socket_by_bitness(registry
->bits_per_long
,
486 ret
= consumer_close_metadata(socket
, registry
->metadata_key
);
491 /* Metadata successfully closed. Flag the registry. */
492 registry
->metadata_closed
= 1;
500 * Delete ust app session safely. RCU read lock must be held before calling
504 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
,
508 struct lttng_ht_iter iter
;
509 struct ust_app_channel
*ua_chan
;
510 struct ust_registry_session
*registry
;
514 registry
= get_session_registry(ua_sess
);
516 /* Push metadata for application before freeing the application. */
517 (void) push_metadata(registry
, ua_sess
->consumer
);
520 * Don't ask to close metadata for global per UID buffers. Close
521 * metadata only on destroy trace session in this case.
523 if (ua_sess
->buffer_type
!= LTTNG_BUFFER_PER_UID
) {
524 /* And ask to close it for this session registry. */
525 (void) close_metadata(registry
, ua_sess
->consumer
);
529 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
531 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
533 delete_ust_app_channel(sock
, ua_chan
, app
);
535 lttng_ht_destroy(ua_sess
->channels
);
537 /* In case of per PID, the registry is kept in the session. */
538 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_PID
) {
539 struct buffer_reg_pid
*reg_pid
= buffer_reg_pid_find(ua_sess
->id
);
541 buffer_reg_pid_remove(reg_pid
);
542 buffer_reg_pid_destroy(reg_pid
);
546 if (ua_sess
->handle
!= -1) {
547 ret
= ustctl_release_handle(sock
, ua_sess
->handle
);
548 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
549 ERR("UST app sock %d release session handle failed with ret %d",
557 * Delete a traceable application structure from the global list. Never call
558 * this function outside of a call_rcu call.
561 void delete_ust_app(struct ust_app
*app
)
564 struct ust_app_session
*ua_sess
, *tmp_ua_sess
;
568 /* Delete ust app sessions info */
572 lttng_ht_destroy(app
->sessions
);
575 cds_list_for_each_entry_safe(ua_sess
, tmp_ua_sess
, &app
->teardown_head
,
577 /* Free every object in the session and the session. */
578 delete_ust_app_session(sock
, ua_sess
, app
);
580 lttng_ht_destroy(app
->ust_objd
);
583 * Wait until we have deleted the application from the sock hash table
584 * before closing this socket, otherwise an application could re-use the
585 * socket ID and race with the teardown, using the same hash table entry.
587 * It's OK to leave the close in call_rcu. We want it to stay unique for
588 * all RCU readers that could run concurrently with unregister app,
589 * therefore we _need_ to only close that socket after a grace period. So
590 * it should stay in this RCU callback.
592 * This close() is a very important step of the synchronization model so
593 * every modification to this function must be carefully reviewed.
599 lttng_fd_put(LTTNG_FD_APPS
, 1);
601 DBG2("UST app pid %d deleted", app
->pid
);
608 * URCU intermediate call to delete an UST app.
611 void delete_ust_app_rcu(struct rcu_head
*head
)
613 struct lttng_ht_node_ulong
*node
=
614 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
615 struct ust_app
*app
=
616 caa_container_of(node
, struct ust_app
, pid_n
);
618 DBG3("Call RCU deleting app PID %d", app
->pid
);
623 * Delete the session from the application ht and delete the data structure by
624 * freeing every object inside and releasing them.
626 static void destroy_app_session(struct ust_app
*app
,
627 struct ust_app_session
*ua_sess
)
630 struct lttng_ht_iter iter
;
635 iter
.iter
.node
= &ua_sess
->node
.node
;
636 ret
= lttng_ht_del(app
->sessions
, &iter
);
638 /* Already scheduled for teardown. */
642 /* Once deleted, free the data structure. */
643 delete_ust_app_session(app
->sock
, ua_sess
, app
);
650 * Alloc new UST app session.
653 struct ust_app_session
*alloc_ust_app_session(struct ust_app
*app
)
655 struct ust_app_session
*ua_sess
;
657 /* Init most of the default value by allocating and zeroing */
658 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
659 if (ua_sess
== NULL
) {
664 ua_sess
->handle
= -1;
665 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
666 pthread_mutex_init(&ua_sess
->lock
, NULL
);
675 * Alloc new UST app channel.
678 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
679 struct ust_app_session
*ua_sess
,
680 struct lttng_ust_channel_attr
*attr
)
682 struct ust_app_channel
*ua_chan
;
684 /* Init most of the default value by allocating and zeroing */
685 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
686 if (ua_chan
== NULL
) {
691 /* Setup channel name */
692 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
693 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
695 ua_chan
->enabled
= 1;
696 ua_chan
->handle
= -1;
697 ua_chan
->session
= ua_sess
;
698 ua_chan
->key
= get_next_channel_key();
699 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
700 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
701 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
703 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
705 /* Copy attributes */
707 /* Translate from lttng_ust_channel to ustctl_consumer_channel_attr. */
708 ua_chan
->attr
.subbuf_size
= attr
->subbuf_size
;
709 ua_chan
->attr
.num_subbuf
= attr
->num_subbuf
;
710 ua_chan
->attr
.overwrite
= attr
->overwrite
;
711 ua_chan
->attr
.switch_timer_interval
= attr
->switch_timer_interval
;
712 ua_chan
->attr
.read_timer_interval
= attr
->read_timer_interval
;
713 ua_chan
->attr
.output
= attr
->output
;
715 /* By default, the channel is a per cpu channel. */
716 ua_chan
->attr
.type
= LTTNG_UST_CHAN_PER_CPU
;
718 DBG3("UST app channel %s allocated", ua_chan
->name
);
727 * Allocate and initialize a UST app stream.
729 * Return newly allocated stream pointer or NULL on error.
731 struct ust_app_stream
*ust_app_alloc_stream(void)
733 struct ust_app_stream
*stream
= NULL
;
735 stream
= zmalloc(sizeof(*stream
));
736 if (stream
== NULL
) {
737 PERROR("zmalloc ust app stream");
741 /* Zero could be a valid value for a handle so flag it to -1. */
749 * Alloc new UST app event.
752 struct ust_app_event
*alloc_ust_app_event(char *name
,
753 struct lttng_ust_event
*attr
)
755 struct ust_app_event
*ua_event
;
757 /* Init most of the default value by allocating and zeroing */
758 ua_event
= zmalloc(sizeof(struct ust_app_event
));
759 if (ua_event
== NULL
) {
764 ua_event
->enabled
= 1;
765 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
766 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
767 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
769 /* Copy attributes */
771 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
774 DBG3("UST app event %s allocated", ua_event
->name
);
783 * Alloc new UST app context.
786 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
788 struct ust_app_ctx
*ua_ctx
;
790 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
791 if (ua_ctx
== NULL
) {
796 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
799 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
806 * Allocate a filter and copy the given original filter.
808 * Return allocated filter or NULL on error.
810 static struct lttng_ust_filter_bytecode
*alloc_copy_ust_app_filter(
811 struct lttng_ust_filter_bytecode
*orig_f
)
813 struct lttng_ust_filter_bytecode
*filter
= NULL
;
815 /* Copy filter bytecode */
816 filter
= zmalloc(sizeof(*filter
) + orig_f
->len
);
818 PERROR("zmalloc alloc ust app filter");
822 memcpy(filter
, orig_f
, sizeof(*filter
) + orig_f
->len
);
829 * Find an ust_app using the sock and return it. RCU read side lock must be
830 * held before calling this helper function.
833 struct ust_app
*find_app_by_sock(int sock
)
835 struct lttng_ht_node_ulong
*node
;
836 struct lttng_ht_iter iter
;
838 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
839 node
= lttng_ht_iter_get_node_ulong(&iter
);
841 DBG2("UST app find by sock %d not found", sock
);
845 return caa_container_of(node
, struct ust_app
, sock_n
);
852 * Find an ust_app using the notify sock and return it. RCU read side lock must
853 * be held before calling this helper function.
855 static struct ust_app
*find_app_by_notify_sock(int sock
)
857 struct lttng_ht_node_ulong
*node
;
858 struct lttng_ht_iter iter
;
860 lttng_ht_lookup(ust_app_ht_by_notify_sock
, (void *)((unsigned long) sock
),
862 node
= lttng_ht_iter_get_node_ulong(&iter
);
864 DBG2("UST app find by notify sock %d not found", sock
);
868 return caa_container_of(node
, struct ust_app
, notify_sock_n
);
875 * Lookup for an ust app event based on event name, filter bytecode and the
878 * Return an ust_app_event object or NULL on error.
880 static struct ust_app_event
*find_ust_app_event(struct lttng_ht
*ht
,
881 char *name
, struct lttng_ust_filter_bytecode
*filter
, int loglevel
)
883 struct lttng_ht_iter iter
;
884 struct lttng_ht_node_str
*node
;
885 struct ust_app_event
*event
= NULL
;
886 struct ust_app_ht_key key
;
891 /* Setup key for event lookup. */
894 key
.loglevel
= loglevel
;
896 /* Lookup using the event name as hash and a custom match fct. */
897 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
898 ht_match_ust_app_event
, &key
, &iter
.iter
);
899 node
= lttng_ht_iter_get_node_str(&iter
);
904 event
= caa_container_of(node
, struct ust_app_event
, node
);
911 * Create the channel context on the tracer.
913 * Called with UST app session lock held.
916 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
917 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
921 health_code_update();
923 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
924 ua_chan
->obj
, &ua_ctx
->obj
);
926 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
927 ERR("UST app create channel context failed for app (pid: %d) "
928 "with ret %d", app
->pid
, ret
);
930 DBG3("UST app disable event failed. Application is dead.");
935 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
937 DBG2("UST app context handle %d created successfully for channel %s",
938 ua_ctx
->handle
, ua_chan
->name
);
941 health_code_update();
946 * Set the filter on the tracer.
949 int set_ust_event_filter(struct ust_app_event
*ua_event
,
954 health_code_update();
956 if (!ua_event
->filter
) {
961 ret
= ustctl_set_filter(app
->sock
, ua_event
->filter
,
964 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
965 ERR("UST app event %s filter failed for app (pid: %d) "
966 "with ret %d", ua_event
->attr
.name
, app
->pid
, ret
);
968 DBG3("UST app filter event failed. Application is dead.");
973 DBG2("UST filter set successfully for event %s", ua_event
->name
);
976 health_code_update();
981 * Disable the specified event on to UST tracer for the UST session.
983 static int disable_ust_event(struct ust_app
*app
,
984 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
988 health_code_update();
990 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
992 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
993 ERR("UST app event %s disable failed for app (pid: %d) "
994 "and session handle %d with ret %d",
995 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
997 DBG3("UST app disable event failed. Application is dead.");
1002 DBG2("UST app event %s disabled successfully for app (pid: %d)",
1003 ua_event
->attr
.name
, app
->pid
);
1006 health_code_update();
1011 * Disable the specified channel on to UST tracer for the UST session.
1013 static int disable_ust_channel(struct ust_app
*app
,
1014 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
1018 health_code_update();
1020 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
1022 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1023 ERR("UST app channel %s disable failed for app (pid: %d) "
1024 "and session handle %d with ret %d",
1025 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
1027 DBG3("UST app disable channel failed. Application is dead.");
1032 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
1033 ua_chan
->name
, app
->pid
);
1036 health_code_update();
1041 * Enable the specified channel on to UST tracer for the UST session.
1043 static int enable_ust_channel(struct ust_app
*app
,
1044 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
1048 health_code_update();
1050 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
1052 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1053 ERR("UST app channel %s enable failed for app (pid: %d) "
1054 "and session handle %d with ret %d",
1055 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
1057 DBG3("UST app enable channel failed. Application is dead.");
1062 ua_chan
->enabled
= 1;
1064 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
1065 ua_chan
->name
, app
->pid
);
1068 health_code_update();
1073 * Enable the specified event on to UST tracer for the UST session.
1075 static int enable_ust_event(struct ust_app
*app
,
1076 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
1080 health_code_update();
1082 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
1084 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1085 ERR("UST app event %s enable failed for app (pid: %d) "
1086 "and session handle %d with ret %d",
1087 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
1089 DBG3("UST app enable event failed. Application is dead.");
1094 DBG2("UST app event %s enabled successfully for app (pid: %d)",
1095 ua_event
->attr
.name
, app
->pid
);
1098 health_code_update();
1103 * Send channel and stream buffer to application.
1105 * Return 0 on success. On error, a negative value is returned.
1107 static int send_channel_pid_to_ust(struct ust_app
*app
,
1108 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
1111 struct ust_app_stream
*stream
, *stmp
;
1117 health_code_update();
1119 DBG("UST app sending channel %s to UST app sock %d", ua_chan
->name
,
1122 /* Send channel to the application. */
1123 ret
= ust_consumer_send_channel_to_ust(app
, ua_sess
, ua_chan
);
1128 health_code_update();
1130 /* Send all streams to application. */
1131 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
1132 ret
= ust_consumer_send_stream_to_ust(app
, ua_chan
, stream
);
1136 /* We don't need the stream anymore once sent to the tracer. */
1137 cds_list_del(&stream
->list
);
1138 delete_ust_app_stream(-1, stream
);
1140 /* Flag the channel that it is sent to the application. */
1141 ua_chan
->is_sent
= 1;
1144 health_code_update();
1149 * Create the specified event onto the UST tracer for a UST session.
1151 * Should be called with session mutex held.
1154 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
1155 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
1159 health_code_update();
1161 /* Create UST event on tracer */
1162 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
1165 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1166 ERR("Error ustctl create event %s for app pid: %d with ret %d",
1167 ua_event
->attr
.name
, app
->pid
, ret
);
1169 DBG3("UST app create event failed. Application is dead.");
1174 ua_event
->handle
= ua_event
->obj
->handle
;
1176 DBG2("UST app event %s created successfully for pid:%d",
1177 ua_event
->attr
.name
, app
->pid
);
1179 health_code_update();
1181 /* Set filter if one is present. */
1182 if (ua_event
->filter
) {
1183 ret
= set_ust_event_filter(ua_event
, app
);
1189 /* If event not enabled, disable it on the tracer */
1190 if (ua_event
->enabled
== 0) {
1191 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1194 * If we hit an EPERM, something is wrong with our disable call. If
1195 * we get an EEXIST, there is a problem on the tracer side since we
1199 case -LTTNG_UST_ERR_PERM
:
1200 /* Code flow problem */
1202 case -LTTNG_UST_ERR_EXIST
:
1203 /* It's OK for our use case. */
1214 health_code_update();
1219 * Copy data between an UST app event and a LTT event.
1221 static void shadow_copy_event(struct ust_app_event
*ua_event
,
1222 struct ltt_ust_event
*uevent
)
1224 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
1225 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
1227 ua_event
->enabled
= uevent
->enabled
;
1229 /* Copy event attributes */
1230 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
1232 /* Copy filter bytecode */
1233 if (uevent
->filter
) {
1234 ua_event
->filter
= alloc_copy_ust_app_filter(uevent
->filter
);
1235 /* Filter might be NULL here in case of ENONEM. */
1240 * Copy data between an UST app channel and a LTT channel.
1242 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
1243 struct ltt_ust_channel
*uchan
)
1245 struct lttng_ht_iter iter
;
1246 struct ltt_ust_event
*uevent
;
1247 struct ltt_ust_context
*uctx
;
1248 struct ust_app_event
*ua_event
;
1249 struct ust_app_ctx
*ua_ctx
;
1251 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
1253 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
1254 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
1256 /* Copy event attributes since the layout is different. */
1257 ua_chan
->attr
.subbuf_size
= uchan
->attr
.subbuf_size
;
1258 ua_chan
->attr
.num_subbuf
= uchan
->attr
.num_subbuf
;
1259 ua_chan
->attr
.overwrite
= uchan
->attr
.overwrite
;
1260 ua_chan
->attr
.switch_timer_interval
= uchan
->attr
.switch_timer_interval
;
1261 ua_chan
->attr
.read_timer_interval
= uchan
->attr
.read_timer_interval
;
1262 ua_chan
->attr
.output
= uchan
->attr
.output
;
1264 * Note that the attribute channel type is not set since the channel on the
1265 * tracing registry side does not have this information.
1268 ua_chan
->enabled
= uchan
->enabled
;
1269 ua_chan
->tracing_channel_id
= uchan
->id
;
1271 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
1272 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
1273 if (ua_ctx
== NULL
) {
1276 lttng_ht_node_init_ulong(&ua_ctx
->node
,
1277 (unsigned long) ua_ctx
->ctx
.ctx
);
1278 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1281 /* Copy all events from ltt ust channel to ust app channel */
1282 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
1283 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
1284 uevent
->filter
, uevent
->attr
.loglevel
);
1285 if (ua_event
== NULL
) {
1286 DBG2("UST event %s not found on shadow copy channel",
1288 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1289 if (ua_event
== NULL
) {
1292 shadow_copy_event(ua_event
, uevent
);
1293 add_unique_ust_app_event(ua_chan
, ua_event
);
1297 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
1301 * Copy data between a UST app session and a regular LTT session.
1303 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
1304 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1306 struct lttng_ht_node_str
*ua_chan_node
;
1307 struct lttng_ht_iter iter
;
1308 struct ltt_ust_channel
*uchan
;
1309 struct ust_app_channel
*ua_chan
;
1311 struct tm
*timeinfo
;
1315 /* Get date and time for unique app path */
1317 timeinfo
= localtime(&rawtime
);
1318 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
1320 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
1322 ua_sess
->tracing_id
= usess
->id
;
1323 ua_sess
->id
= get_next_session_id();
1324 ua_sess
->uid
= app
->uid
;
1325 ua_sess
->gid
= app
->gid
;
1326 ua_sess
->euid
= usess
->uid
;
1327 ua_sess
->egid
= usess
->gid
;
1328 ua_sess
->buffer_type
= usess
->buffer_type
;
1329 ua_sess
->bits_per_long
= app
->bits_per_long
;
1330 /* There is only one consumer object per session possible. */
1331 ua_sess
->consumer
= usess
->consumer
;
1333 switch (ua_sess
->buffer_type
) {
1334 case LTTNG_BUFFER_PER_PID
:
1335 ret
= snprintf(ua_sess
->path
, sizeof(ua_sess
->path
),
1336 DEFAULT_UST_TRACE_PID_PATH
"/%s-%d-%s/", app
->name
, app
->pid
,
1339 case LTTNG_BUFFER_PER_UID
:
1340 ret
= snprintf(ua_sess
->path
, sizeof(ua_sess
->path
),
1341 DEFAULT_UST_TRACE_UID_PATH
, ua_sess
->uid
, app
->bits_per_long
);
1348 PERROR("asprintf UST shadow copy session");
1353 /* Iterate over all channels in global domain. */
1354 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
1356 struct lttng_ht_iter uiter
;
1358 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1359 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1360 if (ua_chan_node
!= NULL
) {
1361 /* Session exist. Contiuing. */
1365 DBG2("Channel %s not found on shadow session copy, creating it",
1367 ua_chan
= alloc_ust_app_channel(uchan
->name
, ua_sess
, &uchan
->attr
);
1368 if (ua_chan
== NULL
) {
1369 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
1372 shadow_copy_channel(ua_chan
, uchan
);
1374 * The concept of metadata channel does not exist on the tracing
1375 * registry side of the session daemon so this can only be a per CPU
1376 * channel and not metadata.
1378 ua_chan
->attr
.type
= LTTNG_UST_CHAN_PER_CPU
;
1380 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1388 * Lookup sesison wrapper.
1391 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
1392 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
1394 /* Get right UST app session from app */
1395 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
1399 * Return ust app session from the app session hashtable using the UST session
1402 static struct ust_app_session
*lookup_session_by_app(
1403 struct ltt_ust_session
*usess
, struct ust_app
*app
)
1405 struct lttng_ht_iter iter
;
1406 struct lttng_ht_node_ulong
*node
;
1408 __lookup_session_by_app(usess
, app
, &iter
);
1409 node
= lttng_ht_iter_get_node_ulong(&iter
);
1414 return caa_container_of(node
, struct ust_app_session
, node
);
1421 * Setup buffer registry per PID for the given session and application. If none
1422 * is found, a new one is created, added to the global registry and
1423 * initialized. If regp is valid, it's set with the newly created object.
1425 * Return 0 on success or else a negative value.
1427 static int setup_buffer_reg_pid(struct ust_app_session
*ua_sess
,
1428 struct ust_app
*app
, struct buffer_reg_pid
**regp
)
1431 struct buffer_reg_pid
*reg_pid
;
1438 reg_pid
= buffer_reg_pid_find(ua_sess
->id
);
1441 * This is the create channel path meaning that if there is NO
1442 * registry available, we have to create one for this session.
1444 ret
= buffer_reg_pid_create(ua_sess
->id
, ®_pid
);
1448 buffer_reg_pid_add(reg_pid
);
1453 /* Initialize registry. */
1454 ret
= ust_registry_session_init(®_pid
->registry
->reg
.ust
, app
,
1455 app
->bits_per_long
, app
->uint8_t_alignment
,
1456 app
->uint16_t_alignment
, app
->uint32_t_alignment
,
1457 app
->uint64_t_alignment
, app
->long_alignment
, app
->byte_order
);
1462 DBG3("UST app buffer registry per PID created successfully");
1474 * Setup buffer registry per UID for the given session and application. If none
1475 * is found, a new one is created, added to the global registry and
1476 * initialized. If regp is valid, it's set with the newly created object.
1478 * Return 0 on success or else a negative value.
1480 static int setup_buffer_reg_uid(struct ltt_ust_session
*usess
,
1481 struct ust_app
*app
, struct buffer_reg_uid
**regp
)
1484 struct buffer_reg_uid
*reg_uid
;
1491 reg_uid
= buffer_reg_uid_find(usess
->id
, app
->bits_per_long
, app
->uid
);
1494 * This is the create channel path meaning that if there is NO
1495 * registry available, we have to create one for this session.
1497 ret
= buffer_reg_uid_create(usess
->id
, app
->bits_per_long
, app
->uid
,
1498 LTTNG_DOMAIN_UST
, ®_uid
);
1502 buffer_reg_uid_add(reg_uid
);
1507 /* Initialize registry. */
1508 ret
= ust_registry_session_init(®_uid
->registry
->reg
.ust
, app
,
1509 app
->bits_per_long
, app
->uint8_t_alignment
,
1510 app
->uint16_t_alignment
, app
->uint32_t_alignment
,
1511 app
->uint64_t_alignment
, app
->long_alignment
, app
->byte_order
);
1515 /* Add node to teardown list of the session. */
1516 cds_list_add(®_uid
->lnode
, &usess
->buffer_reg_uid_list
);
1518 DBG3("UST app buffer registry per UID created successfully");
1530 * Create a session on the tracer side for the given app.
1532 * On success, ua_sess_ptr is populated with the session pointer or else left
1533 * untouched. If the session was created, is_created is set to 1. On error,
1534 * it's left untouched. Note that ua_sess_ptr is mandatory but is_created can
1537 * Returns 0 on success or else a negative code which is either -ENOMEM or
1538 * -ENOTCONN which is the default code if the ustctl_create_session fails.
1540 static int create_ust_app_session(struct ltt_ust_session
*usess
,
1541 struct ust_app
*app
, struct ust_app_session
**ua_sess_ptr
,
1544 int ret
, created
= 0;
1545 struct ust_app_session
*ua_sess
;
1549 assert(ua_sess_ptr
);
1551 health_code_update();
1553 ua_sess
= lookup_session_by_app(usess
, app
);
1554 if (ua_sess
== NULL
) {
1555 DBG2("UST app pid: %d session id %d not found, creating it",
1556 app
->pid
, usess
->id
);
1557 ua_sess
= alloc_ust_app_session(app
);
1558 if (ua_sess
== NULL
) {
1559 /* Only malloc can failed so something is really wrong */
1563 shadow_copy_session(ua_sess
, usess
, app
);
1567 switch (usess
->buffer_type
) {
1568 case LTTNG_BUFFER_PER_PID
:
1569 /* Init local registry. */
1570 ret
= setup_buffer_reg_pid(ua_sess
, app
, NULL
);
1575 case LTTNG_BUFFER_PER_UID
:
1576 /* Look for a global registry. If none exists, create one. */
1577 ret
= setup_buffer_reg_uid(usess
, app
, NULL
);
1588 health_code_update();
1590 if (ua_sess
->handle
== -1) {
1591 ret
= ustctl_create_session(app
->sock
);
1593 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
1594 ERR("Creating session for app pid %d with ret %d",
1597 DBG("UST app creating session failed. Application is dead");
1599 delete_ust_app_session(-1, ua_sess
, app
);
1600 if (ret
!= -ENOMEM
) {
1602 * Tracer is probably gone or got an internal error so let's
1603 * behave like it will soon unregister or not usable.
1610 ua_sess
->handle
= ret
;
1612 /* Add ust app session to app's HT */
1613 lttng_ht_node_init_ulong(&ua_sess
->node
,
1614 (unsigned long) ua_sess
->tracing_id
);
1615 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
1617 DBG2("UST app session created successfully with handle %d", ret
);
1620 *ua_sess_ptr
= ua_sess
;
1622 *is_created
= created
;
1625 /* Everything went well. */
1629 health_code_update();
1634 * Create a context for the channel on the tracer.
1636 * Called with UST app session lock held and a RCU read side lock.
1639 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
1640 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
1641 struct ust_app
*app
)
1644 struct lttng_ht_iter iter
;
1645 struct lttng_ht_node_ulong
*node
;
1646 struct ust_app_ctx
*ua_ctx
;
1648 DBG2("UST app adding context to channel %s", ua_chan
->name
);
1650 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
1651 node
= lttng_ht_iter_get_node_ulong(&iter
);
1657 ua_ctx
= alloc_ust_app_ctx(uctx
);
1658 if (ua_ctx
== NULL
) {
1664 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
1665 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
1667 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
1677 * Enable on the tracer side a ust app event for the session and channel.
1679 * Called with UST app session lock held.
1682 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1683 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1687 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1692 ua_event
->enabled
= 1;
1699 * Disable on the tracer side a ust app event for the session and channel.
1701 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1702 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1706 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1711 ua_event
->enabled
= 0;
1718 * Lookup ust app channel for session and disable it on the tracer side.
1721 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1722 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1726 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1731 ua_chan
->enabled
= 0;
1738 * Lookup ust app channel for session and enable it on the tracer side. This
1739 * MUST be called with a RCU read side lock acquired.
1741 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1742 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1745 struct lttng_ht_iter iter
;
1746 struct lttng_ht_node_str
*ua_chan_node
;
1747 struct ust_app_channel
*ua_chan
;
1749 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1750 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1751 if (ua_chan_node
== NULL
) {
1752 DBG2("Unable to find channel %s in ust session id %u",
1753 uchan
->name
, ua_sess
->tracing_id
);
1757 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1759 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1769 * Ask the consumer to create a channel and get it if successful.
1771 * Return 0 on success or else a negative value.
1773 static int do_consumer_create_channel(struct ltt_ust_session
*usess
,
1774 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
,
1775 int bitness
, struct ust_registry_session
*registry
)
1778 unsigned int nb_fd
= 0;
1779 struct consumer_socket
*socket
;
1787 health_code_update();
1789 /* Get the right consumer socket for the application. */
1790 socket
= consumer_find_socket_by_bitness(bitness
, usess
->consumer
);
1796 health_code_update();
1798 /* Need one fd for the channel. */
1799 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
1801 ERR("Exhausted number of available FD upon create channel");
1806 * Ask consumer to create channel. The consumer will return the number of
1807 * stream we have to expect.
1809 ret
= ust_consumer_ask_channel(ua_sess
, ua_chan
, usess
->consumer
, socket
,
1816 * Compute the number of fd needed before receiving them. It must be 2 per
1817 * stream (2 being the default value here).
1819 nb_fd
= DEFAULT_UST_STREAM_FD_NUM
* ua_chan
->expected_stream_count
;
1821 /* Reserve the amount of file descriptor we need. */
1822 ret
= lttng_fd_get(LTTNG_FD_APPS
, nb_fd
);
1824 ERR("Exhausted number of available FD upon create channel");
1825 goto error_fd_get_stream
;
1828 health_code_update();
1831 * Now get the channel from the consumer. This call wil populate the stream
1832 * list of that channel and set the ust objects.
1834 ret
= ust_consumer_get_channel(socket
, ua_chan
);
1843 lttng_fd_put(LTTNG_FD_APPS
, nb_fd
);
1844 error_fd_get_stream
:
1846 * Initiate a destroy channel on the consumer since we had an error
1847 * handling it on our side. The return value is of no importance since we
1848 * already have a ret value set by the previous error that we need to
1851 (void) ust_consumer_destroy_channel(socket
, ua_chan
);
1853 lttng_fd_put(LTTNG_FD_APPS
, 1);
1855 health_code_update();
1861 * Duplicate the ust data object of the ust app stream and save it in the
1862 * buffer registry stream.
1864 * Return 0 on success or else a negative value.
1866 static int duplicate_stream_object(struct buffer_reg_stream
*reg_stream
,
1867 struct ust_app_stream
*stream
)
1874 /* Reserve the amount of file descriptor we need. */
1875 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
1877 ERR("Exhausted number of available FD upon duplicate stream");
1881 /* Duplicate object for stream once the original is in the registry. */
1882 ret
= ustctl_duplicate_ust_object_data(&stream
->obj
,
1883 reg_stream
->obj
.ust
);
1885 ERR("Duplicate stream obj from %p to %p failed with ret %d",
1886 reg_stream
->obj
.ust
, stream
->obj
, ret
);
1887 lttng_fd_put(LTTNG_FD_APPS
, 2);
1890 stream
->handle
= stream
->obj
->handle
;
1897 * Duplicate the ust data object of the ust app. channel and save it in the
1898 * buffer registry channel.
1900 * Return 0 on success or else a negative value.
1902 static int duplicate_channel_object(struct buffer_reg_channel
*reg_chan
,
1903 struct ust_app_channel
*ua_chan
)
1910 /* Need two fds for the channel. */
1911 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
1913 ERR("Exhausted number of available FD upon duplicate channel");
1917 /* Duplicate object for stream once the original is in the registry. */
1918 ret
= ustctl_duplicate_ust_object_data(&ua_chan
->obj
, reg_chan
->obj
.ust
);
1920 ERR("Duplicate channel obj from %p to %p failed with ret: %d",
1921 reg_chan
->obj
.ust
, ua_chan
->obj
, ret
);
1924 ua_chan
->handle
= ua_chan
->obj
->handle
;
1929 lttng_fd_put(LTTNG_FD_APPS
, 1);
1935 * For a given channel buffer registry, setup all streams of the given ust
1936 * application channel.
1938 * Return 0 on success or else a negative value.
1940 static int setup_buffer_reg_streams(struct buffer_reg_channel
*reg_chan
,
1941 struct ust_app_channel
*ua_chan
)
1944 struct ust_app_stream
*stream
, *stmp
;
1949 DBG2("UST app setup buffer registry stream");
1951 /* Send all streams to application. */
1952 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
1953 struct buffer_reg_stream
*reg_stream
;
1955 ret
= buffer_reg_stream_create(®_stream
);
1961 * Keep original pointer and nullify it in the stream so the delete
1962 * stream call does not release the object.
1964 reg_stream
->obj
.ust
= stream
->obj
;
1966 buffer_reg_stream_add(reg_stream
, reg_chan
);
1968 /* We don't need the streams anymore. */
1969 cds_list_del(&stream
->list
);
1970 delete_ust_app_stream(-1, stream
);
1978 * Create a buffer registry channel for the given session registry and
1979 * application channel object. If regp pointer is valid, it's set with the
1980 * created object. Important, the created object is NOT added to the session
1981 * registry hash table.
1983 * Return 0 on success else a negative value.
1985 static int create_buffer_reg_channel(struct buffer_reg_session
*reg_sess
,
1986 struct ust_app_channel
*ua_chan
, struct buffer_reg_channel
**regp
)
1989 struct buffer_reg_channel
*reg_chan
= NULL
;
1994 DBG2("UST app creating buffer registry channel for %s", ua_chan
->name
);
1996 /* Create buffer registry channel. */
1997 ret
= buffer_reg_channel_create(ua_chan
->tracing_channel_id
, ®_chan
);
2002 reg_chan
->consumer_key
= ua_chan
->key
;
2004 /* Create and add a channel registry to session. */
2005 ret
= ust_registry_channel_add(reg_sess
->reg
.ust
,
2006 ua_chan
->tracing_channel_id
);
2010 buffer_reg_channel_add(reg_sess
, reg_chan
);
2019 /* Safe because the registry channel object was not added to any HT. */
2020 buffer_reg_channel_destroy(reg_chan
, LTTNG_DOMAIN_UST
);
2026 * Setup buffer registry channel for the given session registry and application
2027 * channel object. If regp pointer is valid, it's set with the created object.
2029 * Return 0 on success else a negative value.
2031 static int setup_buffer_reg_channel(struct buffer_reg_session
*reg_sess
,
2032 struct ust_app_channel
*ua_chan
, struct buffer_reg_channel
*reg_chan
)
2039 assert(ua_chan
->obj
);
2041 DBG2("UST app setup buffer registry channel for %s", ua_chan
->name
);
2043 /* Setup all streams for the registry. */
2044 ret
= setup_buffer_reg_streams(reg_chan
, ua_chan
);
2049 reg_chan
->obj
.ust
= ua_chan
->obj
;
2050 ua_chan
->obj
= NULL
;
2055 buffer_reg_channel_remove(reg_sess
, reg_chan
);
2056 buffer_reg_channel_destroy(reg_chan
, LTTNG_DOMAIN_UST
);
2061 * Send buffer registry channel to the application.
2063 * Return 0 on success else a negative value.
2065 static int send_channel_uid_to_ust(struct buffer_reg_channel
*reg_chan
,
2066 struct ust_app
*app
, struct ust_app_session
*ua_sess
,
2067 struct ust_app_channel
*ua_chan
)
2070 struct buffer_reg_stream
*reg_stream
;
2077 DBG("UST app sending buffer registry channel to ust sock %d", app
->sock
);
2079 ret
= duplicate_channel_object(reg_chan
, ua_chan
);
2084 /* Send channel to the application. */
2085 ret
= ust_consumer_send_channel_to_ust(app
, ua_sess
, ua_chan
);
2090 health_code_update();
2092 /* Send all streams to application. */
2093 pthread_mutex_lock(®_chan
->stream_list_lock
);
2094 cds_list_for_each_entry(reg_stream
, ®_chan
->streams
, lnode
) {
2095 struct ust_app_stream stream
;
2097 ret
= duplicate_stream_object(reg_stream
, &stream
);
2099 goto error_stream_unlock
;
2102 ret
= ust_consumer_send_stream_to_ust(app
, ua_chan
, &stream
);
2104 goto error_stream_unlock
;
2108 * The return value is not important here. This function will output an
2111 (void) release_ust_app_stream(-1, &stream
);
2113 ua_chan
->is_sent
= 1;
2115 error_stream_unlock
:
2116 pthread_mutex_unlock(®_chan
->stream_list_lock
);
2122 * Create and send to the application the created buffers with per UID buffers.
2124 * Return 0 on success else a negative value.
2126 static int create_channel_per_uid(struct ust_app
*app
,
2127 struct ltt_ust_session
*usess
, struct ust_app_session
*ua_sess
,
2128 struct ust_app_channel
*ua_chan
)
2131 struct buffer_reg_uid
*reg_uid
;
2132 struct buffer_reg_channel
*reg_chan
;
2139 DBG("UST app creating channel %s with per UID buffers", ua_chan
->name
);
2141 reg_uid
= buffer_reg_uid_find(usess
->id
, app
->bits_per_long
, app
->uid
);
2143 * The session creation handles the creation of this global registry
2144 * object. If none can be find, there is a code flow problem or a
2149 reg_chan
= buffer_reg_channel_find(ua_chan
->tracing_channel_id
,
2152 /* Create the buffer registry channel object. */
2153 ret
= create_buffer_reg_channel(reg_uid
->registry
, ua_chan
, ®_chan
);
2160 * Create the buffers on the consumer side. This call populates the
2161 * ust app channel object with all streams and data object.
2163 ret
= do_consumer_create_channel(usess
, ua_sess
, ua_chan
,
2164 app
->bits_per_long
, reg_uid
->registry
->reg
.ust
);
2170 * Setup the streams and add it to the session registry.
2172 ret
= setup_buffer_reg_channel(reg_uid
->registry
, ua_chan
, reg_chan
);
2179 /* Send buffers to the application. */
2180 ret
= send_channel_uid_to_ust(reg_chan
, app
, ua_sess
, ua_chan
);
2190 * Create and send to the application the created buffers with per PID buffers.
2192 * Return 0 on success else a negative value.
2194 static int create_channel_per_pid(struct ust_app
*app
,
2195 struct ltt_ust_session
*usess
, struct ust_app_session
*ua_sess
,
2196 struct ust_app_channel
*ua_chan
)
2199 struct ust_registry_session
*registry
;
2206 DBG("UST app creating channel %s with per PID buffers", ua_chan
->name
);
2210 registry
= get_session_registry(ua_sess
);
2213 /* Create and add a new channel registry to session. */
2214 ret
= ust_registry_channel_add(registry
, ua_chan
->key
);
2219 /* Create and get channel on the consumer side. */
2220 ret
= do_consumer_create_channel(usess
, ua_sess
, ua_chan
,
2221 app
->bits_per_long
, registry
);
2226 ret
= send_channel_pid_to_ust(app
, ua_sess
, ua_chan
);
2237 * From an already allocated ust app channel, create the channel buffers if
2238 * need and send it to the application. This MUST be called with a RCU read
2239 * side lock acquired.
2241 * Return 0 on success or else a negative value.
2243 static int do_create_channel(struct ust_app
*app
,
2244 struct ltt_ust_session
*usess
, struct ust_app_session
*ua_sess
,
2245 struct ust_app_channel
*ua_chan
)
2254 /* Handle buffer type before sending the channel to the application. */
2255 switch (usess
->buffer_type
) {
2256 case LTTNG_BUFFER_PER_UID
:
2258 ret
= create_channel_per_uid(app
, usess
, ua_sess
, ua_chan
);
2264 case LTTNG_BUFFER_PER_PID
:
2266 ret
= create_channel_per_pid(app
, usess
, ua_sess
, ua_chan
);
2278 /* Initialize ust objd object using the received handle and add it. */
2279 lttng_ht_node_init_ulong(&ua_chan
->ust_objd_node
, ua_chan
->handle
);
2280 lttng_ht_add_unique_ulong(app
->ust_objd
, &ua_chan
->ust_objd_node
);
2282 /* If channel is not enabled, disable it on the tracer */
2283 if (!ua_chan
->enabled
) {
2284 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
2295 * Create UST app channel and create it on the tracer. Set ua_chanp of the
2296 * newly created channel if not NULL.
2298 * Called with UST app session lock held.
2300 * Return 0 on success or else a negative value.
2302 static int create_ust_app_channel(struct ust_app_session
*ua_sess
,
2303 struct ltt_ust_channel
*uchan
, struct ust_app
*app
,
2304 enum lttng_ust_chan_type type
, struct ltt_ust_session
*usess
,
2305 struct ust_app_channel
**ua_chanp
)
2308 struct lttng_ht_iter iter
;
2309 struct lttng_ht_node_str
*ua_chan_node
;
2310 struct ust_app_channel
*ua_chan
;
2312 /* Lookup channel in the ust app session */
2313 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2314 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2315 if (ua_chan_node
!= NULL
) {
2316 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2320 ua_chan
= alloc_ust_app_channel(uchan
->name
, ua_sess
, &uchan
->attr
);
2321 if (ua_chan
== NULL
) {
2322 /* Only malloc can fail here */
2326 shadow_copy_channel(ua_chan
, uchan
);
2328 /* Set channel type. */
2329 ua_chan
->attr
.type
= type
;
2331 ret
= do_create_channel(app
, usess
, ua_sess
, ua_chan
);
2336 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
2339 /* Only add the channel if successful on the tracer side. */
2340 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
2344 *ua_chanp
= ua_chan
;
2347 /* Everything went well. */
2351 delete_ust_app_channel(ua_chan
->is_sent
? app
->sock
: -1, ua_chan
, app
);
2356 * Create UST app event and create it on the tracer side.
2358 * Called with ust app session mutex held.
2361 int create_ust_app_event(struct ust_app_session
*ua_sess
,
2362 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
2363 struct ust_app
*app
)
2366 struct ust_app_event
*ua_event
;
2368 /* Get event node */
2369 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
2370 uevent
->filter
, uevent
->attr
.loglevel
);
2371 if (ua_event
!= NULL
) {
2376 /* Does not exist so create one */
2377 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
2378 if (ua_event
== NULL
) {
2379 /* Only malloc can failed so something is really wrong */
2383 shadow_copy_event(ua_event
, uevent
);
2385 /* Create it on the tracer side */
2386 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2388 /* Not found previously means that it does not exist on the tracer */
2389 assert(ret
!= -LTTNG_UST_ERR_EXIST
);
2393 add_unique_ust_app_event(ua_chan
, ua_event
);
2395 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
2402 /* Valid. Calling here is already in a read side lock */
2403 delete_ust_app_event(-1, ua_event
);
2408 * Create UST metadata and open it on the tracer side.
2410 * Called with UST app session lock held and RCU read side lock.
2412 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
2413 struct ust_app
*app
, struct consumer_output
*consumer
)
2416 struct ust_app_channel
*metadata
;
2417 struct consumer_socket
*socket
;
2418 struct ust_registry_session
*registry
;
2424 registry
= get_session_registry(ua_sess
);
2427 /* Metadata already exists for this registry. */
2428 if (registry
->metadata_key
) {
2433 /* Allocate UST metadata */
2434 metadata
= alloc_ust_app_channel(DEFAULT_METADATA_NAME
, ua_sess
, NULL
);
2436 /* malloc() failed */
2441 /* Set default attributes for metadata. */
2442 metadata
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
2443 metadata
->attr
.subbuf_size
= default_get_metadata_subbuf_size();
2444 metadata
->attr
.num_subbuf
= DEFAULT_METADATA_SUBBUF_NUM
;
2445 metadata
->attr
.switch_timer_interval
= DEFAULT_UST_CHANNEL_SWITCH_TIMER
;
2446 metadata
->attr
.read_timer_interval
= DEFAULT_UST_CHANNEL_READ_TIMER
;
2447 metadata
->attr
.output
= LTTNG_UST_MMAP
;
2448 metadata
->attr
.type
= LTTNG_UST_CHAN_METADATA
;
2450 /* Get the right consumer socket for the application. */
2451 socket
= consumer_find_socket_by_bitness(app
->bits_per_long
, consumer
);
2454 goto error_consumer
;
2457 /* Need one fd for the channel. */
2458 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
2460 ERR("Exhausted number of available FD upon create metadata");
2465 * Ask the metadata channel creation to the consumer. The metadata object
2466 * will be created by the consumer and kept their. However, the stream is
2467 * never added or monitored until we do a first push metadata to the
2470 ret
= ust_consumer_ask_channel(ua_sess
, metadata
, consumer
, socket
,
2474 * Safe because the metadata obj pointer is not set so the delete below
2475 * will not put a FD back again.
2477 lttng_fd_put(LTTNG_FD_APPS
, 1);
2478 goto error_consumer
;
2482 * The setup command will make the metadata stream be sent to the relayd,
2483 * if applicable, and the thread managing the metadatas. This is important
2484 * because after this point, if an error occurs, the only way the stream
2485 * can be deleted is to be monitored in the consumer.
2487 ret
= consumer_setup_metadata(socket
, metadata
->key
);
2490 * Safe because the metadata obj pointer is not set so the delete below
2491 * will not put a FD back again.
2493 lttng_fd_put(LTTNG_FD_APPS
, 1);
2494 goto error_consumer
;
2497 /* Keep metadata key so we can identify it on the consumer side. */
2498 registry
->metadata_key
= metadata
->key
;
2500 DBG2("UST metadata with key %" PRIu64
" created for app pid %d",
2501 metadata
->key
, app
->pid
);
2504 delete_ust_app_channel(-1, metadata
, app
);
2510 * Return pointer to traceable apps list.
2512 struct lttng_ht
*ust_app_get_ht(void)
2518 * Return ust app pointer or NULL if not found. RCU read side lock MUST be
2519 * acquired before calling this function.
2521 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
2523 struct ust_app
*app
= NULL
;
2524 struct lttng_ht_node_ulong
*node
;
2525 struct lttng_ht_iter iter
;
2527 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
2528 node
= lttng_ht_iter_get_node_ulong(&iter
);
2530 DBG2("UST app no found with pid %d", pid
);
2534 DBG2("Found UST app by pid %d", pid
);
2536 app
= caa_container_of(node
, struct ust_app
, pid_n
);
2543 * Allocate and init an UST app object using the registration information and
2544 * the command socket. This is called when the command socket connects to the
2547 * The object is returned on success or else NULL.
2549 struct ust_app
*ust_app_create(struct ust_register_msg
*msg
, int sock
)
2551 struct ust_app
*lta
= NULL
;
2556 DBG3("UST app creating application for socket %d", sock
);
2558 if ((msg
->bits_per_long
== 64 &&
2559 (uatomic_read(&ust_consumerd64_fd
) == -EINVAL
))
2560 || (msg
->bits_per_long
== 32 &&
2561 (uatomic_read(&ust_consumerd32_fd
) == -EINVAL
))) {
2562 ERR("Registration failed: application \"%s\" (pid: %d) has "
2563 "%d-bit long, but no consumerd for this size is available.\n",
2564 msg
->name
, msg
->pid
, msg
->bits_per_long
);
2568 lta
= zmalloc(sizeof(struct ust_app
));
2574 lta
->ppid
= msg
->ppid
;
2575 lta
->uid
= msg
->uid
;
2576 lta
->gid
= msg
->gid
;
2578 lta
->bits_per_long
= msg
->bits_per_long
;
2579 lta
->uint8_t_alignment
= msg
->uint8_t_alignment
;
2580 lta
->uint16_t_alignment
= msg
->uint16_t_alignment
;
2581 lta
->uint32_t_alignment
= msg
->uint32_t_alignment
;
2582 lta
->uint64_t_alignment
= msg
->uint64_t_alignment
;
2583 lta
->long_alignment
= msg
->long_alignment
;
2584 lta
->byte_order
= msg
->byte_order
;
2586 lta
->v_major
= msg
->major
;
2587 lta
->v_minor
= msg
->minor
;
2588 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2589 lta
->ust_objd
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2590 lta
->notify_sock
= -1;
2592 /* Copy name and make sure it's NULL terminated. */
2593 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
2594 lta
->name
[UST_APP_PROCNAME_LEN
] = '\0';
2597 * Before this can be called, when receiving the registration information,
2598 * the application compatibility is checked. So, at this point, the
2599 * application can work with this session daemon.
2601 lta
->compatible
= 1;
2603 lta
->pid
= msg
->pid
;
2604 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long) lta
->pid
);
2606 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long) lta
->sock
);
2608 CDS_INIT_LIST_HEAD(<a
->teardown_head
);
2615 * For a given application object, add it to every hash table.
2617 void ust_app_add(struct ust_app
*app
)
2620 assert(app
->notify_sock
>= 0);
2625 * On a re-registration, we want to kick out the previous registration of
2628 lttng_ht_add_replace_ulong(ust_app_ht
, &app
->pid_n
);
2631 * The socket _should_ be unique until _we_ call close. So, a add_unique
2632 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
2633 * already in the table.
2635 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, &app
->sock_n
);
2637 /* Add application to the notify socket hash table. */
2638 lttng_ht_node_init_ulong(&app
->notify_sock_n
, app
->notify_sock
);
2639 lttng_ht_add_unique_ulong(ust_app_ht_by_notify_sock
, &app
->notify_sock_n
);
2641 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s "
2642 "notify_sock:%d (version %d.%d)", app
->pid
, app
->ppid
, app
->uid
,
2643 app
->gid
, app
->sock
, app
->name
, app
->notify_sock
, app
->v_major
,
2650 * Set the application version into the object.
2652 * Return 0 on success else a negative value either an errno code or a
2653 * LTTng-UST error code.
2655 int ust_app_version(struct ust_app
*app
)
2661 ret
= ustctl_tracer_version(app
->sock
, &app
->version
);
2663 if (ret
!= -LTTNG_UST_ERR_EXITING
&& ret
!= -EPIPE
) {
2664 ERR("UST app %d verson failed with ret %d", app
->sock
, ret
);
2666 DBG3("UST app %d verion failed. Application is dead", app
->sock
);
2674 * Unregister app by removing it from the global traceable app list and freeing
2677 * The socket is already closed at this point so no close to sock.
2679 void ust_app_unregister(int sock
)
2681 struct ust_app
*lta
;
2682 struct lttng_ht_node_ulong
*node
;
2683 struct lttng_ht_iter iter
;
2684 struct ust_app_session
*ua_sess
;
2689 /* Get the node reference for a call_rcu */
2690 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
2691 node
= lttng_ht_iter_get_node_ulong(&iter
);
2694 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
2695 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
2697 /* Remove application from PID hash table */
2698 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
2702 * Remove application from notify hash table. The thread handling the
2703 * notify socket could have deleted the node so ignore on error because
2704 * either way it's valid. The close of that socket is handled by the other
2707 iter
.iter
.node
= <a
->notify_sock_n
.node
;
2708 (void) lttng_ht_del(ust_app_ht_by_notify_sock
, &iter
);
2711 * Ignore return value since the node might have been removed before by an
2712 * add replace during app registration because the PID can be reassigned by
2715 iter
.iter
.node
= <a
->pid_n
.node
;
2716 ret
= lttng_ht_del(ust_app_ht
, &iter
);
2718 DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
2722 /* Remove sessions so they are not visible during deletion.*/
2723 cds_lfht_for_each_entry(lta
->sessions
->ht
, &iter
.iter
, ua_sess
,
2725 struct ust_registry_session
*registry
;
2727 ret
= lttng_ht_del(lta
->sessions
, &iter
);
2729 /* The session was already removed so scheduled for teardown. */
2734 * Add session to list for teardown. This is safe since at this point we
2735 * are the only one using this list.
2737 pthread_mutex_lock(&ua_sess
->lock
);
2740 * Normally, this is done in the delete session process which is
2741 * executed in the call rcu below. However, upon registration we can't
2742 * afford to wait for the grace period before pushing data or else the
2743 * data pending feature can race between the unregistration and stop
2744 * command where the data pending command is sent *before* the grace
2747 * The close metadata below nullifies the metadata pointer in the
2748 * session so the delete session will NOT push/close a second time.
2750 registry
= get_session_registry(ua_sess
);
2752 /* Push metadata for application before freeing the application. */
2753 (void) push_metadata(registry
, ua_sess
->consumer
);
2756 * Don't ask to close metadata for global per UID buffers. Close
2757 * metadata only on destroy trace session in this case.
2759 if (ua_sess
->buffer_type
!= LTTNG_BUFFER_PER_UID
) {
2760 /* And ask to close it for this session registry. */
2761 (void) close_metadata(registry
, ua_sess
->consumer
);
2765 cds_list_add(&ua_sess
->teardown_node
, <a
->teardown_head
);
2766 pthread_mutex_unlock(&ua_sess
->lock
);
2770 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
2777 * Return traceable_app_count
2779 unsigned long ust_app_list_count(void)
2781 unsigned long count
;
2784 count
= lttng_ht_get_count(ust_app_ht
);
2791 * Fill events array with all events name of all registered apps.
2793 int ust_app_list_events(struct lttng_event
**events
)
2796 size_t nbmem
, count
= 0;
2797 struct lttng_ht_iter iter
;
2798 struct ust_app
*app
;
2799 struct lttng_event
*tmp_event
;
2801 nbmem
= UST_APP_EVENT_LIST_SIZE
;
2802 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event
));
2803 if (tmp_event
== NULL
) {
2804 PERROR("zmalloc ust app events");
2811 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2812 struct lttng_ust_tracepoint_iter uiter
;
2814 health_code_update();
2816 if (!app
->compatible
) {
2818 * TODO: In time, we should notice the caller of this error by
2819 * telling him that this is a version error.
2823 handle
= ustctl_tracepoint_list(app
->sock
);
2825 if (handle
!= -EPIPE
&& handle
!= -LTTNG_UST_ERR_EXITING
) {
2826 ERR("UST app list events getting handle failed for app pid %d",
2832 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
2833 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
2834 /* Handle ustctl error. */
2837 if (ret
!= -LTTNG_UST_ERR_EXITING
|| ret
!= -EPIPE
) {
2838 ERR("UST app tp list get failed for app %d with ret %d",
2841 DBG3("UST app tp list get failed. Application is dead");
2846 health_code_update();
2847 if (count
>= nbmem
) {
2848 /* In case the realloc fails, we free the memory */
2851 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
2854 ptr
= realloc(tmp_event
, nbmem
* sizeof(struct lttng_event
));
2856 PERROR("realloc ust app events");
2863 memcpy(tmp_event
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
2864 tmp_event
[count
].loglevel
= uiter
.loglevel
;
2865 tmp_event
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
2866 tmp_event
[count
].pid
= app
->pid
;
2867 tmp_event
[count
].enabled
= -1;
2873 *events
= tmp_event
;
2875 DBG2("UST app list events done (%zu events)", count
);
2880 health_code_update();
2885 * Fill events array with all events name of all registered apps.
2887 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
2890 size_t nbmem
, count
= 0;
2891 struct lttng_ht_iter iter
;
2892 struct ust_app
*app
;
2893 struct lttng_event_field
*tmp_event
;
2895 nbmem
= UST_APP_EVENT_LIST_SIZE
;
2896 tmp_event
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
2897 if (tmp_event
== NULL
) {
2898 PERROR("zmalloc ust app event fields");
2905 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2906 struct lttng_ust_field_iter uiter
;
2908 health_code_update();
2910 if (!app
->compatible
) {
2912 * TODO: In time, we should notice the caller of this error by
2913 * telling him that this is a version error.
2917 handle
= ustctl_tracepoint_field_list(app
->sock
);
2919 if (handle
!= -EPIPE
&& handle
!= -LTTNG_UST_ERR_EXITING
) {
2920 ERR("UST app list field getting handle failed for app pid %d",
2926 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
2927 &uiter
)) != -LTTNG_UST_ERR_NOENT
) {
2928 /* Handle ustctl error. */
2931 if (ret
!= -LTTNG_UST_ERR_EXITING
|| ret
!= -EPIPE
) {
2932 ERR("UST app tp list field failed for app %d with ret %d",
2935 DBG3("UST app tp list field failed. Application is dead");
2940 health_code_update();
2941 if (count
>= nbmem
) {
2942 /* In case the realloc fails, we free the memory */
2945 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
2948 ptr
= realloc(tmp_event
, nbmem
* sizeof(struct lttng_event_field
));
2950 PERROR("realloc ust app event fields");
2958 memcpy(tmp_event
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
2959 tmp_event
[count
].type
= uiter
.type
;
2960 tmp_event
[count
].nowrite
= uiter
.nowrite
;
2962 memcpy(tmp_event
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
2963 tmp_event
[count
].event
.loglevel
= uiter
.loglevel
;
2964 tmp_event
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
2965 tmp_event
[count
].event
.pid
= app
->pid
;
2966 tmp_event
[count
].event
.enabled
= -1;
2972 *fields
= tmp_event
;
2974 DBG2("UST app list event fields done (%zu events)", count
);
2979 health_code_update();
2984 * Free and clean all traceable apps of the global list.
2986 void ust_app_clean_list(void)
2989 struct ust_app
*app
;
2990 struct lttng_ht_iter iter
;
2992 DBG2("UST app cleaning registered apps hash table");
2996 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2997 ret
= lttng_ht_del(ust_app_ht
, &iter
);
2999 call_rcu(&app
->pid_n
.head
, delete_ust_app_rcu
);
3002 /* Cleanup socket hash table */
3003 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, app
,
3005 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
3009 /* Cleanup notify socket hash table */
3010 cds_lfht_for_each_entry(ust_app_ht_by_notify_sock
->ht
, &iter
.iter
, app
,
3011 notify_sock_n
.node
) {
3012 ret
= lttng_ht_del(ust_app_ht_by_notify_sock
, &iter
);
3016 /* Destroy is done only when the ht is empty */
3017 lttng_ht_destroy(ust_app_ht
);
3018 lttng_ht_destroy(ust_app_ht_by_sock
);
3019 lttng_ht_destroy(ust_app_ht_by_notify_sock
);
3025 * Init UST app hash table.
3027 void ust_app_ht_alloc(void)
3029 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3030 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3031 ust_app_ht_by_notify_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
3035 * For a specific UST session, disable the channel for all registered apps.
3037 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
3038 struct ltt_ust_channel
*uchan
)
3041 struct lttng_ht_iter iter
;
3042 struct lttng_ht_node_str
*ua_chan_node
;
3043 struct ust_app
*app
;
3044 struct ust_app_session
*ua_sess
;
3045 struct ust_app_channel
*ua_chan
;
3047 if (usess
== NULL
|| uchan
== NULL
) {
3048 ERR("Disabling UST global channel with NULL values");
3053 DBG2("UST app disabling channel %s from global domain for session id %d",
3054 uchan
->name
, usess
->id
);
3058 /* For every registered applications */
3059 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3060 struct lttng_ht_iter uiter
;
3061 if (!app
->compatible
) {
3063 * TODO: In time, we should notice the caller of this error by
3064 * telling him that this is a version error.
3068 ua_sess
= lookup_session_by_app(usess
, app
);
3069 if (ua_sess
== NULL
) {
3074 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3075 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3076 /* If the session if found for the app, the channel must be there */
3077 assert(ua_chan_node
);
3079 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3080 /* The channel must not be already disabled */
3081 assert(ua_chan
->enabled
== 1);
3083 /* Disable channel onto application */
3084 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
3086 /* XXX: We might want to report this error at some point... */
3098 * For a specific UST session, enable the channel for all registered apps.
3100 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
3101 struct ltt_ust_channel
*uchan
)
3104 struct lttng_ht_iter iter
;
3105 struct ust_app
*app
;
3106 struct ust_app_session
*ua_sess
;
3108 if (usess
== NULL
|| uchan
== NULL
) {
3109 ERR("Adding UST global channel to NULL values");
3114 DBG2("UST app enabling channel %s to global domain for session id %d",
3115 uchan
->name
, usess
->id
);
3119 /* For every registered applications */
3120 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3121 if (!app
->compatible
) {
3123 * TODO: In time, we should notice the caller of this error by
3124 * telling him that this is a version error.
3128 ua_sess
= lookup_session_by_app(usess
, app
);
3129 if (ua_sess
== NULL
) {
3133 /* Enable channel onto application */
3134 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
3136 /* XXX: We might want to report this error at some point... */
3148 * Disable an event in a channel and for a specific session.
3150 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
3151 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
3154 struct lttng_ht_iter iter
, uiter
;
3155 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
3156 struct ust_app
*app
;
3157 struct ust_app_session
*ua_sess
;
3158 struct ust_app_channel
*ua_chan
;
3159 struct ust_app_event
*ua_event
;
3161 DBG("UST app disabling event %s for all apps in channel "
3162 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
3166 /* For all registered applications */
3167 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3168 if (!app
->compatible
) {
3170 * TODO: In time, we should notice the caller of this error by
3171 * telling him that this is a version error.
3175 ua_sess
= lookup_session_by_app(usess
, app
);
3176 if (ua_sess
== NULL
) {
3181 /* Lookup channel in the ust app session */
3182 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3183 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3184 if (ua_chan_node
== NULL
) {
3185 DBG2("Channel %s not found in session id %d for app pid %d."
3186 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
3189 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3191 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
3192 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
3193 if (ua_event_node
== NULL
) {
3194 DBG2("Event %s not found in channel %s for app pid %d."
3195 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
3198 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
3200 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
3202 /* XXX: Report error someday... */
3213 * For a specific UST session and UST channel, the event for all
3216 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
3217 struct ltt_ust_channel
*uchan
)
3220 struct lttng_ht_iter iter
, uiter
;
3221 struct lttng_ht_node_str
*ua_chan_node
;
3222 struct ust_app
*app
;
3223 struct ust_app_session
*ua_sess
;
3224 struct ust_app_channel
*ua_chan
;
3225 struct ust_app_event
*ua_event
;
3227 DBG("UST app disabling all event for all apps in channel "
3228 "%s for session id %d", uchan
->name
, usess
->id
);
3232 /* For all registered applications */
3233 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3234 if (!app
->compatible
) {
3236 * TODO: In time, we should notice the caller of this error by
3237 * telling him that this is a version error.
3241 ua_sess
= lookup_session_by_app(usess
, app
);
3243 /* The application has problem or is probably dead. */
3247 /* Lookup channel in the ust app session */
3248 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3249 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3250 /* If the channel is not found, there is a code flow error */
3251 assert(ua_chan_node
);
3253 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3255 /* Disable each events of channel */
3256 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
3258 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
3260 /* XXX: Report error someday... */
3272 * For a specific UST session, create the channel for all registered apps.
3274 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
3275 struct ltt_ust_channel
*uchan
)
3277 int ret
= 0, created
;
3278 struct lttng_ht_iter iter
;
3279 struct ust_app
*app
;
3280 struct ust_app_session
*ua_sess
= NULL
;
3282 /* Very wrong code flow */
3286 DBG2("UST app adding channel %s to UST domain for session id %d",
3287 uchan
->name
, usess
->id
);
3291 /* For every registered applications */
3292 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3293 if (!app
->compatible
) {
3295 * TODO: In time, we should notice the caller of this error by
3296 * telling him that this is a version error.
3301 * Create session on the tracer side and add it to app session HT. Note
3302 * that if session exist, it will simply return a pointer to the ust
3305 ret
= create_ust_app_session(usess
, app
, &ua_sess
, &created
);
3310 * The application's socket is not valid. Either a bad socket
3311 * or a timeout on it. We can't inform the caller that for a
3312 * specific app, the session failed so lets continue here.
3317 goto error_rcu_unlock
;
3322 pthread_mutex_lock(&ua_sess
->lock
);
3323 /* Create channel onto application. We don't need the chan ref. */
3324 ret
= create_ust_app_channel(ua_sess
, uchan
, app
,
3325 LTTNG_UST_CHAN_PER_CPU
, usess
, NULL
);
3326 pthread_mutex_unlock(&ua_sess
->lock
);
3328 if (ret
== -ENOMEM
) {
3329 /* No more memory is a fatal error. Stop right now. */
3330 goto error_rcu_unlock
;
3332 /* Cleanup the created session if it's the case. */
3334 destroy_app_session(app
, ua_sess
);
3345 * Enable event for a specific session and channel on the tracer.
3347 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
3348 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
3351 struct lttng_ht_iter iter
, uiter
;
3352 struct lttng_ht_node_str
*ua_chan_node
;
3353 struct ust_app
*app
;
3354 struct ust_app_session
*ua_sess
;
3355 struct ust_app_channel
*ua_chan
;
3356 struct ust_app_event
*ua_event
;
3358 DBG("UST app enabling event %s for all apps for session id %d",
3359 uevent
->attr
.name
, usess
->id
);
3362 * NOTE: At this point, this function is called only if the session and
3363 * channel passed are already created for all apps. and enabled on the
3369 /* For all registered applications */
3370 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3371 if (!app
->compatible
) {
3373 * TODO: In time, we should notice the caller of this error by
3374 * telling him that this is a version error.
3378 ua_sess
= lookup_session_by_app(usess
, app
);
3380 /* The application has problem or is probably dead. */
3384 pthread_mutex_lock(&ua_sess
->lock
);
3386 /* Lookup channel in the ust app session */
3387 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3388 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3389 /* If the channel is not found, there is a code flow error */
3390 assert(ua_chan_node
);
3392 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3394 /* Get event node */
3395 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
3396 uevent
->filter
, uevent
->attr
.loglevel
);
3397 if (ua_event
== NULL
) {
3398 DBG3("UST app enable event %s not found for app PID %d."
3399 "Skipping app", uevent
->attr
.name
, app
->pid
);
3403 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
3405 pthread_mutex_unlock(&ua_sess
->lock
);
3409 pthread_mutex_unlock(&ua_sess
->lock
);
3418 * For a specific existing UST session and UST channel, creates the event for
3419 * all registered apps.
3421 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
3422 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
3425 struct lttng_ht_iter iter
, uiter
;
3426 struct lttng_ht_node_str
*ua_chan_node
;
3427 struct ust_app
*app
;
3428 struct ust_app_session
*ua_sess
;
3429 struct ust_app_channel
*ua_chan
;
3431 DBG("UST app creating event %s for all apps for session id %d",
3432 uevent
->attr
.name
, usess
->id
);
3436 /* For all registered applications */
3437 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3438 if (!app
->compatible
) {
3440 * TODO: In time, we should notice the caller of this error by
3441 * telling him that this is a version error.
3445 ua_sess
= lookup_session_by_app(usess
, app
);
3447 /* The application has problem or is probably dead. */
3451 pthread_mutex_lock(&ua_sess
->lock
);
3452 /* Lookup channel in the ust app session */
3453 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3454 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3455 /* If the channel is not found, there is a code flow error */
3456 assert(ua_chan_node
);
3458 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
3460 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
3461 pthread_mutex_unlock(&ua_sess
->lock
);
3463 if (ret
!= -LTTNG_UST_ERR_EXIST
) {
3464 /* Possible value at this point: -ENOMEM. If so, we stop! */
3467 DBG2("UST app event %s already exist on app PID %d",
3468 uevent
->attr
.name
, app
->pid
);
3479 * Start tracing for a specific UST session and app.
3481 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
3484 struct ust_app_session
*ua_sess
;
3486 DBG("Starting tracing for ust app pid %d", app
->pid
);
3490 if (!app
->compatible
) {
3494 ua_sess
= lookup_session_by_app(usess
, app
);
3495 if (ua_sess
== NULL
) {
3496 /* The session is in teardown process. Ignore and continue. */
3500 pthread_mutex_lock(&ua_sess
->lock
);
3502 /* Upon restart, we skip the setup, already done */
3503 if (ua_sess
->started
) {
3507 /* Create directories if consumer is LOCAL and has a path defined. */
3508 if (usess
->consumer
->type
== CONSUMER_DST_LOCAL
&&
3509 strlen(usess
->consumer
->dst
.trace_path
) > 0) {
3510 ret
= run_as_mkdir_recursive(usess
->consumer
->dst
.trace_path
,
3511 S_IRWXU
| S_IRWXG
, ua_sess
->euid
, ua_sess
->egid
);
3513 if (ret
!= -EEXIST
) {
3514 ERR("Trace directory creation error");
3520 /* Create the metadata for the application. */
3521 ret
= create_ust_app_metadata(ua_sess
, app
, usess
->consumer
);
3526 health_code_update();
3529 /* This start the UST tracing */
3530 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
3532 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
3533 ERR("Error starting tracing for app pid: %d (ret: %d)",
3536 DBG("UST app start session failed. Application is dead.");
3541 /* Indicate that the session has been started once */
3542 ua_sess
->started
= 1;
3544 pthread_mutex_unlock(&ua_sess
->lock
);
3546 health_code_update();
3548 /* Quiescent wait after starting trace */
3549 ret
= ustctl_wait_quiescent(app
->sock
);
3550 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
3551 ERR("UST app wait quiescent failed for app pid %d ret %d",
3557 health_code_update();
3561 pthread_mutex_unlock(&ua_sess
->lock
);
3563 health_code_update();
3568 * Stop tracing for a specific UST session and app.
3570 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
3573 struct lttng_ht_iter iter
;
3574 struct ust_app_session
*ua_sess
;
3575 struct ust_app_channel
*ua_chan
;
3576 struct ust_registry_session
*registry
;
3578 DBG("Stopping tracing for ust app pid %d", app
->pid
);
3582 if (!app
->compatible
) {
3583 goto end_no_session
;
3586 ua_sess
= lookup_session_by_app(usess
, app
);
3587 if (ua_sess
== NULL
) {
3588 goto end_no_session
;
3591 pthread_mutex_lock(&ua_sess
->lock
);
3594 * If started = 0, it means that stop trace has been called for a session
3595 * that was never started. It's possible since we can have a fail start
3596 * from either the application manager thread or the command thread. Simply
3597 * indicate that this is a stop error.
3599 if (!ua_sess
->started
) {
3600 goto error_rcu_unlock
;
3603 health_code_update();
3605 /* This inhibits UST tracing */
3606 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
3608 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
3609 ERR("Error stopping tracing for app pid: %d (ret: %d)",
3612 DBG("UST app stop session failed. Application is dead.");
3614 goto error_rcu_unlock
;
3617 health_code_update();
3619 /* Quiescent wait after stopping trace */
3620 ret
= ustctl_wait_quiescent(app
->sock
);
3621 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
3622 ERR("UST app wait quiescent failed for app pid %d ret %d",
3626 health_code_update();
3628 /* Flushing buffers */
3629 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
3631 health_code_update();
3632 assert(ua_chan
->is_sent
);
3633 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
3635 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
3636 ERR("UST app PID %d channel %s flush failed with ret %d",
3637 app
->pid
, ua_chan
->name
, ret
);
3639 DBG3("UST app failed to flush %s. Application is dead.",
3641 /* No need to continue. */
3644 /* Continuing flushing all buffers */
3649 health_code_update();
3651 registry
= get_session_registry(ua_sess
);
3653 /* Push metadata for application before freeing the application. */
3654 (void) push_metadata(registry
, ua_sess
->consumer
);
3656 pthread_mutex_unlock(&ua_sess
->lock
);
3659 health_code_update();
3663 pthread_mutex_unlock(&ua_sess
->lock
);
3665 health_code_update();
3670 * Destroy a specific UST session in apps.
3672 static int destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
3675 struct ust_app_session
*ua_sess
;
3676 struct lttng_ht_iter iter
;
3677 struct lttng_ht_node_ulong
*node
;
3679 DBG("Destroy tracing for ust app pid %d", app
->pid
);
3683 if (!app
->compatible
) {
3687 __lookup_session_by_app(usess
, app
, &iter
);
3688 node
= lttng_ht_iter_get_node_ulong(&iter
);
3690 /* Session is being or is deleted. */
3693 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
3695 health_code_update();
3696 destroy_app_session(app
, ua_sess
);
3698 health_code_update();
3700 /* Quiescent wait after stopping trace */
3701 ret
= ustctl_wait_quiescent(app
->sock
);
3702 if (ret
< 0 && ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
3703 ERR("UST app wait quiescent failed for app pid %d ret %d",
3708 health_code_update();
3713 * Start tracing for the UST session.
3715 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
3718 struct lttng_ht_iter iter
;
3719 struct ust_app
*app
;
3721 DBG("Starting all UST traces");
3725 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3726 ret
= ust_app_start_trace(usess
, app
);
3728 /* Continue to next apps even on error */
3739 * Start tracing for the UST session.
3741 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
3744 struct lttng_ht_iter iter
;
3745 struct ust_app
*app
;
3747 DBG("Stopping all UST traces");
3751 /* Flush all per UID buffers associated to that session. */
3752 if (usess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
3753 struct buffer_reg_uid
*reg
;
3754 cds_list_for_each_entry(reg
, &usess
->buffer_reg_uid_list
, lnode
) {
3755 struct buffer_reg_channel
*reg_chan
;
3756 struct consumer_socket
*socket
;
3758 /* Get consumer socket to use to push the metadata.*/
3759 socket
= consumer_find_socket_by_bitness(reg
->bits_per_long
,
3762 /* Ignore request if no consumer is found for the session. */
3766 cds_lfht_for_each_entry(reg
->registry
->channels
->ht
, &iter
.iter
,
3767 reg_chan
, node
.node
) {
3769 * The following call will print error values so the return
3770 * code is of little importance because whatever happens, we
3771 * have to try them all.
3773 (void) consumer_flush_channel(socket
, reg_chan
->consumer_key
);
3778 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3779 ret
= ust_app_stop_trace(usess
, app
);
3781 /* Continue to next apps even on error */
3792 * Destroy app UST session.
3794 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
3797 struct lttng_ht_iter iter
;
3798 struct ust_app
*app
;
3800 DBG("Destroy all UST traces");
3804 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3805 ret
= destroy_trace(usess
, app
);
3807 /* Continue to next apps even on error */
3818 * Add channels/events from UST global domain to registered apps at sock.
3820 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
3823 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
3824 struct ust_app
*app
;
3825 struct ust_app_session
*ua_sess
= NULL
;
3826 struct ust_app_channel
*ua_chan
;
3827 struct ust_app_event
*ua_event
;
3828 struct ust_app_ctx
*ua_ctx
;
3833 DBG2("UST app global update for app sock %d for session id %d", sock
,
3838 app
= find_app_by_sock(sock
);
3841 * Application can be unregistered before so this is possible hence
3842 * simply stopping the update.
3844 DBG3("UST app update failed to find app sock %d", sock
);
3848 if (!app
->compatible
) {
3852 ret
= create_ust_app_session(usess
, app
, &ua_sess
, NULL
);
3854 /* Tracer is probably gone or ENOMEM. */
3859 pthread_mutex_lock(&ua_sess
->lock
);
3862 * We can iterate safely here over all UST app session since the create ust
3863 * app session above made a shadow copy of the UST global domain from the
3866 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
3868 ret
= do_create_channel(app
, usess
, ua_sess
, ua_chan
);
3871 * Stop everything. On error, the application failed, no more file
3872 * descriptor are available or ENOMEM so stopping here is the only
3873 * thing we can do for now.
3878 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
3880 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
3887 /* For each events */
3888 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
3890 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
3897 pthread_mutex_unlock(&ua_sess
->lock
);
3899 if (usess
->start_trace
) {
3900 ret
= ust_app_start_trace(usess
, app
);
3905 DBG2("UST trace started for app pid %d", app
->pid
);
3908 /* Everything went well at this point. */
3913 pthread_mutex_unlock(&ua_sess
->lock
);
3916 destroy_app_session(app
, ua_sess
);
3923 * Add context to a specific channel for global UST domain.
3925 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
3926 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
3929 struct lttng_ht_node_str
*ua_chan_node
;
3930 struct lttng_ht_iter iter
, uiter
;
3931 struct ust_app_channel
*ua_chan
= NULL
;
3932 struct ust_app_session
*ua_sess
;
3933 struct ust_app
*app
;
3937 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
3938 if (!app
->compatible
) {
3940 * TODO: In time, we should notice the caller of this error by
3941 * telling him that this is a version error.
3945 ua_sess
= lookup_session_by_app(usess
, app
);
3946 if (ua_sess
== NULL
) {
3950 pthread_mutex_lock(&ua_sess
->lock
);
3951 /* Lookup channel in the ust app session */
3952 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
3953 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
3954 if (ua_chan_node
== NULL
) {
3957 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
3959 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
3964 pthread_mutex_unlock(&ua_sess
->lock
);
3972 * Enable event for a channel from a UST session for a specific PID.
3974 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
3975 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
3978 struct lttng_ht_iter iter
;
3979 struct lttng_ht_node_str
*ua_chan_node
;
3980 struct ust_app
*app
;
3981 struct ust_app_session
*ua_sess
;
3982 struct ust_app_channel
*ua_chan
;
3983 struct ust_app_event
*ua_event
;
3985 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
3989 app
= ust_app_find_by_pid(pid
);
3991 ERR("UST app enable event per PID %d not found", pid
);
3996 if (!app
->compatible
) {
4001 ua_sess
= lookup_session_by_app(usess
, app
);
4003 /* The application has problem or is probably dead. */
4008 pthread_mutex_lock(&ua_sess
->lock
);
4009 /* Lookup channel in the ust app session */
4010 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
4011 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
4012 /* If the channel is not found, there is a code flow error */
4013 assert(ua_chan_node
);
4015 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
4017 ua_event
= find_ust_app_event(ua_chan
->events
, uevent
->attr
.name
,
4018 uevent
->filter
, uevent
->attr
.loglevel
);
4019 if (ua_event
== NULL
) {
4020 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
4025 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
4032 pthread_mutex_unlock(&ua_sess
->lock
);
4039 * Disable event for a channel from a UST session for a specific PID.
4041 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
4042 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
4045 struct lttng_ht_iter iter
;
4046 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
4047 struct ust_app
*app
;
4048 struct ust_app_session
*ua_sess
;
4049 struct ust_app_channel
*ua_chan
;
4050 struct ust_app_event
*ua_event
;
4052 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
4056 app
= ust_app_find_by_pid(pid
);
4058 ERR("UST app disable event per PID %d not found", pid
);
4063 if (!app
->compatible
) {
4068 ua_sess
= lookup_session_by_app(usess
, app
);
4070 /* The application has problem or is probably dead. */
4074 /* Lookup channel in the ust app session */
4075 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
4076 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
4077 if (ua_chan_node
== NULL
) {
4078 /* Channel does not exist, skip disabling */
4081 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
4083 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
4084 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
4085 if (ua_event_node
== NULL
) {
4086 /* Event does not exist, skip disabling */
4089 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
4091 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
4102 * Calibrate registered applications.
4104 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
4107 struct lttng_ht_iter iter
;
4108 struct ust_app
*app
;
4112 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
4113 if (!app
->compatible
) {
4115 * TODO: In time, we should notice the caller of this error by
4116 * telling him that this is a version error.
4121 health_code_update();
4123 ret
= ustctl_calibrate(app
->sock
, calibrate
);
4127 /* Means that it's not implemented on the tracer side. */
4131 DBG2("Calibrate app PID %d returned with error %d",
4138 DBG("UST app global domain calibration finished");
4142 health_code_update();
4148 * Receive registration and populate the given msg structure.
4150 * On success return 0 else a negative value returned by the ustctl call.
4152 int ust_app_recv_registration(int sock
, struct ust_register_msg
*msg
)
4155 uint32_t pid
, ppid
, uid
, gid
;
4159 ret
= ustctl_recv_reg_msg(sock
, &msg
->type
, &msg
->major
, &msg
->minor
,
4160 &pid
, &ppid
, &uid
, &gid
,
4161 &msg
->bits_per_long
,
4162 &msg
->uint8_t_alignment
,
4163 &msg
->uint16_t_alignment
,
4164 &msg
->uint32_t_alignment
,
4165 &msg
->uint64_t_alignment
,
4166 &msg
->long_alignment
,
4173 case LTTNG_UST_ERR_EXITING
:
4174 DBG3("UST app recv reg message failed. Application died");
4176 case LTTNG_UST_ERR_UNSUP_MAJOR
:
4177 ERR("UST app recv reg unsupported version %d.%d. Supporting %d.%d",
4178 msg
->major
, msg
->minor
, LTTNG_UST_ABI_MAJOR_VERSION
,
4179 LTTNG_UST_ABI_MINOR_VERSION
);
4182 ERR("UST app recv reg message failed with ret %d", ret
);
4187 msg
->pid
= (pid_t
) pid
;
4188 msg
->ppid
= (pid_t
) ppid
;
4189 msg
->uid
= (uid_t
) uid
;
4190 msg
->gid
= (gid_t
) gid
;
4197 * Return a ust app channel object using the application object and the channel
4198 * object descriptor has a key. If not found, NULL is returned. A RCU read side
4199 * lock MUST be acquired before calling this function.
4201 static struct ust_app_channel
*find_channel_by_objd(struct ust_app
*app
,
4204 struct lttng_ht_node_ulong
*node
;
4205 struct lttng_ht_iter iter
;
4206 struct ust_app_channel
*ua_chan
= NULL
;
4210 lttng_ht_lookup(app
->ust_objd
, (void *)((unsigned long) objd
), &iter
);
4211 node
= lttng_ht_iter_get_node_ulong(&iter
);
4213 DBG2("UST app channel find by objd %d not found", objd
);
4217 ua_chan
= caa_container_of(node
, struct ust_app_channel
, ust_objd_node
);
4224 * Reply to a register channel notification from an application on the notify
4225 * socket. The channel metadata is also created.
4227 * The session UST registry lock is acquired in this function.
4229 * On success 0 is returned else a negative value.
4231 static int reply_ust_register_channel(int sock
, int sobjd
, int cobjd
,
4232 size_t nr_fields
, struct ustctl_field
*fields
)
4234 int ret
, ret_code
= 0;
4235 uint32_t chan_id
, reg_count
;
4236 uint64_t chan_reg_key
;
4237 enum ustctl_channel_header type
;
4238 struct ust_app
*app
;
4239 struct ust_app_channel
*ua_chan
;
4240 struct ust_app_session
*ua_sess
;
4241 struct ust_registry_session
*registry
;
4242 struct ust_registry_channel
*chan_reg
;
4246 /* Lookup application. If not found, there is a code flow error. */
4247 app
= find_app_by_notify_sock(sock
);
4249 DBG("Application socket %d is being teardown. Abort event notify",
4252 goto error_rcu_unlock
;
4255 /* Lookup channel by UST object descriptor. Should always be found. */
4256 ua_chan
= find_channel_by_objd(app
, cobjd
);
4258 assert(ua_chan
->session
);
4259 ua_sess
= ua_chan
->session
;
4261 /* Get right session registry depending on the session buffer type. */
4262 registry
= get_session_registry(ua_sess
);
4265 /* Depending on the buffer type, a different channel key is used. */
4266 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
4267 chan_reg_key
= ua_chan
->tracing_channel_id
;
4269 chan_reg_key
= ua_chan
->key
;
4272 pthread_mutex_lock(®istry
->lock
);
4274 chan_reg
= ust_registry_channel_find(registry
, chan_reg_key
);
4277 if (!chan_reg
->register_done
) {
4278 reg_count
= ust_registry_get_event_count(chan_reg
);
4279 if (reg_count
< 31) {
4280 type
= USTCTL_CHANNEL_HEADER_COMPACT
;
4282 type
= USTCTL_CHANNEL_HEADER_LARGE
;
4285 chan_reg
->nr_ctx_fields
= nr_fields
;
4286 chan_reg
->ctx_fields
= fields
;
4287 chan_reg
->header_type
= type
;
4289 /* Get current already assigned values. */
4290 type
= chan_reg
->header_type
;
4292 /* Channel id is set during the object creation. */
4293 chan_id
= chan_reg
->chan_id
;
4295 /* Append to metadata */
4296 if (!chan_reg
->metadata_dumped
) {
4297 ret_code
= ust_metadata_channel_statedump(registry
, chan_reg
);
4299 ERR("Error appending channel metadata (errno = %d)", ret_code
);
4305 DBG3("UST app replying to register channel key %" PRIu64
4306 " with id %u, type: %d, ret: %d", chan_reg_key
, chan_id
, type
,
4309 ret
= ustctl_reply_register_channel(sock
, chan_id
, type
, ret_code
);
4311 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4312 ERR("UST app reply channel failed with ret %d", ret
);
4314 DBG3("UST app reply channel failed. Application died");
4319 /* This channel registry registration is completed. */
4320 chan_reg
->register_done
= 1;
4323 pthread_mutex_unlock(®istry
->lock
);
4330 * Add event to the UST channel registry. When the event is added to the
4331 * registry, the metadata is also created. Once done, this replies to the
4332 * application with the appropriate error code.
4334 * The session UST registry lock is acquired in the function.
4336 * On success 0 is returned else a negative value.
4338 static int add_event_ust_registry(int sock
, int sobjd
, int cobjd
, char *name
,
4339 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
, int loglevel
,
4340 char *model_emf_uri
)
4343 uint32_t event_id
= 0;
4344 uint64_t chan_reg_key
;
4345 struct ust_app
*app
;
4346 struct ust_app_channel
*ua_chan
;
4347 struct ust_app_session
*ua_sess
;
4348 struct ust_registry_session
*registry
;
4352 /* Lookup application. If not found, there is a code flow error. */
4353 app
= find_app_by_notify_sock(sock
);
4355 DBG("Application socket %d is being teardown. Abort event notify",
4358 goto error_rcu_unlock
;
4361 /* Lookup channel by UST object descriptor. Should always be found. */
4362 ua_chan
= find_channel_by_objd(app
, cobjd
);
4364 assert(ua_chan
->session
);
4365 ua_sess
= ua_chan
->session
;
4367 registry
= get_session_registry(ua_sess
);
4370 if (ua_sess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
4371 chan_reg_key
= ua_chan
->tracing_channel_id
;
4373 chan_reg_key
= ua_chan
->key
;
4376 pthread_mutex_lock(®istry
->lock
);
4378 ret_code
= ust_registry_create_event(registry
, chan_reg_key
,
4379 sobjd
, cobjd
, name
, sig
, nr_fields
, fields
, loglevel
,
4380 model_emf_uri
, ua_sess
->buffer_type
, &event_id
);
4383 * The return value is returned to ustctl so in case of an error, the
4384 * application can be notified. In case of an error, it's important not to
4385 * return a negative error or else the application will get closed.
4387 ret
= ustctl_reply_register_event(sock
, event_id
, ret_code
);
4389 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4390 ERR("UST app reply event failed with ret %d", ret
);
4392 DBG3("UST app reply event failed. Application died");
4395 * No need to wipe the create event since the application socket will
4396 * get close on error hence cleaning up everything by itself.
4401 DBG3("UST registry event %s with id %" PRId32
" added successfully",
4405 pthread_mutex_unlock(®istry
->lock
);
4412 * Handle application notification through the given notify socket.
4414 * Return 0 on success or else a negative value.
4416 int ust_app_recv_notify(int sock
)
4419 enum ustctl_notify_cmd cmd
;
4421 DBG3("UST app receiving notify from sock %d", sock
);
4423 ret
= ustctl_recv_notify(sock
, &cmd
);
4425 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4426 ERR("UST app recv notify failed with ret %d", ret
);
4428 DBG3("UST app recv notify failed. Application died");
4434 case USTCTL_NOTIFY_CMD_EVENT
:
4436 int sobjd
, cobjd
, loglevel
;
4437 char name
[LTTNG_UST_SYM_NAME_LEN
], *sig
, *model_emf_uri
;
4439 struct ustctl_field
*fields
;
4441 DBG2("UST app ustctl register event received");
4443 ret
= ustctl_recv_register_event(sock
, &sobjd
, &cobjd
, name
, &loglevel
,
4444 &sig
, &nr_fields
, &fields
, &model_emf_uri
);
4446 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4447 ERR("UST app recv event failed with ret %d", ret
);
4449 DBG3("UST app recv event failed. Application died");
4454 /* Add event to the UST registry coming from the notify socket. */
4455 ret
= add_event_ust_registry(sock
, sobjd
, cobjd
, name
, sig
, nr_fields
,
4456 fields
, loglevel
, model_emf_uri
);
4463 case USTCTL_NOTIFY_CMD_CHANNEL
:
4467 struct ustctl_field
*fields
;
4469 DBG2("UST app ustctl register channel received");
4471 ret
= ustctl_recv_register_channel(sock
, &sobjd
, &cobjd
, &nr_fields
,
4474 if (ret
!= -EPIPE
&& ret
!= -LTTNG_UST_ERR_EXITING
) {
4475 ERR("UST app recv channel failed with ret %d", ret
);
4477 DBG3("UST app recv channel failed. Application died");
4482 ret
= reply_ust_register_channel(sock
, sobjd
, cobjd
, nr_fields
,
4491 /* Should NEVER happen. */
4500 * Once the notify socket hangs up, this is called. First, it tries to find the
4501 * corresponding application. On failure, the call_rcu to close the socket is
4502 * executed. If an application is found, it tries to delete it from the notify
4503 * socket hash table. Whathever the result, it proceeds to the call_rcu.
4505 * Note that an object needs to be allocated here so on ENOMEM failure, the
4506 * call RCU is not done but the rest of the cleanup is.
4508 void ust_app_notify_sock_unregister(int sock
)
4511 struct lttng_ht_iter iter
;
4512 struct ust_app
*app
;
4513 struct ust_app_notify_sock_obj
*obj
;
4519 obj
= zmalloc(sizeof(*obj
));
4522 * An ENOMEM is kind of uncool. If this strikes we continue the
4523 * procedure but the call_rcu will not be called. In this case, we
4524 * accept the fd leak rather than possibly creating an unsynchronized
4525 * state between threads.
4527 * TODO: The notify object should be created once the notify socket is
4528 * registered and stored independantely from the ust app object. The
4529 * tricky part is to synchronize the teardown of the application and
4530 * this notify object. Let's keep that in mind so we can avoid this
4531 * kind of shenanigans with ENOMEM in the teardown path.
4538 DBG("UST app notify socket unregister %d", sock
);
4541 * Lookup application by notify socket. If this fails, this means that the
4542 * hash table delete has already been done by the application
4543 * unregistration process so we can safely close the notify socket in a
4546 app
= find_app_by_notify_sock(sock
);
4551 iter
.iter
.node
= &app
->notify_sock_n
.node
;
4554 * Whatever happens here either we fail or succeed, in both cases we have
4555 * to close the socket after a grace period to continue to the call RCU
4556 * here. If the deletion is successful, the application is not visible
4557 * anymore by other threads and is it fails it means that it was already
4558 * deleted from the hash table so either way we just have to close the
4561 (void) lttng_ht_del(ust_app_ht_by_notify_sock
, &iter
);
4567 * Close socket after a grace period to avoid for the socket to be reused
4568 * before the application object is freed creating potential race between
4569 * threads trying to add unique in the global hash table.
4572 call_rcu(&obj
->head
, close_notify_sock_rcu
);