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
*obj
)
555 struct consumer_output
*output
;
559 output
= consumer_create_output(obj
->type
);
560 if (output
== NULL
) {
563 output
->enabled
= obj
->enabled
;
564 output
->net_seq_index
= obj
->net_seq_index
;
565 memcpy(output
->subdir
, obj
->subdir
, sizeof(output
->subdir
));
566 output
->snapshot
= obj
->snapshot
;
567 output
->relay_major_version
= obj
->relay_major_version
;
568 output
->relay_minor_version
= obj
->relay_minor_version
;
569 memcpy(&output
->dst
, &obj
->dst
, sizeof(output
->dst
));
570 ret
= consumer_copy_sockets(output
, obj
);
578 consumer_output_put(output
);
583 * Copy consumer sockets from src to dst.
585 * Return 0 on success or else a negative value.
587 int consumer_copy_sockets(struct consumer_output
*dst
,
588 struct consumer_output
*src
)
591 struct lttng_ht_iter iter
;
592 struct consumer_socket
*socket
, *copy_sock
;
598 cds_lfht_for_each_entry(src
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
599 /* Ignore socket that are already there. */
600 copy_sock
= consumer_find_socket(*socket
->fd_ptr
, dst
);
605 /* Create new socket object. */
606 copy_sock
= consumer_allocate_socket(socket
->fd_ptr
);
607 if (copy_sock
== NULL
) {
613 copy_sock
->registered
= socket
->registered
;
615 * This is valid because this lock is shared accross all consumer
616 * object being the global lock of the consumer data structure of the
619 copy_sock
->lock
= socket
->lock
;
620 consumer_add_socket(copy_sock
, dst
);
629 * Set network URI to the consumer output object.
631 * Return 0 on success. Return 1 if the URI were equal. Else, negative value on
634 int consumer_set_network_uri(struct consumer_output
*obj
,
635 struct lttng_uri
*uri
)
638 char tmp_path
[PATH_MAX
];
639 char hostname
[HOST_NAME_MAX
];
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
= &obj
->dst
.net
.control
;
649 obj
->dst
.net
.control_isset
= 1;
650 if (uri
->port
== 0) {
651 /* Assign default port. */
652 uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
654 if (obj
->dst
.net
.data_isset
&& uri
->port
==
655 obj
->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
= &obj
->dst
.net
.data
;
664 obj
->dst
.net
.data_isset
= 1;
665 if (uri
->port
== 0) {
666 /* Assign default port. */
667 uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
669 if (obj
->dst
.net
.control_isset
&& uri
->port
==
670 obj
->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 memset(dst_uri
, 0, sizeof(struct lttng_uri
));
692 memcpy(dst_uri
, uri
, sizeof(struct lttng_uri
));
693 obj
->type
= CONSUMER_DST_NET
;
695 /* Handle subdir and add hostname in front. */
696 if (dst_uri
->stype
== LTTNG_STREAM_CONTROL
) {
697 /* Get hostname to append it in the pathname */
698 ret
= gethostname(hostname
, sizeof(hostname
));
700 PERROR("gethostname. Fallback on default localhost");
701 strncpy(hostname
, "localhost", sizeof(hostname
));
703 hostname
[sizeof(hostname
) - 1] = '\0';
705 /* Setup consumer subdir if none present in the control URI */
706 if (strlen(dst_uri
->subdir
) == 0) {
707 ret
= snprintf(tmp_path
, sizeof(tmp_path
), "%s/%s",
708 hostname
, obj
->subdir
);
710 ret
= snprintf(tmp_path
, sizeof(tmp_path
), "%s/%s",
711 hostname
, dst_uri
->subdir
);
714 PERROR("snprintf set consumer uri subdir");
715 ret
= -LTTNG_ERR_NOMEM
;
719 if (lttng_strncpy(obj
->dst
.net
.base_dir
, tmp_path
,
720 sizeof(obj
->dst
.net
.base_dir
))) {
721 ret
= -LTTNG_ERR_INVALID
;
724 DBG3("Consumer set network uri base_dir path %s", tmp_path
);
735 * Send file descriptor to consumer via sock.
737 * The consumer socket lock must be held by the caller.
739 int consumer_send_fds(struct consumer_socket
*sock
, const int *fds
,
747 assert(pthread_mutex_trylock(sock
->lock
) == EBUSY
);
749 ret
= lttcomm_send_fds_unix_sock(*sock
->fd_ptr
, fds
, nb_fd
);
751 /* The above call will print a PERROR on error. */
752 DBG("Error when sending consumer fds on sock %d", *sock
->fd_ptr
);
756 ret
= consumer_recv_status_reply(sock
);
762 * Consumer send communication message structure to consumer.
764 * The consumer socket lock must be held by the caller.
766 int consumer_send_msg(struct consumer_socket
*sock
,
767 struct lttcomm_consumer_msg
*msg
)
773 assert(pthread_mutex_trylock(sock
->lock
) == EBUSY
);
775 ret
= consumer_socket_send(sock
, msg
, sizeof(struct lttcomm_consumer_msg
));
780 ret
= consumer_recv_status_reply(sock
);
787 * Consumer send channel communication message structure to consumer.
789 * The consumer socket lock must be held by the caller.
791 int consumer_send_channel(struct consumer_socket
*sock
,
792 struct lttcomm_consumer_msg
*msg
)
799 ret
= consumer_send_msg(sock
, msg
);
809 * Populate the given consumer msg structure with the ask_channel command
812 void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
813 uint64_t subbuf_size
,
816 unsigned int switch_timer_interval
,
817 unsigned int read_timer_interval
,
818 unsigned int live_timer_interval
,
819 unsigned int monitor_timer_interval
,
823 const char *pathname
,
831 uint64_t tracefile_size
,
832 uint64_t tracefile_count
,
833 uint64_t session_id_per_pid
,
834 unsigned int monitor
,
835 uint32_t ust_app_uid
,
836 int64_t blocking_timeout
,
837 const char *root_shm_path
,
838 const char *shm_path
,
839 uint64_t trace_archive_id
)
843 /* Zeroed structure */
844 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
846 msg
->cmd_type
= LTTNG_CONSUMER_ASK_CHANNEL_CREATION
;
847 msg
->u
.ask_channel
.subbuf_size
= subbuf_size
;
848 msg
->u
.ask_channel
.num_subbuf
= num_subbuf
;
849 msg
->u
.ask_channel
.overwrite
= overwrite
;
850 msg
->u
.ask_channel
.switch_timer_interval
= switch_timer_interval
;
851 msg
->u
.ask_channel
.read_timer_interval
= read_timer_interval
;
852 msg
->u
.ask_channel
.live_timer_interval
= live_timer_interval
;
853 msg
->u
.ask_channel
.monitor_timer_interval
= monitor_timer_interval
;
854 msg
->u
.ask_channel
.output
= output
;
855 msg
->u
.ask_channel
.type
= type
;
856 msg
->u
.ask_channel
.session_id
= session_id
;
857 msg
->u
.ask_channel
.session_id_per_pid
= session_id_per_pid
;
858 msg
->u
.ask_channel
.uid
= uid
;
859 msg
->u
.ask_channel
.gid
= gid
;
860 msg
->u
.ask_channel
.relayd_id
= relayd_id
;
861 msg
->u
.ask_channel
.key
= key
;
862 msg
->u
.ask_channel
.chan_id
= chan_id
;
863 msg
->u
.ask_channel
.tracefile_size
= tracefile_size
;
864 msg
->u
.ask_channel
.tracefile_count
= tracefile_count
;
865 msg
->u
.ask_channel
.monitor
= monitor
;
866 msg
->u
.ask_channel
.ust_app_uid
= ust_app_uid
;
867 msg
->u
.ask_channel
.blocking_timeout
= blocking_timeout
;
868 msg
->u
.ask_channel
.trace_archive_id
= trace_archive_id
;
870 memcpy(msg
->u
.ask_channel
.uuid
, uuid
, sizeof(msg
->u
.ask_channel
.uuid
));
873 strncpy(msg
->u
.ask_channel
.pathname
, pathname
,
874 sizeof(msg
->u
.ask_channel
.pathname
));
875 msg
->u
.ask_channel
.pathname
[sizeof(msg
->u
.ask_channel
.pathname
)-1] = '\0';
878 strncpy(msg
->u
.ask_channel
.name
, name
, sizeof(msg
->u
.ask_channel
.name
));
879 msg
->u
.ask_channel
.name
[sizeof(msg
->u
.ask_channel
.name
) - 1] = '\0';
882 strncpy(msg
->u
.ask_channel
.root_shm_path
, root_shm_path
,
883 sizeof(msg
->u
.ask_channel
.root_shm_path
));
884 msg
->u
.ask_channel
.root_shm_path
[sizeof(msg
->u
.ask_channel
.root_shm_path
) - 1] = '\0';
887 strncpy(msg
->u
.ask_channel
.shm_path
, shm_path
,
888 sizeof(msg
->u
.ask_channel
.shm_path
));
889 msg
->u
.ask_channel
.shm_path
[sizeof(msg
->u
.ask_channel
.shm_path
) - 1] = '\0';
894 * Init channel communication message structure.
896 void consumer_init_add_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
897 uint64_t channel_key
,
899 const char *pathname
,
904 unsigned int nb_init_streams
,
905 enum lttng_event_output output
,
907 uint64_t tracefile_size
,
908 uint64_t tracefile_count
,
909 unsigned int monitor
,
910 unsigned int live_timer_interval
,
911 unsigned int monitor_timer_interval
)
915 /* Zeroed structure */
916 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
919 msg
->cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
920 msg
->u
.channel
.channel_key
= channel_key
;
921 msg
->u
.channel
.session_id
= session_id
;
922 msg
->u
.channel
.uid
= uid
;
923 msg
->u
.channel
.gid
= gid
;
924 msg
->u
.channel
.relayd_id
= relayd_id
;
925 msg
->u
.channel
.nb_init_streams
= nb_init_streams
;
926 msg
->u
.channel
.output
= output
;
927 msg
->u
.channel
.type
= type
;
928 msg
->u
.channel
.tracefile_size
= tracefile_size
;
929 msg
->u
.channel
.tracefile_count
= tracefile_count
;
930 msg
->u
.channel
.monitor
= monitor
;
931 msg
->u
.channel
.live_timer_interval
= live_timer_interval
;
932 msg
->u
.channel
.monitor_timer_interval
= monitor_timer_interval
;
934 strncpy(msg
->u
.channel
.pathname
, pathname
,
935 sizeof(msg
->u
.channel
.pathname
));
936 msg
->u
.channel
.pathname
[sizeof(msg
->u
.channel
.pathname
) - 1] = '\0';
938 strncpy(msg
->u
.channel
.name
, name
, sizeof(msg
->u
.channel
.name
));
939 msg
->u
.channel
.name
[sizeof(msg
->u
.channel
.name
) - 1] = '\0';
943 * Init stream communication message structure.
945 void consumer_init_add_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
946 uint64_t channel_key
,
949 uint64_t trace_archive_id
)
953 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
955 msg
->cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
956 msg
->u
.stream
.channel_key
= channel_key
;
957 msg
->u
.stream
.stream_key
= stream_key
;
958 msg
->u
.stream
.cpu
= cpu
;
959 msg
->u
.stream
.trace_archive_id
= trace_archive_id
;
962 void consumer_init_streams_sent_comm_msg(struct lttcomm_consumer_msg
*msg
,
963 enum lttng_consumer_command cmd
,
964 uint64_t channel_key
, uint64_t net_seq_idx
)
968 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
971 msg
->u
.sent_streams
.channel_key
= channel_key
;
972 msg
->u
.sent_streams
.net_seq_idx
= net_seq_idx
;
976 * Send stream communication structure to the consumer.
978 int consumer_send_stream(struct consumer_socket
*sock
,
979 struct consumer_output
*dst
, struct lttcomm_consumer_msg
*msg
,
980 const int *fds
, size_t nb_fd
)
989 ret
= consumer_send_msg(sock
, msg
);
994 ret
= consumer_send_fds(sock
, fds
, nb_fd
);
1004 * Send relayd socket to consumer associated with a session name.
1006 * The consumer socket lock must be held by the caller.
1008 * On success return positive value. On error, negative value.
1010 int consumer_send_relayd_socket(struct consumer_socket
*consumer_sock
,
1011 struct lttcomm_relayd_sock
*rsock
, struct consumer_output
*consumer
,
1012 enum lttng_stream_type type
, uint64_t session_id
,
1013 char *session_name
, char *hostname
, int session_live_timer
)
1016 struct lttcomm_consumer_msg msg
;
1018 /* Code flow error. Safety net. */
1021 assert(consumer_sock
);
1023 memset(&msg
, 0, sizeof(msg
));
1024 /* Bail out if consumer is disabled */
1025 if (!consumer
->enabled
) {
1030 if (type
== LTTNG_STREAM_CONTROL
) {
1031 ret
= relayd_create_session(rsock
,
1032 &msg
.u
.relayd_sock
.relayd_session_id
,
1033 session_name
, hostname
, session_live_timer
,
1034 consumer
->snapshot
);
1036 /* Close the control socket. */
1037 (void) relayd_close(rsock
);
1042 msg
.cmd_type
= LTTNG_CONSUMER_ADD_RELAYD_SOCKET
;
1044 * Assign network consumer output index using the temporary consumer since
1045 * this call should only be made from within a set_consumer_uri() function
1046 * call in the session daemon.
1048 msg
.u
.relayd_sock
.net_index
= consumer
->net_seq_index
;
1049 msg
.u
.relayd_sock
.type
= type
;
1050 msg
.u
.relayd_sock
.session_id
= session_id
;
1051 memcpy(&msg
.u
.relayd_sock
.sock
, rsock
, sizeof(msg
.u
.relayd_sock
.sock
));
1053 DBG3("Sending relayd sock info to consumer on %d", *consumer_sock
->fd_ptr
);
1054 ret
= consumer_send_msg(consumer_sock
, &msg
);
1059 DBG3("Sending relayd socket file descriptor to consumer");
1060 ret
= consumer_send_fds(consumer_sock
, &rsock
->sock
.fd
, 1);
1065 DBG2("Consumer relayd socket sent");
1072 int consumer_send_pipe(struct consumer_socket
*consumer_sock
,
1073 enum lttng_consumer_command cmd
, int pipe
)
1076 struct lttcomm_consumer_msg msg
;
1077 const char *pipe_name
;
1078 const char *command_name
;
1081 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1082 pipe_name
= "channel monitor";
1083 command_name
= "SET_CHANNEL_MONITOR_PIPE";
1086 ERR("Unexpected command received in %s (cmd = %d)", __func__
,
1091 /* Code flow error. Safety net. */
1093 memset(&msg
, 0, sizeof(msg
));
1096 pthread_mutex_lock(consumer_sock
->lock
);
1097 DBG3("Sending %s command to consumer", command_name
);
1098 ret
= consumer_send_msg(consumer_sock
, &msg
);
1103 DBG3("Sending %s pipe %d to consumer on socket %d",
1105 pipe
, *consumer_sock
->fd_ptr
);
1106 ret
= consumer_send_fds(consumer_sock
, &pipe
, 1);
1111 DBG2("%s pipe successfully sent", pipe_name
);
1113 pthread_mutex_unlock(consumer_sock
->lock
);
1117 int consumer_send_channel_monitor_pipe(struct consumer_socket
*consumer_sock
,
1120 return consumer_send_pipe(consumer_sock
,
1121 LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
, pipe
);
1125 * Set consumer subdirectory using the session name and a generated datetime if
1126 * needed. This is appended to the current subdirectory.
1128 int consumer_set_subdir(struct consumer_output
*consumer
,
1129 const char *session_name
)
1132 unsigned int have_default_name
= 0;
1133 char datetime
[16], tmp_path
[PATH_MAX
];
1135 struct tm
*timeinfo
;
1138 assert(session_name
);
1140 memset(tmp_path
, 0, sizeof(tmp_path
));
1142 /* Flag if we have a default session. */
1143 if (strncmp(session_name
, DEFAULT_SESSION_NAME
"-",
1144 strlen(DEFAULT_SESSION_NAME
) + 1) == 0) {
1145 have_default_name
= 1;
1147 /* Get date and time for session path */
1149 timeinfo
= localtime(&rawtime
);
1150 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
1153 if (have_default_name
) {
1154 ret
= snprintf(tmp_path
, sizeof(tmp_path
),
1155 "%s/%s", consumer
->subdir
, session_name
);
1157 ret
= snprintf(tmp_path
, sizeof(tmp_path
),
1158 "%s/%s-%s/", consumer
->subdir
, session_name
, datetime
);
1161 PERROR("snprintf session name date");
1165 if (lttng_strncpy(consumer
->subdir
, tmp_path
,
1166 sizeof(consumer
->subdir
))) {
1170 DBG2("Consumer subdir set to %s", consumer
->subdir
);
1177 * Ask the consumer if the data is pending for the specific session id.
1178 * Returns 1 if data is pending, 0 otherwise, or < 0 on error.
1180 int consumer_is_data_pending(uint64_t session_id
,
1181 struct consumer_output
*consumer
)
1184 int32_t ret_code
= 0; /* Default is that the data is NOT pending */
1185 struct consumer_socket
*socket
;
1186 struct lttng_ht_iter iter
;
1187 struct lttcomm_consumer_msg msg
;
1191 DBG3("Consumer data pending for id %" PRIu64
, session_id
);
1193 memset(&msg
, 0, sizeof(msg
));
1194 msg
.cmd_type
= LTTNG_CONSUMER_DATA_PENDING
;
1195 msg
.u
.data_pending
.session_id
= session_id
;
1197 /* Send command for each consumer */
1199 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1201 pthread_mutex_lock(socket
->lock
);
1202 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1204 pthread_mutex_unlock(socket
->lock
);
1209 * No need for a recv reply status because the answer to the command is
1210 * the reply status message.
1213 ret
= consumer_socket_recv(socket
, &ret_code
, sizeof(ret_code
));
1215 pthread_mutex_unlock(socket
->lock
);
1218 pthread_mutex_unlock(socket
->lock
);
1220 if (ret_code
== 1) {
1226 DBG("Consumer data is %s pending for session id %" PRIu64
,
1227 ret_code
== 1 ? "" : "NOT", session_id
);
1236 * Send a flush command to consumer using the given channel key.
1238 * Return 0 on success else a negative value.
1240 int consumer_flush_channel(struct consumer_socket
*socket
, uint64_t key
)
1243 struct lttcomm_consumer_msg msg
;
1247 DBG2("Consumer flush channel key %" PRIu64
, key
);
1249 memset(&msg
, 0, sizeof(msg
));
1250 msg
.cmd_type
= LTTNG_CONSUMER_FLUSH_CHANNEL
;
1251 msg
.u
.flush_channel
.key
= key
;
1253 pthread_mutex_lock(socket
->lock
);
1254 health_code_update();
1256 ret
= consumer_send_msg(socket
, &msg
);
1262 health_code_update();
1263 pthread_mutex_unlock(socket
->lock
);
1268 * Send a clear quiescent command to consumer using the given channel key.
1270 * Return 0 on success else a negative value.
1272 int consumer_clear_quiescent_channel(struct consumer_socket
*socket
, uint64_t key
)
1275 struct lttcomm_consumer_msg msg
;
1279 DBG2("Consumer clear quiescent channel key %" PRIu64
, key
);
1281 memset(&msg
, 0, sizeof(msg
));
1282 msg
.cmd_type
= LTTNG_CONSUMER_CLEAR_QUIESCENT_CHANNEL
;
1283 msg
.u
.clear_quiescent_channel
.key
= key
;
1285 pthread_mutex_lock(socket
->lock
);
1286 health_code_update();
1288 ret
= consumer_send_msg(socket
, &msg
);
1294 health_code_update();
1295 pthread_mutex_unlock(socket
->lock
);
1300 * Send a close metadata command to consumer using the given channel key.
1301 * Called with registry lock held.
1303 * Return 0 on success else a negative value.
1305 int consumer_close_metadata(struct consumer_socket
*socket
,
1306 uint64_t metadata_key
)
1309 struct lttcomm_consumer_msg msg
;
1313 DBG2("Consumer close metadata channel key %" PRIu64
, metadata_key
);
1315 memset(&msg
, 0, sizeof(msg
));
1316 msg
.cmd_type
= LTTNG_CONSUMER_CLOSE_METADATA
;
1317 msg
.u
.close_metadata
.key
= metadata_key
;
1319 pthread_mutex_lock(socket
->lock
);
1320 health_code_update();
1322 ret
= consumer_send_msg(socket
, &msg
);
1328 health_code_update();
1329 pthread_mutex_unlock(socket
->lock
);
1334 * Send a setup metdata command to consumer using the given channel key.
1336 * Return 0 on success else a negative value.
1338 int consumer_setup_metadata(struct consumer_socket
*socket
,
1339 uint64_t metadata_key
)
1342 struct lttcomm_consumer_msg msg
;
1346 DBG2("Consumer setup metadata channel key %" PRIu64
, metadata_key
);
1348 memset(&msg
, 0, sizeof(msg
));
1349 msg
.cmd_type
= LTTNG_CONSUMER_SETUP_METADATA
;
1350 msg
.u
.setup_metadata
.key
= metadata_key
;
1352 pthread_mutex_lock(socket
->lock
);
1353 health_code_update();
1355 ret
= consumer_send_msg(socket
, &msg
);
1361 health_code_update();
1362 pthread_mutex_unlock(socket
->lock
);
1367 * Send metadata string to consumer.
1368 * RCU read-side lock must be held to guarantee existence of socket.
1370 * Return 0 on success else a negative value.
1372 int consumer_push_metadata(struct consumer_socket
*socket
,
1373 uint64_t metadata_key
, char *metadata_str
, size_t len
,
1374 size_t target_offset
, uint64_t version
)
1377 struct lttcomm_consumer_msg msg
;
1381 DBG2("Consumer push metadata to consumer socket %d", *socket
->fd_ptr
);
1383 pthread_mutex_lock(socket
->lock
);
1385 memset(&msg
, 0, sizeof(msg
));
1386 msg
.cmd_type
= LTTNG_CONSUMER_PUSH_METADATA
;
1387 msg
.u
.push_metadata
.key
= metadata_key
;
1388 msg
.u
.push_metadata
.target_offset
= target_offset
;
1389 msg
.u
.push_metadata
.len
= len
;
1390 msg
.u
.push_metadata
.version
= version
;
1392 health_code_update();
1393 ret
= consumer_send_msg(socket
, &msg
);
1394 if (ret
< 0 || len
== 0) {
1398 DBG3("Consumer pushing metadata on sock %d of len %zu", *socket
->fd_ptr
,
1401 ret
= consumer_socket_send(socket
, metadata_str
, len
);
1406 health_code_update();
1407 ret
= consumer_recv_status_reply(socket
);
1413 pthread_mutex_unlock(socket
->lock
);
1414 health_code_update();
1419 * Ask the consumer to snapshot a specific channel using the key.
1421 * Return 0 on success or else a negative error.
1423 int consumer_snapshot_channel(struct consumer_socket
*socket
, uint64_t key
,
1424 struct snapshot_output
*output
, int metadata
, uid_t uid
, gid_t gid
,
1425 const char *session_path
, int wait
, uint64_t nb_packets_per_stream
,
1426 uint64_t trace_archive_id
)
1429 struct lttcomm_consumer_msg msg
;
1433 assert(output
->consumer
);
1435 DBG("Consumer snapshot channel key %" PRIu64
, key
);
1437 memset(&msg
, 0, sizeof(msg
));
1438 msg
.cmd_type
= LTTNG_CONSUMER_SNAPSHOT_CHANNEL
;
1439 msg
.u
.snapshot_channel
.key
= key
;
1440 msg
.u
.snapshot_channel
.nb_packets_per_stream
= nb_packets_per_stream
;
1441 msg
.u
.snapshot_channel
.metadata
= metadata
;
1442 msg
.u
.snapshot_channel
.trace_archive_id
= trace_archive_id
;
1444 if (output
->consumer
->type
== CONSUMER_DST_NET
) {
1445 msg
.u
.snapshot_channel
.relayd_id
= output
->consumer
->net_seq_index
;
1446 msg
.u
.snapshot_channel
.use_relayd
= 1;
1447 ret
= snprintf(msg
.u
.snapshot_channel
.pathname
,
1448 sizeof(msg
.u
.snapshot_channel
.pathname
),
1449 "%s/%s/%s-%s-%" PRIu64
"%s",
1450 output
->consumer
->dst
.net
.base_dir
,
1451 output
->consumer
->subdir
,
1452 output
->name
, output
->datetime
,
1453 output
->nb_snapshot
,
1456 ret
= -LTTNG_ERR_NOMEM
;
1458 } else if (ret
>= sizeof(msg
.u
.snapshot_channel
.pathname
)) {
1459 ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s/%s-%s-%" PRIu64
"%s\"",
1460 sizeof(msg
.u
.snapshot_channel
.pathname
),
1461 ret
, output
->consumer
->dst
.net
.base_dir
,
1462 output
->consumer
->subdir
,
1463 output
->name
, output
->datetime
,
1464 output
->nb_snapshot
,
1466 ret
= -LTTNG_ERR_SNAPSHOT_FAIL
;
1470 ret
= snprintf(msg
.u
.snapshot_channel
.pathname
,
1471 sizeof(msg
.u
.snapshot_channel
.pathname
),
1472 "%s/%s-%s-%" PRIu64
"%s",
1473 output
->consumer
->dst
.session_root_path
,
1474 output
->name
, output
->datetime
,
1475 output
->nb_snapshot
,
1478 ret
= -LTTNG_ERR_NOMEM
;
1480 } else if (ret
>= sizeof(msg
.u
.snapshot_channel
.pathname
)) {
1481 ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s-%s-%" PRIu64
"%s\"",
1482 sizeof(msg
.u
.snapshot_channel
.pathname
),
1483 ret
, output
->consumer
->dst
.session_root_path
,
1484 output
->name
, output
->datetime
, output
->nb_snapshot
,
1486 ret
= -LTTNG_ERR_SNAPSHOT_FAIL
;
1490 msg
.u
.snapshot_channel
.relayd_id
= (uint64_t) -1ULL;
1492 /* Create directory. Ignore if exist. */
1493 ret
= run_as_mkdir_recursive(msg
.u
.snapshot_channel
.pathname
,
1494 S_IRWXU
| S_IRWXG
, uid
, gid
);
1496 if (errno
!= EEXIST
) {
1497 ERR("Trace directory creation error");
1503 health_code_update();
1504 pthread_mutex_lock(socket
->lock
);
1505 ret
= consumer_send_msg(socket
, &msg
);
1506 pthread_mutex_unlock(socket
->lock
);
1509 case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
:
1510 ret
= -LTTNG_ERR_CHAN_NOT_FOUND
;
1513 ret
= -LTTNG_ERR_SNAPSHOT_FAIL
;
1520 health_code_update();
1525 * Ask the consumer the number of discarded events for a channel.
1527 int consumer_get_discarded_events(uint64_t session_id
, uint64_t channel_key
,
1528 struct consumer_output
*consumer
, uint64_t *discarded
)
1531 struct consumer_socket
*socket
;
1532 struct lttng_ht_iter iter
;
1533 struct lttcomm_consumer_msg msg
;
1537 DBG3("Consumer discarded events id %" PRIu64
, session_id
);
1539 memset(&msg
, 0, sizeof(msg
));
1540 msg
.cmd_type
= LTTNG_CONSUMER_DISCARDED_EVENTS
;
1541 msg
.u
.discarded_events
.session_id
= session_id
;
1542 msg
.u
.discarded_events
.channel_key
= channel_key
;
1546 /* Send command for each consumer */
1548 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1550 uint64_t consumer_discarded
= 0;
1551 pthread_mutex_lock(socket
->lock
);
1552 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1554 pthread_mutex_unlock(socket
->lock
);
1559 * No need for a recv reply status because the answer to the
1560 * command is the reply status message.
1562 ret
= consumer_socket_recv(socket
, &consumer_discarded
,
1563 sizeof(consumer_discarded
));
1565 ERR("get discarded events");
1566 pthread_mutex_unlock(socket
->lock
);
1569 pthread_mutex_unlock(socket
->lock
);
1570 *discarded
+= consumer_discarded
;
1573 DBG("Consumer discarded %" PRIu64
" events in session id %" PRIu64
,
1574 *discarded
, session_id
);
1582 * Ask the consumer the number of lost packets for a channel.
1584 int consumer_get_lost_packets(uint64_t session_id
, uint64_t channel_key
,
1585 struct consumer_output
*consumer
, uint64_t *lost
)
1588 struct consumer_socket
*socket
;
1589 struct lttng_ht_iter iter
;
1590 struct lttcomm_consumer_msg msg
;
1594 DBG3("Consumer lost packets id %" PRIu64
, session_id
);
1596 memset(&msg
, 0, sizeof(msg
));
1597 msg
.cmd_type
= LTTNG_CONSUMER_LOST_PACKETS
;
1598 msg
.u
.lost_packets
.session_id
= session_id
;
1599 msg
.u
.lost_packets
.channel_key
= channel_key
;
1603 /* Send command for each consumer */
1605 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
1607 uint64_t consumer_lost
= 0;
1608 pthread_mutex_lock(socket
->lock
);
1609 ret
= consumer_socket_send(socket
, &msg
, sizeof(msg
));
1611 pthread_mutex_unlock(socket
->lock
);
1616 * No need for a recv reply status because the answer to the
1617 * command is the reply status message.
1619 ret
= consumer_socket_recv(socket
, &consumer_lost
,
1620 sizeof(consumer_lost
));
1622 ERR("get lost packets");
1623 pthread_mutex_unlock(socket
->lock
);
1626 pthread_mutex_unlock(socket
->lock
);
1627 *lost
+= consumer_lost
;
1630 DBG("Consumer lost %" PRIu64
" packets in session id %" PRIu64
,
1639 * Ask the consumer to rotate a channel.
1640 * domain_path contains "/kernel" for kernel or the complete path for UST
1641 * (ex: /ust/uid/1000/64-bit);
1643 * The new_chunk_id is the session->rotate_count that has been incremented
1644 * when the rotation started. On the relay, this allows to keep track in which
1645 * chunk each stream is currently writing to (for the rotate_pending operation).
1647 int consumer_rotate_channel(struct consumer_socket
*socket
, uint64_t key
,
1648 uid_t uid
, gid_t gid
, struct consumer_output
*output
,
1649 char *domain_path
, bool is_metadata_channel
,
1650 uint64_t new_chunk_id
)
1653 struct lttcomm_consumer_msg msg
;
1657 DBG("Consumer rotate channel key %" PRIu64
, key
);
1659 pthread_mutex_lock(socket
->lock
);
1660 memset(&msg
, 0, sizeof(msg
));
1661 msg
.cmd_type
= LTTNG_CONSUMER_ROTATE_CHANNEL
;
1662 msg
.u
.rotate_channel
.key
= key
;
1663 msg
.u
.rotate_channel
.metadata
= !!is_metadata_channel
;
1664 msg
.u
.rotate_channel
.new_chunk_id
= new_chunk_id
;
1666 if (output
->type
== CONSUMER_DST_NET
) {
1667 msg
.u
.rotate_channel
.relayd_id
= output
->net_seq_index
;
1668 ret
= snprintf(msg
.u
.rotate_channel
.pathname
,
1669 sizeof(msg
.u
.rotate_channel
.pathname
), "%s%s%s",
1670 output
->dst
.net
.base_dir
,
1671 output
->chunk_path
, domain_path
);
1672 if (ret
< 0 || ret
== sizeof(msg
.u
.rotate_channel
.pathname
)) {
1673 ERR("Failed to format channel path name when asking consumer to rotate channel");
1674 ret
= -LTTNG_ERR_INVALID
;
1678 msg
.u
.rotate_channel
.relayd_id
= (uint64_t) -1ULL;
1679 ret
= snprintf(msg
.u
.rotate_channel
.pathname
,
1680 sizeof(msg
.u
.rotate_channel
.pathname
), "%s%s%s",
1681 output
->dst
.session_root_path
,
1682 output
->chunk_path
, domain_path
);
1683 if (ret
< 0 || ret
== sizeof(msg
.u
.rotate_channel
.pathname
)) {
1684 ERR("Failed to format channel path name when asking consumer to rotate channel");
1685 ret
= -LTTNG_ERR_INVALID
;
1690 health_code_update();
1691 ret
= consumer_send_msg(socket
, &msg
);
1694 case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
:
1695 ret
= -LTTNG_ERR_CHAN_NOT_FOUND
;
1698 ret
= -LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1704 pthread_mutex_unlock(socket
->lock
);
1705 health_code_update();
1709 int consumer_rotate_rename(struct consumer_socket
*socket
, uint64_t session_id
,
1710 const struct consumer_output
*output
, const char *old_path
,
1711 const char *new_path
, uid_t uid
, gid_t gid
)
1714 struct lttcomm_consumer_msg msg
;
1715 size_t old_path_length
, new_path_length
;
1721 DBG("Consumer rotate rename session %" PRIu64
", old path = \"%s\", new_path = \"%s\"",
1722 session_id
, old_path
, new_path
);
1724 old_path_length
= strlen(old_path
);
1725 if (old_path_length
>= sizeof(msg
.u
.rotate_rename
.old_path
)) {
1726 ERR("consumer_rotate_rename: old path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)",
1727 old_path_length
+ 1, sizeof(msg
.u
.rotate_rename
.old_path
));
1728 ret
= -LTTNG_ERR_INVALID
;
1732 new_path_length
= strlen(new_path
);
1733 if (new_path_length
>= sizeof(msg
.u
.rotate_rename
.new_path
)) {
1734 ERR("consumer_rotate_rename: new path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)",
1735 new_path_length
+ 1, sizeof(msg
.u
.rotate_rename
.new_path
));
1736 ret
= -LTTNG_ERR_INVALID
;
1740 memset(&msg
, 0, sizeof(msg
));
1741 msg
.cmd_type
= LTTNG_CONSUMER_ROTATE_RENAME
;
1742 msg
.u
.rotate_rename
.session_id
= session_id
;
1743 msg
.u
.rotate_rename
.uid
= uid
;
1744 msg
.u
.rotate_rename
.gid
= gid
;
1745 strcpy(msg
.u
.rotate_rename
.old_path
, old_path
);
1746 strcpy(msg
.u
.rotate_rename
.new_path
, new_path
);
1748 if (output
->type
== CONSUMER_DST_NET
) {
1749 msg
.u
.rotate_rename
.relayd_id
= output
->net_seq_index
;
1751 msg
.u
.rotate_rename
.relayd_id
= -1ULL;
1754 health_code_update();
1755 ret
= consumer_send_msg(socket
, &msg
);
1757 ret
= -LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER
;
1762 health_code_update();
1767 * Ask the consumer if a rotation is locally pending. Must be called with the
1770 * Return 1 if the rotation is still pending, 0 if finished, a negative value
1773 int consumer_check_rotation_pending_local(struct consumer_socket
*socket
,
1774 uint64_t session_id
, uint64_t chunk_id
)
1777 struct lttcomm_consumer_msg msg
;
1778 uint32_t pending
= 0;
1782 DBG("Asking consumer to locally check for pending rotation for session %" PRIu64
", chunk id %" PRIu64
,
1783 session_id
, chunk_id
);
1785 memset(&msg
, 0, sizeof(msg
));
1786 msg
.cmd_type
= LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
;
1787 msg
.u
.check_rotation_pending_local
.session_id
= session_id
;
1788 msg
.u
.check_rotation_pending_local
.chunk_id
= chunk_id
;
1790 health_code_update();
1791 ret
= consumer_send_msg(socket
, &msg
);
1793 ret
= -LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER
;
1797 ret
= consumer_socket_recv(socket
, &pending
, sizeof(pending
));
1805 health_code_update();
1810 * Ask the consumer if a rotation is pending on the relayd. Must be called with
1811 * the socket lock held.
1813 * Return 1 if the rotation is still pending, 0 if finished, a negative value
1816 int consumer_check_rotation_pending_relay(struct consumer_socket
*socket
,
1817 const struct consumer_output
*output
, uint64_t session_id
,
1821 struct lttcomm_consumer_msg msg
;
1822 uint32_t pending
= 0;
1826 DBG("Asking consumer to check for pending rotation on relay for session %" PRIu64
", chunk id %" PRIu64
,
1827 session_id
, chunk_id
);
1828 assert(output
->type
== CONSUMER_DST_NET
);
1830 memset(&msg
, 0, sizeof(msg
));
1831 msg
.cmd_type
= LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
;
1832 msg
.u
.check_rotation_pending_relay
.session_id
= session_id
;
1833 msg
.u
.check_rotation_pending_relay
.relayd_id
= output
->net_seq_index
;
1834 msg
.u
.check_rotation_pending_relay
.chunk_id
= chunk_id
;
1836 health_code_update();
1837 ret
= consumer_send_msg(socket
, &msg
);
1839 ret
= -LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER
;
1843 ret
= consumer_socket_recv(socket
, &pending
, sizeof(pending
));
1851 health_code_update();
1856 * Ask the consumer to create a directory.
1858 * Called with the consumer socket lock held.
1860 int consumer_mkdir(struct consumer_socket
*socket
, uint64_t session_id
,
1861 const struct consumer_output
*output
, const char *path
,
1862 uid_t uid
, gid_t gid
)
1865 struct lttcomm_consumer_msg msg
;
1869 DBG("Consumer mkdir %s in session %" PRIu64
, path
, session_id
);
1871 memset(&msg
, 0, sizeof(msg
));
1872 msg
.cmd_type
= LTTNG_CONSUMER_MKDIR
;
1873 msg
.u
.mkdir
.session_id
= session_id
;
1874 msg
.u
.mkdir
.uid
= uid
;
1875 msg
.u
.mkdir
.gid
= gid
;
1876 ret
= snprintf(msg
.u
.mkdir
.path
, sizeof(msg
.u
.mkdir
.path
), "%s", path
);
1877 if (ret
< 0 || ret
>= sizeof(msg
.u
.mkdir
.path
)) {
1879 ret
= -LTTNG_ERR_INVALID
;
1883 if (output
->type
== CONSUMER_DST_NET
) {
1884 msg
.u
.mkdir
.relayd_id
= output
->net_seq_index
;
1886 msg
.u
.mkdir
.relayd_id
= -1ULL;
1889 health_code_update();
1890 ret
= consumer_send_msg(socket
, &msg
);
1892 ret
= -LTTNG_ERR_MKDIR_FAIL_CONSUMER
;
1897 health_code_update();