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"
38 #include "lttng-sessiond.h"
41 * Send a data payload using a given consumer socket of size len.
43 * The consumer socket lock MUST be acquired before calling this since this
44 * function can change the fd value.
46 * Return 0 on success else a negative value on error.
48 int consumer_socket_send(struct consumer_socket
*socket
, void *msg
, size_t len
)
54 assert(socket
->fd_ptr
);
57 /* Consumer socket is invalid. Stopping. */
63 size
= lttcomm_send_unix_sock(fd
, msg
, len
);
65 /* The above call will print a PERROR on error. */
66 DBG("Error when sending data to consumer on sock %d", fd
);
68 * At this point, the socket is not usable anymore thus closing it and
69 * setting the file descriptor to -1 so it is not reused.
72 /* This call will PERROR on error. */
73 (void) lttcomm_close_unix_sock(fd
);
85 * Receive a data payload using a given consumer socket of size len.
87 * The consumer socket lock MUST be acquired before calling this since this
88 * function can change the fd value.
90 * Return 0 on success else a negative value on error.
92 int consumer_socket_recv(struct consumer_socket
*socket
, void *msg
, size_t len
)
98 assert(socket
->fd_ptr
);
101 /* Consumer socket is invalid. Stopping. */
102 fd
= *socket
->fd_ptr
;
107 size
= lttcomm_recv_unix_sock(fd
, msg
, len
);
109 /* The above call will print a PERROR on error. */
110 DBG("Error when receiving data from the consumer socket %d", fd
);
112 * At this point, the socket is not usable anymore thus closing it and
113 * setting the file descriptor to -1 so it is not reused.
116 /* This call will PERROR on error. */
117 (void) lttcomm_close_unix_sock(fd
);
118 *socket
->fd_ptr
= -1;
129 * Receive a reply command status message from the consumer. Consumer socket
130 * lock MUST be acquired before calling this function.
132 * Return 0 on success, -1 on recv error or a negative lttng error code which
133 * was possibly returned by the consumer.
135 int consumer_recv_status_reply(struct consumer_socket
*sock
)
138 struct lttcomm_consumer_status_msg reply
;
142 ret
= consumer_socket_recv(sock
, &reply
, sizeof(reply
));
147 if (reply
.ret_code
== LTTCOMM_CONSUMERD_SUCCESS
) {
151 ret
= -reply
.ret_code
;
152 DBG("Consumer ret code %d", ret
);
160 * Once the ASK_CHANNEL command is sent to the consumer, the channel
161 * information are sent back. This call receives that data and populates key
164 * On success return 0 and both key and stream_count are set. On error, a
165 * negative value is sent back and both parameters are untouched.
167 int consumer_recv_status_channel(struct consumer_socket
*sock
,
168 uint64_t *key
, unsigned int *stream_count
)
171 struct lttcomm_consumer_status_channel reply
;
174 assert(stream_count
);
177 ret
= consumer_socket_recv(sock
, &reply
, sizeof(reply
));
182 /* An error is possible so don't touch the key and stream_count. */
183 if (reply
.ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
189 *stream_count
= reply
.stream_count
;
197 * Send destroy relayd command to consumer.
199 * On success return positive value. On error, negative value.
201 int consumer_send_destroy_relayd(struct consumer_socket
*sock
,
202 struct consumer_output
*consumer
)
205 struct lttcomm_consumer_msg msg
;
210 DBG2("Sending destroy relayd command to consumer sock %d", *sock
->fd_ptr
);
212 memset(&msg
, 0, sizeof(msg
));
213 msg
.cmd_type
= LTTNG_CONSUMER_DESTROY_RELAYD
;
214 msg
.u
.destroy_relayd
.net_seq_idx
= consumer
->net_seq_index
;
216 pthread_mutex_lock(sock
->lock
);
217 ret
= consumer_socket_send(sock
, &msg
, sizeof(msg
));
222 /* Don't check the return value. The caller will do it. */
223 ret
= consumer_recv_status_reply(sock
);
225 DBG2("Consumer send destroy relayd command done");
228 pthread_mutex_unlock(sock
->lock
);
233 * For each consumer socket in the consumer output object, send a destroy
236 void consumer_output_send_destroy_relayd(struct consumer_output
*consumer
)
238 struct lttng_ht_iter iter
;
239 struct consumer_socket
*socket
;
243 /* Destroy any relayd connection */
244 if (consumer
->type
== CONSUMER_DST_NET
) {
246 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
250 /* Send destroy relayd command */
251 ret
= consumer_send_destroy_relayd(socket
, consumer
);
253 DBG("Unable to send destroy relayd command to consumer");
254 /* Continue since we MUST delete everything at this point. */
262 * From a consumer_data structure, allocate and add a consumer socket to the
265 * Return 0 on success, else negative value on error
267 int consumer_create_socket(struct consumer_data
*data
,
268 struct consumer_output
*output
)
271 struct consumer_socket
*socket
;
275 if (output
== NULL
|| data
->cmd_sock
< 0) {
277 * Not an error. Possible there is simply not spawned consumer or it's
278 * disabled for the tracing session asking the socket.
284 socket
= consumer_find_socket(data
->cmd_sock
, output
);
286 if (socket
== NULL
) {
287 socket
= consumer_allocate_socket(&data
->cmd_sock
);
288 if (socket
== NULL
) {
293 socket
->registered
= 0;
294 socket
->lock
= &data
->lock
;
296 consumer_add_socket(socket
, output
);
300 socket
->type
= data
->type
;
302 DBG3("Consumer socket created (fd: %d) and added to output",
310 * Return the consumer socket from the given consumer output with the right
311 * bitness. On error, returns NULL.
313 * The caller MUST acquire a rcu read side lock and keep it until the socket
314 * object reference is not needed anymore.
316 struct consumer_socket
*consumer_find_socket_by_bitness(int bits
,
317 struct consumer_output
*consumer
)
320 struct consumer_socket
*socket
= NULL
;
324 consumer_fd
= uatomic_read(&ust_consumerd64_fd
);
327 consumer_fd
= uatomic_read(&ust_consumerd32_fd
);
334 socket
= consumer_find_socket(consumer_fd
, consumer
);
336 ERR("Consumer socket fd %d not found in consumer obj %p",
337 consumer_fd
, consumer
);
345 * Find a consumer_socket in a consumer_output hashtable. Read side lock must
346 * be acquired before calling this function and across use of the
347 * returned consumer_socket.
349 struct consumer_socket
*consumer_find_socket(int key
,
350 struct consumer_output
*consumer
)
352 struct lttng_ht_iter iter
;
353 struct lttng_ht_node_ulong
*node
;
354 struct consumer_socket
*socket
= NULL
;
356 /* Negative keys are lookup failures */
357 if (key
< 0 || consumer
== NULL
) {
361 lttng_ht_lookup(consumer
->socks
, (void *)((unsigned long) key
),
363 node
= lttng_ht_iter_get_node_ulong(&iter
);
365 socket
= caa_container_of(node
, struct consumer_socket
, node
);
372 * Allocate a new consumer_socket and return the pointer.
374 struct consumer_socket
*consumer_allocate_socket(int *fd
)
376 struct consumer_socket
*socket
= NULL
;
380 socket
= zmalloc(sizeof(struct consumer_socket
));
381 if (socket
== NULL
) {
382 PERROR("zmalloc consumer socket");
387 lttng_ht_node_init_ulong(&socket
->node
, *fd
);
394 * Add consumer socket to consumer output object. Read side lock must be
395 * acquired before calling this function.
397 void consumer_add_socket(struct consumer_socket
*sock
,
398 struct consumer_output
*consumer
)
403 lttng_ht_add_unique_ulong(consumer
->socks
, &sock
->node
);
407 * Delte consumer socket to consumer output object. Read side lock must be
408 * acquired before calling this function.
410 void consumer_del_socket(struct consumer_socket
*sock
,
411 struct consumer_output
*consumer
)
414 struct lttng_ht_iter iter
;
419 iter
.iter
.node
= &sock
->node
.node
;
420 ret
= lttng_ht_del(consumer
->socks
, &iter
);
425 * RCU destroy call function.
427 static void destroy_socket_rcu(struct rcu_head
*head
)
429 struct lttng_ht_node_ulong
*node
=
430 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
431 struct consumer_socket
*socket
=
432 caa_container_of(node
, struct consumer_socket
, node
);
438 * Destroy and free socket pointer in a call RCU. Read side lock must be
439 * acquired before calling this function.
441 void consumer_destroy_socket(struct consumer_socket
*sock
)
446 * We DO NOT close the file descriptor here since it is global to the
447 * session daemon and is closed only if the consumer dies or a custom
448 * consumer was registered,
450 if (sock
->registered
) {
451 DBG3("Consumer socket was registered. Closing fd %d", *sock
->fd_ptr
);
452 lttcomm_close_unix_sock(*sock
->fd_ptr
);
455 call_rcu(&sock
->node
.head
, destroy_socket_rcu
);
459 * Allocate and assign data to a consumer_output object.
461 * Return pointer to structure.
463 struct consumer_output
*consumer_create_output(enum consumer_dst_type type
)
465 struct consumer_output
*output
= NULL
;
467 output
= zmalloc(sizeof(struct consumer_output
));
468 if (output
== NULL
) {
469 PERROR("zmalloc consumer_output");
473 /* By default, consumer output is enabled */
476 output
->net_seq_index
= (uint64_t) -1ULL;
477 urcu_ref_init(&output
->ref
);
479 output
->socks
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
486 * Iterate over the consumer output socket hash table and destroy them. The
487 * socket file descriptor are only closed if the consumer output was
488 * registered meaning it's an external consumer.
490 void consumer_destroy_output_sockets(struct consumer_output
*obj
)
492 struct lttng_ht_iter iter
;
493 struct consumer_socket
*socket
;
500 cds_lfht_for_each_entry(obj
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
501 consumer_del_socket(socket
, obj
);
502 consumer_destroy_socket(socket
);
508 * Delete the consumer_output object from the list and free the ptr.
510 * Should *NOT* be called with RCU read-side lock held.
512 static void consumer_release_output(struct urcu_ref
*ref
)
514 struct consumer_output
*obj
=
515 caa_container_of(ref
, struct consumer_output
, ref
);
517 consumer_destroy_output_sockets(obj
);
520 /* Finally destroy HT */
521 ht_cleanup_push(obj
->socks
);
528 * Get the consumer_output object.
530 void consumer_output_get(struct consumer_output
*obj
)
532 urcu_ref_get(&obj
->ref
);
536 * Put the consumer_output object.
538 * Should *NOT* be called with RCU read-side lock held.
540 void consumer_output_put(struct consumer_output
*obj
)
545 urcu_ref_put(&obj
->ref
, consumer_release_output
);
549 * Copy consumer output and returned the newly allocated copy.
551 * Should *NOT* be called with RCU read-side lock held.
553 struct consumer_output
*consumer_copy_output(struct consumer_output
*src
)
556 struct consumer_output
*output
;
560 output
= consumer_create_output(src
->type
);
561 if (output
== NULL
) {
564 output
->enabled
= src
->enabled
;
565 output
->net_seq_index
= src
->net_seq_index
;
566 memcpy(output
->domain_subdir
, src
->domain_subdir
,
567 sizeof(output
->domain_subdir
));
568 output
->snapshot
= src
->snapshot
;
569 output
->relay_major_version
= src
->relay_major_version
;
570 output
->relay_minor_version
= src
->relay_minor_version
;
571 memcpy(&output
->dst
, &src
->dst
, sizeof(output
->dst
));
572 ret
= consumer_copy_sockets(output
, src
);
580 consumer_output_put(output
);
585 * Copy consumer sockets from src to dst.
587 * Return 0 on success or else a negative value.
589 int consumer_copy_sockets(struct consumer_output
*dst
,
590 struct consumer_output
*src
)
593 struct lttng_ht_iter iter
;
594 struct consumer_socket
*socket
, *copy_sock
;
600 cds_lfht_for_each_entry(src
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
601 /* Ignore socket that are already there. */
602 copy_sock
= consumer_find_socket(*socket
->fd_ptr
, dst
);
607 /* Create new socket object. */
608 copy_sock
= consumer_allocate_socket(socket
->fd_ptr
);
609 if (copy_sock
== NULL
) {
615 copy_sock
->registered
= socket
->registered
;
617 * This is valid because this lock is shared accross all consumer
618 * object being the global lock of the consumer data structure of the
621 copy_sock
->lock
= socket
->lock
;
622 consumer_add_socket(copy_sock
, dst
);
631 * Set network URI to the consumer output.
633 * Return 0 on success. Return 1 if the URI were equal. Else, negative value on
636 int consumer_set_network_uri(const struct ltt_session
*session
,
637 struct consumer_output
*output
,
638 struct lttng_uri
*uri
)
641 struct lttng_uri
*dst_uri
= NULL
;
643 /* Code flow error safety net. */
647 switch (uri
->stype
) {
648 case LTTNG_STREAM_CONTROL
:
649 dst_uri
= &output
->dst
.net
.control
;
650 output
->dst
.net
.control_isset
= 1;
651 if (uri
->port
== 0) {
652 /* Assign default port. */
653 uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
655 if (output
->dst
.net
.data_isset
&& uri
->port
==
656 output
->dst
.net
.data
.port
) {
657 ret
= -LTTNG_ERR_INVALID
;
661 DBG3("Consumer control URI set with port %d", uri
->port
);
663 case LTTNG_STREAM_DATA
:
664 dst_uri
= &output
->dst
.net
.data
;
665 output
->dst
.net
.data_isset
= 1;
666 if (uri
->port
== 0) {
667 /* Assign default port. */
668 uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
670 if (output
->dst
.net
.control_isset
&& uri
->port
==
671 output
->dst
.net
.control
.port
) {
672 ret
= -LTTNG_ERR_INVALID
;
676 DBG3("Consumer data URI set with port %d", uri
->port
);
679 ERR("Set network uri type unknown %d", uri
->stype
);
680 ret
= -LTTNG_ERR_INVALID
;
684 ret
= uri_compare(dst_uri
, uri
);
686 /* Same URI, don't touch it and return success. */
687 DBG3("URI network compare are the same");
691 /* URIs were not equal, replacing it. */
692 memcpy(dst_uri
, uri
, sizeof(struct lttng_uri
));
693 output
->type
= CONSUMER_DST_NET
;
694 if (dst_uri
->stype
!= LTTNG_STREAM_CONTROL
) {
695 /* Only the control uri needs to contain the path. */
700 * If the user has specified a subdir as part of the control
701 * URL, the session's base output directory is:
702 * /RELAYD_OUTPUT_PATH/HOSTNAME/USER_SPECIFIED_DIR
704 * Hence, the "base_dir" from which all stream files and
705 * session rotation chunks are created takes the form
706 * /HOSTNAME/USER_SPECIFIED_DIR
708 * If the user has not specified an output directory as part of
709 * the control URL, the base output directory has the form:
710 * /RELAYD_OUTPUT_PATH/HOSTNAME/SESSION_NAME-CREATION_TIME
712 * Hence, the "base_dir" from which all stream files and
713 * session rotation chunks are created takes the form
714 * /HOSTNAME/SESSION_NAME-CREATION_TIME
716 * Note that automatically generated session names already
717 * contain the session's creation time. In that case, the
718 * creation time is omitted to prevent it from being duplicated
719 * in the final directory hierarchy.
722 if (strstr(uri
->subdir
, "../")) {
723 ERR("Network URI subdirs are not allowed to walk up the path hierarchy");
724 ret
= -LTTNG_ERR_INVALID
;
727 ret
= snprintf(output
->dst
.net
.base_dir
,
728 sizeof(output
->dst
.net
.base_dir
),
729 "/%s/%s/", session
->hostname
, uri
->subdir
);
731 if (session
->has_auto_generated_name
) {
732 ret
= snprintf(output
->dst
.net
.base_dir
,
733 sizeof(output
->dst
.net
.base_dir
),
734 "/%s/%s/", session
->hostname
,
737 char session_creation_datetime
[16];
741 timeinfo
= localtime(&session
->creation_time
);
743 ret
= -LTTNG_ERR_FATAL
;
746 strftime_ret
= strftime(session_creation_datetime
,
747 sizeof(session_creation_datetime
),
748 "%Y%m%d-%H%M%S", timeinfo
);
749 if (strftime_ret
== 0) {
750 ERR("Failed to format session creation timestamp while setting network URI");
751 ret
= -LTTNG_ERR_FATAL
;
754 ret
= snprintf(output
->dst
.net
.base_dir
,
755 sizeof(output
->dst
.net
.base_dir
),
756 "/%s/%s-%s/", session
->hostname
,
758 session_creation_datetime
);
761 if (ret
>= sizeof(output
->dst
.net
.base_dir
)) {
762 ret
= -LTTNG_ERR_INVALID
;
763 ERR("Truncation occurred while setting network output base directory");
765 } else if (ret
== -1) {
766 ret
= -LTTNG_ERR_INVALID
;
767 PERROR("Error occurred while setting network output base directory");
771 DBG3("Consumer set network uri base_dir path %s",
772 output
->dst
.net
.base_dir
);
783 * Send file descriptor to consumer via sock.
785 * The consumer socket lock must be held by the caller.
787 int consumer_send_fds(struct consumer_socket
*sock
, const int *fds
,
795 assert(pthread_mutex_trylock(sock
->lock
) == EBUSY
);
797 ret
= lttcomm_send_fds_unix_sock(*sock
->fd_ptr
, fds
, nb_fd
);
799 /* The above call will print a PERROR on error. */
800 DBG("Error when sending consumer fds on sock %d", *sock
->fd_ptr
);
804 ret
= consumer_recv_status_reply(sock
);
810 * Consumer send communication message structure to consumer.
812 * The consumer socket lock must be held by the caller.
814 int consumer_send_msg(struct consumer_socket
*sock
,
815 struct lttcomm_consumer_msg
*msg
)
821 assert(pthread_mutex_trylock(sock
->lock
) == EBUSY
);
823 ret
= consumer_socket_send(sock
, msg
, sizeof(struct lttcomm_consumer_msg
));
828 ret
= consumer_recv_status_reply(sock
);
835 * Consumer send channel communication message structure to consumer.
837 * The consumer socket lock must be held by the caller.
839 int consumer_send_channel(struct consumer_socket
*sock
,
840 struct lttcomm_consumer_msg
*msg
)
847 ret
= consumer_send_msg(sock
, msg
);
857 * Populate the given consumer msg structure with the ask_channel command
860 void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
861 uint64_t subbuf_size
,
864 unsigned int switch_timer_interval
,
865 unsigned int read_timer_interval
,
866 unsigned int live_timer_interval
,
867 unsigned int monitor_timer_interval
,
871 const char *pathname
,
879 uint64_t tracefile_size
,
880 uint64_t tracefile_count
,
881 uint64_t session_id_per_pid
,
882 unsigned int monitor
,
883 uint32_t ust_app_uid
,
884 int64_t blocking_timeout
,
885 const char *root_shm_path
,
886 const char *shm_path
,
887 uint64_t trace_archive_id
)
891 /* Zeroed structure */
892 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
894 msg
->cmd_type
= LTTNG_CONSUMER_ASK_CHANNEL_CREATION
;
895 msg
->u
.ask_channel
.subbuf_size
= subbuf_size
;
896 msg
->u
.ask_channel
.num_subbuf
= num_subbuf
;
897 msg
->u
.ask_channel
.overwrite
= overwrite
;
898 msg
->u
.ask_channel
.switch_timer_interval
= switch_timer_interval
;
899 msg
->u
.ask_channel
.read_timer_interval
= read_timer_interval
;
900 msg
->u
.ask_channel
.live_timer_interval
= live_timer_interval
;
901 msg
->u
.ask_channel
.monitor_timer_interval
= monitor_timer_interval
;
902 msg
->u
.ask_channel
.output
= output
;
903 msg
->u
.ask_channel
.type
= type
;
904 msg
->u
.ask_channel
.session_id
= session_id
;
905 msg
->u
.ask_channel
.session_id_per_pid
= session_id_per_pid
;
906 msg
->u
.ask_channel
.uid
= uid
;
907 msg
->u
.ask_channel
.gid
= gid
;
908 msg
->u
.ask_channel
.relayd_id
= relayd_id
;
909 msg
->u
.ask_channel
.key
= key
;
910 msg
->u
.ask_channel
.chan_id
= chan_id
;
911 msg
->u
.ask_channel
.tracefile_size
= tracefile_size
;
912 msg
->u
.ask_channel
.tracefile_count
= tracefile_count
;
913 msg
->u
.ask_channel
.monitor
= monitor
;
914 msg
->u
.ask_channel
.ust_app_uid
= ust_app_uid
;
915 msg
->u
.ask_channel
.blocking_timeout
= blocking_timeout
;
916 msg
->u
.ask_channel
.trace_archive_id
= trace_archive_id
;
918 memcpy(msg
->u
.ask_channel
.uuid
, uuid
, sizeof(msg
->u
.ask_channel
.uuid
));
921 strncpy(msg
->u
.ask_channel
.pathname
, pathname
,
922 sizeof(msg
->u
.ask_channel
.pathname
));
923 msg
->u
.ask_channel
.pathname
[sizeof(msg
->u
.ask_channel
.pathname
)-1] = '\0';
926 strncpy(msg
->u
.ask_channel
.name
, name
, sizeof(msg
->u
.ask_channel
.name
));
927 msg
->u
.ask_channel
.name
[sizeof(msg
->u
.ask_channel
.name
) - 1] = '\0';
930 strncpy(msg
->u
.ask_channel
.root_shm_path
, root_shm_path
,
931 sizeof(msg
->u
.ask_channel
.root_shm_path
));
932 msg
->u
.ask_channel
.root_shm_path
[sizeof(msg
->u
.ask_channel
.root_shm_path
) - 1] = '\0';
935 strncpy(msg
->u
.ask_channel
.shm_path
, shm_path
,
936 sizeof(msg
->u
.ask_channel
.shm_path
));
937 msg
->u
.ask_channel
.shm_path
[sizeof(msg
->u
.ask_channel
.shm_path
) - 1] = '\0';
942 * Init channel communication message structure.
944 void consumer_init_add_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
945 uint64_t channel_key
,
947 const char *pathname
,
952 unsigned int nb_init_streams
,
953 enum lttng_event_output output
,
955 uint64_t tracefile_size
,
956 uint64_t tracefile_count
,
957 unsigned int monitor
,
958 unsigned int live_timer_interval
,
959 unsigned int monitor_timer_interval
)
963 /* Zeroed structure */
964 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
967 msg
->cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
968 msg
->u
.channel
.channel_key
= channel_key
;
969 msg
->u
.channel
.session_id
= session_id
;
970 msg
->u
.channel
.uid
= uid
;
971 msg
->u
.channel
.gid
= gid
;
972 msg
->u
.channel
.relayd_id
= relayd_id
;
973 msg
->u
.channel
.nb_init_streams
= nb_init_streams
;
974 msg
->u
.channel
.output
= output
;
975 msg
->u
.channel
.type
= type
;
976 msg
->u
.channel
.tracefile_size
= tracefile_size
;
977 msg
->u
.channel
.tracefile_count
= tracefile_count
;
978 msg
->u
.channel
.monitor
= monitor
;
979 msg
->u
.channel
.live_timer_interval
= live_timer_interval
;
980 msg
->u
.channel
.monitor_timer_interval
= monitor_timer_interval
;
982 strncpy(msg
->u
.channel
.pathname
, pathname
,
983 sizeof(msg
->u
.channel
.pathname
));
984 msg
->u
.channel
.pathname
[sizeof(msg
->u
.channel
.pathname
) - 1] = '\0';
986 strncpy(msg
->u
.channel
.name
, name
, sizeof(msg
->u
.channel
.name
));
987 msg
->u
.channel
.name
[sizeof(msg
->u
.channel
.name
) - 1] = '\0';
991 * Init stream communication message structure.
993 void consumer_init_add_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
994 uint64_t channel_key
,
997 uint64_t trace_archive_id
)
1001 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
1003 msg
->cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
1004 msg
->u
.stream
.channel_key
= channel_key
;
1005 msg
->u
.stream
.stream_key
= stream_key
;
1006 msg
->u
.stream
.cpu
= cpu
;
1007 msg
->u
.stream
.trace_archive_id
= trace_archive_id
;
1010 void consumer_init_streams_sent_comm_msg(struct lttcomm_consumer_msg
*msg
,
1011 enum lttng_consumer_command cmd
,
1012 uint64_t channel_key
, uint64_t net_seq_idx
)
1016 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
1018 msg
->cmd_type
= cmd
;
1019 msg
->u
.sent_streams
.channel_key
= channel_key
;
1020 msg
->u
.sent_streams
.net_seq_idx
= net_seq_idx
;
1024 * Send stream communication structure to the consumer.
1026 int consumer_send_stream(struct consumer_socket
*sock
,
1027 struct consumer_output
*dst
, struct lttcomm_consumer_msg
*msg
,
1028 const int *fds
, size_t nb_fd
)
1037 ret
= consumer_send_msg(sock
, msg
);
1042 ret
= consumer_send_fds(sock
, fds
, nb_fd
);
1052 * Send relayd socket to consumer associated with a session name.
1054 * The consumer socket lock must be held by the caller.
1056 * On success return positive value. On error, negative value.
1058 int consumer_send_relayd_socket(struct consumer_socket
*consumer_sock
,
1059 struct lttcomm_relayd_sock
*rsock
, struct consumer_output
*consumer
,
1060 enum lttng_stream_type type
, uint64_t session_id
,
1061 char *session_name
, char *hostname
, int session_live_timer
)
1064 struct lttcomm_consumer_msg msg
;
1066 /* Code flow error. Safety net. */
1069 assert(consumer_sock
);
1071 memset(&msg
, 0, sizeof(msg
));
1072 /* Bail out if consumer is disabled */
1073 if (!consumer
->enabled
) {
1078 if (type
== LTTNG_STREAM_CONTROL
) {
1079 ret
= relayd_create_session(rsock
,
1080 &msg
.u
.relayd_sock
.relayd_session_id
,
1081 session_name
, hostname
, session_live_timer
,
1082 consumer
->snapshot
, session_id
,
1085 /* Close the control socket. */
1086 (void) relayd_close(rsock
);
1091 msg
.cmd_type
= LTTNG_CONSUMER_ADD_RELAYD_SOCKET
;
1093 * Assign network consumer output index using the temporary consumer since
1094 * this call should only be made from within a set_consumer_uri() function
1095 * call in the session daemon.
1097 msg
.u
.relayd_sock
.net_index
= consumer
->net_seq_index
;
1098 msg
.u
.relayd_sock
.type
= type
;
1099 msg
.u
.relayd_sock
.session_id
= session_id
;
1100 memcpy(&msg
.u
.relayd_sock
.sock
, rsock
, sizeof(msg
.u
.relayd_sock
.sock
));
1102 DBG3("Sending relayd sock info to consumer on %d", *consumer_sock
->fd_ptr
);
1103 ret
= consumer_send_msg(consumer_sock
, &msg
);
1108 DBG3("Sending relayd socket file descriptor to consumer");
1109 ret
= consumer_send_fds(consumer_sock
, &rsock
->sock
.fd
, 1);
1114 DBG2("Consumer relayd socket sent");
1121 int consumer_send_pipe(struct consumer_socket
*consumer_sock
,
1122 enum lttng_consumer_command cmd
, int pipe
)
1125 struct lttcomm_consumer_msg msg
;
1126 const char *pipe_name
;
1127 const char *command_name
;
1130 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1131 pipe_name
= "channel monitor";
1132 command_name
= "SET_CHANNEL_MONITOR_PIPE";
1135 ERR("Unexpected command received in %s (cmd = %d)", __func__
,
1140 /* Code flow error. Safety net. */
1142 memset(&msg
, 0, sizeof(msg
));
1145 pthread_mutex_lock(consumer_sock
->lock
);
1146 DBG3("Sending %s command to consumer", command_name
);
1147 ret
= consumer_send_msg(consumer_sock
, &msg
);
1152 DBG3("Sending %s pipe %d to consumer on socket %d",
1154 pipe
, *consumer_sock
->fd_ptr
);
1155 ret
= consumer_send_fds(consumer_sock
, &pipe
, 1);
1160 DBG2("%s pipe successfully sent", pipe_name
);
1162 pthread_mutex_unlock(consumer_sock
->lock
);
1166 int consumer_send_channel_monitor_pipe(struct consumer_socket
*consumer_sock
,
1169 return consumer_send_pipe(consumer_sock
,
1170 LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
, pipe
);
1174 * Ask the consumer if the data is pending for the specific session id.
1175 * Returns 1 if data is pending, 0 otherwise, or < 0 on error.
1177 int consumer_is_data_pending(uint64_t session_id
,
1178 struct consumer_output
*consumer
)
1181 int32_t ret_code
= 0; /* Default is that the data is NOT pending */
1182 struct consumer_socket
*socket
;
1183 struct lttng_ht_iter iter
;
1184 struct lttcomm_consumer_msg msg
;
1188 DBG3("Consumer data pending for id %" PRIu64
, session_id
);
1190 memset(&msg
, 0, sizeof(msg
));
1191 msg
.cmd_type
= LTTNG_CONSUMER_DATA_PENDING
;
1192 msg
.u
.data_pending
.session_id
= session_id
;
1194 /* Send command for each consumer */
1196 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1198 pthread_mutex_lock(socket
->lock
);
1199 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1201 pthread_mutex_unlock(socket
->lock
);
1206 * No need for a recv reply status because the answer to the command is
1207 * the reply status message.
1210 ret
= consumer_socket_recv(socket
, &ret_code
, sizeof(ret_code
));
1212 pthread_mutex_unlock(socket
->lock
);
1215 pthread_mutex_unlock(socket
->lock
);
1217 if (ret_code
== 1) {
1223 DBG("Consumer data is %s pending for session id %" PRIu64
,
1224 ret_code
== 1 ? "" : "NOT", session_id
);
1233 * Send a flush command to consumer using the given channel key.
1235 * Return 0 on success else a negative value.
1237 int consumer_flush_channel(struct consumer_socket
*socket
, uint64_t key
)
1240 struct lttcomm_consumer_msg msg
;
1244 DBG2("Consumer flush channel key %" PRIu64
, key
);
1246 memset(&msg
, 0, sizeof(msg
));
1247 msg
.cmd_type
= LTTNG_CONSUMER_FLUSH_CHANNEL
;
1248 msg
.u
.flush_channel
.key
= key
;
1250 pthread_mutex_lock(socket
->lock
);
1251 health_code_update();
1253 ret
= consumer_send_msg(socket
, &msg
);
1259 health_code_update();
1260 pthread_mutex_unlock(socket
->lock
);
1265 * Send a clear quiescent command to consumer using the given channel key.
1267 * Return 0 on success else a negative value.
1269 int consumer_clear_quiescent_channel(struct consumer_socket
*socket
, uint64_t key
)
1272 struct lttcomm_consumer_msg msg
;
1276 DBG2("Consumer clear quiescent channel key %" PRIu64
, key
);
1278 memset(&msg
, 0, sizeof(msg
));
1279 msg
.cmd_type
= LTTNG_CONSUMER_CLEAR_QUIESCENT_CHANNEL
;
1280 msg
.u
.clear_quiescent_channel
.key
= key
;
1282 pthread_mutex_lock(socket
->lock
);
1283 health_code_update();
1285 ret
= consumer_send_msg(socket
, &msg
);
1291 health_code_update();
1292 pthread_mutex_unlock(socket
->lock
);
1297 * Send a close metadata command to consumer using the given channel key.
1298 * Called with registry lock held.
1300 * Return 0 on success else a negative value.
1302 int consumer_close_metadata(struct consumer_socket
*socket
,
1303 uint64_t metadata_key
)
1306 struct lttcomm_consumer_msg msg
;
1310 DBG2("Consumer close metadata channel key %" PRIu64
, metadata_key
);
1312 memset(&msg
, 0, sizeof(msg
));
1313 msg
.cmd_type
= LTTNG_CONSUMER_CLOSE_METADATA
;
1314 msg
.u
.close_metadata
.key
= metadata_key
;
1316 pthread_mutex_lock(socket
->lock
);
1317 health_code_update();
1319 ret
= consumer_send_msg(socket
, &msg
);
1325 health_code_update();
1326 pthread_mutex_unlock(socket
->lock
);
1331 * Send a setup metdata command to consumer using the given channel key.
1333 * Return 0 on success else a negative value.
1335 int consumer_setup_metadata(struct consumer_socket
*socket
,
1336 uint64_t metadata_key
)
1339 struct lttcomm_consumer_msg msg
;
1343 DBG2("Consumer setup metadata channel key %" PRIu64
, metadata_key
);
1345 memset(&msg
, 0, sizeof(msg
));
1346 msg
.cmd_type
= LTTNG_CONSUMER_SETUP_METADATA
;
1347 msg
.u
.setup_metadata
.key
= metadata_key
;
1349 pthread_mutex_lock(socket
->lock
);
1350 health_code_update();
1352 ret
= consumer_send_msg(socket
, &msg
);
1358 health_code_update();
1359 pthread_mutex_unlock(socket
->lock
);
1364 * Send metadata string to consumer.
1365 * RCU read-side lock must be held to guarantee existence of socket.
1367 * Return 0 on success else a negative value.
1369 int consumer_push_metadata(struct consumer_socket
*socket
,
1370 uint64_t metadata_key
, char *metadata_str
, size_t len
,
1371 size_t target_offset
, uint64_t version
)
1374 struct lttcomm_consumer_msg msg
;
1378 DBG2("Consumer push metadata to consumer socket %d", *socket
->fd_ptr
);
1380 pthread_mutex_lock(socket
->lock
);
1382 memset(&msg
, 0, sizeof(msg
));
1383 msg
.cmd_type
= LTTNG_CONSUMER_PUSH_METADATA
;
1384 msg
.u
.push_metadata
.key
= metadata_key
;
1385 msg
.u
.push_metadata
.target_offset
= target_offset
;
1386 msg
.u
.push_metadata
.len
= len
;
1387 msg
.u
.push_metadata
.version
= version
;
1389 health_code_update();
1390 ret
= consumer_send_msg(socket
, &msg
);
1391 if (ret
< 0 || len
== 0) {
1395 DBG3("Consumer pushing metadata on sock %d of len %zu", *socket
->fd_ptr
,
1398 ret
= consumer_socket_send(socket
, metadata_str
, len
);
1403 health_code_update();
1404 ret
= consumer_recv_status_reply(socket
);
1410 pthread_mutex_unlock(socket
->lock
);
1411 health_code_update();
1416 * Ask the consumer to snapshot a specific channel using the key.
1418 * Returns LTTNG_OK on success or else an LTTng error code.
1420 enum lttng_error_code
consumer_snapshot_channel(struct consumer_socket
*socket
,
1421 uint64_t key
, struct snapshot_output
*output
, int metadata
,
1422 uid_t uid
, gid_t gid
, const char *session_path
, int wait
,
1423 uint64_t nb_packets_per_stream
, uint64_t trace_archive_id
)
1426 enum lttng_error_code status
= LTTNG_OK
;
1427 struct lttcomm_consumer_msg msg
;
1431 assert(output
->consumer
);
1433 DBG("Consumer snapshot channel key %" PRIu64
, key
);
1435 memset(&msg
, 0, sizeof(msg
));
1436 msg
.cmd_type
= LTTNG_CONSUMER_SNAPSHOT_CHANNEL
;
1437 msg
.u
.snapshot_channel
.key
= key
;
1438 msg
.u
.snapshot_channel
.nb_packets_per_stream
= nb_packets_per_stream
;
1439 msg
.u
.snapshot_channel
.metadata
= metadata
;
1440 msg
.u
.snapshot_channel
.trace_archive_id
= trace_archive_id
;
1442 if (output
->consumer
->type
== CONSUMER_DST_NET
) {
1443 msg
.u
.snapshot_channel
.relayd_id
= output
->consumer
->net_seq_index
;
1444 msg
.u
.snapshot_channel
.use_relayd
= 1;
1445 ret
= snprintf(msg
.u
.snapshot_channel
.pathname
,
1446 sizeof(msg
.u
.snapshot_channel
.pathname
),
1447 "%s/%s/%s-%s-%" PRIu64
"%s",
1448 output
->consumer
->dst
.net
.base_dir
,
1449 output
->consumer
->domain_subdir
,
1450 output
->name
, output
->datetime
,
1451 output
->nb_snapshot
,
1454 status
= LTTNG_ERR_INVALID
;
1456 } else if (ret
>= sizeof(msg
.u
.snapshot_channel
.pathname
)) {
1457 ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s/%s-%s-%" PRIu64
"%s\"",
1458 sizeof(msg
.u
.snapshot_channel
.pathname
),
1459 ret
, output
->consumer
->dst
.net
.base_dir
,
1460 output
->consumer
->domain_subdir
,
1461 output
->name
, output
->datetime
,
1462 output
->nb_snapshot
,
1464 status
= LTTNG_ERR_SNAPSHOT_FAIL
;
1468 ret
= snprintf(msg
.u
.snapshot_channel
.pathname
,
1469 sizeof(msg
.u
.snapshot_channel
.pathname
),
1470 "%s/%s-%s-%" PRIu64
"%s",
1471 output
->consumer
->dst
.session_root_path
,
1472 output
->name
, output
->datetime
,
1473 output
->nb_snapshot
,
1476 status
= LTTNG_ERR_NOMEM
;
1478 } else if (ret
>= sizeof(msg
.u
.snapshot_channel
.pathname
)) {
1479 ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s-%s-%" PRIu64
"%s\"",
1480 sizeof(msg
.u
.snapshot_channel
.pathname
),
1481 ret
, output
->consumer
->dst
.session_root_path
,
1482 output
->name
, output
->datetime
, output
->nb_snapshot
,
1484 status
= LTTNG_ERR_SNAPSHOT_FAIL
;
1488 msg
.u
.snapshot_channel
.relayd_id
= (uint64_t) -1ULL;
1490 /* Create directory. Ignore if exist. */
1491 ret
= run_as_mkdir_recursive(msg
.u
.snapshot_channel
.pathname
,
1492 S_IRWXU
| S_IRWXG
, uid
, gid
);
1494 if (errno
!= EEXIST
) {
1495 status
= LTTNG_ERR_CREATE_DIR_FAIL
;
1496 PERROR("Trace directory creation error");
1502 health_code_update();
1503 pthread_mutex_lock(socket
->lock
);
1504 ret
= consumer_send_msg(socket
, &msg
);
1505 pthread_mutex_unlock(socket
->lock
);
1508 case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
:
1509 status
= LTTNG_ERR_CHAN_NOT_FOUND
;
1512 status
= LTTNG_ERR_SNAPSHOT_FAIL
;
1519 health_code_update();
1524 * Ask the consumer the number of discarded events for a channel.
1526 int consumer_get_discarded_events(uint64_t session_id
, uint64_t channel_key
,
1527 struct consumer_output
*consumer
, uint64_t *discarded
)
1530 struct consumer_socket
*socket
;
1531 struct lttng_ht_iter iter
;
1532 struct lttcomm_consumer_msg msg
;
1536 DBG3("Consumer discarded events id %" PRIu64
, session_id
);
1538 memset(&msg
, 0, sizeof(msg
));
1539 msg
.cmd_type
= LTTNG_CONSUMER_DISCARDED_EVENTS
;
1540 msg
.u
.discarded_events
.session_id
= session_id
;
1541 msg
.u
.discarded_events
.channel_key
= channel_key
;
1545 /* Send command for each consumer */
1547 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1549 uint64_t consumer_discarded
= 0;
1550 pthread_mutex_lock(socket
->lock
);
1551 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1553 pthread_mutex_unlock(socket
->lock
);
1558 * No need for a recv reply status because the answer to the
1559 * command is the reply status message.
1561 ret
= consumer_socket_recv(socket
, &consumer_discarded
,
1562 sizeof(consumer_discarded
));
1564 ERR("get discarded events");
1565 pthread_mutex_unlock(socket
->lock
);
1568 pthread_mutex_unlock(socket
->lock
);
1569 *discarded
+= consumer_discarded
;
1572 DBG("Consumer discarded %" PRIu64
" events in session id %" PRIu64
,
1573 *discarded
, session_id
);
1581 * Ask the consumer the number of lost packets for a channel.
1583 int consumer_get_lost_packets(uint64_t session_id
, uint64_t channel_key
,
1584 struct consumer_output
*consumer
, uint64_t *lost
)
1587 struct consumer_socket
*socket
;
1588 struct lttng_ht_iter iter
;
1589 struct lttcomm_consumer_msg msg
;
1593 DBG3("Consumer lost packets id %" PRIu64
, session_id
);
1595 memset(&msg
, 0, sizeof(msg
));
1596 msg
.cmd_type
= LTTNG_CONSUMER_LOST_PACKETS
;
1597 msg
.u
.lost_packets
.session_id
= session_id
;
1598 msg
.u
.lost_packets
.channel_key
= channel_key
;
1602 /* Send command for each consumer */
1604 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1606 uint64_t consumer_lost
= 0;
1607 pthread_mutex_lock(socket
->lock
);
1608 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1610 pthread_mutex_unlock(socket
->lock
);
1615 * No need for a recv reply status because the answer to the
1616 * command is the reply status message.
1618 ret
= consumer_socket_recv(socket
, &consumer_lost
,
1619 sizeof(consumer_lost
));
1621 ERR("get lost packets");
1622 pthread_mutex_unlock(socket
->lock
);
1625 pthread_mutex_unlock(socket
->lock
);
1626 *lost
+= consumer_lost
;
1629 DBG("Consumer lost %" PRIu64
" packets in session id %" PRIu64
,
1638 * Ask the consumer to rotate a channel.
1639 * domain_path contains "/kernel" for kernel or the complete path for UST
1640 * (ex: /ust/uid/1000/64-bit);
1642 * The new_chunk_id is the session->rotate_count that has been incremented
1643 * when the rotation started. On the relay, this allows to keep track in which
1644 * chunk each stream is currently writing to (for the rotate_pending operation).
1646 int consumer_rotate_channel(struct consumer_socket
*socket
, uint64_t key
,
1647 uid_t uid
, gid_t gid
, struct consumer_output
*output
,
1648 const char *domain_path
, bool is_metadata_channel
,
1649 uint64_t new_chunk_id
)
1652 struct lttcomm_consumer_msg msg
;
1656 DBG("Consumer rotate channel key %" PRIu64
, key
);
1658 pthread_mutex_lock(socket
->lock
);
1659 memset(&msg
, 0, sizeof(msg
));
1660 msg
.cmd_type
= LTTNG_CONSUMER_ROTATE_CHANNEL
;
1661 msg
.u
.rotate_channel
.key
= key
;
1662 msg
.u
.rotate_channel
.metadata
= !!is_metadata_channel
;
1663 msg
.u
.rotate_channel
.new_chunk_id
= new_chunk_id
;
1665 if (output
->type
== CONSUMER_DST_NET
) {
1666 msg
.u
.rotate_channel
.relayd_id
= output
->net_seq_index
;
1667 ret
= snprintf(msg
.u
.rotate_channel
.pathname
,
1668 sizeof(msg
.u
.rotate_channel
.pathname
), "%s%s%s",
1669 output
->dst
.net
.base_dir
,
1670 output
->chunk_path
, domain_path
);
1671 if (ret
< 0 || ret
>= sizeof(msg
.u
.rotate_channel
.pathname
)) {
1672 ERR("Failed to format channel path name when asking consumer to rotate channel");
1673 ret
= -LTTNG_ERR_INVALID
;
1677 msg
.u
.rotate_channel
.relayd_id
= (uint64_t) -1ULL;
1678 ret
= snprintf(msg
.u
.rotate_channel
.pathname
,
1679 sizeof(msg
.u
.rotate_channel
.pathname
), "%s/%s%s",
1680 output
->dst
.session_root_path
,
1681 output
->chunk_path
, domain_path
);
1682 if (ret
< 0 || ret
>= sizeof(msg
.u
.rotate_channel
.pathname
)) {
1683 ERR("Failed to format channel path name when asking consumer to rotate channel");
1684 ret
= -LTTNG_ERR_INVALID
;
1689 health_code_update();
1690 ret
= consumer_send_msg(socket
, &msg
);
1693 case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
:
1694 ret
= -LTTNG_ERR_CHAN_NOT_FOUND
;
1697 ret
= -LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1703 pthread_mutex_unlock(socket
->lock
);
1704 health_code_update();
1708 int consumer_rotate_rename(struct consumer_socket
*socket
, uint64_t session_id
,
1709 const struct consumer_output
*output
, const char *old_path
,
1710 const char *new_path
, uid_t uid
, gid_t gid
)
1713 struct lttcomm_consumer_msg msg
;
1714 size_t old_path_length
, new_path_length
;
1720 DBG("Consumer rotate rename session %" PRIu64
", old path = \"%s\", new_path = \"%s\"",
1721 session_id
, old_path
, new_path
);
1723 old_path_length
= strlen(old_path
);
1724 if (old_path_length
>= sizeof(msg
.u
.rotate_rename
.old_path
)) {
1725 ERR("consumer_rotate_rename: old path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)",
1726 old_path_length
+ 1, sizeof(msg
.u
.rotate_rename
.old_path
));
1727 ret
= -LTTNG_ERR_INVALID
;
1731 new_path_length
= strlen(new_path
);
1732 if (new_path_length
>= sizeof(msg
.u
.rotate_rename
.new_path
)) {
1733 ERR("consumer_rotate_rename: new path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)",
1734 new_path_length
+ 1, sizeof(msg
.u
.rotate_rename
.new_path
));
1735 ret
= -LTTNG_ERR_INVALID
;
1739 memset(&msg
, 0, sizeof(msg
));
1740 msg
.cmd_type
= LTTNG_CONSUMER_ROTATE_RENAME
;
1741 msg
.u
.rotate_rename
.session_id
= session_id
;
1742 msg
.u
.rotate_rename
.uid
= uid
;
1743 msg
.u
.rotate_rename
.gid
= gid
;
1744 strcpy(msg
.u
.rotate_rename
.old_path
, old_path
);
1745 strcpy(msg
.u
.rotate_rename
.new_path
, new_path
);
1747 if (output
->type
== CONSUMER_DST_NET
) {
1748 msg
.u
.rotate_rename
.relayd_id
= output
->net_seq_index
;
1750 msg
.u
.rotate_rename
.relayd_id
= -1ULL;
1753 health_code_update();
1754 ret
= consumer_send_msg(socket
, &msg
);
1756 ret
= -LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER
;
1761 health_code_update();
1766 * Ask the consumer if a rotation is locally pending. Must be called with the
1769 * Return 1 if the rotation is still pending, 0 if finished, a negative value
1772 int consumer_check_rotation_pending_local(struct consumer_socket
*socket
,
1773 uint64_t session_id
, uint64_t chunk_id
)
1776 struct lttcomm_consumer_msg msg
;
1777 uint32_t pending
= 0;
1781 DBG("Asking consumer to locally check for pending rotation for session %" PRIu64
", chunk id %" PRIu64
,
1782 session_id
, chunk_id
);
1784 memset(&msg
, 0, sizeof(msg
));
1785 msg
.cmd_type
= LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
;
1786 msg
.u
.check_rotation_pending_local
.session_id
= session_id
;
1787 msg
.u
.check_rotation_pending_local
.chunk_id
= chunk_id
;
1789 health_code_update();
1790 ret
= consumer_send_msg(socket
, &msg
);
1792 ret
= -LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER
;
1796 ret
= consumer_socket_recv(socket
, &pending
, sizeof(pending
));
1804 health_code_update();
1809 * Ask the consumer if a rotation is pending on the relayd. Must be called with
1810 * the socket lock held.
1812 * Return 1 if the rotation is still pending, 0 if finished, a negative value
1815 int consumer_check_rotation_pending_relay(struct consumer_socket
*socket
,
1816 const struct consumer_output
*output
, uint64_t session_id
,
1820 struct lttcomm_consumer_msg msg
;
1821 uint32_t pending
= 0;
1825 DBG("Asking consumer to check for pending rotation on relay for session %" PRIu64
", chunk id %" PRIu64
,
1826 session_id
, chunk_id
);
1827 assert(output
->type
== CONSUMER_DST_NET
);
1829 memset(&msg
, 0, sizeof(msg
));
1830 msg
.cmd_type
= LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
;
1831 msg
.u
.check_rotation_pending_relay
.session_id
= session_id
;
1832 msg
.u
.check_rotation_pending_relay
.relayd_id
= output
->net_seq_index
;
1833 msg
.u
.check_rotation_pending_relay
.chunk_id
= chunk_id
;
1835 health_code_update();
1836 ret
= consumer_send_msg(socket
, &msg
);
1838 ret
= -LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER
;
1842 ret
= consumer_socket_recv(socket
, &pending
, sizeof(pending
));
1850 health_code_update();
1855 * Ask the consumer to create a directory.
1857 * Called with the consumer socket lock held.
1859 int consumer_mkdir(struct consumer_socket
*socket
, uint64_t session_id
,
1860 const struct consumer_output
*output
, const char *path
,
1861 uid_t uid
, gid_t gid
)
1864 struct lttcomm_consumer_msg msg
;
1868 DBG("Consumer mkdir %s in session %" PRIu64
, path
, session_id
);
1870 memset(&msg
, 0, sizeof(msg
));
1871 msg
.cmd_type
= LTTNG_CONSUMER_MKDIR
;
1872 msg
.u
.mkdir
.session_id
= session_id
;
1873 msg
.u
.mkdir
.uid
= uid
;
1874 msg
.u
.mkdir
.gid
= gid
;
1875 ret
= snprintf(msg
.u
.mkdir
.path
, sizeof(msg
.u
.mkdir
.path
), "%s", path
);
1876 if (ret
< 0 || ret
>= sizeof(msg
.u
.mkdir
.path
)) {
1878 ret
= -LTTNG_ERR_INVALID
;
1882 if (output
->type
== CONSUMER_DST_NET
) {
1883 msg
.u
.mkdir
.relayd_id
= output
->net_seq_index
;
1885 msg
.u
.mkdir
.relayd_id
= -1ULL;
1888 health_code_update();
1889 ret
= consumer_send_msg(socket
, &msg
);
1891 ret
= -LTTNG_ERR_MKDIR_FAIL_CONSUMER
;
1896 health_code_update();
1900 int consumer_init(struct consumer_socket
*socket
,
1901 const lttng_uuid sessiond_uuid
)
1904 struct lttcomm_consumer_msg msg
= {
1905 .cmd_type
= LTTNG_CONSUMER_INIT
,
1910 DBG("Sending consumer initialization command");
1911 lttng_uuid_copy(msg
.u
.init
.sessiond_uuid
, sessiond_uuid
);
1913 health_code_update();
1914 ret
= consumer_send_msg(socket
, &msg
);
1920 health_code_update();