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