8f4f07a2088f75fbe0774bb240eb1d887806d958
[lttng-tools.git] / src / common / relayd / relayd.c
1 /*
2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 *
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.
7 *
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
11 * more details.
12 *
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.
16 */
17
18 #define _GNU_SOURCE
19 #define _LGPL_SOURCE
20 #include <assert.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/stat.h>
25 #include <inttypes.h>
26
27 #include <common/common.h>
28 #include <common/defaults.h>
29 #include <common/compat/endian.h>
30 #include <common/sessiond-comm/relayd.h>
31 #include <common/index/ctf-index.h>
32
33 #include "relayd.h"
34
35 /*
36 * Send command. Fill up the header and append the data.
37 */
38 static int send_command(struct lttcomm_relayd_sock *rsock,
39 enum lttcomm_relayd_command cmd, void *data, size_t size,
40 int flags)
41 {
42 int ret;
43 struct lttcomm_relayd_hdr header;
44 char *buf;
45 uint64_t buf_size = sizeof(header);
46
47 if (rsock->sock.fd < 0) {
48 return -ECONNRESET;
49 }
50
51 if (data) {
52 buf_size += size;
53 }
54
55 buf = zmalloc(buf_size);
56 if (buf == NULL) {
57 PERROR("zmalloc relayd send command buf");
58 ret = -1;
59 goto alloc_error;
60 }
61
62 memset(&header, 0, sizeof(header));
63 header.cmd = htobe32(cmd);
64 header.data_size = htobe64(size);
65
66 /* Zeroed for now since not used. */
67 header.cmd_version = 0;
68 header.circuit_id = 0;
69
70 /* Prepare buffer to send. */
71 memcpy(buf, &header, sizeof(header));
72 if (data) {
73 memcpy(buf + sizeof(header), data, size);
74 }
75
76 ret = rsock->sock.ops->sendmsg(&rsock->sock, buf, buf_size, flags);
77 if (ret < 0) {
78 ret = -errno;
79 goto error;
80 }
81
82 DBG3("Relayd sending command %d of size %" PRIu64, cmd, buf_size);
83
84 error:
85 free(buf);
86 alloc_error:
87 return ret;
88 }
89
90 /*
91 * Receive reply data on socket. This MUST be call after send_command or else
92 * could result in unexpected behavior(s).
93 */
94 static int recv_reply(struct lttcomm_relayd_sock *rsock, void *data, size_t size)
95 {
96 int ret;
97
98 if (rsock->sock.fd < 0) {
99 return -ECONNRESET;
100 }
101
102 DBG3("Relayd waiting for reply of size %zu", size);
103
104 ret = rsock->sock.ops->recvmsg(&rsock->sock, data, size, 0);
105 if (ret <= 0 || ret != size) {
106 if (ret == 0) {
107 /* Orderly shutdown. */
108 DBG("Socket %d has performed an orderly shutdown", rsock->sock.fd);
109 } else {
110 DBG("Receiving reply failed on sock %d for size %zu with ret %d",
111 rsock->sock.fd, size, ret);
112 }
113 /* Always return -1 here and the caller can use errno. */
114 ret = -1;
115 goto error;
116 }
117
118 error:
119 return ret;
120 }
121
122 /*
123 * Starting at 2.4, RELAYD_CREATE_SESSION takes additional parameters to
124 * support the live reading capability.
125 */
126 static int relayd_create_session_2_4(struct lttcomm_relayd_sock *rsock,
127 uint64_t *session_id, char *session_name, char *hostname,
128 int session_live_timer, unsigned int snapshot)
129 {
130 int ret;
131 struct lttcomm_relayd_create_session_2_4 msg;
132
133 if (lttng_strncpy(msg.session_name, session_name,
134 sizeof(msg.session_name))) {
135 ret = -1;
136 goto error;
137 }
138 if (lttng_strncpy(msg.hostname, hostname, sizeof(msg.hostname))) {
139 ret = -1;
140 goto error;
141 }
142 msg.live_timer = htobe32(session_live_timer);
143 msg.snapshot = htobe32(snapshot);
144
145 /* Send command */
146 ret = send_command(rsock, RELAYD_CREATE_SESSION, &msg, sizeof(msg), 0);
147 if (ret < 0) {
148 goto error;
149 }
150
151 error:
152 return ret;
153 }
154
155 /*
156 * RELAYD_CREATE_SESSION from 2.1 to 2.3.
157 */
158 static int relayd_create_session_2_1(struct lttcomm_relayd_sock *rsock,
159 uint64_t *session_id)
160 {
161 int ret;
162
163 /* Send command */
164 ret = send_command(rsock, RELAYD_CREATE_SESSION, NULL, 0, 0);
165 if (ret < 0) {
166 goto error;
167 }
168
169 error:
170 return ret;
171 }
172
173 /*
174 * Send a RELAYD_CREATE_SESSION command to the relayd with the given socket and
175 * set session_id of the relayd if we have a successful reply from the relayd.
176 *
177 * On success, return 0 else a negative value which is either an errno error or
178 * a lttng error code from the relayd.
179 */
180 int relayd_create_session(struct lttcomm_relayd_sock *rsock, uint64_t *session_id,
181 char *session_name, char *hostname, int session_live_timer,
182 unsigned int snapshot)
183 {
184 int ret;
185 struct lttcomm_relayd_status_session reply;
186
187 assert(rsock);
188 assert(session_id);
189
190 DBG("Relayd create session");
191
192 switch(rsock->minor) {
193 case 1:
194 case 2:
195 case 3:
196 ret = relayd_create_session_2_1(rsock, session_id);
197 break;
198 case 4:
199 default:
200 ret = relayd_create_session_2_4(rsock, session_id, session_name,
201 hostname, session_live_timer, snapshot);
202 break;
203 }
204
205 if (ret < 0) {
206 goto error;
207 }
208
209 /* Receive response */
210 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
211 if (ret < 0) {
212 goto error;
213 }
214
215 reply.session_id = be64toh(reply.session_id);
216 reply.ret_code = be32toh(reply.ret_code);
217
218 /* Return session id or negative ret code. */
219 if (reply.ret_code != LTTNG_OK) {
220 ret = -1;
221 ERR("Relayd create session replied error %d", reply.ret_code);
222 goto error;
223 } else {
224 ret = 0;
225 *session_id = reply.session_id;
226 }
227
228 DBG("Relayd session created with id %" PRIu64, reply.session_id);
229
230 error:
231 return ret;
232 }
233
234 /*
235 * Add stream on the relayd and assign stream handle to the stream_id argument.
236 *
237 * On success return 0 else return ret_code negative value.
238 */
239 int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_name,
240 const char *pathname, uint64_t *stream_id,
241 uint64_t tracefile_size, uint64_t tracefile_count)
242 {
243 int ret;
244 struct lttcomm_relayd_add_stream msg;
245 struct lttcomm_relayd_add_stream_2_2 msg_2_2;
246 struct lttcomm_relayd_status_stream reply;
247
248 /* Code flow error. Safety net. */
249 assert(rsock);
250 assert(channel_name);
251 assert(pathname);
252
253 DBG("Relayd adding stream for channel name %s", channel_name);
254
255 /* Compat with relayd 2.1 */
256 if (rsock->minor == 1) {
257 memset(&msg, 0, sizeof(msg));
258 strncpy(msg.channel_name, channel_name, sizeof(msg.channel_name));
259 strncpy(msg.pathname, pathname, sizeof(msg.pathname));
260
261 /* Send command */
262 ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg, sizeof(msg), 0);
263 if (ret < 0) {
264 goto error;
265 }
266 } else {
267 memset(&msg_2_2, 0, sizeof(msg_2_2));
268 /* Compat with relayd 2.2+ */
269 strncpy(msg_2_2.channel_name, channel_name, sizeof(msg_2_2.channel_name));
270 strncpy(msg_2_2.pathname, pathname, sizeof(msg_2_2.pathname));
271 msg_2_2.tracefile_size = htobe64(tracefile_size);
272 msg_2_2.tracefile_count = htobe64(tracefile_count);
273
274 /* Send command */
275 ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg_2_2, sizeof(msg_2_2), 0);
276 if (ret < 0) {
277 goto error;
278 }
279 }
280
281 /* Waiting for reply */
282 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
283 if (ret < 0) {
284 goto error;
285 }
286
287 /* Back to host bytes order. */
288 reply.handle = be64toh(reply.handle);
289 reply.ret_code = be32toh(reply.ret_code);
290
291 /* Return session id or negative ret code. */
292 if (reply.ret_code != LTTNG_OK) {
293 ret = -1;
294 ERR("Relayd add stream replied error %d", reply.ret_code);
295 } else {
296 /* Success */
297 ret = 0;
298 *stream_id = reply.handle;
299 }
300
301 DBG("Relayd stream added successfully with handle %" PRIu64,
302 reply.handle);
303
304 error:
305 return ret;
306 }
307
308 /*
309 * Inform the relay that all the streams for the current channel has been sent.
310 *
311 * On success return 0 else return ret_code negative value.
312 */
313 int relayd_streams_sent(struct lttcomm_relayd_sock *rsock)
314 {
315 int ret;
316 struct lttcomm_relayd_generic_reply reply;
317
318 /* Code flow error. Safety net. */
319 assert(rsock);
320
321 DBG("Relayd sending streams sent.");
322
323 /* This feature was introduced in 2.4, ignore it for earlier versions. */
324 if (rsock->minor < 4) {
325 ret = 0;
326 goto end;
327 }
328
329 /* Send command */
330 ret = send_command(rsock, RELAYD_STREAMS_SENT, NULL, 0, 0);
331 if (ret < 0) {
332 goto error;
333 }
334
335 /* Waiting for reply */
336 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
337 if (ret < 0) {
338 goto error;
339 }
340
341 /* Back to host bytes order. */
342 reply.ret_code = be32toh(reply.ret_code);
343
344 /* Return session id or negative ret code. */
345 if (reply.ret_code != LTTNG_OK) {
346 ret = -1;
347 ERR("Relayd streams sent replied error %d", reply.ret_code);
348 goto error;
349 } else {
350 /* Success */
351 ret = 0;
352 }
353
354 DBG("Relayd streams sent success");
355
356 error:
357 end:
358 return ret;
359 }
360
361 /*
362 * Check version numbers on the relayd.
363 * If major versions are compatible, we assign minor_to_use to the
364 * minor version of the procotol we are going to use for this session.
365 *
366 * Return 0 if compatible else negative value.
367 */
368 int relayd_version_check(struct lttcomm_relayd_sock *rsock)
369 {
370 int ret;
371 struct lttcomm_relayd_version msg;
372
373 /* Code flow error. Safety net. */
374 assert(rsock);
375
376 DBG("Relayd version check for major.minor %u.%u", rsock->major,
377 rsock->minor);
378
379 memset(&msg, 0, sizeof(msg));
380 /* Prepare network byte order before transmission. */
381 msg.major = htobe32(rsock->major);
382 msg.minor = htobe32(rsock->minor);
383
384 /* Send command */
385 ret = send_command(rsock, RELAYD_VERSION, (void *) &msg, sizeof(msg), 0);
386 if (ret < 0) {
387 goto error;
388 }
389
390 /* Receive response */
391 ret = recv_reply(rsock, (void *) &msg, sizeof(msg));
392 if (ret < 0) {
393 goto error;
394 }
395
396 /* Set back to host bytes order */
397 msg.major = be32toh(msg.major);
398 msg.minor = be32toh(msg.minor);
399
400 /*
401 * Only validate the major version. If the other side is higher,
402 * communication is not possible. Only major version equal can talk to each
403 * other. If the minor version differs, the lowest version is used by both
404 * sides.
405 */
406 if (msg.major != rsock->major) {
407 /* Not compatible */
408 ret = -1;
409 DBG2("Relayd version is NOT compatible. Relayd version %u != %u (us)",
410 msg.major, rsock->major);
411 goto error;
412 }
413
414 /*
415 * If the relayd's minor version is higher, it will adapt to our version so
416 * we can continue to use the latest relayd communication data structure.
417 * If the received minor version is higher, the relayd should adapt to us.
418 */
419 if (rsock->minor > msg.minor) {
420 rsock->minor = msg.minor;
421 }
422
423 /* Version number compatible */
424 DBG2("Relayd version is compatible, using protocol version %u.%u",
425 rsock->major, rsock->minor);
426 ret = 0;
427
428 error:
429 return ret;
430 }
431
432 /*
433 * Add stream on the relayd and assign stream handle to the stream_id argument.
434 *
435 * On success return 0 else return ret_code negative value.
436 */
437 int relayd_send_metadata(struct lttcomm_relayd_sock *rsock, size_t len)
438 {
439 int ret;
440
441 /* Code flow error. Safety net. */
442 assert(rsock);
443
444 DBG("Relayd sending metadata of size %zu", len);
445
446 /* Send command */
447 ret = send_command(rsock, RELAYD_SEND_METADATA, NULL, len, 0);
448 if (ret < 0) {
449 goto error;
450 }
451
452 DBG2("Relayd metadata added successfully");
453
454 /*
455 * After that call, the metadata data MUST be sent to the relayd so the
456 * receive size on the other end matches the len of the metadata packet
457 * header. This is why we don't wait for a reply here.
458 */
459
460 error:
461 return ret;
462 }
463
464 /*
465 * Connect to relay daemon with an allocated lttcomm_relayd_sock.
466 */
467 int relayd_connect(struct lttcomm_relayd_sock *rsock)
468 {
469 /* Code flow error. Safety net. */
470 assert(rsock);
471
472 if (!rsock->sock.ops) {
473 /*
474 * Attempting a connect on a non-initialized socket.
475 */
476 return -ECONNRESET;
477 }
478
479 DBG3("Relayd connect ...");
480
481 return rsock->sock.ops->connect(&rsock->sock);
482 }
483
484 /*
485 * Close relayd socket with an allocated lttcomm_relayd_sock.
486 *
487 * If no socket operations are found, simply return 0 meaning that everything
488 * is fine. Without operations, the socket can not possibly be opened or used.
489 * This is possible if the socket was allocated but not created. However, the
490 * caller could simply use it to store a valid file descriptor for instance
491 * passed over a Unix socket and call this to cleanup but still without a valid
492 * ops pointer.
493 *
494 * Return the close returned value. On error, a negative value is usually
495 * returned back from close(2).
496 */
497 int relayd_close(struct lttcomm_relayd_sock *rsock)
498 {
499 int ret;
500
501 /* Code flow error. Safety net. */
502 assert(rsock);
503
504 /* An invalid fd is fine, return success. */
505 if (rsock->sock.fd < 0) {
506 ret = 0;
507 goto end;
508 }
509
510 DBG3("Relayd closing socket %d", rsock->sock.fd);
511
512 if (rsock->sock.ops) {
513 ret = rsock->sock.ops->close(&rsock->sock);
514 } else {
515 /* Default call if no specific ops found. */
516 ret = close(rsock->sock.fd);
517 if (ret < 0) {
518 PERROR("relayd_close default close");
519 }
520 }
521 rsock->sock.fd = -1;
522
523 end:
524 return ret;
525 }
526
527 /*
528 * Send data header structure to the relayd.
529 */
530 int relayd_send_data_hdr(struct lttcomm_relayd_sock *rsock,
531 struct lttcomm_relayd_data_hdr *hdr, size_t size)
532 {
533 int ret;
534
535 /* Code flow error. Safety net. */
536 assert(rsock);
537 assert(hdr);
538
539 if (rsock->sock.fd < 0) {
540 return -ECONNRESET;
541 }
542
543 DBG3("Relayd sending data header of size %zu", size);
544
545 /* Again, safety net */
546 if (size == 0) {
547 size = sizeof(struct lttcomm_relayd_data_hdr);
548 }
549
550 /* Only send data header. */
551 ret = rsock->sock.ops->sendmsg(&rsock->sock, hdr, size, 0);
552 if (ret < 0) {
553 ret = -errno;
554 goto error;
555 }
556
557 /*
558 * The data MUST be sent right after that command for the receive on the
559 * other end to match the size in the header.
560 */
561
562 error:
563 return ret;
564 }
565
566 /*
567 * Send close stream command to the relayd.
568 */
569 int relayd_send_close_stream(struct lttcomm_relayd_sock *rsock, uint64_t stream_id,
570 uint64_t last_net_seq_num)
571 {
572 int ret;
573 struct lttcomm_relayd_close_stream msg;
574 struct lttcomm_relayd_generic_reply reply;
575
576 /* Code flow error. Safety net. */
577 assert(rsock);
578
579 DBG("Relayd closing stream id %" PRIu64, stream_id);
580
581 memset(&msg, 0, sizeof(msg));
582 msg.stream_id = htobe64(stream_id);
583 msg.last_net_seq_num = htobe64(last_net_seq_num);
584
585 /* Send command */
586 ret = send_command(rsock, RELAYD_CLOSE_STREAM, (void *) &msg, sizeof(msg), 0);
587 if (ret < 0) {
588 goto error;
589 }
590
591 /* Receive response */
592 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
593 if (ret < 0) {
594 goto error;
595 }
596
597 reply.ret_code = be32toh(reply.ret_code);
598
599 /* Return session id or negative ret code. */
600 if (reply.ret_code != LTTNG_OK) {
601 ret = -1;
602 ERR("Relayd close stream replied error %d", reply.ret_code);
603 } else {
604 /* Success */
605 ret = 0;
606 }
607
608 DBG("Relayd close stream id %" PRIu64 " successfully", stream_id);
609
610 error:
611 return ret;
612 }
613
614 /*
615 * Check for data availability for a given stream id.
616 *
617 * Return 0 if NOT pending, 1 if so and a negative value on error.
618 */
619 int relayd_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t stream_id,
620 uint64_t last_net_seq_num)
621 {
622 int ret;
623 struct lttcomm_relayd_data_pending msg;
624 struct lttcomm_relayd_generic_reply reply;
625
626 /* Code flow error. Safety net. */
627 assert(rsock);
628
629 DBG("Relayd data pending for stream id %" PRIu64, stream_id);
630
631 memset(&msg, 0, sizeof(msg));
632 msg.stream_id = htobe64(stream_id);
633 msg.last_net_seq_num = htobe64(last_net_seq_num);
634
635 /* Send command */
636 ret = send_command(rsock, RELAYD_DATA_PENDING, (void *) &msg,
637 sizeof(msg), 0);
638 if (ret < 0) {
639 goto error;
640 }
641
642 /* Receive response */
643 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
644 if (ret < 0) {
645 goto error;
646 }
647
648 reply.ret_code = be32toh(reply.ret_code);
649
650 /* Return session id or negative ret code. */
651 if (reply.ret_code >= LTTNG_OK) {
652 ERR("Relayd data pending replied error %d", reply.ret_code);
653 }
654
655 /* At this point, the ret code is either 1 or 0 */
656 ret = reply.ret_code;
657
658 DBG("Relayd data is %s pending for stream id %" PRIu64,
659 ret == 1 ? "" : "NOT", stream_id);
660
661 error:
662 return ret;
663 }
664
665 /*
666 * Check on the relayd side for a quiescent state on the control socket.
667 */
668 int relayd_quiescent_control(struct lttcomm_relayd_sock *rsock,
669 uint64_t metadata_stream_id)
670 {
671 int ret;
672 struct lttcomm_relayd_quiescent_control msg;
673 struct lttcomm_relayd_generic_reply reply;
674
675 /* Code flow error. Safety net. */
676 assert(rsock);
677
678 DBG("Relayd checking quiescent control state");
679
680 memset(&msg, 0, sizeof(msg));
681 msg.stream_id = htobe64(metadata_stream_id);
682
683 /* Send command */
684 ret = send_command(rsock, RELAYD_QUIESCENT_CONTROL, &msg, sizeof(msg), 0);
685 if (ret < 0) {
686 goto error;
687 }
688
689 /* Receive response */
690 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
691 if (ret < 0) {
692 goto error;
693 }
694
695 reply.ret_code = be32toh(reply.ret_code);
696
697 /* Return session id or negative ret code. */
698 if (reply.ret_code != LTTNG_OK) {
699 ret = -1;
700 ERR("Relayd quiescent control replied error %d", reply.ret_code);
701 goto error;
702 }
703
704 /* Control socket is quiescent */
705 return 0;
706
707 error:
708 return ret;
709 }
710
711 /*
712 * Begin a data pending command for a specific session id.
713 */
714 int relayd_begin_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t id)
715 {
716 int ret;
717 struct lttcomm_relayd_begin_data_pending msg;
718 struct lttcomm_relayd_generic_reply reply;
719
720 /* Code flow error. Safety net. */
721 assert(rsock);
722
723 DBG("Relayd begin data pending");
724
725 memset(&msg, 0, sizeof(msg));
726 msg.session_id = htobe64(id);
727
728 /* Send command */
729 ret = send_command(rsock, RELAYD_BEGIN_DATA_PENDING, &msg, sizeof(msg), 0);
730 if (ret < 0) {
731 goto error;
732 }
733
734 /* Receive response */
735 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
736 if (ret < 0) {
737 goto error;
738 }
739
740 reply.ret_code = be32toh(reply.ret_code);
741
742 /* Return session id or negative ret code. */
743 if (reply.ret_code != LTTNG_OK) {
744 ret = -1;
745 ERR("Relayd begin data pending replied error %d", reply.ret_code);
746 goto error;
747 }
748
749 return 0;
750
751 error:
752 return ret;
753 }
754
755 /*
756 * End a data pending command for a specific session id.
757 *
758 * Return 0 on success and set is_data_inflight to 0 if no data is being
759 * streamed or 1 if it is the case.
760 */
761 int relayd_end_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t id,
762 unsigned int *is_data_inflight)
763 {
764 int ret, recv_ret;
765 struct lttcomm_relayd_end_data_pending msg;
766 struct lttcomm_relayd_generic_reply reply;
767
768 /* Code flow error. Safety net. */
769 assert(rsock);
770
771 DBG("Relayd end data pending");
772
773 memset(&msg, 0, sizeof(msg));
774 msg.session_id = htobe64(id);
775
776 /* Send command */
777 ret = send_command(rsock, RELAYD_END_DATA_PENDING, &msg, sizeof(msg), 0);
778 if (ret < 0) {
779 goto error;
780 }
781
782 /* Receive response */
783 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
784 if (ret < 0) {
785 goto error;
786 }
787
788 recv_ret = be32toh(reply.ret_code);
789 if (recv_ret < 0) {
790 ret = recv_ret;
791 goto error;
792 }
793
794 *is_data_inflight = recv_ret;
795
796 DBG("Relayd end data pending is data inflight: %d", recv_ret);
797
798 return 0;
799
800 error:
801 return ret;
802 }
803
804 /*
805 * Send index to the relayd.
806 */
807 int relayd_send_index(struct lttcomm_relayd_sock *rsock,
808 struct ctf_packet_index *index, uint64_t relay_stream_id,
809 uint64_t net_seq_num)
810 {
811 int ret;
812 struct lttcomm_relayd_index msg;
813 struct lttcomm_relayd_generic_reply reply;
814
815 /* Code flow error. Safety net. */
816 assert(rsock);
817
818 if (rsock->minor < 4) {
819 DBG("Not sending indexes before protocol 2.4");
820 ret = 0;
821 goto error;
822 }
823
824 DBG("Relayd sending index for stream ID %" PRIu64, relay_stream_id);
825
826 memset(&msg, 0, sizeof(msg));
827 msg.relay_stream_id = htobe64(relay_stream_id);
828 msg.net_seq_num = htobe64(net_seq_num);
829
830 /* The index is already in big endian. */
831 msg.packet_size = index->packet_size;
832 msg.content_size = index->content_size;
833 msg.timestamp_begin = index->timestamp_begin;
834 msg.timestamp_end = index->timestamp_end;
835 msg.events_discarded = index->events_discarded;
836 msg.stream_id = index->stream_id;
837
838 /* Send command */
839 ret = send_command(rsock, RELAYD_SEND_INDEX, &msg, sizeof(msg), 0);
840 if (ret < 0) {
841 goto error;
842 }
843
844 /* Receive response */
845 ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
846 if (ret < 0) {
847 goto error;
848 }
849
850 reply.ret_code = be32toh(reply.ret_code);
851
852 /* Return session id or negative ret code. */
853 if (reply.ret_code != LTTNG_OK) {
854 ret = -1;
855 ERR("Relayd send index replied error %d", reply.ret_code);
856 } else {
857 /* Success */
858 ret = 0;
859 }
860
861 error:
862 return ret;
863 }
This page took 0.04426 seconds and 3 git commands to generate.