2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
28 #include <common/common.h>
29 #include <common/defaults.h>
30 #include <common/uri.h>
37 * Receive a reply command status message from the consumer. Consumer socket
38 * lock MUST be acquired before calling this function.
40 * Return 0 on success, -1 on recv error or a negative lttng error code which
41 * was possibly returned by the consumer.
43 int consumer_recv_status_reply(struct consumer_socket
*sock
)
46 struct lttcomm_consumer_status_msg reply
;
50 ret
= lttcomm_recv_unix_sock(sock
->fd
, &reply
, sizeof(reply
));
53 /* Orderly shutdown. Don't return 0 which means success. */
56 /* The above call will print a PERROR on error. */
57 DBG("Fail to receive status reply on sock %d", sock
->fd
);
61 if (reply
.ret_code
== LTTNG_OK
) {
65 ret
= -reply
.ret_code
;
66 DBG("Consumer ret code %d", ret
);
74 * Once the ASK_CHANNEL command is sent to the consumer, the channel
75 * information are sent back. This call receives that data and populates key
78 * On success return 0 and both key and stream_count are set. On error, a
79 * negative value is sent back and both parameters are untouched.
81 int consumer_recv_status_channel(struct consumer_socket
*sock
,
82 uint64_t *key
, unsigned int *stream_count
)
85 struct lttcomm_consumer_status_channel reply
;
91 ret
= lttcomm_recv_unix_sock(sock
->fd
, &reply
, sizeof(reply
));
94 /* Orderly shutdown. Don't return 0 which means success. */
97 /* The above call will print a PERROR on error. */
98 DBG("Fail to receive status reply on sock %d", sock
->fd
);
102 /* An error is possible so don't touch the key and stream_count. */
103 if (reply
.ret_code
!= LTTNG_OK
) {
109 *stream_count
= reply
.stream_count
;
116 * Send destroy relayd command to consumer.
118 * On success return positive value. On error, negative value.
120 int consumer_send_destroy_relayd(struct consumer_socket
*sock
,
121 struct consumer_output
*consumer
)
124 struct lttcomm_consumer_msg msg
;
129 DBG2("Sending destroy relayd command to consumer sock %d", sock
->fd
);
131 /* Bail out if consumer is disabled */
132 if (!consumer
->enabled
) {
134 DBG3("Consumer is disabled");
138 msg
.cmd_type
= LTTNG_CONSUMER_DESTROY_RELAYD
;
139 msg
.u
.destroy_relayd
.net_seq_idx
= consumer
->net_seq_index
;
141 pthread_mutex_lock(sock
->lock
);
142 ret
= lttcomm_send_unix_sock(sock
->fd
, &msg
, sizeof(msg
));
144 /* Indicate that the consumer is probably closing at this point. */
145 DBG("send consumer destroy relayd command");
149 /* Don't check the return value. The caller will do it. */
150 ret
= consumer_recv_status_reply(sock
);
152 DBG2("Consumer send destroy relayd command done");
155 pthread_mutex_unlock(sock
->lock
);
161 * For each consumer socket in the consumer output object, send a destroy
164 void consumer_output_send_destroy_relayd(struct consumer_output
*consumer
)
166 struct lttng_ht_iter iter
;
167 struct consumer_socket
*socket
;
171 /* Destroy any relayd connection */
172 if (consumer
&& consumer
->type
== CONSUMER_DST_NET
) {
174 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
178 /* Send destroy relayd command */
179 ret
= consumer_send_destroy_relayd(socket
, consumer
);
181 DBG("Unable to send destroy relayd command to consumer");
182 /* Continue since we MUST delete everything at this point. */
190 * From a consumer_data structure, allocate and add a consumer socket to the
193 * Return 0 on success, else negative value on error
195 int consumer_create_socket(struct consumer_data
*data
,
196 struct consumer_output
*output
)
199 struct consumer_socket
*socket
;
203 if (output
== NULL
|| data
->cmd_sock
< 0) {
205 * Not an error. Possible there is simply not spawned consumer or it's
206 * disabled for the tracing session asking the socket.
212 socket
= consumer_find_socket(data
->cmd_sock
, output
);
214 if (socket
== NULL
) {
215 socket
= consumer_allocate_socket(data
->cmd_sock
);
216 if (socket
== NULL
) {
221 socket
->registered
= 0;
222 socket
->lock
= &data
->lock
;
224 consumer_add_socket(socket
, output
);
228 DBG3("Consumer socket created (fd: %d) and added to output",
236 * Return the consumer socket from the given consumer output with the right
237 * bitness. On error, returns NULL.
239 * The caller MUST acquire a rcu read side lock and keep it until the socket
240 * object reference is not needed anymore.
242 struct consumer_socket
*consumer_find_socket_by_bitness(int bits
,
243 struct consumer_output
*consumer
)
246 struct consumer_socket
*socket
= NULL
;
250 consumer_fd
= uatomic_read(&ust_consumerd64_fd
);
253 consumer_fd
= uatomic_read(&ust_consumerd32_fd
);
260 socket
= consumer_find_socket(consumer_fd
, consumer
);
262 ERR("Consumer socket fd %d not found in consumer obj %p",
263 consumer_fd
, consumer
);
271 * Find a consumer_socket in a consumer_output hashtable. Read side lock must
272 * be acquired before calling this function and across use of the
273 * returned consumer_socket.
275 struct consumer_socket
*consumer_find_socket(int key
,
276 struct consumer_output
*consumer
)
278 struct lttng_ht_iter iter
;
279 struct lttng_ht_node_ulong
*node
;
280 struct consumer_socket
*socket
= NULL
;
282 /* Negative keys are lookup failures */
283 if (key
< 0 || consumer
== NULL
) {
287 lttng_ht_lookup(consumer
->socks
, (void *)((unsigned long) key
),
289 node
= lttng_ht_iter_get_node_ulong(&iter
);
291 socket
= caa_container_of(node
, struct consumer_socket
, node
);
298 * Allocate a new consumer_socket and return the pointer.
300 struct consumer_socket
*consumer_allocate_socket(int fd
)
302 struct consumer_socket
*socket
= NULL
;
304 socket
= zmalloc(sizeof(struct consumer_socket
));
305 if (socket
== NULL
) {
306 PERROR("zmalloc consumer socket");
311 lttng_ht_node_init_ulong(&socket
->node
, fd
);
318 * Add consumer socket to consumer output object. Read side lock must be
319 * acquired before calling this function.
321 void consumer_add_socket(struct consumer_socket
*sock
,
322 struct consumer_output
*consumer
)
327 lttng_ht_add_unique_ulong(consumer
->socks
, &sock
->node
);
331 * Delte consumer socket to consumer output object. Read side lock must be
332 * acquired before calling this function.
334 void consumer_del_socket(struct consumer_socket
*sock
,
335 struct consumer_output
*consumer
)
338 struct lttng_ht_iter iter
;
343 iter
.iter
.node
= &sock
->node
.node
;
344 ret
= lttng_ht_del(consumer
->socks
, &iter
);
349 * RCU destroy call function.
351 static void destroy_socket_rcu(struct rcu_head
*head
)
353 struct lttng_ht_node_ulong
*node
=
354 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
355 struct consumer_socket
*socket
=
356 caa_container_of(node
, struct consumer_socket
, node
);
362 * Destroy and free socket pointer in a call RCU. Read side lock must be
363 * acquired before calling this function.
365 void consumer_destroy_socket(struct consumer_socket
*sock
)
370 * We DO NOT close the file descriptor here since it is global to the
371 * session daemon and is closed only if the consumer dies or a custom
372 * consumer was registered,
374 if (sock
->registered
) {
375 DBG3("Consumer socket was registered. Closing fd %d", sock
->fd
);
376 lttcomm_close_unix_sock(sock
->fd
);
379 call_rcu(&sock
->node
.head
, destroy_socket_rcu
);
383 * Allocate and assign data to a consumer_output object.
385 * Return pointer to structure.
387 struct consumer_output
*consumer_create_output(enum consumer_dst_type type
)
389 struct consumer_output
*output
= NULL
;
391 output
= zmalloc(sizeof(struct consumer_output
));
392 if (output
== NULL
) {
393 PERROR("zmalloc consumer_output");
397 /* By default, consumer output is enabled */
400 output
->net_seq_index
= (uint64_t) -1ULL;
402 output
->socks
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
409 * Delete the consumer_output object from the list and free the ptr.
411 * Should *NOT* be called with RCU read-side lock held.
413 void consumer_destroy_output(struct consumer_output
*obj
)
420 struct lttng_ht_iter iter
;
421 struct consumer_socket
*socket
;
424 cds_lfht_for_each_entry(obj
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
425 consumer_del_socket(socket
, obj
);
426 consumer_destroy_socket(socket
);
430 /* Finally destroy HT */
431 lttng_ht_destroy(obj
->socks
);
438 * Copy consumer output and returned the newly allocated copy.
440 * Should *NOT* be called with RCU read-side lock held.
442 struct consumer_output
*consumer_copy_output(struct consumer_output
*obj
)
444 struct lttng_ht
*tmp_ht_ptr
;
445 struct lttng_ht_iter iter
;
446 struct consumer_socket
*socket
, *copy_sock
;
447 struct consumer_output
*output
;
451 output
= consumer_create_output(obj
->type
);
452 if (output
== NULL
) {
455 /* Avoid losing the HT reference after the memcpy() */
456 tmp_ht_ptr
= output
->socks
;
458 memcpy(output
, obj
, sizeof(struct consumer_output
));
460 /* Putting back the HT pointer and start copying socket(s). */
461 output
->socks
= tmp_ht_ptr
;
464 cds_lfht_for_each_entry(obj
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
465 /* Create new socket object. */
466 copy_sock
= consumer_allocate_socket(socket
->fd
);
467 if (copy_sock
== NULL
) {
472 copy_sock
->registered
= socket
->registered
;
473 copy_sock
->lock
= socket
->lock
;
474 consumer_add_socket(copy_sock
, output
);
482 consumer_destroy_output(output
);
487 * Set network URI to the consumer output object.
489 * Return 0 on success. Return 1 if the URI were equal. Else, negative value on
492 int consumer_set_network_uri(struct consumer_output
*obj
,
493 struct lttng_uri
*uri
)
496 char tmp_path
[PATH_MAX
];
497 char hostname
[HOST_NAME_MAX
];
498 struct lttng_uri
*dst_uri
= NULL
;
500 /* Code flow error safety net. */
504 switch (uri
->stype
) {
505 case LTTNG_STREAM_CONTROL
:
506 dst_uri
= &obj
->dst
.net
.control
;
507 obj
->dst
.net
.control_isset
= 1;
508 if (uri
->port
== 0) {
509 /* Assign default port. */
510 uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
512 if (obj
->dst
.net
.data_isset
&& uri
->port
==
513 obj
->dst
.net
.data
.port
) {
514 ret
= -LTTNG_ERR_INVALID
;
518 DBG3("Consumer control URI set with port %d", uri
->port
);
520 case LTTNG_STREAM_DATA
:
521 dst_uri
= &obj
->dst
.net
.data
;
522 obj
->dst
.net
.data_isset
= 1;
523 if (uri
->port
== 0) {
524 /* Assign default port. */
525 uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
527 if (obj
->dst
.net
.control_isset
&& uri
->port
==
528 obj
->dst
.net
.control
.port
) {
529 ret
= -LTTNG_ERR_INVALID
;
533 DBG3("Consumer data URI set with port %d", uri
->port
);
536 ERR("Set network uri type unknown %d", uri
->stype
);
537 ret
= -LTTNG_ERR_INVALID
;
541 ret
= uri_compare(dst_uri
, uri
);
543 /* Same URI, don't touch it and return success. */
544 DBG3("URI network compare are the same");
548 /* URIs were not equal, replacing it. */
549 memset(dst_uri
, 0, sizeof(struct lttng_uri
));
550 memcpy(dst_uri
, uri
, sizeof(struct lttng_uri
));
551 obj
->type
= CONSUMER_DST_NET
;
553 /* Handle subdir and add hostname in front. */
554 if (dst_uri
->stype
== LTTNG_STREAM_CONTROL
) {
555 /* Get hostname to append it in the pathname */
556 ret
= gethostname(hostname
, sizeof(hostname
));
558 PERROR("gethostname. Fallback on default localhost");
559 strncpy(hostname
, "localhost", sizeof(hostname
));
561 hostname
[sizeof(hostname
) - 1] = '\0';
563 /* Setup consumer subdir if none present in the control URI */
564 if (strlen(dst_uri
->subdir
) == 0) {
565 ret
= snprintf(tmp_path
, sizeof(tmp_path
), "%s/%s",
566 hostname
, obj
->subdir
);
568 ret
= snprintf(tmp_path
, sizeof(tmp_path
), "%s/%s",
569 hostname
, dst_uri
->subdir
);
572 PERROR("snprintf set consumer uri subdir");
573 ret
= -LTTNG_ERR_NOMEM
;
577 strncpy(obj
->subdir
, tmp_path
, sizeof(obj
->subdir
));
578 DBG3("Consumer set network uri subdir path %s", tmp_path
);
589 * Send file descriptor to consumer via sock.
591 int consumer_send_fds(struct consumer_socket
*sock
, int *fds
, size_t nb_fd
)
599 ret
= lttcomm_send_fds_unix_sock(sock
->fd
, fds
, nb_fd
);
601 /* The above call will print a PERROR on error. */
602 DBG("Error when sending consumer fds on sock %d", sock
->fd
);
606 ret
= consumer_recv_status_reply(sock
);
613 * Consumer send communication message structure to consumer.
615 int consumer_send_msg(struct consumer_socket
*sock
,
616 struct lttcomm_consumer_msg
*msg
)
622 assert(sock
->fd
>= 0);
624 ret
= lttcomm_send_unix_sock(sock
->fd
, msg
,
625 sizeof(struct lttcomm_consumer_msg
));
627 /* The above call will print a PERROR on error. */
628 DBG("Error when sending consumer channel on sock %d", sock
->fd
);
632 ret
= consumer_recv_status_reply(sock
);
639 * Consumer send channel communication message structure to consumer.
641 int consumer_send_channel(struct consumer_socket
*sock
,
642 struct lttcomm_consumer_msg
*msg
)
648 assert(sock
->fd
>= 0);
650 ret
= lttcomm_send_unix_sock(sock
->fd
, msg
,
651 sizeof(struct lttcomm_consumer_msg
));
653 /* The above call will print a PERROR on error. */
654 DBG("Error when sending consumer channel on sock %d", sock
->fd
);
658 ret
= consumer_recv_status_reply(sock
);
665 * Populate the given consumer msg structure with the ask_channel command
668 void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
669 uint64_t subbuf_size
,
672 unsigned int switch_timer_interval
,
673 unsigned int read_timer_interval
,
677 const char *pathname
,
685 uint64_t tracefile_size
,
686 uint64_t tracefile_count
)
690 /* Zeroed structure */
691 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
693 msg
->cmd_type
= LTTNG_CONSUMER_ASK_CHANNEL_CREATION
;
694 msg
->u
.ask_channel
.subbuf_size
= subbuf_size
;
695 msg
->u
.ask_channel
.num_subbuf
= num_subbuf
;
696 msg
->u
.ask_channel
.overwrite
= overwrite
;
697 msg
->u
.ask_channel
.switch_timer_interval
= switch_timer_interval
;
698 msg
->u
.ask_channel
.read_timer_interval
= read_timer_interval
;
699 msg
->u
.ask_channel
.output
= output
;
700 msg
->u
.ask_channel
.type
= type
;
701 msg
->u
.ask_channel
.session_id
= session_id
;
702 msg
->u
.ask_channel
.uid
= uid
;
703 msg
->u
.ask_channel
.gid
= gid
;
704 msg
->u
.ask_channel
.relayd_id
= relayd_id
;
705 msg
->u
.ask_channel
.key
= key
;
706 msg
->u
.ask_channel
.chan_id
= chan_id
;
707 msg
->u
.ask_channel
.tracefile_size
= tracefile_size
;
708 msg
->u
.ask_channel
.tracefile_count
= tracefile_count
;
710 memcpy(msg
->u
.ask_channel
.uuid
, uuid
, sizeof(msg
->u
.ask_channel
.uuid
));
712 strncpy(msg
->u
.ask_channel
.pathname
, pathname
,
713 sizeof(msg
->u
.ask_channel
.pathname
));
714 msg
->u
.ask_channel
.pathname
[sizeof(msg
->u
.ask_channel
.pathname
)-1] = '\0';
716 strncpy(msg
->u
.ask_channel
.name
, name
, sizeof(msg
->u
.ask_channel
.name
));
717 msg
->u
.ask_channel
.name
[sizeof(msg
->u
.ask_channel
.name
) - 1] = '\0';
721 * Init channel communication message structure.
723 void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
724 enum lttng_consumer_command cmd
,
725 uint64_t channel_key
,
727 const char *pathname
,
732 unsigned int nb_init_streams
,
733 enum lttng_event_output output
,
735 uint64_t tracefile_size
,
736 uint64_t tracefile_count
)
740 /* Zeroed structure */
741 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
745 msg
->u
.channel
.channel_key
= channel_key
;
746 msg
->u
.channel
.session_id
= session_id
;
747 msg
->u
.channel
.uid
= uid
;
748 msg
->u
.channel
.gid
= gid
;
749 msg
->u
.channel
.relayd_id
= relayd_id
;
750 msg
->u
.channel
.nb_init_streams
= nb_init_streams
;
751 msg
->u
.channel
.output
= output
;
752 msg
->u
.channel
.type
= type
;
753 msg
->u
.channel
.tracefile_size
= tracefile_size
;
754 msg
->u
.channel
.tracefile_count
= tracefile_count
;
756 strncpy(msg
->u
.channel
.pathname
, pathname
,
757 sizeof(msg
->u
.channel
.pathname
));
758 msg
->u
.channel
.pathname
[sizeof(msg
->u
.channel
.pathname
) - 1] = '\0';
760 strncpy(msg
->u
.channel
.name
, name
, sizeof(msg
->u
.channel
.name
));
761 msg
->u
.channel
.name
[sizeof(msg
->u
.channel
.name
) - 1] = '\0';
765 * Init stream communication message structure.
767 void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
768 enum lttng_consumer_command cmd
,
769 uint64_t channel_key
,
775 memset(msg
, 0, sizeof(struct lttcomm_consumer_msg
));
778 msg
->u
.stream
.channel_key
= channel_key
;
779 msg
->u
.stream
.stream_key
= stream_key
;
780 msg
->u
.stream
.cpu
= cpu
;
784 * Send stream communication structure to the consumer.
786 int consumer_send_stream(struct consumer_socket
*sock
,
787 struct consumer_output
*dst
, struct lttcomm_consumer_msg
*msg
,
788 int *fds
, size_t nb_fd
)
798 ret
= lttcomm_send_unix_sock(sock
->fd
, msg
,
799 sizeof(struct lttcomm_consumer_msg
));
801 /* The above call will print a PERROR on error. */
802 DBG("Error when sending consumer stream on sock %d", sock
->fd
);
806 ret
= consumer_recv_status_reply(sock
);
811 ret
= consumer_send_fds(sock
, fds
, nb_fd
);
821 * Send relayd socket to consumer associated with a session name.
823 * On success return positive value. On error, negative value.
825 int consumer_send_relayd_socket(struct consumer_socket
*consumer_sock
,
826 struct lttcomm_relayd_sock
*rsock
, struct consumer_output
*consumer
,
827 enum lttng_stream_type type
, uint64_t session_id
)
830 struct lttcomm_consumer_msg msg
;
832 /* Code flow error. Safety net. */
835 assert(consumer_sock
);
837 /* Bail out if consumer is disabled */
838 if (!consumer
->enabled
) {
843 msg
.cmd_type
= LTTNG_CONSUMER_ADD_RELAYD_SOCKET
;
845 * Assign network consumer output index using the temporary consumer since
846 * this call should only be made from within a set_consumer_uri() function
847 * call in the session daemon.
849 msg
.u
.relayd_sock
.net_index
= consumer
->net_seq_index
;
850 msg
.u
.relayd_sock
.type
= type
;
851 msg
.u
.relayd_sock
.session_id
= session_id
;
852 memcpy(&msg
.u
.relayd_sock
.sock
, rsock
, sizeof(msg
.u
.relayd_sock
.sock
));
854 DBG3("Sending relayd sock info to consumer on %d", consumer_sock
->fd
);
855 ret
= lttcomm_send_unix_sock(consumer_sock
->fd
, &msg
, sizeof(msg
));
857 /* The above call will print a PERROR on error. */
858 DBG("Error when sending relayd sockets on sock %d", rsock
->sock
.fd
);
862 ret
= consumer_recv_status_reply(consumer_sock
);
867 DBG3("Sending relayd socket file descriptor to consumer");
868 ret
= consumer_send_fds(consumer_sock
, &rsock
->sock
.fd
, 1);
873 DBG2("Consumer relayd socket sent");
880 * Set consumer subdirectory using the session name and a generated datetime if
881 * needed. This is appended to the current subdirectory.
883 int consumer_set_subdir(struct consumer_output
*consumer
,
884 const char *session_name
)
887 unsigned int have_default_name
= 0;
888 char datetime
[16], tmp_path
[PATH_MAX
];
893 assert(session_name
);
895 memset(tmp_path
, 0, sizeof(tmp_path
));
897 /* Flag if we have a default session. */
898 if (strncmp(session_name
, DEFAULT_SESSION_NAME
"-",
899 strlen(DEFAULT_SESSION_NAME
) + 1) == 0) {
900 have_default_name
= 1;
902 /* Get date and time for session path */
904 timeinfo
= localtime(&rawtime
);
905 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
908 if (have_default_name
) {
909 ret
= snprintf(tmp_path
, sizeof(tmp_path
),
910 "%s/%s", consumer
->subdir
, session_name
);
912 ret
= snprintf(tmp_path
, sizeof(tmp_path
),
913 "%s/%s-%s/", consumer
->subdir
, session_name
, datetime
);
916 PERROR("snprintf session name date");
920 strncpy(consumer
->subdir
, tmp_path
, sizeof(consumer
->subdir
));
921 DBG2("Consumer subdir set to %s", consumer
->subdir
);
928 * Ask the consumer if the data is ready to read (NOT pending) for the specific
931 * This function has a different behavior with the consumer i.e. that it waits
932 * for a reply from the consumer if yes or no the data is pending.
934 int consumer_is_data_pending(uint64_t session_id
,
935 struct consumer_output
*consumer
)
938 int32_t ret_code
= 0; /* Default is that the data is NOT pending */
939 struct consumer_socket
*socket
;
940 struct lttng_ht_iter iter
;
941 struct lttcomm_consumer_msg msg
;
945 msg
.cmd_type
= LTTNG_CONSUMER_DATA_PENDING
;
947 msg
.u
.data_pending
.session_id
= session_id
;
949 DBG3("Consumer data pending for id %" PRIu64
, session_id
);
951 /* Send command for each consumer */
953 cds_lfht_for_each_entry(consumer
->socks
->ht
, &iter
.iter
, socket
,
955 /* Code flow error */
956 assert(socket
->fd
>= 0);
958 pthread_mutex_lock(socket
->lock
);
960 ret
= lttcomm_send_unix_sock(socket
->fd
, &msg
, sizeof(msg
));
962 /* The above call will print a PERROR on error. */
963 DBG("Error on consumer is data pending on sock %d", socket
->fd
);
964 pthread_mutex_unlock(socket
->lock
);
969 * No need for a recv reply status because the answer to the command is
970 * the reply status message.
973 ret
= lttcomm_recv_unix_sock(socket
->fd
, &ret_code
, sizeof(ret_code
));
976 /* Orderly shutdown. Don't return 0 which means success. */
979 /* The above call will print a PERROR on error. */
980 DBG("Error on recv consumer is data pending on sock %d", socket
->fd
);
981 pthread_mutex_unlock(socket
->lock
);
985 pthread_mutex_unlock(socket
->lock
);
993 DBG("Consumer data is %s pending for session id %" PRIu64
,
994 ret_code
== 1 ? "" : "NOT", session_id
);
1003 * Send a flush command to consumer using the given channel key.
1005 * Return 0 on success else a negative value.
1007 int consumer_flush_channel(struct consumer_socket
*socket
, uint64_t key
)
1010 struct lttcomm_consumer_msg msg
;
1013 assert(socket
->fd
>= 0);
1015 DBG2("Consumer flush channel key %" PRIu64
, key
);
1017 msg
.cmd_type
= LTTNG_CONSUMER_FLUSH_CHANNEL
;
1018 msg
.u
.flush_channel
.key
= key
;
1020 pthread_mutex_lock(socket
->lock
);
1021 health_code_update();
1023 ret
= consumer_send_msg(socket
, &msg
);
1029 health_code_update();
1030 pthread_mutex_unlock(socket
->lock
);
1035 * Send a close metdata command to consumer using the given channel key.
1037 * Return 0 on success else a negative value.
1039 int consumer_close_metadata(struct consumer_socket
*socket
,
1040 uint64_t metadata_key
)
1043 struct lttcomm_consumer_msg msg
;
1046 assert(socket
->fd
>= 0);
1048 DBG2("Consumer close metadata channel key %" PRIu64
, metadata_key
);
1050 msg
.cmd_type
= LTTNG_CONSUMER_CLOSE_METADATA
;
1051 msg
.u
.close_metadata
.key
= metadata_key
;
1053 pthread_mutex_lock(socket
->lock
);
1054 health_code_update();
1056 ret
= consumer_send_msg(socket
, &msg
);
1062 health_code_update();
1063 pthread_mutex_unlock(socket
->lock
);
1068 * Send a setup metdata command to consumer using the given channel key.
1070 * Return 0 on success else a negative value.
1072 int consumer_setup_metadata(struct consumer_socket
*socket
,
1073 uint64_t metadata_key
)
1076 struct lttcomm_consumer_msg msg
;
1079 assert(socket
->fd
>= 0);
1081 DBG2("Consumer setup metadata channel key %" PRIu64
, metadata_key
);
1083 msg
.cmd_type
= LTTNG_CONSUMER_SETUP_METADATA
;
1084 msg
.u
.setup_metadata
.key
= metadata_key
;
1086 pthread_mutex_lock(socket
->lock
);
1087 health_code_update();
1089 ret
= consumer_send_msg(socket
, &msg
);
1095 health_code_update();
1096 pthread_mutex_unlock(socket
->lock
);
1101 * Send metadata string to consumer. Socket lock MUST be acquired.
1103 * Return 0 on success else a negative value.
1105 int consumer_push_metadata(struct consumer_socket
*socket
,
1106 uint64_t metadata_key
, char *metadata_str
, size_t len
,
1107 size_t target_offset
)
1110 struct lttcomm_consumer_msg msg
;
1113 assert(socket
->fd
>= 0);
1115 DBG2("Consumer push metadata to consumer socket %d", socket
->fd
);
1117 msg
.cmd_type
= LTTNG_CONSUMER_PUSH_METADATA
;
1118 msg
.u
.push_metadata
.key
= metadata_key
;
1119 msg
.u
.push_metadata
.target_offset
= target_offset
;
1120 msg
.u
.push_metadata
.len
= len
;
1122 health_code_update();
1123 ret
= consumer_send_msg(socket
, &msg
);
1124 if (ret
< 0 || len
== 0) {
1128 DBG3("Consumer pushing metadata on sock %d of len %zu", socket
->fd
, len
);
1130 ret
= lttcomm_send_unix_sock(socket
->fd
, metadata_str
, len
);
1135 health_code_update();
1136 ret
= consumer_recv_status_reply(socket
);
1142 health_code_update();