2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 * 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/types.h>
29 #include <common/common.h>
30 #include <common/defaults.h>
31 #include <common/uri.h>
32 #include <common/relayd/relayd.h>
35 #include "health-sessiond.h"
40 * Send a data payload using a given consumer socket of size len.
42 * The consumer socket lock MUST be acquired before calling this since this
43 * function can change the fd value.
45 * Return 0 on success else a negative value on error.
47 int consumer_socket_send(struct consumer_socket
*socket
, void *msg
, size_t len
)
53 assert(socket
->fd_ptr
);
56 /* Consumer socket is invalid. Stopping. */
62 size
= lttcomm_send_unix_sock(fd
, msg
, len
);
64 /* The above call will print a PERROR on error. */
65 DBG("Error when sending data to consumer on sock %d", fd
);
67 * At this point, the socket is not usable anymore thus closing it and
68 * setting the file descriptor to -1 so it is not reused.
71 /* This call will PERROR on error. */
72 (void) lttcomm_close_unix_sock(fd
);
84 * Receive a data payload using a given consumer socket of size len.
86 * The consumer socket lock MUST be acquired before calling this since this
87 * function can change the fd value.
89 * Return 0 on success else a negative value on error.
91 int consumer_socket_recv(struct consumer_socket
*socket
, void *msg
, size_t len
)
97 assert(socket
->fd_ptr
);
100 /* Consumer socket is invalid. Stopping. */
101 fd
= *socket
->fd_ptr
;
106 size
= lttcomm_recv_unix_sock(fd
, msg
, len
);
108 /* The above call will print a PERROR on error. */
109 DBG("Error when receiving data from the consumer socket %d", fd
);
111 * At this point, the socket is not usable anymore thus closing it and
112 * setting the file descriptor to -1 so it is not reused.
115 /* This call will PERROR on error. */
116 (void) lttcomm_close_unix_sock(fd
);
117 *socket
->fd_ptr
= -1;
128 * Receive a reply command status message from the consumer. Consumer socket
129 * lock MUST be acquired before calling this function.
131 * Return 0 on success, -1 on recv error or a negative lttng error code which
132 * was possibly returned by the consumer.
134 int consumer_recv_status_reply(struct consumer_socket
*sock
)
137 struct lttcomm_consumer_status_msg reply
;
141 ret
= consumer_socket_recv(sock
, &reply
, sizeof(reply
));
146 if (reply
.ret_code
== LTTCOMM_CONSUMERD_SUCCESS
) {
150 ret
= -reply
.ret_code
;
151 DBG("Consumer ret code %d", ret
);
159 * Once the ASK_CHANNEL command is sent to the consumer, the channel
160 * information are sent back. This call receives that data and populates key
163 * On success return 0 and both key and stream_count are set. On error, a
164 * negative value is sent back and both parameters are untouched.
166 int consumer_recv_status_channel(struct consumer_socket
*sock
,
167 uint64_t *key
, unsigned int *stream_count
)
170 struct lttcomm_consumer_status_channel reply
;
173 assert(stream_count
);
176 ret
= consumer_socket_recv(sock
, &reply
, sizeof(reply
));
181 /* An error is possible so don't touch the key and stream_count. */
182 if (reply
.ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
188 *stream_count
= reply
.stream_count
;
196 * Send destroy relayd command to consumer.
198 * On success return positive value. On error, negative value.
200 int consumer_send_destroy_relayd(struct consumer_socket
*sock
,
201 struct consumer_output
*consumer
)
204 struct lttcomm_consumer_msg msg
;
209 DBG2("Sending destroy relayd command to consumer sock %d", *sock
->fd_ptr
);
211 memset(&msg
, 0, sizeof(msg
));
212 msg
.cmd_type
= LTTNG_CONSUMER_DESTROY_RELAYD
;
213 msg
.u
.destroy_relayd
.net_seq_idx
= consumer
->net_seq_index
;
215 pthread_mutex_lock(sock
->lock
);
216 ret
= consumer_socket_send(sock
, &msg
, sizeof(msg
));
221 /* Don't check the return value. The caller will do it. */
222 ret
= consumer_recv_status_reply(sock
);
224 DBG2("Consumer send destroy relayd command done");
227 pthread_mutex_unlock(sock
->lock
);
232 * For each consumer socket in the consumer output object, send a destroy
235 void consumer_output_send_destroy_relayd(struct consumer_output
*consumer
)
237 struct lttng_ht_iter iter
;
238 struct consumer_socket
*socket
;
242 /* Destroy any relayd connection */
243 if (consumer
->type
== CONSUMER_DST_NET
) {
245 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
249 /* Send destroy relayd command */
250 ret
= consumer_send_destroy_relayd(socket
, consumer
);
252 DBG("Unable to send destroy relayd command to consumer");
253 /* Continue since we MUST delete everything at this point. */
261 * From a consumer_data structure, allocate and add a consumer socket to the
264 * Return 0 on success, else negative value on error
266 int consumer_create_socket(struct consumer_data
*data
,
267 struct consumer_output
*output
)
270 struct consumer_socket
*socket
;
274 if (output
== NULL
|| data
->cmd_sock
< 0) {
276 * Not an error. Possible there is simply not spawned consumer or it's
277 * disabled for the tracing session asking the socket.
283 socket
= consumer_find_socket(data
->cmd_sock
, output
);
285 if (socket
== NULL
) {
286 socket
= consumer_allocate_socket(&data
->cmd_sock
);
287 if (socket
== NULL
) {
292 socket
->registered
= 0;
293 socket
->lock
= &data
->lock
;
295 consumer_add_socket(socket
, output
);
299 socket
->type
= data
->type
;
301 DBG3("Consumer socket created (fd: %d) and added to output",
309 * Return the consumer socket from the given consumer output with the right
310 * bitness. On error, returns NULL.
312 * The caller MUST acquire a rcu read side lock and keep it until the socket
313 * object reference is not needed anymore.
315 struct consumer_socket
*consumer_find_socket_by_bitness(int bits
,
316 struct consumer_output
*consumer
)
319 struct consumer_socket
*socket
= NULL
;
323 consumer_fd
= uatomic_read(&ust_consumerd64_fd
);
326 consumer_fd
= uatomic_read(&ust_consumerd32_fd
);
333 socket
= consumer_find_socket(consumer_fd
, consumer
);
335 ERR("Consumer socket fd %d not found in consumer obj %p",
336 consumer_fd
, consumer
);
344 * Find a consumer_socket in a consumer_output hashtable. Read side lock must
345 * be acquired before calling this function and across use of the
346 * returned consumer_socket.
348 struct consumer_socket
*consumer_find_socket(int key
,
349 struct consumer_output
*consumer
)
351 struct lttng_ht_iter iter
;
352 struct lttng_ht_node_ulong
*node
;
353 struct consumer_socket
*socket
= NULL
;
355 /* Negative keys are lookup failures */
356 if (key
< 0 || consumer
== NULL
) {
360 lttng_ht_lookup(consumer
->socks
, (void *)((unsigned long) key
),
362 node
= lttng_ht_iter_get_node_ulong(&iter
);
364 socket
= caa_container_of(node
, struct consumer_socket
, node
);
371 * Allocate a new consumer_socket and return the pointer.
373 struct consumer_socket
*consumer_allocate_socket(int *fd
)
375 struct consumer_socket
*socket
= NULL
;
379 socket
= zmalloc(sizeof(struct consumer_socket
));
380 if (socket
== NULL
) {
381 PERROR("zmalloc consumer socket");
386 lttng_ht_node_init_ulong(&socket
->node
, *fd
);
393 * Add consumer socket to consumer output object. Read side lock must be
394 * acquired before calling this function.
396 void consumer_add_socket(struct consumer_socket
*sock
,
397 struct consumer_output
*consumer
)
402 lttng_ht_add_unique_ulong(consumer
->socks
, &sock
->node
);
406 * Delte consumer socket to consumer output object. Read side lock must be
407 * acquired before calling this function.
409 void consumer_del_socket(struct consumer_socket
*sock
,
410 struct consumer_output
*consumer
)
413 struct lttng_ht_iter iter
;
418 iter
.iter
.node
= &sock
->node
.node
;
419 ret
= lttng_ht_del(consumer
->socks
, &iter
);
424 * RCU destroy call function.
426 static void destroy_socket_rcu(struct rcu_head
*head
)
428 struct lttng_ht_node_ulong
*node
=
429 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
430 struct consumer_socket
*socket
=
431 caa_container_of(node
, struct consumer_socket
, node
);
437 * Destroy and free socket pointer in a call RCU. Read side lock must be
438 * acquired before calling this function.
440 void consumer_destroy_socket(struct consumer_socket
*sock
)
445 * We DO NOT close the file descriptor here since it is global to the
446 * session daemon and is closed only if the consumer dies or a custom
447 * consumer was registered,
449 if (sock
->registered
) {
450 DBG3("Consumer socket was registered. Closing fd %d", *sock
->fd_ptr
);
451 lttcomm_close_unix_sock(*sock
->fd_ptr
);
454 call_rcu(&sock
->node
.head
, destroy_socket_rcu
);
458 * Allocate and assign data to a consumer_output object.
460 * Return pointer to structure.
462 struct consumer_output
*consumer_create_output(enum consumer_dst_type type
)
464 struct consumer_output
*output
= NULL
;
466 output
= zmalloc(sizeof(struct consumer_output
));
467 if (output
== NULL
) {
468 PERROR("zmalloc consumer_output");
472 /* By default, consumer output is enabled */
475 output
->net_seq_index
= (uint64_t) -1ULL;
476 urcu_ref_init(&output
->ref
);
478 output
->socks
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
485 * Iterate over the consumer output socket hash table and destroy them. The
486 * socket file descriptor are only closed if the consumer output was
487 * registered meaning it's an external consumer.
489 void consumer_destroy_output_sockets(struct consumer_output
*obj
)
491 struct lttng_ht_iter iter
;
492 struct consumer_socket
*socket
;
499 cds_lfht_for_each_entry(obj
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
500 consumer_del_socket(socket
, obj
);
501 consumer_destroy_socket(socket
);
507 * Delete the consumer_output object from the list and free the ptr.
509 * Should *NOT* be called with RCU read-side lock held.
511 static void consumer_release_output(struct urcu_ref
*ref
)
513 struct consumer_output
*obj
=
514 caa_container_of(ref
, struct consumer_output
, ref
);
516 consumer_destroy_output_sockets(obj
);
519 /* Finally destroy HT */
520 ht_cleanup_push(obj
->socks
);
527 * Get the consumer_output object.
529 void consumer_output_get(struct consumer_output
*obj
)
531 urcu_ref_get(&obj
->ref
);
535 * Put the consumer_output object.
537 * Should *NOT* be called with RCU read-side lock held.
539 void consumer_output_put(struct consumer_output
*obj
)
544 urcu_ref_put(&obj
->ref
, consumer_release_output
);
548 * Copy consumer output and returned the newly allocated copy.
550 * Should *NOT* be called with RCU read-side lock held.
552 struct consumer_output
*consumer_copy_output(struct consumer_output
*src
)
555 struct consumer_output
*output
;
559 output
= consumer_create_output(src
->type
);
560 if (output
== NULL
) {
563 output
->enabled
= src
->enabled
;
564 output
->net_seq_index
= src
->net_seq_index
;
565 memcpy(output
->domain_subdir
, src
->domain_subdir
,
566 sizeof(output
->domain_subdir
));
567 output
->snapshot
= src
->snapshot
;
568 output
->relay_major_version
= src
->relay_major_version
;
569 output
->relay_minor_version
= src
->relay_minor_version
;
570 memcpy(&output
->dst
, &src
->dst
, sizeof(output
->dst
));
571 ret
= consumer_copy_sockets(output
, src
);
579 consumer_output_put(output
);
584 * Copy consumer sockets from src to dst.
586 * Return 0 on success or else a negative value.
588 int consumer_copy_sockets(struct consumer_output
*dst
,
589 struct consumer_output
*src
)
592 struct lttng_ht_iter iter
;
593 struct consumer_socket
*socket
, *copy_sock
;
599 cds_lfht_for_each_entry(src
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
600 /* Ignore socket that are already there. */
601 copy_sock
= consumer_find_socket(*socket
->fd_ptr
, dst
);
606 /* Create new socket object. */
607 copy_sock
= consumer_allocate_socket(socket
->fd_ptr
);
608 if (copy_sock
== NULL
) {
614 copy_sock
->registered
= socket
->registered
;
616 * This is valid because this lock is shared accross all consumer
617 * object being the global lock of the consumer data structure of the
620 copy_sock
->lock
= socket
->lock
;
621 consumer_add_socket(copy_sock
, dst
);
630 * Set network URI to the consumer output.
632 * Return 0 on success. Return 1 if the URI were equal. Else, negative value on
635 int consumer_set_network_uri(const struct ltt_session
*session
,
636 struct consumer_output
*output
,
637 struct lttng_uri
*uri
)
640 struct lttng_uri
*dst_uri
= NULL
;
642 /* Code flow error safety net. */
646 switch (uri
->stype
) {
647 case LTTNG_STREAM_CONTROL
:
648 dst_uri
= &output
->dst
.net
.control
;
649 output
->dst
.net
.control_isset
= 1;
650 if (uri
->port
== 0) {
651 /* Assign default port. */
652 uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
654 if (output
->dst
.net
.data_isset
&& uri
->port
==
655 output
->dst
.net
.data
.port
) {
656 ret
= -LTTNG_ERR_INVALID
;
660 DBG3("Consumer control URI set with port %d", uri
->port
);
662 case LTTNG_STREAM_DATA
:
663 dst_uri
= &output
->dst
.net
.data
;
664 output
->dst
.net
.data_isset
= 1;
665 if (uri
->port
== 0) {
666 /* Assign default port. */
667 uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
669 if (output
->dst
.net
.control_isset
&& uri
->port
==
670 output
->dst
.net
.control
.port
) {
671 ret
= -LTTNG_ERR_INVALID
;
675 DBG3("Consumer data URI set with port %d", uri
->port
);
678 ERR("Set network uri type unknown %d", uri
->stype
);
679 ret
= -LTTNG_ERR_INVALID
;
683 ret
= uri_compare(dst_uri
, uri
);
685 /* Same URI, don't touch it and return success. */
686 DBG3("URI network compare are the same");
690 /* URIs were not equal, replacing it. */
691 memcpy(dst_uri
, uri
, sizeof(struct lttng_uri
));
692 output
->type
= CONSUMER_DST_NET
;
693 if (dst_uri
->stype
!= LTTNG_STREAM_CONTROL
) {
694 /* Only the control uri needs to contain the path. */
699 * If the user has specified a subdir as part of the control
700 * URL, the session's base output directory is:
701 * /RELAYD_OUTPUT_PATH/HOSTNAME/USER_SPECIFIED_DIR
703 * Hence, the "base_dir" from which all stream files and
704 * session rotation chunks are created takes the form
705 * /HOSTNAME/USER_SPECIFIED_DIR
707 * If the user has not specified an output directory as part of
708 * the control URL, the base output directory has the form:
709 * /RELAYD_OUTPUT_PATH/HOSTNAME/SESSION_NAME-CREATION_TIME
711 * Hence, the "base_dir" from which all stream files and
712 * session rotation chunks are created takes the form
713 * /HOSTNAME/SESSION_NAME-CREATION_TIME
715 * Note that automatically generated session names already
716 * contain the session's creation time. In that case, the
717 * creation time is omitted to prevent it from being duplicated
718 * in the final directory hierarchy.
721 if (strstr(uri
->subdir
, "../")) {
722 ERR("Network URI subdirs are not allowed to walk up the path hierarchy");
723 ret
= -LTTNG_ERR_INVALID
;
726 ret
= snprintf(output
->dst
.net
.base_dir
,
727 sizeof(output
->dst
.net
.base_dir
),
728 "/%s/%s/", session
->hostname
, uri
->subdir
);
730 if (session
->has_auto_generated_name
) {
731 ret
= snprintf(output
->dst
.net
.base_dir
,
732 sizeof(output
->dst
.net
.base_dir
),
733 "/%s/%s/", session
->hostname
,
736 char session_creation_datetime
[16];
740 timeinfo
= localtime(&session
->creation_time
);
742 ret
= -LTTNG_ERR_FATAL
;
745 strftime_ret
= strftime(session_creation_datetime
,
746 sizeof(session_creation_datetime
),
747 "%Y%m%d-%H%M%S", timeinfo
);
748 if (strftime_ret
== 0) {
749 ERR("Failed to format session creation timestamp while setting network URI");
750 ret
= -LTTNG_ERR_FATAL
;
753 ret
= snprintf(output
->dst
.net
.base_dir
,
754 sizeof(output
->dst
.net
.base_dir
),
755 "/%s/%s-%s/", session
->hostname
,
757 session_creation_datetime
);
760 if (ret
>= sizeof(output
->dst
.net
.base_dir
)) {
761 ret
= -LTTNG_ERR_INVALID
;
762 ERR("Truncation occurred while setting network output base directory");
764 } else if (ret
== -1) {
765 ret
= -LTTNG_ERR_INVALID
;
766 PERROR("Error occurred while setting network output base directory");
770 DBG3("Consumer set network uri base_dir path %s",
771 output
->dst
.net
.base_dir
);
782 * Send file descriptor to consumer via sock.
784 * The consumer socket lock must be held by the caller.
786 int consumer_send_fds(struct consumer_socket
*sock
, const int *fds
,
794 assert(pthread_mutex_trylock(sock
->lock
) == EBUSY
);
796 ret
= lttcomm_send_fds_unix_sock(*sock
->fd_ptr
, fds
, nb_fd
);
798 /* The above call will print a PERROR on error. */
799 DBG("Error when sending consumer fds on sock %d", *sock
->fd_ptr
);
803 ret
= consumer_recv_status_reply(sock
);
809 * Consumer send communication message structure to consumer.
811 * The consumer socket lock must be held by the caller.
813 int consumer_send_msg(struct consumer_socket
*sock
,
814 struct lttcomm_consumer_msg
*msg
)
820 assert(pthread_mutex_trylock(sock
->lock
) == EBUSY
);
822 ret
= consumer_socket_send(sock
, msg
, sizeof(struct lttcomm_consumer_msg
));
827 ret
= consumer_recv_status_reply(sock
);
834 * Consumer send channel communication message structure to consumer.
836 * The consumer socket lock must be held by the caller.
838 int consumer_send_channel(struct consumer_socket
*sock
,
839 struct lttcomm_consumer_msg
*msg
)
846 ret
= consumer_send_msg(sock
, msg
);
856 * Populate the given consumer msg structure with the ask_channel command
859 void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
860 uint64_t subbuf_size
,
863 unsigned int switch_timer_interval
,
864 unsigned int read_timer_interval
,
865 unsigned int live_timer_interval
,
866 unsigned int monitor_timer_interval
,
870 const char *pathname
,
878 uint64_t tracefile_size
,
879 uint64_t tracefile_count
,
880 uint64_t session_id_per_pid
,
881 unsigned int monitor
,
882 uint32_t ust_app_uid
,
883 int64_t blocking_timeout
,
884 const char *root_shm_path
,
885 const char *shm_path
,
886 uint64_t trace_archive_id
)
890 /* Zeroed structure */
891 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
893 msg
->cmd_type
= LTTNG_CONSUMER_ASK_CHANNEL_CREATION
;
894 msg
->u
.ask_channel
.subbuf_size
= subbuf_size
;
895 msg
->u
.ask_channel
.num_subbuf
= num_subbuf
;
896 msg
->u
.ask_channel
.overwrite
= overwrite
;
897 msg
->u
.ask_channel
.switch_timer_interval
= switch_timer_interval
;
898 msg
->u
.ask_channel
.read_timer_interval
= read_timer_interval
;
899 msg
->u
.ask_channel
.live_timer_interval
= live_timer_interval
;
900 msg
->u
.ask_channel
.monitor_timer_interval
= monitor_timer_interval
;
901 msg
->u
.ask_channel
.output
= output
;
902 msg
->u
.ask_channel
.type
= type
;
903 msg
->u
.ask_channel
.session_id
= session_id
;
904 msg
->u
.ask_channel
.session_id_per_pid
= session_id_per_pid
;
905 msg
->u
.ask_channel
.uid
= uid
;
906 msg
->u
.ask_channel
.gid
= gid
;
907 msg
->u
.ask_channel
.relayd_id
= relayd_id
;
908 msg
->u
.ask_channel
.key
= key
;
909 msg
->u
.ask_channel
.chan_id
= chan_id
;
910 msg
->u
.ask_channel
.tracefile_size
= tracefile_size
;
911 msg
->u
.ask_channel
.tracefile_count
= tracefile_count
;
912 msg
->u
.ask_channel
.monitor
= monitor
;
913 msg
->u
.ask_channel
.ust_app_uid
= ust_app_uid
;
914 msg
->u
.ask_channel
.blocking_timeout
= blocking_timeout
;
915 msg
->u
.ask_channel
.trace_archive_id
= trace_archive_id
;
917 memcpy(msg
->u
.ask_channel
.uuid
, uuid
, sizeof(msg
->u
.ask_channel
.uuid
));
920 strncpy(msg
->u
.ask_channel
.pathname
, pathname
,
921 sizeof(msg
->u
.ask_channel
.pathname
));
922 msg
->u
.ask_channel
.pathname
[sizeof(msg
->u
.ask_channel
.pathname
)-1] = '\0';
925 strncpy(msg
->u
.ask_channel
.name
, name
, sizeof(msg
->u
.ask_channel
.name
));
926 msg
->u
.ask_channel
.name
[sizeof(msg
->u
.ask_channel
.name
) - 1] = '\0';
929 strncpy(msg
->u
.ask_channel
.root_shm_path
, root_shm_path
,
930 sizeof(msg
->u
.ask_channel
.root_shm_path
));
931 msg
->u
.ask_channel
.root_shm_path
[sizeof(msg
->u
.ask_channel
.root_shm_path
) - 1] = '\0';
934 strncpy(msg
->u
.ask_channel
.shm_path
, shm_path
,
935 sizeof(msg
->u
.ask_channel
.shm_path
));
936 msg
->u
.ask_channel
.shm_path
[sizeof(msg
->u
.ask_channel
.shm_path
) - 1] = '\0';
941 * Init channel communication message structure.
943 void consumer_init_add_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
944 uint64_t channel_key
,
946 const char *pathname
,
951 unsigned int nb_init_streams
,
952 enum lttng_event_output output
,
954 uint64_t tracefile_size
,
955 uint64_t tracefile_count
,
956 unsigned int monitor
,
957 unsigned int live_timer_interval
,
958 unsigned int monitor_timer_interval
)
962 /* Zeroed structure */
963 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
966 msg
->cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
967 msg
->u
.channel
.channel_key
= channel_key
;
968 msg
->u
.channel
.session_id
= session_id
;
969 msg
->u
.channel
.uid
= uid
;
970 msg
->u
.channel
.gid
= gid
;
971 msg
->u
.channel
.relayd_id
= relayd_id
;
972 msg
->u
.channel
.nb_init_streams
= nb_init_streams
;
973 msg
->u
.channel
.output
= output
;
974 msg
->u
.channel
.type
= type
;
975 msg
->u
.channel
.tracefile_size
= tracefile_size
;
976 msg
->u
.channel
.tracefile_count
= tracefile_count
;
977 msg
->u
.channel
.monitor
= monitor
;
978 msg
->u
.channel
.live_timer_interval
= live_timer_interval
;
979 msg
->u
.channel
.monitor_timer_interval
= monitor_timer_interval
;
981 strncpy(msg
->u
.channel
.pathname
, pathname
,
982 sizeof(msg
->u
.channel
.pathname
));
983 msg
->u
.channel
.pathname
[sizeof(msg
->u
.channel
.pathname
) - 1] = '\0';
985 strncpy(msg
->u
.channel
.name
, name
, sizeof(msg
->u
.channel
.name
));
986 msg
->u
.channel
.name
[sizeof(msg
->u
.channel
.name
) - 1] = '\0';
990 * Init stream communication message structure.
992 void consumer_init_add_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
993 uint64_t channel_key
,
996 uint64_t trace_archive_id
)
1000 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
1002 msg
->cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
1003 msg
->u
.stream
.channel_key
= channel_key
;
1004 msg
->u
.stream
.stream_key
= stream_key
;
1005 msg
->u
.stream
.cpu
= cpu
;
1006 msg
->u
.stream
.trace_archive_id
= trace_archive_id
;
1009 void consumer_init_streams_sent_comm_msg(struct lttcomm_consumer_msg
*msg
,
1010 enum lttng_consumer_command cmd
,
1011 uint64_t channel_key
, uint64_t net_seq_idx
)
1015 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
1017 msg
->cmd_type
= cmd
;
1018 msg
->u
.sent_streams
.channel_key
= channel_key
;
1019 msg
->u
.sent_streams
.net_seq_idx
= net_seq_idx
;
1023 * Send stream communication structure to the consumer.
1025 int consumer_send_stream(struct consumer_socket
*sock
,
1026 struct consumer_output
*dst
, struct lttcomm_consumer_msg
*msg
,
1027 const int *fds
, size_t nb_fd
)
1036 ret
= consumer_send_msg(sock
, msg
);
1041 ret
= consumer_send_fds(sock
, fds
, nb_fd
);
1051 * Send relayd socket to consumer associated with a session name.
1053 * The consumer socket lock must be held by the caller.
1055 * On success return positive value. On error, negative value.
1057 int consumer_send_relayd_socket(struct consumer_socket
*consumer_sock
,
1058 struct lttcomm_relayd_sock
*rsock
, struct consumer_output
*consumer
,
1059 enum lttng_stream_type type
, uint64_t session_id
,
1060 char *session_name
, char *hostname
, int session_live_timer
)
1063 struct lttcomm_consumer_msg msg
;
1065 /* Code flow error. Safety net. */
1068 assert(consumer_sock
);
1070 memset(&msg
, 0, sizeof(msg
));
1071 /* Bail out if consumer is disabled */
1072 if (!consumer
->enabled
) {
1077 if (type
== LTTNG_STREAM_CONTROL
) {
1078 ret
= relayd_create_session(rsock
,
1079 &msg
.u
.relayd_sock
.relayd_session_id
,
1080 session_name
, hostname
, session_live_timer
,
1081 consumer
->snapshot
);
1083 /* Close the control socket. */
1084 (void) relayd_close(rsock
);
1089 msg
.cmd_type
= LTTNG_CONSUMER_ADD_RELAYD_SOCKET
;
1091 * Assign network consumer output index using the temporary consumer since
1092 * this call should only be made from within a set_consumer_uri() function
1093 * call in the session daemon.
1095 msg
.u
.relayd_sock
.net_index
= consumer
->net_seq_index
;
1096 msg
.u
.relayd_sock
.type
= type
;
1097 msg
.u
.relayd_sock
.session_id
= session_id
;
1098 memcpy(&msg
.u
.relayd_sock
.sock
, rsock
, sizeof(msg
.u
.relayd_sock
.sock
));
1100 DBG3("Sending relayd sock info to consumer on %d", *consumer_sock
->fd_ptr
);
1101 ret
= consumer_send_msg(consumer_sock
, &msg
);
1106 DBG3("Sending relayd socket file descriptor to consumer");
1107 ret
= consumer_send_fds(consumer_sock
, &rsock
->sock
.fd
, 1);
1112 DBG2("Consumer relayd socket sent");
1119 int consumer_send_pipe(struct consumer_socket
*consumer_sock
,
1120 enum lttng_consumer_command cmd
, int pipe
)
1123 struct lttcomm_consumer_msg msg
;
1124 const char *pipe_name
;
1125 const char *command_name
;
1128 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1129 pipe_name
= "channel monitor";
1130 command_name
= "SET_CHANNEL_MONITOR_PIPE";
1133 ERR("Unexpected command received in %s (cmd = %d)", __func__
,
1138 /* Code flow error. Safety net. */
1140 memset(&msg
, 0, sizeof(msg
));
1143 pthread_mutex_lock(consumer_sock
->lock
);
1144 DBG3("Sending %s command to consumer", command_name
);
1145 ret
= consumer_send_msg(consumer_sock
, &msg
);
1150 DBG3("Sending %s pipe %d to consumer on socket %d",
1152 pipe
, *consumer_sock
->fd_ptr
);
1153 ret
= consumer_send_fds(consumer_sock
, &pipe
, 1);
1158 DBG2("%s pipe successfully sent", pipe_name
);
1160 pthread_mutex_unlock(consumer_sock
->lock
);
1164 int consumer_send_channel_monitor_pipe(struct consumer_socket
*consumer_sock
,
1167 return consumer_send_pipe(consumer_sock
,
1168 LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
, pipe
);
1172 * Ask the consumer if the data is pending for the specific session id.
1173 * Returns 1 if data is pending, 0 otherwise, or < 0 on error.
1175 int consumer_is_data_pending(uint64_t session_id
,
1176 struct consumer_output
*consumer
)
1179 int32_t ret_code
= 0; /* Default is that the data is NOT pending */
1180 struct consumer_socket
*socket
;
1181 struct lttng_ht_iter iter
;
1182 struct lttcomm_consumer_msg msg
;
1186 DBG3("Consumer data pending for id %" PRIu64
, session_id
);
1188 memset(&msg
, 0, sizeof(msg
));
1189 msg
.cmd_type
= LTTNG_CONSUMER_DATA_PENDING
;
1190 msg
.u
.data_pending
.session_id
= session_id
;
1192 /* Send command for each consumer */
1194 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1196 pthread_mutex_lock(socket
->lock
);
1197 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1199 pthread_mutex_unlock(socket
->lock
);
1204 * No need for a recv reply status because the answer to the command is
1205 * the reply status message.
1208 ret
= consumer_socket_recv(socket
, &ret_code
, sizeof(ret_code
));
1210 pthread_mutex_unlock(socket
->lock
);
1213 pthread_mutex_unlock(socket
->lock
);
1215 if (ret_code
== 1) {
1221 DBG("Consumer data is %s pending for session id %" PRIu64
,
1222 ret_code
== 1 ? "" : "NOT", session_id
);
1231 * Send a flush command to consumer using the given channel key.
1233 * Return 0 on success else a negative value.
1235 int consumer_flush_channel(struct consumer_socket
*socket
, uint64_t key
)
1238 struct lttcomm_consumer_msg msg
;
1242 DBG2("Consumer flush channel key %" PRIu64
, key
);
1244 memset(&msg
, 0, sizeof(msg
));
1245 msg
.cmd_type
= LTTNG_CONSUMER_FLUSH_CHANNEL
;
1246 msg
.u
.flush_channel
.key
= key
;
1248 pthread_mutex_lock(socket
->lock
);
1249 health_code_update();
1251 ret
= consumer_send_msg(socket
, &msg
);
1257 health_code_update();
1258 pthread_mutex_unlock(socket
->lock
);
1263 * Send a clear quiescent command to consumer using the given channel key.
1265 * Return 0 on success else a negative value.
1267 int consumer_clear_quiescent_channel(struct consumer_socket
*socket
, uint64_t key
)
1270 struct lttcomm_consumer_msg msg
;
1274 DBG2("Consumer clear quiescent channel key %" PRIu64
, key
);
1276 memset(&msg
, 0, sizeof(msg
));
1277 msg
.cmd_type
= LTTNG_CONSUMER_CLEAR_QUIESCENT_CHANNEL
;
1278 msg
.u
.clear_quiescent_channel
.key
= key
;
1280 pthread_mutex_lock(socket
->lock
);
1281 health_code_update();
1283 ret
= consumer_send_msg(socket
, &msg
);
1289 health_code_update();
1290 pthread_mutex_unlock(socket
->lock
);
1295 * Send a close metadata command to consumer using the given channel key.
1296 * Called with registry lock held.
1298 * Return 0 on success else a negative value.
1300 int consumer_close_metadata(struct consumer_socket
*socket
,
1301 uint64_t metadata_key
)
1304 struct lttcomm_consumer_msg msg
;
1308 DBG2("Consumer close metadata channel key %" PRIu64
, metadata_key
);
1310 memset(&msg
, 0, sizeof(msg
));
1311 msg
.cmd_type
= LTTNG_CONSUMER_CLOSE_METADATA
;
1312 msg
.u
.close_metadata
.key
= metadata_key
;
1314 pthread_mutex_lock(socket
->lock
);
1315 health_code_update();
1317 ret
= consumer_send_msg(socket
, &msg
);
1323 health_code_update();
1324 pthread_mutex_unlock(socket
->lock
);
1329 * Send a setup metdata command to consumer using the given channel key.
1331 * Return 0 on success else a negative value.
1333 int consumer_setup_metadata(struct consumer_socket
*socket
,
1334 uint64_t metadata_key
)
1337 struct lttcomm_consumer_msg msg
;
1341 DBG2("Consumer setup metadata channel key %" PRIu64
, metadata_key
);
1343 memset(&msg
, 0, sizeof(msg
));
1344 msg
.cmd_type
= LTTNG_CONSUMER_SETUP_METADATA
;
1345 msg
.u
.setup_metadata
.key
= metadata_key
;
1347 pthread_mutex_lock(socket
->lock
);
1348 health_code_update();
1350 ret
= consumer_send_msg(socket
, &msg
);
1356 health_code_update();
1357 pthread_mutex_unlock(socket
->lock
);
1362 * Send metadata string to consumer.
1363 * RCU read-side lock must be held to guarantee existence of socket.
1365 * Return 0 on success else a negative value.
1367 int consumer_push_metadata(struct consumer_socket
*socket
,
1368 uint64_t metadata_key
, char *metadata_str
, size_t len
,
1369 size_t target_offset
, uint64_t version
)
1372 struct lttcomm_consumer_msg msg
;
1376 DBG2("Consumer push metadata to consumer socket %d", *socket
->fd_ptr
);
1378 pthread_mutex_lock(socket
->lock
);
1380 memset(&msg
, 0, sizeof(msg
));
1381 msg
.cmd_type
= LTTNG_CONSUMER_PUSH_METADATA
;
1382 msg
.u
.push_metadata
.key
= metadata_key
;
1383 msg
.u
.push_metadata
.target_offset
= target_offset
;
1384 msg
.u
.push_metadata
.len
= len
;
1385 msg
.u
.push_metadata
.version
= version
;
1387 health_code_update();
1388 ret
= consumer_send_msg(socket
, &msg
);
1389 if (ret
< 0 || len
== 0) {
1393 DBG3("Consumer pushing metadata on sock %d of len %zu", *socket
->fd_ptr
,
1396 ret
= consumer_socket_send(socket
, metadata_str
, len
);
1401 health_code_update();
1402 ret
= consumer_recv_status_reply(socket
);
1408 pthread_mutex_unlock(socket
->lock
);
1409 health_code_update();
1414 * Ask the consumer to snapshot a specific channel using the key.
1416 * Returns LTTNG_OK on success or else an LTTng error code.
1418 enum lttng_error_code
consumer_snapshot_channel(struct consumer_socket
*socket
,
1419 uint64_t key
, struct snapshot_output
*output
, int metadata
,
1420 uid_t uid
, gid_t gid
, const char *session_path
, int wait
,
1421 uint64_t nb_packets_per_stream
, uint64_t trace_archive_id
)
1424 enum lttng_error_code status
= LTTNG_OK
;
1425 struct lttcomm_consumer_msg msg
;
1429 assert(output
->consumer
);
1431 DBG("Consumer snapshot channel key %" PRIu64
, key
);
1433 memset(&msg
, 0, sizeof(msg
));
1434 msg
.cmd_type
= LTTNG_CONSUMER_SNAPSHOT_CHANNEL
;
1435 msg
.u
.snapshot_channel
.key
= key
;
1436 msg
.u
.snapshot_channel
.nb_packets_per_stream
= nb_packets_per_stream
;
1437 msg
.u
.snapshot_channel
.metadata
= metadata
;
1438 msg
.u
.snapshot_channel
.trace_archive_id
= trace_archive_id
;
1440 if (output
->consumer
->type
== CONSUMER_DST_NET
) {
1441 msg
.u
.snapshot_channel
.relayd_id
= output
->consumer
->net_seq_index
;
1442 msg
.u
.snapshot_channel
.use_relayd
= 1;
1443 ret
= snprintf(msg
.u
.snapshot_channel
.pathname
,
1444 sizeof(msg
.u
.snapshot_channel
.pathname
),
1445 "%s/%s/%s-%s-%" PRIu64
"%s",
1446 output
->consumer
->dst
.net
.base_dir
,
1447 output
->consumer
->domain_subdir
,
1448 output
->name
, output
->datetime
,
1449 output
->nb_snapshot
,
1452 status
= LTTNG_ERR_INVALID
;
1454 } else if (ret
>= sizeof(msg
.u
.snapshot_channel
.pathname
)) {
1455 ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s/%s-%s-%" PRIu64
"%s\"",
1456 sizeof(msg
.u
.snapshot_channel
.pathname
),
1457 ret
, output
->consumer
->dst
.net
.base_dir
,
1458 output
->consumer
->domain_subdir
,
1459 output
->name
, output
->datetime
,
1460 output
->nb_snapshot
,
1462 status
= LTTNG_ERR_SNAPSHOT_FAIL
;
1466 ret
= snprintf(msg
.u
.snapshot_channel
.pathname
,
1467 sizeof(msg
.u
.snapshot_channel
.pathname
),
1468 "%s/%s-%s-%" PRIu64
"%s",
1469 output
->consumer
->dst
.session_root_path
,
1470 output
->name
, output
->datetime
,
1471 output
->nb_snapshot
,
1474 status
= LTTNG_ERR_NOMEM
;
1476 } else if (ret
>= sizeof(msg
.u
.snapshot_channel
.pathname
)) {
1477 ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s-%s-%" PRIu64
"%s\"",
1478 sizeof(msg
.u
.snapshot_channel
.pathname
),
1479 ret
, output
->consumer
->dst
.session_root_path
,
1480 output
->name
, output
->datetime
, output
->nb_snapshot
,
1482 status
= LTTNG_ERR_SNAPSHOT_FAIL
;
1486 msg
.u
.snapshot_channel
.relayd_id
= (uint64_t) -1ULL;
1488 /* Create directory. Ignore if exist. */
1489 ret
= run_as_mkdir_recursive(msg
.u
.snapshot_channel
.pathname
,
1490 S_IRWXU
| S_IRWXG
, uid
, gid
);
1492 if (errno
!= EEXIST
) {
1493 status
= LTTNG_ERR_CREATE_DIR_FAIL
;
1494 PERROR("Trace directory creation error");
1500 health_code_update();
1501 pthread_mutex_lock(socket
->lock
);
1502 ret
= consumer_send_msg(socket
, &msg
);
1503 pthread_mutex_unlock(socket
->lock
);
1506 case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
:
1507 status
= LTTNG_ERR_CHAN_NOT_FOUND
;
1510 status
= LTTNG_ERR_SNAPSHOT_FAIL
;
1517 health_code_update();
1522 * Ask the consumer the number of discarded events for a channel.
1524 int consumer_get_discarded_events(uint64_t session_id
, uint64_t channel_key
,
1525 struct consumer_output
*consumer
, uint64_t *discarded
)
1528 struct consumer_socket
*socket
;
1529 struct lttng_ht_iter iter
;
1530 struct lttcomm_consumer_msg msg
;
1534 DBG3("Consumer discarded events id %" PRIu64
, session_id
);
1536 memset(&msg
, 0, sizeof(msg
));
1537 msg
.cmd_type
= LTTNG_CONSUMER_DISCARDED_EVENTS
;
1538 msg
.u
.discarded_events
.session_id
= session_id
;
1539 msg
.u
.discarded_events
.channel_key
= channel_key
;
1543 /* Send command for each consumer */
1545 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1547 uint64_t consumer_discarded
= 0;
1548 pthread_mutex_lock(socket
->lock
);
1549 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1551 pthread_mutex_unlock(socket
->lock
);
1556 * No need for a recv reply status because the answer to the
1557 * command is the reply status message.
1559 ret
= consumer_socket_recv(socket
, &consumer_discarded
,
1560 sizeof(consumer_discarded
));
1562 ERR("get discarded events");
1563 pthread_mutex_unlock(socket
->lock
);
1566 pthread_mutex_unlock(socket
->lock
);
1567 *discarded
+= consumer_discarded
;
1570 DBG("Consumer discarded %" PRIu64
" events in session id %" PRIu64
,
1571 *discarded
, session_id
);
1579 * Ask the consumer the number of lost packets for a channel.
1581 int consumer_get_lost_packets(uint64_t session_id
, uint64_t channel_key
,
1582 struct consumer_output
*consumer
, uint64_t *lost
)
1585 struct consumer_socket
*socket
;
1586 struct lttng_ht_iter iter
;
1587 struct lttcomm_consumer_msg msg
;
1591 DBG3("Consumer lost packets id %" PRIu64
, session_id
);
1593 memset(&msg
, 0, sizeof(msg
));
1594 msg
.cmd_type
= LTTNG_CONSUMER_LOST_PACKETS
;
1595 msg
.u
.lost_packets
.session_id
= session_id
;
1596 msg
.u
.lost_packets
.channel_key
= channel_key
;
1600 /* Send command for each consumer */
1602 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1604 uint64_t consumer_lost
= 0;
1605 pthread_mutex_lock(socket
->lock
);
1606 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1608 pthread_mutex_unlock(socket
->lock
);
1613 * No need for a recv reply status because the answer to the
1614 * command is the reply status message.
1616 ret
= consumer_socket_recv(socket
, &consumer_lost
,
1617 sizeof(consumer_lost
));
1619 ERR("get lost packets");
1620 pthread_mutex_unlock(socket
->lock
);
1623 pthread_mutex_unlock(socket
->lock
);
1624 *lost
+= consumer_lost
;
1627 DBG("Consumer lost %" PRIu64
" packets in session id %" PRIu64
,
1636 * Ask the consumer to rotate a channel.
1637 * domain_path contains "/kernel" for kernel or the complete path for UST
1638 * (ex: /ust/uid/1000/64-bit);
1640 * The new_chunk_id is the session->rotate_count that has been incremented
1641 * when the rotation started. On the relay, this allows to keep track in which
1642 * chunk each stream is currently writing to (for the rotate_pending operation).
1644 int consumer_rotate_channel(struct consumer_socket
*socket
, uint64_t key
,
1645 uid_t uid
, gid_t gid
, struct consumer_output
*output
,
1646 const char *domain_path
, bool is_metadata_channel
,
1647 uint64_t new_chunk_id
)
1650 struct lttcomm_consumer_msg msg
;
1654 DBG("Consumer rotate channel key %" PRIu64
, key
);
1656 pthread_mutex_lock(socket
->lock
);
1657 memset(&msg
, 0, sizeof(msg
));
1658 msg
.cmd_type
= LTTNG_CONSUMER_ROTATE_CHANNEL
;
1659 msg
.u
.rotate_channel
.key
= key
;
1660 msg
.u
.rotate_channel
.metadata
= !!is_metadata_channel
;
1661 msg
.u
.rotate_channel
.new_chunk_id
= new_chunk_id
;
1663 if (output
->type
== CONSUMER_DST_NET
) {
1664 msg
.u
.rotate_channel
.relayd_id
= output
->net_seq_index
;
1665 ret
= snprintf(msg
.u
.rotate_channel
.pathname
,
1666 sizeof(msg
.u
.rotate_channel
.pathname
), "%s%s%s",
1667 output
->dst
.net
.base_dir
,
1668 output
->chunk_path
, domain_path
);
1669 if (ret
< 0 || ret
>= sizeof(msg
.u
.rotate_channel
.pathname
)) {
1670 ERR("Failed to format channel path name when asking consumer to rotate channel");
1671 ret
= -LTTNG_ERR_INVALID
;
1675 msg
.u
.rotate_channel
.relayd_id
= (uint64_t) -1ULL;
1676 ret
= snprintf(msg
.u
.rotate_channel
.pathname
,
1677 sizeof(msg
.u
.rotate_channel
.pathname
), "%s/%s%s",
1678 output
->dst
.session_root_path
,
1679 output
->chunk_path
, domain_path
);
1680 if (ret
< 0 || ret
>= sizeof(msg
.u
.rotate_channel
.pathname
)) {
1681 ERR("Failed to format channel path name when asking consumer to rotate channel");
1682 ret
= -LTTNG_ERR_INVALID
;
1687 health_code_update();
1688 ret
= consumer_send_msg(socket
, &msg
);
1691 case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
:
1692 ret
= -LTTNG_ERR_CHAN_NOT_FOUND
;
1695 ret
= -LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1701 pthread_mutex_unlock(socket
->lock
);
1702 health_code_update();
1706 int consumer_rotate_rename(struct consumer_socket
*socket
, uint64_t session_id
,
1707 const struct consumer_output
*output
, const char *old_path
,
1708 const char *new_path
, uid_t uid
, gid_t gid
)
1711 struct lttcomm_consumer_msg msg
;
1712 size_t old_path_length
, new_path_length
;
1718 DBG("Consumer rotate rename session %" PRIu64
", old path = \"%s\", new_path = \"%s\"",
1719 session_id
, old_path
, new_path
);
1721 old_path_length
= strlen(old_path
);
1722 if (old_path_length
>= sizeof(msg
.u
.rotate_rename
.old_path
)) {
1723 ERR("consumer_rotate_rename: old path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)",
1724 old_path_length
+ 1, sizeof(msg
.u
.rotate_rename
.old_path
));
1725 ret
= -LTTNG_ERR_INVALID
;
1729 new_path_length
= strlen(new_path
);
1730 if (new_path_length
>= sizeof(msg
.u
.rotate_rename
.new_path
)) {
1731 ERR("consumer_rotate_rename: new path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)",
1732 new_path_length
+ 1, sizeof(msg
.u
.rotate_rename
.new_path
));
1733 ret
= -LTTNG_ERR_INVALID
;
1737 memset(&msg
, 0, sizeof(msg
));
1738 msg
.cmd_type
= LTTNG_CONSUMER_ROTATE_RENAME
;
1739 msg
.u
.rotate_rename
.session_id
= session_id
;
1740 msg
.u
.rotate_rename
.uid
= uid
;
1741 msg
.u
.rotate_rename
.gid
= gid
;
1742 strcpy(msg
.u
.rotate_rename
.old_path
, old_path
);
1743 strcpy(msg
.u
.rotate_rename
.new_path
, new_path
);
1745 if (output
->type
== CONSUMER_DST_NET
) {
1746 msg
.u
.rotate_rename
.relayd_id
= output
->net_seq_index
;
1748 msg
.u
.rotate_rename
.relayd_id
= -1ULL;
1751 health_code_update();
1752 ret
= consumer_send_msg(socket
, &msg
);
1754 ret
= -LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER
;
1759 health_code_update();
1764 * Ask the consumer if a rotation is locally pending. Must be called with the
1767 * Return 1 if the rotation is still pending, 0 if finished, a negative value
1770 int consumer_check_rotation_pending_local(struct consumer_socket
*socket
,
1771 uint64_t session_id
, uint64_t chunk_id
)
1774 struct lttcomm_consumer_msg msg
;
1775 uint32_t pending
= 0;
1779 DBG("Asking consumer to locally check for pending rotation for session %" PRIu64
", chunk id %" PRIu64
,
1780 session_id
, chunk_id
);
1782 memset(&msg
, 0, sizeof(msg
));
1783 msg
.cmd_type
= LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
;
1784 msg
.u
.check_rotation_pending_local
.session_id
= session_id
;
1785 msg
.u
.check_rotation_pending_local
.chunk_id
= chunk_id
;
1787 health_code_update();
1788 ret
= consumer_send_msg(socket
, &msg
);
1790 ret
= -LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER
;
1794 ret
= consumer_socket_recv(socket
, &pending
, sizeof(pending
));
1802 health_code_update();
1807 * Ask the consumer if a rotation is pending on the relayd. Must be called with
1808 * the socket lock held.
1810 * Return 1 if the rotation is still pending, 0 if finished, a negative value
1813 int consumer_check_rotation_pending_relay(struct consumer_socket
*socket
,
1814 const struct consumer_output
*output
, uint64_t session_id
,
1818 struct lttcomm_consumer_msg msg
;
1819 uint32_t pending
= 0;
1823 DBG("Asking consumer to check for pending rotation on relay for session %" PRIu64
", chunk id %" PRIu64
,
1824 session_id
, chunk_id
);
1825 assert(output
->type
== CONSUMER_DST_NET
);
1827 memset(&msg
, 0, sizeof(msg
));
1828 msg
.cmd_type
= LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
;
1829 msg
.u
.check_rotation_pending_relay
.session_id
= session_id
;
1830 msg
.u
.check_rotation_pending_relay
.relayd_id
= output
->net_seq_index
;
1831 msg
.u
.check_rotation_pending_relay
.chunk_id
= chunk_id
;
1833 health_code_update();
1834 ret
= consumer_send_msg(socket
, &msg
);
1836 ret
= -LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER
;
1840 ret
= consumer_socket_recv(socket
, &pending
, sizeof(pending
));
1848 health_code_update();
1853 * Ask the consumer to create a directory.
1855 * Called with the consumer socket lock held.
1857 int consumer_mkdir(struct consumer_socket
*socket
, uint64_t session_id
,
1858 const struct consumer_output
*output
, const char *path
,
1859 uid_t uid
, gid_t gid
)
1862 struct lttcomm_consumer_msg msg
;
1866 DBG("Consumer mkdir %s in session %" PRIu64
, path
, session_id
);
1868 memset(&msg
, 0, sizeof(msg
));
1869 msg
.cmd_type
= LTTNG_CONSUMER_MKDIR
;
1870 msg
.u
.mkdir
.session_id
= session_id
;
1871 msg
.u
.mkdir
.uid
= uid
;
1872 msg
.u
.mkdir
.gid
= gid
;
1873 ret
= snprintf(msg
.u
.mkdir
.path
, sizeof(msg
.u
.mkdir
.path
), "%s", path
);
1874 if (ret
< 0 || ret
>= sizeof(msg
.u
.mkdir
.path
)) {
1876 ret
= -LTTNG_ERR_INVALID
;
1880 if (output
->type
== CONSUMER_DST_NET
) {
1881 msg
.u
.mkdir
.relayd_id
= output
->net_seq_index
;
1883 msg
.u
.mkdir
.relayd_id
= -1ULL;
1886 health_code_update();
1887 ret
= consumer_send_msg(socket
, &msg
);
1889 ret
= -LTTNG_ERR_MKDIR_FAIL_CONSUMER
;
1894 health_code_update();
1898 int consumer_init(struct consumer_socket
*socket
,
1899 const lttng_uuid sessiond_uuid
)
1902 struct lttcomm_consumer_msg msg
= {
1903 .cmd_type
= LTTNG_CONSUMER_INIT
,
1908 DBG("Sending consumer initialization command");
1909 lttng_uuid_copy(msg
.u
.init
.sessiond_uuid
, sessiond_uuid
);
1911 health_code_update();
1912 ret
= consumer_send_msg(socket
, &msg
);
1918 health_code_update();