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.
26 #include <common/common.h>
27 #include <common/defaults.h>
28 #include <common/compat/endian.h>
29 #include <common/sessiond-comm/relayd.h>
30 #include <common/index/ctf-index.h>
35 * Send command. Fill up the header and append the data.
37 static int send_command(struct lttcomm_relayd_sock
*rsock
,
38 enum lttcomm_relayd_command cmd
, void *data
, size_t size
,
42 struct lttcomm_relayd_hdr header
;
44 uint64_t buf_size
= sizeof(header
);
46 if (rsock
->sock
.fd
< 0) {
54 buf
= zmalloc(buf_size
);
56 PERROR("zmalloc relayd send command buf");
61 memset(&header
, 0, sizeof(header
));
62 header
.cmd
= htobe32(cmd
);
63 header
.data_size
= htobe64(size
);
65 /* Zeroed for now since not used. */
66 header
.cmd_version
= 0;
67 header
.circuit_id
= 0;
69 /* Prepare buffer to send. */
70 memcpy(buf
, &header
, sizeof(header
));
72 memcpy(buf
+ sizeof(header
), data
, size
);
75 DBG3("Relayd sending command %d of size %" PRIu64
, (int) cmd
, buf_size
);
76 ret
= rsock
->sock
.ops
->sendmsg(&rsock
->sock
, buf
, buf_size
, flags
);
78 PERROR("Failed to send command %d of size %" PRIu64
,
89 static int recv_reply_ignore(struct lttcomm_relayd_sock
*rsock
, size_t size
)
95 * To prevent ever growing size of recv_reply to ignore, if the number
96 * of bytes we want to ignore is bigger than `cutoff`, consume half of
97 * the cutoff. We might block on it but still, most of bytes to ignore
98 * should already be ready to consume at this point.
100 * This kind of scenario can easily happen on stopped session with a
101 * live_timer since no actual receive is done on the socket that would
102 * discard the `ignore` portion.
104 * TCP guarantee in-order transmission both on send and receive so this
107 if (rsock
->bytes_to_ignore_on_recv
>= cutfoff
) {
108 size_t to_discard
= cutfoff
/ 2;
110 ret
= rsock
->sock
.ops
->recvmsg(&rsock
->sock
, NULL
, to_discard
, MSG_TRUNC
);
111 if (ret
<= 0 || ret
!= to_discard
) {
113 /* Orderly shutdown. */
114 DBG("Socket %d has performed an orderly shutdown", rsock
->sock
.fd
);
116 DBG("Receiving reply to discard failed on sock %d for size %zu with ret %d",
117 rsock
->sock
.fd
, to_discard
, ret
);
123 DBG("Force discard of %zu bytes for socket %d", to_discard
, rsock
->sock
.fd
);
124 rsock
->bytes_to_ignore_on_recv
-= to_discard
;
127 DBG3("Relayd ignore reply of %zu bytes for socket %d.", size
, rsock
->sock
.fd
);
128 /* Do not wait for the current reply to be ignored */
129 rsock
->bytes_to_ignore_on_recv
+= size
;
137 * Receive reply data on socket. This MUST be call after send_command or else
138 * could result in unexpected behavior(s).
140 static int recv_reply(struct lttcomm_relayd_sock
*rsock
, void *data
, size_t size
)
144 if (rsock
->sock
.fd
< 0) {
149 * We have to consume the bytes that are marked to ignore.
151 if (rsock
->bytes_to_ignore_on_recv
!= 0) {
152 ret
= rsock
->sock
.ops
->recvmsg(&rsock
->sock
, NULL
, rsock
->bytes_to_ignore_on_recv
, MSG_TRUNC
);
153 if (ret
<= 0 || ret
!= rsock
->bytes_to_ignore_on_recv
) {
155 /* Orderly shutdown. */
156 DBG("Socket %d has performed an orderly shutdown", rsock
->sock
.fd
);
158 DBG("Receiving reply to skip failed on sock %d for size %zu with ret %d",
159 rsock
->sock
.fd
, rsock
->bytes_to_ignore_on_recv
, ret
);
164 DBG("Discarded %zu bytes on sock %d", rsock
->bytes_to_ignore_on_recv
, rsock
->sock
.fd
);
165 rsock
->bytes_to_ignore_on_recv
= 0;
168 DBG3("Relayd waiting for reply of size %zu", size
);
170 ret
= rsock
->sock
.ops
->recvmsg(&rsock
->sock
, data
, size
, 0);
171 if (ret
<= 0 || ret
!= size
) {
173 /* Orderly shutdown. */
174 DBG("Socket %d has performed an orderly shutdown", rsock
->sock
.fd
);
176 DBG("Receiving reply failed on sock %d for size %zu with ret %d",
177 rsock
->sock
.fd
, size
, ret
);
179 /* Always return -1 here and the caller can use errno. */
189 * Starting at 2.4, RELAYD_CREATE_SESSION takes additional parameters to
190 * support the live reading capability.
192 static int relayd_create_session_2_4(struct lttcomm_relayd_sock
*rsock
,
193 uint64_t *session_id
, char *session_name
, char *hostname
,
194 int session_live_timer
, unsigned int snapshot
)
197 struct lttcomm_relayd_create_session_2_4 msg
;
199 if (lttng_strncpy(msg
.session_name
, session_name
,
200 sizeof(msg
.session_name
))) {
204 if (lttng_strncpy(msg
.hostname
, hostname
, sizeof(msg
.hostname
))) {
208 msg
.live_timer
= htobe32(session_live_timer
);
209 msg
.snapshot
= htobe32(snapshot
);
212 ret
= send_command(rsock
, RELAYD_CREATE_SESSION
, &msg
, sizeof(msg
), 0);
222 * RELAYD_CREATE_SESSION from 2.1 to 2.3.
224 static int relayd_create_session_2_1(struct lttcomm_relayd_sock
*rsock
,
225 uint64_t *session_id
)
230 ret
= send_command(rsock
, RELAYD_CREATE_SESSION
, NULL
, 0, 0);
240 * Send a RELAYD_CREATE_SESSION command to the relayd with the given socket and
241 * set session_id of the relayd if we have a successful reply from the relayd.
243 * On success, return 0 else a negative value which is either an errno error or
244 * a lttng error code from the relayd.
246 int relayd_create_session(struct lttcomm_relayd_sock
*rsock
, uint64_t *session_id
,
247 char *session_name
, char *hostname
, int session_live_timer
,
248 unsigned int snapshot
)
251 struct lttcomm_relayd_status_session reply
;
256 DBG("Relayd create session");
258 switch(rsock
->minor
) {
262 ret
= relayd_create_session_2_1(rsock
, session_id
);
266 ret
= relayd_create_session_2_4(rsock
, session_id
, session_name
,
267 hostname
, session_live_timer
, snapshot
);
275 /* Receive response */
276 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
281 reply
.session_id
= be64toh(reply
.session_id
);
282 reply
.ret_code
= be32toh(reply
.ret_code
);
284 /* Return session id or negative ret code. */
285 if (reply
.ret_code
!= LTTNG_OK
) {
287 ERR("Relayd create session replied error %d", reply
.ret_code
);
291 *session_id
= reply
.session_id
;
294 DBG("Relayd session created with id %" PRIu64
, reply
.session_id
);
301 * Add stream on the relayd and assign stream handle to the stream_id argument.
303 * On success return 0 else return ret_code negative value.
305 int relayd_add_stream(struct lttcomm_relayd_sock
*rsock
, const char *channel_name
,
306 const char *pathname
, uint64_t *stream_id
,
307 uint64_t tracefile_size
, uint64_t tracefile_count
)
310 struct lttcomm_relayd_add_stream msg
;
311 struct lttcomm_relayd_add_stream_2_2 msg_2_2
;
312 struct lttcomm_relayd_status_stream reply
;
314 /* Code flow error. Safety net. */
316 assert(channel_name
);
319 DBG("Relayd adding stream for channel name %s", channel_name
);
321 /* Compat with relayd 2.1 */
322 if (rsock
->minor
== 1) {
323 memset(&msg
, 0, sizeof(msg
));
324 if (lttng_strncpy(msg
.channel_name
, channel_name
,
325 sizeof(msg
.channel_name
))) {
329 if (lttng_strncpy(msg
.pathname
, pathname
,
330 sizeof(msg
.pathname
))) {
336 ret
= send_command(rsock
, RELAYD_ADD_STREAM
, (void *) &msg
, sizeof(msg
), 0);
341 memset(&msg_2_2
, 0, sizeof(msg_2_2
));
342 /* Compat with relayd 2.2+ */
343 if (lttng_strncpy(msg_2_2
.channel_name
, channel_name
,
344 sizeof(msg_2_2
.channel_name
))) {
348 if (lttng_strncpy(msg_2_2
.pathname
, pathname
,
349 sizeof(msg_2_2
.pathname
))) {
353 msg_2_2
.tracefile_size
= htobe64(tracefile_size
);
354 msg_2_2
.tracefile_count
= htobe64(tracefile_count
);
357 ret
= send_command(rsock
, RELAYD_ADD_STREAM
, (void *) &msg_2_2
, sizeof(msg_2_2
), 0);
363 /* Waiting for reply */
364 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
369 /* Back to host bytes order. */
370 reply
.handle
= be64toh(reply
.handle
);
371 reply
.ret_code
= be32toh(reply
.ret_code
);
373 /* Return session id or negative ret code. */
374 if (reply
.ret_code
!= LTTNG_OK
) {
376 ERR("Relayd add stream replied error %d", reply
.ret_code
);
380 *stream_id
= reply
.handle
;
383 DBG("Relayd stream added successfully with handle %" PRIu64
,
391 * Add stream on the relayd. Send part.
393 * On success return 0 else return ret_code negative value.
395 int relayd_add_stream_send(struct lttcomm_relayd_sock
*rsock
, const char *channel_name
,
396 const char *pathname
, uint64_t tracefile_size
, uint64_t tracefile_count
)
399 struct lttcomm_relayd_add_stream msg
;
400 struct lttcomm_relayd_add_stream_2_2 msg_2_2
;
402 /* Code flow error. Safety net. */
404 assert(channel_name
);
407 DBG("Relayd adding stream for channel name %s. Part send", channel_name
);
409 /* Compat with relayd 2.1 */
410 if (rsock
->minor
== 1) {
411 memset(&msg
, 0, sizeof(msg
));
412 if (lttng_strncpy(msg
.channel_name
, channel_name
,
413 sizeof(msg
.channel_name
))) {
417 if (lttng_strncpy(msg
.pathname
, pathname
,
418 sizeof(msg
.pathname
))) {
424 ret
= send_command(rsock
, RELAYD_ADD_STREAM
, (void *) &msg
, sizeof(msg
), 0);
429 memset(&msg_2_2
, 0, sizeof(msg_2_2
));
430 /* Compat with relayd 2.2+ */
431 if (lttng_strncpy(msg_2_2
.channel_name
, channel_name
,
432 sizeof(msg_2_2
.channel_name
))) {
436 if (lttng_strncpy(msg_2_2
.pathname
, pathname
,
437 sizeof(msg_2_2
.pathname
))) {
441 msg_2_2
.tracefile_size
= htobe64(tracefile_size
);
442 msg_2_2
.tracefile_count
= htobe64(tracefile_count
);
445 ret
= send_command(rsock
, RELAYD_ADD_STREAM
, (void *) &msg_2_2
, sizeof(msg_2_2
), 0);
451 DBG("Relayd add stream sent for channel name %s.", channel_name
);
458 int relayd_add_stream_rcv(struct lttcomm_relayd_sock
*rsock
, uint64_t *_stream_id
)
461 struct lttcomm_relayd_status_stream reply
;
463 /* Code flow error. Safety net. */
466 /* Waiting for reply */
467 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
472 /* Back to host bytes order. */
473 reply
.handle
= be64toh(reply
.handle
);
474 reply
.ret_code
= be32toh(reply
.ret_code
);
476 /* Return session id or negative ret code. */
477 if (reply
.ret_code
!= LTTNG_OK
) {
479 ERR("Relayd add stream replied error %d", reply
.ret_code
);
483 *_stream_id
= reply
.handle
;
486 DBG("Relayd stream added successfully with handle %" PRIu64
,
494 * Inform the relay that all the streams for the current channel has been sent.
496 * On success return 0 else return ret_code negative value.
498 int relayd_streams_sent(struct lttcomm_relayd_sock
*rsock
)
501 struct lttcomm_relayd_generic_reply reply
;
503 /* Code flow error. Safety net. */
506 DBG("Relayd sending streams sent.");
508 /* This feature was introduced in 2.4, ignore it for earlier versions. */
509 if (rsock
->minor
< 4) {
515 ret
= send_command(rsock
, RELAYD_STREAMS_SENT
, NULL
, 0, 0);
520 /* Waiting for reply */
521 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
526 /* Back to host bytes order. */
527 reply
.ret_code
= be32toh(reply
.ret_code
);
529 /* Return session id or negative ret code. */
530 if (reply
.ret_code
!= LTTNG_OK
) {
532 ERR("Relayd streams sent replied error %d", reply
.ret_code
);
539 DBG("Relayd streams sent success");
547 * Check version numbers on the relayd.
548 * If major versions are compatible, we assign minor_to_use to the
549 * minor version of the procotol we are going to use for this session.
551 * Return 0 if the two daemons are compatible, LTTNG_ERR_RELAYD_VERSION_FAIL
552 * otherwise, or a negative value on network errors.
554 int relayd_version_check(struct lttcomm_relayd_sock
*rsock
)
557 struct lttcomm_relayd_version msg
;
559 /* Code flow error. Safety net. */
562 DBG("Relayd version check for major.minor %u.%u", rsock
->major
,
565 memset(&msg
, 0, sizeof(msg
));
566 /* Prepare network byte order before transmission. */
567 msg
.major
= htobe32(rsock
->major
);
568 msg
.minor
= htobe32(rsock
->minor
);
571 ret
= send_command(rsock
, RELAYD_VERSION
, (void *) &msg
, sizeof(msg
), 0);
576 /* Receive response */
577 ret
= recv_reply(rsock
, (void *) &msg
, sizeof(msg
));
582 /* Set back to host bytes order */
583 msg
.major
= be32toh(msg
.major
);
584 msg
.minor
= be32toh(msg
.minor
);
587 * Only validate the major version. If the other side is higher,
588 * communication is not possible. Only major version equal can talk to each
589 * other. If the minor version differs, the lowest version is used by both
592 if (msg
.major
!= rsock
->major
) {
594 ret
= LTTNG_ERR_RELAYD_VERSION_FAIL
;
595 DBG2("Relayd version is NOT compatible. Relayd version %u != %u (us)",
596 msg
.major
, rsock
->major
);
601 * If the relayd's minor version is higher, it will adapt to our version so
602 * we can continue to use the latest relayd communication data structure.
603 * If the received minor version is higher, the relayd should adapt to us.
605 if (rsock
->minor
> msg
.minor
) {
606 rsock
->minor
= msg
.minor
;
609 /* Version number compatible */
610 DBG2("Relayd version is compatible, using protocol version %u.%u",
611 rsock
->major
, rsock
->minor
);
619 * Add stream on the relayd and assign stream handle to the stream_id argument.
621 * On success return 0 else return ret_code negative value.
623 int relayd_send_metadata(struct lttcomm_relayd_sock
*rsock
, size_t len
)
627 /* Code flow error. Safety net. */
630 DBG("Relayd sending metadata of size %zu", len
);
633 ret
= send_command(rsock
, RELAYD_SEND_METADATA
, NULL
, len
, 0);
638 DBG2("Relayd metadata added successfully");
641 * After that call, the metadata data MUST be sent to the relayd so the
642 * receive size on the other end matches the len of the metadata packet
643 * header. This is why we don't wait for a reply here.
651 * Connect to relay daemon with an allocated lttcomm_relayd_sock.
653 int relayd_connect(struct lttcomm_relayd_sock
*rsock
)
655 /* Code flow error. Safety net. */
658 if (!rsock
->sock
.ops
) {
660 * Attempting a connect on a non-initialized socket.
665 DBG3("Relayd connect ...");
667 return rsock
->sock
.ops
->connect(&rsock
->sock
);
671 * Close relayd socket with an allocated lttcomm_relayd_sock.
673 * If no socket operations are found, simply return 0 meaning that everything
674 * is fine. Without operations, the socket can not possibly be opened or used.
675 * This is possible if the socket was allocated but not created. However, the
676 * caller could simply use it to store a valid file descriptor for instance
677 * passed over a Unix socket and call this to cleanup but still without a valid
680 * Return the close returned value. On error, a negative value is usually
681 * returned back from close(2).
683 int relayd_close(struct lttcomm_relayd_sock
*rsock
)
687 /* Code flow error. Safety net. */
690 /* An invalid fd is fine, return success. */
691 if (rsock
->sock
.fd
< 0) {
697 * This ensure that we do not close the socket while the lttng-relayd
698 * expects to be able to send a response that we skipped.
699 * While we loose some time to receive everything, this keep the
700 * protocol intact from the point of view of lttng-relayd.
702 if (rsock
->bytes_to_ignore_on_recv
!= 0) {
703 ret
= rsock
->sock
.ops
->recvmsg(&rsock
->sock
, NULL
, rsock
->bytes_to_ignore_on_recv
, MSG_TRUNC
);
704 if (ret
<= 0 || ret
!= rsock
->bytes_to_ignore_on_recv
) {
706 /* Orderly shutdown. */
707 DBG("Socket %d has performed an orderly shutdown", rsock
->sock
.fd
);
709 DBG("Receiving reply to skip failed on sock %d for size %zu with ret %d",
710 rsock
->sock
.fd
, rsock
->bytes_to_ignore_on_recv
, ret
);
713 DBG("Discarded %zu bytes on sock %d", rsock
->bytes_to_ignore_on_recv
, rsock
->sock
.fd
);
714 rsock
->bytes_to_ignore_on_recv
= 0;
717 DBG3("Relayd closing socket %d", rsock
->sock
.fd
);
719 if (rsock
->sock
.ops
) {
720 ret
= rsock
->sock
.ops
->close(&rsock
->sock
);
722 /* Default call if no specific ops found. */
723 ret
= close(rsock
->sock
.fd
);
725 PERROR("relayd_close default close");
735 * Send data header structure to the relayd.
737 int relayd_send_data_hdr(struct lttcomm_relayd_sock
*rsock
,
738 struct lttcomm_relayd_data_hdr
*hdr
, size_t size
)
742 /* Code flow error. Safety net. */
746 if (rsock
->sock
.fd
< 0) {
750 DBG3("Relayd sending data header of size %zu", size
);
752 /* Again, safety net */
754 size
= sizeof(struct lttcomm_relayd_data_hdr
);
757 /* Only send data header. */
758 ret
= rsock
->sock
.ops
->sendmsg(&rsock
->sock
, hdr
, size
, 0);
765 * The data MUST be sent right after that command for the receive on the
766 * other end to match the size in the header.
774 * Send close stream command to the relayd.
776 int relayd_send_close_stream(struct lttcomm_relayd_sock
*rsock
, uint64_t stream_id
,
777 uint64_t last_net_seq_num
)
780 struct lttcomm_relayd_close_stream msg
;
781 struct lttcomm_relayd_generic_reply reply
;
783 /* Code flow error. Safety net. */
786 DBG("Relayd closing stream id %" PRIu64
, stream_id
);
788 memset(&msg
, 0, sizeof(msg
));
789 msg
.stream_id
= htobe64(stream_id
);
790 msg
.last_net_seq_num
= htobe64(last_net_seq_num
);
793 ret
= send_command(rsock
, RELAYD_CLOSE_STREAM
, (void *) &msg
, sizeof(msg
), 0);
799 * Discard response since we do not really care for it and that TCP
800 * guarantee in-order delivery. As for error handling, there is not much
801 * to do at this point (closing).
803 ret
= recv_reply_ignore(rsock
, sizeof(reply
));
808 DBG("Relayd close stream id %" PRIu64
" successfully", stream_id
);
815 * Check for data availability for a given stream id.
817 * Return 0 if NOT pending, 1 if so and a negative value on error.
819 int relayd_data_pending(struct lttcomm_relayd_sock
*rsock
, uint64_t stream_id
,
820 uint64_t last_net_seq_num
)
823 struct lttcomm_relayd_data_pending msg
;
824 struct lttcomm_relayd_generic_reply reply
;
826 /* Code flow error. Safety net. */
829 DBG("Relayd data pending for stream id %" PRIu64
, stream_id
);
831 memset(&msg
, 0, sizeof(msg
));
832 msg
.stream_id
= htobe64(stream_id
);
833 msg
.last_net_seq_num
= htobe64(last_net_seq_num
);
836 ret
= send_command(rsock
, RELAYD_DATA_PENDING
, (void *) &msg
,
842 /* Receive response */
843 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
848 reply
.ret_code
= be32toh(reply
.ret_code
);
850 /* Return session id or negative ret code. */
851 if (reply
.ret_code
>= LTTNG_OK
) {
852 ERR("Relayd data pending replied error %d", reply
.ret_code
);
855 /* At this point, the ret code is either 1 or 0 */
856 ret
= reply
.ret_code
;
858 DBG("Relayd data is %s pending for stream id %" PRIu64
,
859 ret
== 1 ? "" : "NOT", stream_id
);
866 * Check on the relayd side for a quiescent state on the control socket.
868 int relayd_quiescent_control(struct lttcomm_relayd_sock
*rsock
,
869 uint64_t metadata_stream_id
)
872 struct lttcomm_relayd_quiescent_control msg
;
873 struct lttcomm_relayd_generic_reply reply
;
875 /* Code flow error. Safety net. */
878 DBG("Relayd checking quiescent control state");
880 memset(&msg
, 0, sizeof(msg
));
881 msg
.stream_id
= htobe64(metadata_stream_id
);
884 ret
= send_command(rsock
, RELAYD_QUIESCENT_CONTROL
, &msg
, sizeof(msg
), 0);
889 /* Receive response */
890 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
895 reply
.ret_code
= be32toh(reply
.ret_code
);
897 /* Return session id or negative ret code. */
898 if (reply
.ret_code
!= LTTNG_OK
) {
900 ERR("Relayd quiescent control replied error %d", reply
.ret_code
);
904 /* Control socket is quiescent */
912 * Begin a data pending command for a specific session id.
914 int relayd_begin_data_pending(struct lttcomm_relayd_sock
*rsock
, uint64_t id
)
917 struct lttcomm_relayd_begin_data_pending msg
;
918 struct lttcomm_relayd_generic_reply reply
;
920 /* Code flow error. Safety net. */
923 DBG("Relayd begin data pending");
925 memset(&msg
, 0, sizeof(msg
));
926 msg
.session_id
= htobe64(id
);
929 ret
= send_command(rsock
, RELAYD_BEGIN_DATA_PENDING
, &msg
, sizeof(msg
), 0);
934 /* Receive response */
935 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
940 reply
.ret_code
= be32toh(reply
.ret_code
);
942 /* Return session id or negative ret code. */
943 if (reply
.ret_code
!= LTTNG_OK
) {
945 ERR("Relayd begin data pending replied error %d", reply
.ret_code
);
956 * End a data pending command for a specific session id.
958 * Return 0 on success and set is_data_inflight to 0 if no data is being
959 * streamed or 1 if it is the case.
961 int relayd_end_data_pending(struct lttcomm_relayd_sock
*rsock
, uint64_t id
,
962 unsigned int *is_data_inflight
)
965 struct lttcomm_relayd_end_data_pending msg
;
966 struct lttcomm_relayd_generic_reply reply
;
968 /* Code flow error. Safety net. */
971 DBG("Relayd end data pending");
973 memset(&msg
, 0, sizeof(msg
));
974 msg
.session_id
= htobe64(id
);
977 ret
= send_command(rsock
, RELAYD_END_DATA_PENDING
, &msg
, sizeof(msg
), 0);
982 /* Receive response */
983 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
988 recv_ret
= be32toh(reply
.ret_code
);
994 *is_data_inflight
= recv_ret
;
996 DBG("Relayd end data pending is data inflight: %d", recv_ret
);
1005 * Send index to the relayd.
1007 int relayd_send_index(struct lttcomm_relayd_sock
*rsock
,
1008 struct ctf_packet_index
*index
, uint64_t relay_stream_id
,
1009 uint64_t net_seq_num
)
1012 struct lttcomm_relayd_index msg
;
1013 struct lttcomm_relayd_generic_reply reply
;
1015 /* Code flow error. Safety net. */
1018 if (rsock
->minor
< 4) {
1019 DBG("Not sending indexes before protocol 2.4");
1024 DBG("Relayd sending index for stream ID %" PRIu64
, relay_stream_id
);
1026 memset(&msg
, 0, sizeof(msg
));
1027 msg
.relay_stream_id
= htobe64(relay_stream_id
);
1028 msg
.net_seq_num
= htobe64(net_seq_num
);
1030 /* The index is already in big endian. */
1031 msg
.packet_size
= index
->packet_size
;
1032 msg
.content_size
= index
->content_size
;
1033 msg
.timestamp_begin
= index
->timestamp_begin
;
1034 msg
.timestamp_end
= index
->timestamp_end
;
1035 msg
.events_discarded
= index
->events_discarded
;
1036 msg
.stream_id
= index
->stream_id
;
1038 if (rsock
->minor
>= 8) {
1039 msg
.stream_instance_id
= index
->stream_instance_id
;
1040 msg
.packet_seq_num
= index
->packet_seq_num
;
1044 ret
= send_command(rsock
, RELAYD_SEND_INDEX
, &msg
,
1045 lttcomm_relayd_index_len(lttng_to_index_major(rsock
->major
,
1047 lttng_to_index_minor(rsock
->major
, rsock
->minor
)),
1054 * Ignore the response. TCP guarantee in-order arrival and the overall
1055 * protocol do not rely on hard ordering between the control and data
1057 * Indexes are sent either at the end of the buffer consumption or
1058 * during the live timer.
1060 ret
= recv_reply_ignore(rsock
, sizeof(reply
));
1070 * Ask the relay to reset the metadata trace file (regeneration).
1072 int relayd_reset_metadata(struct lttcomm_relayd_sock
*rsock
,
1073 uint64_t stream_id
, uint64_t version
)
1076 struct lttcomm_relayd_reset_metadata msg
;
1077 struct lttcomm_relayd_generic_reply reply
;
1079 /* Code flow error. Safety net. */
1082 /* Should have been prevented by the sessiond. */
1083 if (rsock
->minor
< 8) {
1084 ERR("Metadata regeneration unsupported before 2.8");
1089 DBG("Relayd reset metadata stream id %" PRIu64
, stream_id
);
1091 memset(&msg
, 0, sizeof(msg
));
1092 msg
.stream_id
= htobe64(stream_id
);
1093 msg
.version
= htobe64(version
);
1096 ret
= send_command(rsock
, RELAYD_RESET_METADATA
, (void *) &msg
, sizeof(msg
), 0);
1101 /* Receive response */
1102 ret
= recv_reply(rsock
, (void *) &reply
, sizeof(reply
));
1107 reply
.ret_code
= be32toh(reply
.ret_code
);
1109 /* Return session id or negative ret code. */
1110 if (reply
.ret_code
!= LTTNG_OK
) {
1112 ERR("Relayd reset metadata replied error %d", reply
.ret_code
);
1118 DBG("Relayd reset metadata stream id %" PRIu64
" successfully", stream_id
);