Commit | Line | Data |
---|---|---|
00e2e675 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
00e2e675 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
00e2e675 | 5 | * |
00e2e675 DG |
6 | */ |
7 | ||
6c1c0768 | 8 | #define _LGPL_SOURCE |
00e2e675 DG |
9 | #include <stdio.h> |
10 | #include <stdlib.h> | |
11 | #include <string.h> | |
12 | #include <sys/stat.h> | |
77c7c900 | 13 | #include <inttypes.h> |
00e2e675 DG |
14 | |
15 | #include <common/common.h> | |
16 | #include <common/defaults.h> | |
f263b7fd | 17 | #include <common/compat/endian.h> |
27283937 | 18 | #include <common/compat/string.h> |
00e2e675 | 19 | #include <common/sessiond-comm/relayd.h> |
50adc264 | 20 | #include <common/index/ctf-index.h> |
d2956687 | 21 | #include <common/trace-chunk.h> |
c35f9726 | 22 | #include <common/string-utils/format.h> |
00e2e675 DG |
23 | |
24 | #include "relayd.h" | |
25 | ||
070b6a86 MD |
26 | static |
27 | bool relayd_supports_chunks(const struct lttcomm_relayd_sock *sock) | |
28 | { | |
29 | if (sock->major > 2) { | |
30 | return true; | |
31 | } else if (sock->major == 2 && sock->minor >= 11) { | |
32 | return true; | |
33 | } | |
34 | return false; | |
35 | } | |
36 | ||
8614e600 MD |
37 | static |
38 | bool relayd_supports_get_configuration(const struct lttcomm_relayd_sock *sock) | |
39 | { | |
40 | if (sock->major > 2) { | |
41 | return true; | |
42 | } else if (sock->major == 2 && sock->minor >= 12) { | |
43 | return true; | |
44 | } | |
45 | return false; | |
46 | } | |
47 | ||
00e2e675 DG |
48 | /* |
49 | * Send command. Fill up the header and append the data. | |
50 | */ | |
6151a90f | 51 | static int send_command(struct lttcomm_relayd_sock *rsock, |
76b9afaa | 52 | enum lttcomm_relayd_command cmd, const void *data, size_t size, |
00e2e675 DG |
53 | int flags) |
54 | { | |
55 | int ret; | |
56 | struct lttcomm_relayd_hdr header; | |
57 | char *buf; | |
58 | uint64_t buf_size = sizeof(header); | |
59 | ||
f96e4545 MD |
60 | if (rsock->sock.fd < 0) { |
61 | return -ECONNRESET; | |
62 | } | |
63 | ||
00e2e675 DG |
64 | if (data) { |
65 | buf_size += size; | |
66 | } | |
67 | ||
55caead7 | 68 | buf = (char *) zmalloc(buf_size); |
00e2e675 DG |
69 | if (buf == NULL) { |
70 | PERROR("zmalloc relayd send command buf"); | |
71 | ret = -1; | |
72 | goto alloc_error; | |
73 | } | |
74 | ||
53efb85a | 75 | memset(&header, 0, sizeof(header)); |
00e2e675 DG |
76 | header.cmd = htobe32(cmd); |
77 | header.data_size = htobe64(size); | |
78 | ||
79 | /* Zeroed for now since not used. */ | |
80 | header.cmd_version = 0; | |
81 | header.circuit_id = 0; | |
82 | ||
83 | /* Prepare buffer to send. */ | |
84 | memcpy(buf, &header, sizeof(header)); | |
85 | if (data) { | |
86 | memcpy(buf + sizeof(header), data, size); | |
87 | } | |
88 | ||
00e71031 FD |
89 | DBG3("Relayd sending command %s of size %" PRIu64, |
90 | lttcomm_relayd_command_str(cmd), buf_size); | |
6151a90f | 91 | ret = rsock->sock.ops->sendmsg(&rsock->sock, buf, buf_size, flags); |
00e2e675 | 92 | if (ret < 0) { |
00e71031 FD |
93 | PERROR("Failed to send command %s of size %" PRIu64, |
94 | lttcomm_relayd_command_str(cmd), buf_size); | |
95 | ret = rsock->sock.ops->sendmsg(&rsock->sock, buf, buf_size, flags); | |
8994307f | 96 | ret = -errno; |
00e2e675 DG |
97 | goto error; |
98 | } | |
00e2e675 DG |
99 | error: |
100 | free(buf); | |
101 | alloc_error: | |
102 | return ret; | |
103 | } | |
104 | ||
105 | /* | |
106 | * Receive reply data on socket. This MUST be call after send_command or else | |
107 | * could result in unexpected behavior(s). | |
108 | */ | |
6151a90f | 109 | static int recv_reply(struct lttcomm_relayd_sock *rsock, void *data, size_t size) |
00e2e675 DG |
110 | { |
111 | int ret; | |
112 | ||
f96e4545 MD |
113 | if (rsock->sock.fd < 0) { |
114 | return -ECONNRESET; | |
115 | } | |
116 | ||
8fd623e0 | 117 | DBG3("Relayd waiting for reply of size %zu", size); |
00e2e675 | 118 | |
6151a90f | 119 | ret = rsock->sock.ops->recvmsg(&rsock->sock, data, size, 0); |
20275fe8 DG |
120 | if (ret <= 0 || ret != size) { |
121 | if (ret == 0) { | |
122 | /* Orderly shutdown. */ | |
6151a90f | 123 | DBG("Socket %d has performed an orderly shutdown", rsock->sock.fd); |
20275fe8 | 124 | } else { |
8fd623e0 | 125 | DBG("Receiving reply failed on sock %d for size %zu with ret %d", |
6151a90f | 126 | rsock->sock.fd, size, ret); |
20275fe8 DG |
127 | } |
128 | /* Always return -1 here and the caller can use errno. */ | |
129 | ret = -1; | |
00e2e675 DG |
130 | goto error; |
131 | } | |
132 | ||
133 | error: | |
134 | return ret; | |
135 | } | |
136 | ||
d3e2ba59 | 137 | /* |
6fa5fe7c MD |
138 | * Starting from 2.11, RELAYD_CREATE_SESSION payload (session_name, |
139 | * hostname, and base_path) have no length restriction on the sender side. | |
f86f6389 JR |
140 | * Length for both payloads is stored in the msg struct. A new dynamic size |
141 | * payload size is introduced. | |
142 | */ | |
143 | static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock, | |
fb9a95c4 | 144 | const char *session_name, const char *hostname, |
6fa5fe7c MD |
145 | const char *base_path, int session_live_timer, |
146 | unsigned int snapshot, uint64_t sessiond_session_id, | |
147 | const lttng_uuid sessiond_uuid, const uint64_t *current_chunk_id, | |
ecd1a12f MD |
148 | time_t creation_time, bool session_name_contains_creation_time, |
149 | struct lttcomm_relayd_create_session_reply_2_11 *reply, | |
150 | char *output_path) | |
f86f6389 JR |
151 | { |
152 | int ret; | |
153 | struct lttcomm_relayd_create_session_2_11 *msg = NULL; | |
154 | size_t session_name_len; | |
155 | size_t hostname_len; | |
6fa5fe7c | 156 | size_t base_path_len; |
f86f6389 | 157 | size_t msg_length; |
6fa5fe7c | 158 | char *dst; |
f86f6389 | 159 | |
46ef2188 MD |
160 | if (!base_path) { |
161 | base_path = ""; | |
162 | } | |
163 | /* The three names are sent with a '\0' delimiter between them. */ | |
f86f6389 JR |
164 | session_name_len = strlen(session_name) + 1; |
165 | hostname_len = strlen(hostname) + 1; | |
17e736a5 | 166 | base_path_len = strlen(base_path) + 1; |
f86f6389 | 167 | |
6fa5fe7c | 168 | msg_length = sizeof(*msg) + session_name_len + hostname_len + base_path_len; |
55caead7 | 169 | msg = (lttcomm_relayd_create_session_2_11 *) zmalloc(msg_length); |
f86f6389 JR |
170 | if (!msg) { |
171 | PERROR("zmalloc create_session_2_11 command message"); | |
172 | ret = -1; | |
173 | goto error; | |
174 | } | |
175 | ||
a0377dfe | 176 | LTTNG_ASSERT(session_name_len <= UINT32_MAX); |
f86f6389 JR |
177 | msg->session_name_len = htobe32(session_name_len); |
178 | ||
a0377dfe | 179 | LTTNG_ASSERT(hostname_len <= UINT32_MAX); |
f86f6389 JR |
180 | msg->hostname_len = htobe32(hostname_len); |
181 | ||
a0377dfe | 182 | LTTNG_ASSERT(base_path_len <= UINT32_MAX); |
6fa5fe7c MD |
183 | msg->base_path_len = htobe32(base_path_len); |
184 | ||
185 | dst = msg->names; | |
186 | if (lttng_strncpy(dst, session_name, session_name_len)) { | |
187 | ret = -1; | |
188 | goto error; | |
189 | } | |
190 | dst += session_name_len; | |
191 | if (lttng_strncpy(dst, hostname, hostname_len)) { | |
f86f6389 JR |
192 | ret = -1; |
193 | goto error; | |
194 | } | |
6fa5fe7c | 195 | dst += hostname_len; |
36f9f13b | 196 | if (lttng_strncpy(dst, base_path, base_path_len)) { |
f86f6389 JR |
197 | ret = -1; |
198 | goto error; | |
199 | } | |
200 | ||
201 | msg->live_timer = htobe32(session_live_timer); | |
202 | msg->snapshot = !!snapshot; | |
203 | ||
658f12fa JG |
204 | lttng_uuid_copy(msg->sessiond_uuid, sessiond_uuid); |
205 | msg->session_id = htobe64(sessiond_session_id); | |
46ef2188 | 206 | msg->session_name_contains_creation_time = session_name_contains_creation_time; |
f39bd140 JG |
207 | if (current_chunk_id) { |
208 | LTTNG_OPTIONAL_SET(&msg->current_chunk_id, | |
209 | htobe64(*current_chunk_id)); | |
210 | } | |
211 | ||
db1da059 JG |
212 | msg->creation_time = htobe64((uint64_t) creation_time); |
213 | ||
f86f6389 JR |
214 | /* Send command */ |
215 | ret = send_command(rsock, RELAYD_CREATE_SESSION, msg, msg_length, 0); | |
216 | if (ret < 0) { | |
217 | goto error; | |
218 | } | |
ecd1a12f MD |
219 | /* Receive response */ |
220 | ret = recv_reply(rsock, reply, sizeof(*reply)); | |
221 | if (ret < 0) { | |
222 | goto error; | |
223 | } | |
224 | reply->generic.session_id = be64toh(reply->generic.session_id); | |
225 | reply->generic.ret_code = be32toh(reply->generic.ret_code); | |
226 | reply->output_path_length = be32toh(reply->output_path_length); | |
227 | if (reply->output_path_length >= LTTNG_PATH_MAX) { | |
228 | ERR("Invalid session output path length in reply (%" PRIu32 " bytes) exceeds maximal allowed length (%d bytes)", | |
229 | reply->output_path_length, LTTNG_PATH_MAX); | |
230 | ret = -1; | |
231 | goto error; | |
232 | } | |
233 | ret = recv_reply(rsock, output_path, reply->output_path_length); | |
234 | if (ret < 0) { | |
235 | goto error; | |
236 | } | |
f86f6389 JR |
237 | error: |
238 | free(msg); | |
239 | return ret; | |
240 | } | |
241 | /* | |
242 | * From 2.4 to 2.10, RELAYD_CREATE_SESSION takes additional parameters to | |
d3e2ba59 JD |
243 | * support the live reading capability. |
244 | */ | |
245 | static int relayd_create_session_2_4(struct lttcomm_relayd_sock *rsock, | |
fb9a95c4 | 246 | const char *session_name, const char *hostname, |
ecd1a12f MD |
247 | int session_live_timer, unsigned int snapshot, |
248 | struct lttcomm_relayd_status_session *reply) | |
d3e2ba59 JD |
249 | { |
250 | int ret; | |
251 | struct lttcomm_relayd_create_session_2_4 msg; | |
252 | ||
3a13ffd5 MD |
253 | if (lttng_strncpy(msg.session_name, session_name, |
254 | sizeof(msg.session_name))) { | |
246777db MD |
255 | ret = -1; |
256 | goto error; | |
257 | } | |
3a13ffd5 | 258 | if (lttng_strncpy(msg.hostname, hostname, sizeof(msg.hostname))) { |
246777db MD |
259 | ret = -1; |
260 | goto error; | |
261 | } | |
d3e2ba59 | 262 | msg.live_timer = htobe32(session_live_timer); |
7d2f7452 | 263 | msg.snapshot = htobe32(snapshot); |
d3e2ba59 JD |
264 | |
265 | /* Send command */ | |
266 | ret = send_command(rsock, RELAYD_CREATE_SESSION, &msg, sizeof(msg), 0); | |
267 | if (ret < 0) { | |
268 | goto error; | |
269 | } | |
270 | ||
ecd1a12f MD |
271 | /* Receive response */ |
272 | ret = recv_reply(rsock, reply, sizeof(*reply)); | |
273 | if (ret < 0) { | |
274 | goto error; | |
275 | } | |
276 | reply->session_id = be64toh(reply->session_id); | |
277 | reply->ret_code = be32toh(reply->ret_code); | |
d3e2ba59 JD |
278 | error: |
279 | return ret; | |
280 | } | |
281 | ||
282 | /* | |
283 | * RELAYD_CREATE_SESSION from 2.1 to 2.3. | |
284 | */ | |
ecd1a12f MD |
285 | static int relayd_create_session_2_1(struct lttcomm_relayd_sock *rsock, |
286 | struct lttcomm_relayd_status_session *reply) | |
d3e2ba59 JD |
287 | { |
288 | int ret; | |
289 | ||
290 | /* Send command */ | |
291 | ret = send_command(rsock, RELAYD_CREATE_SESSION, NULL, 0, 0); | |
292 | if (ret < 0) { | |
293 | goto error; | |
294 | } | |
295 | ||
ecd1a12f MD |
296 | /* Receive response */ |
297 | ret = recv_reply(rsock, reply, sizeof(*reply)); | |
298 | if (ret < 0) { | |
299 | goto error; | |
300 | } | |
301 | reply->session_id = be64toh(reply->session_id); | |
302 | reply->ret_code = be32toh(reply->ret_code); | |
d3e2ba59 JD |
303 | error: |
304 | return ret; | |
305 | } | |
306 | ||
c5b6f4f0 DG |
307 | /* |
308 | * Send a RELAYD_CREATE_SESSION command to the relayd with the given socket and | |
309 | * set session_id of the relayd if we have a successful reply from the relayd. | |
310 | * | |
20275fe8 DG |
311 | * On success, return 0 else a negative value which is either an errno error or |
312 | * a lttng error code from the relayd. | |
c5b6f4f0 | 313 | */ |
fb9a95c4 JG |
314 | int relayd_create_session(struct lttcomm_relayd_sock *rsock, |
315 | uint64_t *relayd_session_id, | |
316 | const char *session_name, const char *hostname, | |
6fa5fe7c | 317 | const char *base_path, int session_live_timer, |
658f12fa | 318 | unsigned int snapshot, uint64_t sessiond_session_id, |
f39bd140 | 319 | const lttng_uuid sessiond_uuid, |
db1da059 | 320 | const uint64_t *current_chunk_id, |
ecd1a12f MD |
321 | time_t creation_time, bool session_name_contains_creation_time, |
322 | char *output_path) | |
c5b6f4f0 DG |
323 | { |
324 | int ret; | |
ecd1a12f | 325 | struct lttcomm_relayd_create_session_reply_2_11 reply = {}; |
c5b6f4f0 | 326 | |
a0377dfe FD |
327 | LTTNG_ASSERT(rsock); |
328 | LTTNG_ASSERT(relayd_session_id); | |
c5b6f4f0 DG |
329 | |
330 | DBG("Relayd create session"); | |
331 | ||
f86f6389 JR |
332 | if (rsock->minor < 4) { |
333 | /* From 2.1 to 2.3 */ | |
ecd1a12f | 334 | ret = relayd_create_session_2_1(rsock, &reply.generic); |
f86f6389 JR |
335 | } else if (rsock->minor >= 4 && rsock->minor < 11) { |
336 | /* From 2.4 to 2.10 */ | |
337 | ret = relayd_create_session_2_4(rsock, session_name, | |
ecd1a12f MD |
338 | hostname, session_live_timer, snapshot, |
339 | &reply.generic); | |
f86f6389 JR |
340 | } else { |
341 | /* From 2.11 to ... */ | |
342 | ret = relayd_create_session_2_11(rsock, session_name, | |
6fa5fe7c | 343 | hostname, base_path, session_live_timer, snapshot, |
f39bd140 | 344 | sessiond_session_id, sessiond_uuid, |
46ef2188 | 345 | current_chunk_id, creation_time, |
ecd1a12f MD |
346 | session_name_contains_creation_time, |
347 | &reply, output_path); | |
c5b6f4f0 DG |
348 | } |
349 | ||
c5b6f4f0 DG |
350 | if (ret < 0) { |
351 | goto error; | |
352 | } | |
353 | ||
c5b6f4f0 | 354 | /* Return session id or negative ret code. */ |
ecd1a12f | 355 | if (reply.generic.ret_code != LTTNG_OK) { |
bb63afd9 | 356 | ret = -1; |
ecd1a12f MD |
357 | ERR("Relayd create session replied error %d", |
358 | reply.generic.ret_code); | |
c5b6f4f0 DG |
359 | goto error; |
360 | } else { | |
361 | ret = 0; | |
ecd1a12f | 362 | *relayd_session_id = reply.generic.session_id; |
c5b6f4f0 DG |
363 | } |
364 | ||
ecd1a12f | 365 | DBG("Relayd session created with id %" PRIu64, reply.generic.session_id); |
c5b6f4f0 DG |
366 | |
367 | error: | |
368 | return ret; | |
369 | } | |
370 | ||
2f21a469 JR |
371 | static int relayd_add_stream_2_1(struct lttcomm_relayd_sock *rsock, |
372 | const char *channel_name, const char *pathname) | |
373 | { | |
374 | int ret; | |
375 | struct lttcomm_relayd_add_stream msg; | |
376 | ||
377 | memset(&msg, 0, sizeof(msg)); | |
378 | if (lttng_strncpy(msg.channel_name, channel_name, | |
379 | sizeof(msg.channel_name))) { | |
380 | ret = -1; | |
381 | goto error; | |
382 | } | |
383 | ||
384 | if (lttng_strncpy(msg.pathname, pathname, | |
385 | sizeof(msg.pathname))) { | |
386 | ret = -1; | |
387 | goto error; | |
388 | } | |
389 | ||
390 | /* Send command */ | |
391 | ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg, sizeof(msg), 0); | |
392 | if (ret < 0) { | |
393 | ret = -1; | |
394 | goto error; | |
395 | } | |
396 | ret = 0; | |
397 | error: | |
398 | return ret; | |
399 | } | |
400 | ||
401 | static int relayd_add_stream_2_2(struct lttcomm_relayd_sock *rsock, | |
402 | const char *channel_name, const char *pathname, | |
403 | uint64_t tracefile_size, uint64_t tracefile_count) | |
404 | { | |
405 | int ret; | |
406 | struct lttcomm_relayd_add_stream_2_2 msg; | |
407 | ||
408 | memset(&msg, 0, sizeof(msg)); | |
409 | /* Compat with relayd 2.2 to 2.10 */ | |
410 | if (lttng_strncpy(msg.channel_name, channel_name, | |
411 | sizeof(msg.channel_name))) { | |
412 | ret = -1; | |
413 | goto error; | |
414 | } | |
415 | if (lttng_strncpy(msg.pathname, pathname, | |
416 | sizeof(msg.pathname))) { | |
417 | ret = -1; | |
418 | goto error; | |
419 | } | |
420 | msg.tracefile_size = htobe64(tracefile_size); | |
421 | msg.tracefile_count = htobe64(tracefile_count); | |
422 | ||
423 | /* Send command */ | |
424 | ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg, sizeof(msg), 0); | |
425 | if (ret < 0) { | |
426 | goto error; | |
427 | } | |
428 | ret = 0; | |
429 | error: | |
430 | return ret; | |
431 | } | |
432 | ||
433 | static int relayd_add_stream_2_11(struct lttcomm_relayd_sock *rsock, | |
434 | const char *channel_name, const char *pathname, | |
b00e554e JG |
435 | uint64_t tracefile_size, uint64_t tracefile_count, |
436 | uint64_t trace_archive_id) | |
2f21a469 JR |
437 | { |
438 | int ret; | |
439 | struct lttcomm_relayd_add_stream_2_11 *msg = NULL; | |
440 | size_t channel_name_len; | |
441 | size_t pathname_len; | |
442 | size_t msg_length; | |
443 | ||
444 | /* The two names are sent with a '\0' delimiter between them. */ | |
445 | channel_name_len = strlen(channel_name) + 1; | |
446 | pathname_len = strlen(pathname) + 1; | |
447 | ||
448 | msg_length = sizeof(*msg) + channel_name_len + pathname_len; | |
55caead7 | 449 | msg = (lttcomm_relayd_add_stream_2_11 *) zmalloc(msg_length); |
2f21a469 JR |
450 | if (!msg) { |
451 | PERROR("zmalloc add_stream_2_11 command message"); | |
452 | ret = -1; | |
453 | goto error; | |
454 | } | |
455 | ||
a0377dfe | 456 | LTTNG_ASSERT(channel_name_len <= UINT32_MAX); |
2f21a469 JR |
457 | msg->channel_name_len = htobe32(channel_name_len); |
458 | ||
a0377dfe | 459 | LTTNG_ASSERT(pathname_len <= UINT32_MAX); |
2f21a469 JR |
460 | msg->pathname_len = htobe32(pathname_len); |
461 | ||
462 | if (lttng_strncpy(msg->names, channel_name, channel_name_len)) { | |
463 | ret = -1; | |
464 | goto error; | |
465 | } | |
466 | if (lttng_strncpy(msg->names + channel_name_len, pathname, pathname_len)) { | |
467 | ret = -1; | |
468 | goto error; | |
469 | } | |
470 | ||
471 | msg->tracefile_size = htobe64(tracefile_size); | |
472 | msg->tracefile_count = htobe64(tracefile_count); | |
348a81dc | 473 | msg->trace_chunk_id = htobe64(trace_archive_id); |
2f21a469 JR |
474 | |
475 | /* Send command */ | |
476 | ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) msg, msg_length, 0); | |
477 | if (ret < 0) { | |
478 | goto error; | |
479 | } | |
480 | ret = 0; | |
481 | error: | |
482 | free(msg); | |
483 | return ret; | |
484 | } | |
485 | ||
00e2e675 DG |
486 | /* |
487 | * Add stream on the relayd and assign stream handle to the stream_id argument. | |
488 | * | |
070b6a86 MD |
489 | * Chunks are not supported by relayd prior to 2.11, but are used to |
490 | * internally between session daemon and consumer daemon to keep track | |
491 | * of the channel and stream output path. | |
492 | * | |
00e2e675 DG |
493 | * On success return 0 else return ret_code negative value. |
494 | */ | |
6151a90f | 495 | int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_name, |
5da88b0f | 496 | const char *domain_name, const char *_pathname, uint64_t *stream_id, |
0b50e4b3 | 497 | uint64_t tracefile_size, uint64_t tracefile_count, |
d2956687 | 498 | struct lttng_trace_chunk *trace_chunk) |
00e2e675 DG |
499 | { |
500 | int ret; | |
00e2e675 | 501 | struct lttcomm_relayd_status_stream reply; |
5da88b0f | 502 | char pathname[RELAYD_COMM_LTTNG_PATH_MAX]; |
00e2e675 DG |
503 | |
504 | /* Code flow error. Safety net. */ | |
a0377dfe FD |
505 | LTTNG_ASSERT(rsock); |
506 | LTTNG_ASSERT(channel_name); | |
507 | LTTNG_ASSERT(domain_name); | |
508 | LTTNG_ASSERT(_pathname); | |
509 | LTTNG_ASSERT(trace_chunk); | |
00e2e675 DG |
510 | |
511 | DBG("Relayd adding stream for channel name %s", channel_name); | |
512 | ||
0f907de1 JD |
513 | /* Compat with relayd 2.1 */ |
514 | if (rsock->minor == 1) { | |
2f21a469 | 515 | /* For 2.1 */ |
5fab2976 | 516 | ret = relayd_add_stream_2_1(rsock, channel_name, _pathname); |
55caead7 | 517 | |
2f21a469 JR |
518 | } else if (rsock->minor > 1 && rsock->minor < 11) { |
519 | /* From 2.2 to 2.10 */ | |
5fab2976 | 520 | ret = relayd_add_stream_2_2(rsock, channel_name, _pathname, |
2f21a469 | 521 | tracefile_size, tracefile_count); |
0f907de1 | 522 | } else { |
5fab2976 | 523 | const char *separator; |
d2956687 JG |
524 | enum lttng_trace_chunk_status chunk_status; |
525 | uint64_t chunk_id; | |
526 | ||
5fab2976 JR |
527 | if (_pathname[0] == '\0') { |
528 | separator = ""; | |
529 | } else { | |
530 | separator = "/"; | |
531 | } | |
532 | ||
533 | ret = snprintf(pathname, RELAYD_COMM_LTTNG_PATH_MAX, "%s%s%s", | |
534 | domain_name, separator, _pathname); | |
535 | if (ret <= 0 || ret >= RELAYD_COMM_LTTNG_PATH_MAX) { | |
536 | ERR("Failed to format stream path: %s", | |
537 | ret <= 0 ? "formatting error" : | |
538 | "path exceeds maximal allowed length"); | |
539 | ret = -1; | |
540 | goto error; | |
541 | } | |
542 | ||
d2956687 JG |
543 | chunk_status = lttng_trace_chunk_get_id(trace_chunk, |
544 | &chunk_id); | |
a0377dfe | 545 | LTTNG_ASSERT(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); |
d2956687 | 546 | |
2f21a469 JR |
547 | /* From 2.11 to ...*/ |
548 | ret = relayd_add_stream_2_11(rsock, channel_name, pathname, | |
b00e554e | 549 | tracefile_size, tracefile_count, |
d2956687 | 550 | chunk_id); |
2f21a469 | 551 | } |
0f907de1 | 552 | |
2f21a469 JR |
553 | if (ret) { |
554 | ret = -1; | |
555 | goto error; | |
00e2e675 DG |
556 | } |
557 | ||
633d0084 | 558 | /* Waiting for reply */ |
6151a90f | 559 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); |
00e2e675 DG |
560 | if (ret < 0) { |
561 | goto error; | |
562 | } | |
563 | ||
564 | /* Back to host bytes order. */ | |
565 | reply.handle = be64toh(reply.handle); | |
566 | reply.ret_code = be32toh(reply.ret_code); | |
567 | ||
568 | /* Return session id or negative ret code. */ | |
f73fabfd | 569 | if (reply.ret_code != LTTNG_OK) { |
bb63afd9 DG |
570 | ret = -1; |
571 | ERR("Relayd add stream replied error %d", reply.ret_code); | |
00e2e675 DG |
572 | } else { |
573 | /* Success */ | |
574 | ret = 0; | |
575 | *stream_id = reply.handle; | |
576 | } | |
577 | ||
77c7c900 | 578 | DBG("Relayd stream added successfully with handle %" PRIu64, |
2f21a469 | 579 | reply.handle); |
00e2e675 DG |
580 | |
581 | error: | |
582 | return ret; | |
583 | } | |
584 | ||
a4baae1b JD |
585 | /* |
586 | * Inform the relay that all the streams for the current channel has been sent. | |
587 | * | |
588 | * On success return 0 else return ret_code negative value. | |
589 | */ | |
590 | int relayd_streams_sent(struct lttcomm_relayd_sock *rsock) | |
591 | { | |
592 | int ret; | |
593 | struct lttcomm_relayd_generic_reply reply; | |
594 | ||
595 | /* Code flow error. Safety net. */ | |
a0377dfe | 596 | LTTNG_ASSERT(rsock); |
a4baae1b JD |
597 | |
598 | DBG("Relayd sending streams sent."); | |
599 | ||
600 | /* This feature was introduced in 2.4, ignore it for earlier versions. */ | |
601 | if (rsock->minor < 4) { | |
602 | ret = 0; | |
603 | goto end; | |
604 | } | |
605 | ||
606 | /* Send command */ | |
607 | ret = send_command(rsock, RELAYD_STREAMS_SENT, NULL, 0, 0); | |
608 | if (ret < 0) { | |
609 | goto error; | |
610 | } | |
611 | ||
612 | /* Waiting for reply */ | |
613 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); | |
614 | if (ret < 0) { | |
615 | goto error; | |
616 | } | |
617 | ||
618 | /* Back to host bytes order. */ | |
619 | reply.ret_code = be32toh(reply.ret_code); | |
620 | ||
621 | /* Return session id or negative ret code. */ | |
622 | if (reply.ret_code != LTTNG_OK) { | |
623 | ret = -1; | |
624 | ERR("Relayd streams sent replied error %d", reply.ret_code); | |
625 | goto error; | |
626 | } else { | |
627 | /* Success */ | |
628 | ret = 0; | |
629 | } | |
630 | ||
631 | DBG("Relayd streams sent success"); | |
632 | ||
633 | error: | |
634 | end: | |
635 | return ret; | |
636 | } | |
637 | ||
00e2e675 DG |
638 | /* |
639 | * Check version numbers on the relayd. | |
d4519fa3 JD |
640 | * If major versions are compatible, we assign minor_to_use to the |
641 | * minor version of the procotol we are going to use for this session. | |
00e2e675 | 642 | * |
67d5aa28 JD |
643 | * Return 0 if the two daemons are compatible, LTTNG_ERR_RELAYD_VERSION_FAIL |
644 | * otherwise, or a negative value on network errors. | |
00e2e675 | 645 | */ |
6151a90f | 646 | int relayd_version_check(struct lttcomm_relayd_sock *rsock) |
00e2e675 DG |
647 | { |
648 | int ret; | |
092b6259 | 649 | struct lttcomm_relayd_version msg; |
00e2e675 DG |
650 | |
651 | /* Code flow error. Safety net. */ | |
a0377dfe | 652 | LTTNG_ASSERT(rsock); |
00e2e675 | 653 | |
6151a90f JD |
654 | DBG("Relayd version check for major.minor %u.%u", rsock->major, |
655 | rsock->minor); | |
00e2e675 | 656 | |
53efb85a | 657 | memset(&msg, 0, sizeof(msg)); |
092b6259 | 658 | /* Prepare network byte order before transmission. */ |
6151a90f JD |
659 | msg.major = htobe32(rsock->major); |
660 | msg.minor = htobe32(rsock->minor); | |
092b6259 | 661 | |
00e2e675 | 662 | /* Send command */ |
6151a90f | 663 | ret = send_command(rsock, RELAYD_VERSION, (void *) &msg, sizeof(msg), 0); |
00e2e675 DG |
664 | if (ret < 0) { |
665 | goto error; | |
666 | } | |
667 | ||
20275fe8 | 668 | /* Receive response */ |
6151a90f | 669 | ret = recv_reply(rsock, (void *) &msg, sizeof(msg)); |
00e2e675 DG |
670 | if (ret < 0) { |
671 | goto error; | |
672 | } | |
673 | ||
674 | /* Set back to host bytes order */ | |
092b6259 DG |
675 | msg.major = be32toh(msg.major); |
676 | msg.minor = be32toh(msg.minor); | |
677 | ||
678 | /* | |
679 | * Only validate the major version. If the other side is higher, | |
680 | * communication is not possible. Only major version equal can talk to each | |
681 | * other. If the minor version differs, the lowest version is used by both | |
682 | * sides. | |
092b6259 | 683 | */ |
6151a90f | 684 | if (msg.major != rsock->major) { |
d4519fa3 | 685 | /* Not compatible */ |
67d5aa28 | 686 | ret = LTTNG_ERR_RELAYD_VERSION_FAIL; |
d4519fa3 | 687 | DBG2("Relayd version is NOT compatible. Relayd version %u != %u (us)", |
6151a90f | 688 | msg.major, rsock->major); |
092b6259 | 689 | goto error; |
00e2e675 DG |
690 | } |
691 | ||
092b6259 | 692 | /* |
6151a90f JD |
693 | * If the relayd's minor version is higher, it will adapt to our version so |
694 | * we can continue to use the latest relayd communication data structure. | |
695 | * If the received minor version is higher, the relayd should adapt to us. | |
092b6259 | 696 | */ |
6151a90f JD |
697 | if (rsock->minor > msg.minor) { |
698 | rsock->minor = msg.minor; | |
d4519fa3 | 699 | } |
092b6259 | 700 | |
d4519fa3 JD |
701 | /* Version number compatible */ |
702 | DBG2("Relayd version is compatible, using protocol version %u.%u", | |
6151a90f | 703 | rsock->major, rsock->minor); |
d4519fa3 | 704 | ret = 0; |
00e2e675 DG |
705 | |
706 | error: | |
707 | return ret; | |
708 | } | |
709 | ||
00e2e675 DG |
710 | /* |
711 | * Add stream on the relayd and assign stream handle to the stream_id argument. | |
712 | * | |
713 | * On success return 0 else return ret_code negative value. | |
714 | */ | |
6151a90f | 715 | int relayd_send_metadata(struct lttcomm_relayd_sock *rsock, size_t len) |
00e2e675 DG |
716 | { |
717 | int ret; | |
718 | ||
719 | /* Code flow error. Safety net. */ | |
a0377dfe | 720 | LTTNG_ASSERT(rsock); |
00e2e675 | 721 | |
77c7c900 | 722 | DBG("Relayd sending metadata of size %zu", len); |
00e2e675 DG |
723 | |
724 | /* Send command */ | |
6151a90f | 725 | ret = send_command(rsock, RELAYD_SEND_METADATA, NULL, len, 0); |
00e2e675 DG |
726 | if (ret < 0) { |
727 | goto error; | |
728 | } | |
729 | ||
730 | DBG2("Relayd metadata added successfully"); | |
731 | ||
732 | /* | |
733 | * After that call, the metadata data MUST be sent to the relayd so the | |
734 | * receive size on the other end matches the len of the metadata packet | |
633d0084 | 735 | * header. This is why we don't wait for a reply here. |
00e2e675 DG |
736 | */ |
737 | ||
738 | error: | |
739 | return ret; | |
740 | } | |
741 | ||
742 | /* | |
6151a90f | 743 | * Connect to relay daemon with an allocated lttcomm_relayd_sock. |
00e2e675 | 744 | */ |
6151a90f | 745 | int relayd_connect(struct lttcomm_relayd_sock *rsock) |
00e2e675 DG |
746 | { |
747 | /* Code flow error. Safety net. */ | |
a0377dfe | 748 | LTTNG_ASSERT(rsock); |
00e2e675 | 749 | |
f96e4545 MD |
750 | if (!rsock->sock.ops) { |
751 | /* | |
752 | * Attempting a connect on a non-initialized socket. | |
753 | */ | |
754 | return -ECONNRESET; | |
755 | } | |
756 | ||
00e2e675 DG |
757 | DBG3("Relayd connect ..."); |
758 | ||
6151a90f | 759 | return rsock->sock.ops->connect(&rsock->sock); |
00e2e675 DG |
760 | } |
761 | ||
762 | /* | |
6151a90f | 763 | * Close relayd socket with an allocated lttcomm_relayd_sock. |
ffe60014 DG |
764 | * |
765 | * If no socket operations are found, simply return 0 meaning that everything | |
766 | * is fine. Without operations, the socket can not possibly be opened or used. | |
767 | * This is possible if the socket was allocated but not created. However, the | |
768 | * caller could simply use it to store a valid file descriptor for instance | |
769 | * passed over a Unix socket and call this to cleanup but still without a valid | |
770 | * ops pointer. | |
771 | * | |
772 | * Return the close returned value. On error, a negative value is usually | |
773 | * returned back from close(2). | |
00e2e675 | 774 | */ |
6151a90f | 775 | int relayd_close(struct lttcomm_relayd_sock *rsock) |
00e2e675 | 776 | { |
ffe60014 DG |
777 | int ret; |
778 | ||
00e2e675 | 779 | /* Code flow error. Safety net. */ |
a0377dfe | 780 | LTTNG_ASSERT(rsock); |
00e2e675 | 781 | |
ffe60014 | 782 | /* An invalid fd is fine, return success. */ |
6151a90f | 783 | if (rsock->sock.fd < 0) { |
ffe60014 DG |
784 | ret = 0; |
785 | goto end; | |
786 | } | |
787 | ||
6151a90f | 788 | DBG3("Relayd closing socket %d", rsock->sock.fd); |
00e2e675 | 789 | |
6151a90f JD |
790 | if (rsock->sock.ops) { |
791 | ret = rsock->sock.ops->close(&rsock->sock); | |
ffe60014 DG |
792 | } else { |
793 | /* Default call if no specific ops found. */ | |
6151a90f | 794 | ret = close(rsock->sock.fd); |
ffe60014 DG |
795 | if (ret < 0) { |
796 | PERROR("relayd_close default close"); | |
797 | } | |
798 | } | |
f96e4545 | 799 | rsock->sock.fd = -1; |
ffe60014 DG |
800 | |
801 | end: | |
802 | return ret; | |
00e2e675 DG |
803 | } |
804 | ||
805 | /* | |
806 | * Send data header structure to the relayd. | |
807 | */ | |
6151a90f | 808 | int relayd_send_data_hdr(struct lttcomm_relayd_sock *rsock, |
00e2e675 DG |
809 | struct lttcomm_relayd_data_hdr *hdr, size_t size) |
810 | { | |
811 | int ret; | |
812 | ||
813 | /* Code flow error. Safety net. */ | |
a0377dfe FD |
814 | LTTNG_ASSERT(rsock); |
815 | LTTNG_ASSERT(hdr); | |
00e2e675 | 816 | |
f96e4545 MD |
817 | if (rsock->sock.fd < 0) { |
818 | return -ECONNRESET; | |
819 | } | |
820 | ||
8fd623e0 | 821 | DBG3("Relayd sending data header of size %zu", size); |
00e2e675 DG |
822 | |
823 | /* Again, safety net */ | |
824 | if (size == 0) { | |
825 | size = sizeof(struct lttcomm_relayd_data_hdr); | |
826 | } | |
827 | ||
828 | /* Only send data header. */ | |
6151a90f | 829 | ret = rsock->sock.ops->sendmsg(&rsock->sock, hdr, size, 0); |
00e2e675 | 830 | if (ret < 0) { |
8994307f | 831 | ret = -errno; |
00e2e675 DG |
832 | goto error; |
833 | } | |
834 | ||
835 | /* | |
836 | * The data MUST be sent right after that command for the receive on the | |
837 | * other end to match the size in the header. | |
838 | */ | |
839 | ||
840 | error: | |
841 | return ret; | |
842 | } | |
173af62f DG |
843 | |
844 | /* | |
845 | * Send close stream command to the relayd. | |
846 | */ | |
6151a90f | 847 | int relayd_send_close_stream(struct lttcomm_relayd_sock *rsock, uint64_t stream_id, |
173af62f DG |
848 | uint64_t last_net_seq_num) |
849 | { | |
850 | int ret; | |
851 | struct lttcomm_relayd_close_stream msg; | |
852 | struct lttcomm_relayd_generic_reply reply; | |
853 | ||
854 | /* Code flow error. Safety net. */ | |
a0377dfe | 855 | LTTNG_ASSERT(rsock); |
173af62f | 856 | |
77c7c900 | 857 | DBG("Relayd closing stream id %" PRIu64, stream_id); |
173af62f | 858 | |
53efb85a | 859 | memset(&msg, 0, sizeof(msg)); |
173af62f DG |
860 | msg.stream_id = htobe64(stream_id); |
861 | msg.last_net_seq_num = htobe64(last_net_seq_num); | |
862 | ||
863 | /* Send command */ | |
6151a90f | 864 | ret = send_command(rsock, RELAYD_CLOSE_STREAM, (void *) &msg, sizeof(msg), 0); |
173af62f DG |
865 | if (ret < 0) { |
866 | goto error; | |
867 | } | |
868 | ||
20275fe8 | 869 | /* Receive response */ |
6151a90f | 870 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); |
173af62f DG |
871 | if (ret < 0) { |
872 | goto error; | |
873 | } | |
874 | ||
875 | reply.ret_code = be32toh(reply.ret_code); | |
876 | ||
877 | /* Return session id or negative ret code. */ | |
f73fabfd | 878 | if (reply.ret_code != LTTNG_OK) { |
bb63afd9 DG |
879 | ret = -1; |
880 | ERR("Relayd close stream replied error %d", reply.ret_code); | |
173af62f DG |
881 | } else { |
882 | /* Success */ | |
883 | ret = 0; | |
884 | } | |
885 | ||
77c7c900 | 886 | DBG("Relayd close stream id %" PRIu64 " successfully", stream_id); |
173af62f DG |
887 | |
888 | error: | |
889 | return ret; | |
890 | } | |
c8f59ee5 DG |
891 | |
892 | /* | |
893 | * Check for data availability for a given stream id. | |
894 | * | |
6d805429 | 895 | * Return 0 if NOT pending, 1 if so and a negative value on error. |
c8f59ee5 | 896 | */ |
6151a90f | 897 | int relayd_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t stream_id, |
c8f59ee5 DG |
898 | uint64_t last_net_seq_num) |
899 | { | |
900 | int ret; | |
6d805429 | 901 | struct lttcomm_relayd_data_pending msg; |
c8f59ee5 DG |
902 | struct lttcomm_relayd_generic_reply reply; |
903 | ||
904 | /* Code flow error. Safety net. */ | |
a0377dfe | 905 | LTTNG_ASSERT(rsock); |
c8f59ee5 | 906 | |
6d805429 | 907 | DBG("Relayd data pending for stream id %" PRIu64, stream_id); |
c8f59ee5 | 908 | |
53efb85a | 909 | memset(&msg, 0, sizeof(msg)); |
c8f59ee5 DG |
910 | msg.stream_id = htobe64(stream_id); |
911 | msg.last_net_seq_num = htobe64(last_net_seq_num); | |
912 | ||
913 | /* Send command */ | |
6151a90f | 914 | ret = send_command(rsock, RELAYD_DATA_PENDING, (void *) &msg, |
c8f59ee5 DG |
915 | sizeof(msg), 0); |
916 | if (ret < 0) { | |
917 | goto error; | |
918 | } | |
919 | ||
20275fe8 | 920 | /* Receive response */ |
6151a90f | 921 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); |
c8f59ee5 DG |
922 | if (ret < 0) { |
923 | goto error; | |
924 | } | |
925 | ||
926 | reply.ret_code = be32toh(reply.ret_code); | |
927 | ||
928 | /* Return session id or negative ret code. */ | |
929 | if (reply.ret_code >= LTTNG_OK) { | |
bb63afd9 | 930 | ERR("Relayd data pending replied error %d", reply.ret_code); |
c8f59ee5 DG |
931 | } |
932 | ||
933 | /* At this point, the ret code is either 1 or 0 */ | |
934 | ret = reply.ret_code; | |
935 | ||
6d805429 | 936 | DBG("Relayd data is %s pending for stream id %" PRIu64, |
9dd26bb9 | 937 | ret == 1 ? "" : "NOT", stream_id); |
c8f59ee5 DG |
938 | |
939 | error: | |
940 | return ret; | |
941 | } | |
942 | ||
943 | /* | |
944 | * Check on the relayd side for a quiescent state on the control socket. | |
945 | */ | |
6151a90f | 946 | int relayd_quiescent_control(struct lttcomm_relayd_sock *rsock, |
ad7051c0 | 947 | uint64_t metadata_stream_id) |
c8f59ee5 DG |
948 | { |
949 | int ret; | |
ad7051c0 | 950 | struct lttcomm_relayd_quiescent_control msg; |
c8f59ee5 DG |
951 | struct lttcomm_relayd_generic_reply reply; |
952 | ||
953 | /* Code flow error. Safety net. */ | |
a0377dfe | 954 | LTTNG_ASSERT(rsock); |
c8f59ee5 DG |
955 | |
956 | DBG("Relayd checking quiescent control state"); | |
957 | ||
53efb85a | 958 | memset(&msg, 0, sizeof(msg)); |
ad7051c0 DG |
959 | msg.stream_id = htobe64(metadata_stream_id); |
960 | ||
c8f59ee5 | 961 | /* Send command */ |
6151a90f | 962 | ret = send_command(rsock, RELAYD_QUIESCENT_CONTROL, &msg, sizeof(msg), 0); |
c8f59ee5 DG |
963 | if (ret < 0) { |
964 | goto error; | |
965 | } | |
966 | ||
20275fe8 | 967 | /* Receive response */ |
6151a90f | 968 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); |
c8f59ee5 DG |
969 | if (ret < 0) { |
970 | goto error; | |
971 | } | |
972 | ||
973 | reply.ret_code = be32toh(reply.ret_code); | |
974 | ||
975 | /* Return session id or negative ret code. */ | |
976 | if (reply.ret_code != LTTNG_OK) { | |
bb63afd9 DG |
977 | ret = -1; |
978 | ERR("Relayd quiescent control replied error %d", reply.ret_code); | |
c8f59ee5 DG |
979 | goto error; |
980 | } | |
981 | ||
982 | /* Control socket is quiescent */ | |
6d805429 | 983 | return 0; |
c8f59ee5 DG |
984 | |
985 | error: | |
986 | return ret; | |
987 | } | |
f7079f67 DG |
988 | |
989 | /* | |
990 | * Begin a data pending command for a specific session id. | |
991 | */ | |
6151a90f | 992 | int relayd_begin_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t id) |
f7079f67 DG |
993 | { |
994 | int ret; | |
995 | struct lttcomm_relayd_begin_data_pending msg; | |
996 | struct lttcomm_relayd_generic_reply reply; | |
997 | ||
998 | /* Code flow error. Safety net. */ | |
a0377dfe | 999 | LTTNG_ASSERT(rsock); |
f7079f67 DG |
1000 | |
1001 | DBG("Relayd begin data pending"); | |
1002 | ||
53efb85a | 1003 | memset(&msg, 0, sizeof(msg)); |
f7079f67 DG |
1004 | msg.session_id = htobe64(id); |
1005 | ||
1006 | /* Send command */ | |
6151a90f | 1007 | ret = send_command(rsock, RELAYD_BEGIN_DATA_PENDING, &msg, sizeof(msg), 0); |
f7079f67 DG |
1008 | if (ret < 0) { |
1009 | goto error; | |
1010 | } | |
1011 | ||
20275fe8 | 1012 | /* Receive response */ |
6151a90f | 1013 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); |
f7079f67 DG |
1014 | if (ret < 0) { |
1015 | goto error; | |
1016 | } | |
1017 | ||
1018 | reply.ret_code = be32toh(reply.ret_code); | |
1019 | ||
1020 | /* Return session id or negative ret code. */ | |
1021 | if (reply.ret_code != LTTNG_OK) { | |
bb63afd9 DG |
1022 | ret = -1; |
1023 | ERR("Relayd begin data pending replied error %d", reply.ret_code); | |
f7079f67 DG |
1024 | goto error; |
1025 | } | |
1026 | ||
1027 | return 0; | |
1028 | ||
1029 | error: | |
1030 | return ret; | |
1031 | } | |
1032 | ||
1033 | /* | |
1034 | * End a data pending command for a specific session id. | |
1035 | * | |
1036 | * Return 0 on success and set is_data_inflight to 0 if no data is being | |
1037 | * streamed or 1 if it is the case. | |
1038 | */ | |
6151a90f | 1039 | int relayd_end_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t id, |
f7079f67 DG |
1040 | unsigned int *is_data_inflight) |
1041 | { | |
af6c30b5 | 1042 | int ret, recv_ret; |
f7079f67 DG |
1043 | struct lttcomm_relayd_end_data_pending msg; |
1044 | struct lttcomm_relayd_generic_reply reply; | |
1045 | ||
1046 | /* Code flow error. Safety net. */ | |
a0377dfe | 1047 | LTTNG_ASSERT(rsock); |
f7079f67 DG |
1048 | |
1049 | DBG("Relayd end data pending"); | |
1050 | ||
53efb85a | 1051 | memset(&msg, 0, sizeof(msg)); |
f7079f67 DG |
1052 | msg.session_id = htobe64(id); |
1053 | ||
1054 | /* Send command */ | |
6151a90f | 1055 | ret = send_command(rsock, RELAYD_END_DATA_PENDING, &msg, sizeof(msg), 0); |
f7079f67 DG |
1056 | if (ret < 0) { |
1057 | goto error; | |
1058 | } | |
1059 | ||
20275fe8 | 1060 | /* Receive response */ |
6151a90f | 1061 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); |
f7079f67 DG |
1062 | if (ret < 0) { |
1063 | goto error; | |
1064 | } | |
1065 | ||
af6c30b5 DG |
1066 | recv_ret = be32toh(reply.ret_code); |
1067 | if (recv_ret < 0) { | |
1068 | ret = recv_ret; | |
f7079f67 DG |
1069 | goto error; |
1070 | } | |
1071 | ||
af6c30b5 | 1072 | *is_data_inflight = recv_ret; |
f7079f67 | 1073 | |
af6c30b5 | 1074 | DBG("Relayd end data pending is data inflight: %d", recv_ret); |
f7079f67 DG |
1075 | |
1076 | return 0; | |
1077 | ||
1078 | error: | |
1079 | return ret; | |
1080 | } | |
1c20f0e2 JD |
1081 | |
1082 | /* | |
1083 | * Send index to the relayd. | |
1084 | */ | |
1085 | int relayd_send_index(struct lttcomm_relayd_sock *rsock, | |
50adc264 | 1086 | struct ctf_packet_index *index, uint64_t relay_stream_id, |
1c20f0e2 JD |
1087 | uint64_t net_seq_num) |
1088 | { | |
1089 | int ret; | |
1090 | struct lttcomm_relayd_index msg; | |
1091 | struct lttcomm_relayd_generic_reply reply; | |
1092 | ||
1093 | /* Code flow error. Safety net. */ | |
a0377dfe | 1094 | LTTNG_ASSERT(rsock); |
1c20f0e2 JD |
1095 | |
1096 | if (rsock->minor < 4) { | |
1097 | DBG("Not sending indexes before protocol 2.4"); | |
1098 | ret = 0; | |
1099 | goto error; | |
1100 | } | |
1101 | ||
1102 | DBG("Relayd sending index for stream ID %" PRIu64, relay_stream_id); | |
1103 | ||
53efb85a | 1104 | memset(&msg, 0, sizeof(msg)); |
1c20f0e2 JD |
1105 | msg.relay_stream_id = htobe64(relay_stream_id); |
1106 | msg.net_seq_num = htobe64(net_seq_num); | |
1107 | ||
1108 | /* The index is already in big endian. */ | |
1109 | msg.packet_size = index->packet_size; | |
1110 | msg.content_size = index->content_size; | |
1111 | msg.timestamp_begin = index->timestamp_begin; | |
1112 | msg.timestamp_end = index->timestamp_end; | |
1113 | msg.events_discarded = index->events_discarded; | |
1114 | msg.stream_id = index->stream_id; | |
1115 | ||
234cd636 JD |
1116 | if (rsock->minor >= 8) { |
1117 | msg.stream_instance_id = index->stream_instance_id; | |
1118 | msg.packet_seq_num = index->packet_seq_num; | |
1119 | } | |
1120 | ||
1c20f0e2 | 1121 | /* Send command */ |
f8f3885c MD |
1122 | ret = send_command(rsock, RELAYD_SEND_INDEX, &msg, |
1123 | lttcomm_relayd_index_len(lttng_to_index_major(rsock->major, | |
1124 | rsock->minor), | |
1125 | lttng_to_index_minor(rsock->major, rsock->minor)), | |
1126 | 0); | |
1c20f0e2 JD |
1127 | if (ret < 0) { |
1128 | goto error; | |
1129 | } | |
1130 | ||
1131 | /* Receive response */ | |
1132 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); | |
1133 | if (ret < 0) { | |
1134 | goto error; | |
1135 | } | |
1136 | ||
1137 | reply.ret_code = be32toh(reply.ret_code); | |
1138 | ||
1139 | /* Return session id or negative ret code. */ | |
1140 | if (reply.ret_code != LTTNG_OK) { | |
1141 | ret = -1; | |
1142 | ERR("Relayd send index replied error %d", reply.ret_code); | |
1143 | } else { | |
1144 | /* Success */ | |
1145 | ret = 0; | |
1146 | } | |
1147 | ||
1148 | error: | |
1149 | return ret; | |
1150 | } | |
93ec662e JD |
1151 | |
1152 | /* | |
1153 | * Ask the relay to reset the metadata trace file (regeneration). | |
1154 | */ | |
1155 | int relayd_reset_metadata(struct lttcomm_relayd_sock *rsock, | |
1156 | uint64_t stream_id, uint64_t version) | |
1157 | { | |
1158 | int ret; | |
1159 | struct lttcomm_relayd_reset_metadata msg; | |
1160 | struct lttcomm_relayd_generic_reply reply; | |
1161 | ||
1162 | /* Code flow error. Safety net. */ | |
a0377dfe | 1163 | LTTNG_ASSERT(rsock); |
93ec662e JD |
1164 | |
1165 | /* Should have been prevented by the sessiond. */ | |
1166 | if (rsock->minor < 8) { | |
1167 | ERR("Metadata regeneration unsupported before 2.8"); | |
1168 | ret = -1; | |
1169 | goto error; | |
1170 | } | |
1171 | ||
1172 | DBG("Relayd reset metadata stream id %" PRIu64, stream_id); | |
1173 | ||
1174 | memset(&msg, 0, sizeof(msg)); | |
1175 | msg.stream_id = htobe64(stream_id); | |
1176 | msg.version = htobe64(version); | |
1177 | ||
1178 | /* Send command */ | |
1179 | ret = send_command(rsock, RELAYD_RESET_METADATA, (void *) &msg, sizeof(msg), 0); | |
1180 | if (ret < 0) { | |
1181 | goto error; | |
1182 | } | |
1183 | ||
1184 | /* Receive response */ | |
1185 | ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); | |
1186 | if (ret < 0) { | |
1187 | goto error; | |
1188 | } | |
1189 | ||
1190 | reply.ret_code = be32toh(reply.ret_code); | |
1191 | ||
1192 | /* Return session id or negative ret code. */ | |
1193 | if (reply.ret_code != LTTNG_OK) { | |
1194 | ret = -1; | |
1195 | ERR("Relayd reset metadata replied error %d", reply.ret_code); | |
1196 | } else { | |
1197 | /* Success */ | |
1198 | ret = 0; | |
1199 | } | |
1200 | ||
1201 | DBG("Relayd reset metadata stream id %" PRIu64 " successfully", stream_id); | |
1202 | ||
1203 | error: | |
1204 | return ret; | |
1205 | } | |
a1ae2ea5 | 1206 | |
c35f9726 | 1207 | int relayd_rotate_streams(struct lttcomm_relayd_sock *sock, |
ebb29c10 | 1208 | unsigned int stream_count, const uint64_t *new_chunk_id, |
c35f9726 | 1209 | const struct relayd_stream_rotation_position *positions) |
d73bf3d7 JD |
1210 | { |
1211 | int ret; | |
c35f9726 JG |
1212 | unsigned int i; |
1213 | struct lttng_dynamic_buffer payload; | |
1214 | struct lttcomm_relayd_generic_reply reply = {}; | |
1215 | const struct lttcomm_relayd_rotate_streams msg = { | |
1216 | .stream_count = htobe32((uint32_t) stream_count), | |
1217 | .new_chunk_id = (typeof(msg.new_chunk_id)) { | |
1218 | .is_set = !!new_chunk_id, | |
1219 | .value = htobe64(new_chunk_id ? *new_chunk_id : 0), | |
1220 | }, | |
1221 | }; | |
1222 | char new_chunk_id_buf[MAX_INT_DEC_LEN(*new_chunk_id)] = {}; | |
1223 | const char *new_chunk_id_str; | |
d73bf3d7 | 1224 | |
070b6a86 MD |
1225 | if (!relayd_supports_chunks(sock)) { |
1226 | DBG("Refusing to rotate remote streams: relayd does not support chunks"); | |
1227 | return 0; | |
1228 | } | |
1229 | ||
c35f9726 | 1230 | lttng_dynamic_buffer_init(&payload); |
d73bf3d7 | 1231 | |
c35f9726 | 1232 | /* Code flow error. Safety net. */ |
a0377dfe | 1233 | LTTNG_ASSERT(sock); |
d73bf3d7 | 1234 | |
c35f9726 JG |
1235 | if (new_chunk_id) { |
1236 | ret = snprintf(new_chunk_id_buf, sizeof(new_chunk_id_buf), | |
1237 | "%" PRIu64, *new_chunk_id); | |
1238 | if (ret == -1 || ret >= sizeof(new_chunk_id_buf)) { | |
1239 | new_chunk_id_str = "formatting error"; | |
1240 | } else { | |
1241 | new_chunk_id_str = new_chunk_id_buf; | |
1242 | } | |
1243 | } else { | |
1244 | new_chunk_id_str = "none"; | |
d73bf3d7 JD |
1245 | } |
1246 | ||
c35f9726 JG |
1247 | DBG("Preparing \"rotate streams\" command payload: new_chunk_id = %s, stream_count = %u", |
1248 | new_chunk_id_str, stream_count); | |
d73bf3d7 | 1249 | |
c35f9726 JG |
1250 | ret = lttng_dynamic_buffer_append(&payload, &msg, sizeof(msg)); |
1251 | if (ret) { | |
1252 | ERR("Failed to allocate \"rotate streams\" command payload"); | |
d73bf3d7 JD |
1253 | goto error; |
1254 | } | |
1255 | ||
c35f9726 JG |
1256 | for (i = 0; i < stream_count; i++) { |
1257 | const struct relayd_stream_rotation_position *position = | |
1258 | &positions[i]; | |
1259 | const struct lttcomm_relayd_stream_rotation_position comm_position = { | |
1260 | .stream_id = htobe64(position->stream_id), | |
1261 | .rotate_at_seq_num = htobe64( | |
1262 | position->rotate_at_seq_num), | |
1263 | }; | |
1264 | ||
a269202e | 1265 | DBG("Rotate stream %" PRIu64 " at sequence number %" PRIu64, |
c35f9726 JG |
1266 | position->stream_id, |
1267 | position->rotate_at_seq_num); | |
1268 | ret = lttng_dynamic_buffer_append(&payload, &comm_position, | |
1269 | sizeof(comm_position)); | |
1270 | if (ret) { | |
1271 | ERR("Failed to allocate \"rotate streams\" command payload"); | |
1272 | goto error; | |
1273 | } | |
1274 | } | |
d73bf3d7 JD |
1275 | |
1276 | /* Send command. */ | |
c35f9726 JG |
1277 | ret = send_command(sock, RELAYD_ROTATE_STREAMS, payload.data, |
1278 | payload.size, 0); | |
d73bf3d7 | 1279 | if (ret < 0) { |
c35f9726 | 1280 | ERR("Failed to send \"rotate stream\" command"); |
d73bf3d7 JD |
1281 | goto error; |
1282 | } | |
1283 | ||
1284 | /* Receive response. */ | |
c35f9726 | 1285 | ret = recv_reply(sock, &reply, sizeof(reply)); |
d73bf3d7 | 1286 | if (ret < 0) { |
c35f9726 | 1287 | ERR("Failed to receive \"rotate streams\" command reply"); |
d73bf3d7 JD |
1288 | goto error; |
1289 | } | |
1290 | ||
1291 | reply.ret_code = be32toh(reply.ret_code); | |
d73bf3d7 JD |
1292 | if (reply.ret_code != LTTNG_OK) { |
1293 | ret = -1; | |
c35f9726 | 1294 | ERR("Relayd rotate streams replied error %d", reply.ret_code); |
d73bf3d7 JD |
1295 | } else { |
1296 | /* Success. */ | |
1297 | ret = 0; | |
c35f9726 | 1298 | DBG("Relayd rotated streams successfully"); |
d73bf3d7 JD |
1299 | } |
1300 | ||
1301 | error: | |
c35f9726 | 1302 | lttng_dynamic_buffer_reset(&payload); |
d73bf3d7 JD |
1303 | return ret; |
1304 | } | |
e5add6d0 JG |
1305 | |
1306 | int relayd_create_trace_chunk(struct lttcomm_relayd_sock *sock, | |
1307 | struct lttng_trace_chunk *chunk) | |
1308 | { | |
1309 | int ret = 0; | |
1310 | enum lttng_trace_chunk_status status; | |
1311 | struct lttcomm_relayd_create_trace_chunk msg = {}; | |
1312 | struct lttcomm_relayd_generic_reply reply = {}; | |
1313 | struct lttng_dynamic_buffer payload; | |
1314 | uint64_t chunk_id; | |
1315 | time_t creation_timestamp; | |
1316 | const char *chunk_name; | |
1317 | size_t chunk_name_length; | |
913a542b | 1318 | bool overridden_name; |
e5add6d0 JG |
1319 | |
1320 | lttng_dynamic_buffer_init(&payload); | |
1321 | ||
070b6a86 MD |
1322 | if (!relayd_supports_chunks(sock)) { |
1323 | DBG("Refusing to create remote trace chunk: relayd does not support chunks"); | |
1324 | goto end; | |
1325 | } | |
1326 | ||
e5add6d0 JG |
1327 | status = lttng_trace_chunk_get_id(chunk, &chunk_id); |
1328 | if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { | |
1329 | ret = -1; | |
1330 | goto end; | |
1331 | } | |
1332 | ||
1333 | status = lttng_trace_chunk_get_creation_timestamp( | |
1334 | chunk, &creation_timestamp); | |
1335 | if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { | |
1336 | ret = -1; | |
1337 | goto end; | |
1338 | } | |
1339 | ||
1340 | status = lttng_trace_chunk_get_name( | |
913a542b | 1341 | chunk, &chunk_name, &overridden_name); |
e5add6d0 JG |
1342 | if (status != LTTNG_TRACE_CHUNK_STATUS_OK && |
1343 | status != LTTNG_TRACE_CHUNK_STATUS_NONE) { | |
1344 | ret = -1; | |
1345 | goto end; | |
1346 | } | |
1347 | ||
913a542b | 1348 | chunk_name_length = overridden_name ? (strlen(chunk_name) + 1) : 0; |
e5add6d0 JG |
1349 | msg = (typeof(msg)){ |
1350 | .chunk_id = htobe64(chunk_id), | |
1351 | .creation_timestamp = htobe64((uint64_t) creation_timestamp), | |
1352 | .override_name_length = htobe32((uint32_t) chunk_name_length), | |
1353 | }; | |
1354 | ||
1355 | ret = lttng_dynamic_buffer_append(&payload, &msg, sizeof(msg)); | |
1356 | if (ret) { | |
1357 | goto end; | |
1358 | } | |
1359 | if (chunk_name_length) { | |
1360 | ret = lttng_dynamic_buffer_append( | |
1361 | &payload, chunk_name, chunk_name_length); | |
1362 | if (ret) { | |
1363 | goto end; | |
1364 | } | |
1365 | } | |
1366 | ||
bbc4768c JG |
1367 | ret = send_command(sock, RELAYD_CREATE_TRACE_CHUNK, payload.data, |
1368 | payload.size, 0); | |
e5add6d0 JG |
1369 | if (ret < 0) { |
1370 | ERR("Failed to send trace chunk creation command to relay daemon"); | |
1371 | goto end; | |
1372 | } | |
1373 | ||
1374 | ret = recv_reply(sock, &reply, sizeof(reply)); | |
1375 | if (ret < 0) { | |
1376 | ERR("Failed to receive relay daemon trace chunk creation command reply"); | |
1377 | goto end; | |
1378 | } | |
1379 | ||
1380 | reply.ret_code = be32toh(reply.ret_code); | |
1381 | if (reply.ret_code != LTTNG_OK) { | |
1382 | ret = -1; | |
1383 | ERR("Relayd trace chunk create replied error %d", | |
1384 | reply.ret_code); | |
1385 | } else { | |
1386 | ret = 0; | |
1387 | DBG("Relayd successfully created trace chunk: chunk_id = %" PRIu64, | |
1388 | chunk_id); | |
1389 | } | |
1390 | ||
1391 | end: | |
1392 | lttng_dynamic_buffer_reset(&payload); | |
1393 | return ret; | |
1394 | } | |
bbc4768c JG |
1395 | |
1396 | int relayd_close_trace_chunk(struct lttcomm_relayd_sock *sock, | |
ecd1a12f MD |
1397 | struct lttng_trace_chunk *chunk, |
1398 | char *path) | |
bbc4768c JG |
1399 | { |
1400 | int ret = 0; | |
1401 | enum lttng_trace_chunk_status status; | |
1402 | struct lttcomm_relayd_close_trace_chunk msg = {}; | |
ecd1a12f | 1403 | struct lttcomm_relayd_close_trace_chunk_reply reply = {}; |
bbc4768c JG |
1404 | uint64_t chunk_id; |
1405 | time_t close_timestamp; | |
1406 | LTTNG_OPTIONAL(enum lttng_trace_chunk_command_type) close_command = {}; | |
1407 | ||
070b6a86 MD |
1408 | if (!relayd_supports_chunks(sock)) { |
1409 | DBG("Refusing to close remote trace chunk: relayd does not support chunks"); | |
1410 | goto end; | |
1411 | } | |
1412 | ||
bbc4768c JG |
1413 | status = lttng_trace_chunk_get_id(chunk, &chunk_id); |
1414 | if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { | |
1415 | ERR("Failed to get trace chunk id"); | |
1416 | ret = -1; | |
1417 | goto end; | |
1418 | } | |
1419 | ||
1420 | status = lttng_trace_chunk_get_close_timestamp(chunk, &close_timestamp); | |
1421 | if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { | |
1422 | ERR("Failed to get trace chunk close timestamp"); | |
1423 | ret = -1; | |
1424 | goto end; | |
1425 | } | |
1426 | ||
1427 | status = lttng_trace_chunk_get_close_command(chunk, | |
1428 | &close_command.value); | |
1429 | switch (status) { | |
1430 | case LTTNG_TRACE_CHUNK_STATUS_OK: | |
1431 | close_command.is_set = 1; | |
1432 | break; | |
1433 | case LTTNG_TRACE_CHUNK_STATUS_NONE: | |
1434 | break; | |
1435 | default: | |
1436 | ERR("Failed to get trace chunk close command"); | |
1437 | ret = -1; | |
1438 | goto end; | |
1439 | } | |
1440 | ||
1441 | msg = (typeof(msg)){ | |
1442 | .chunk_id = htobe64(chunk_id), | |
1443 | .close_timestamp = htobe64((uint64_t) close_timestamp), | |
1444 | .close_command = { | |
bbc4768c | 1445 | .is_set = close_command.is_set, |
55caead7 | 1446 | .value = htobe32((uint32_t) close_command.value), |
bbc4768c JG |
1447 | }, |
1448 | }; | |
1449 | ||
1450 | ret = send_command(sock, RELAYD_CLOSE_TRACE_CHUNK, &msg, sizeof(msg), | |
1451 | 0); | |
1452 | if (ret < 0) { | |
1453 | ERR("Failed to send trace chunk close command to relay daemon"); | |
1454 | goto end; | |
1455 | } | |
1456 | ||
1457 | ret = recv_reply(sock, &reply, sizeof(reply)); | |
1458 | if (ret < 0) { | |
1459 | ERR("Failed to receive relay daemon trace chunk close command reply"); | |
1460 | goto end; | |
1461 | } | |
1462 | ||
ecd1a12f MD |
1463 | reply.path_length = be32toh(reply.path_length); |
1464 | if (reply.path_length >= LTTNG_PATH_MAX) { | |
1465 | ERR("Chunk path too long"); | |
1466 | ret = -1; | |
1467 | goto end; | |
1468 | } | |
1469 | ||
1470 | ret = recv_reply(sock, path, reply.path_length); | |
1471 | if (ret < 0) { | |
1472 | ERR("Failed to receive relay daemon trace chunk close command reply"); | |
1473 | goto end; | |
1474 | } | |
1475 | if (path[reply.path_length - 1] != '\0') { | |
1476 | ERR("Invalid trace chunk path returned by relay daemon (not null-terminated)"); | |
1477 | ret = -1; | |
1478 | goto end; | |
1479 | } | |
1480 | ||
1481 | reply.generic.ret_code = be32toh(reply.generic.ret_code); | |
1482 | if (reply.generic.ret_code != LTTNG_OK) { | |
bbc4768c JG |
1483 | ret = -1; |
1484 | ERR("Relayd trace chunk close replied error %d", | |
ecd1a12f | 1485 | reply.generic.ret_code); |
bbc4768c JG |
1486 | } else { |
1487 | ret = 0; | |
1488 | DBG("Relayd successfully closed trace chunk: chunk_id = %" PRIu64, | |
1489 | chunk_id); | |
1490 | } | |
1491 | end: | |
1492 | return ret; | |
1493 | } | |
c35f9726 JG |
1494 | |
1495 | int relayd_trace_chunk_exists(struct lttcomm_relayd_sock *sock, | |
1496 | uint64_t chunk_id, bool *chunk_exists) | |
1497 | { | |
1498 | int ret = 0; | |
1499 | struct lttcomm_relayd_trace_chunk_exists msg = {}; | |
1500 | struct lttcomm_relayd_trace_chunk_exists_reply reply = {}; | |
1501 | ||
070b6a86 MD |
1502 | if (!relayd_supports_chunks(sock)) { |
1503 | DBG("Refusing to check for trace chunk existence: relayd does not support chunks"); | |
caa15afd JR |
1504 | /* The chunk will never exist */ |
1505 | *chunk_exists = false; | |
070b6a86 MD |
1506 | goto end; |
1507 | } | |
1508 | ||
c35f9726 JG |
1509 | msg = (typeof(msg)){ |
1510 | .chunk_id = htobe64(chunk_id), | |
1511 | }; | |
1512 | ||
1513 | ret = send_command(sock, RELAYD_TRACE_CHUNK_EXISTS, &msg, sizeof(msg), | |
1514 | 0); | |
1515 | if (ret < 0) { | |
1516 | ERR("Failed to send trace chunk exists command to relay daemon"); | |
1517 | goto end; | |
1518 | } | |
1519 | ||
1520 | ret = recv_reply(sock, &reply, sizeof(reply)); | |
1521 | if (ret < 0) { | |
1522 | ERR("Failed to receive relay daemon trace chunk close command reply"); | |
1523 | goto end; | |
1524 | } | |
1525 | ||
1526 | reply.generic.ret_code = be32toh(reply.generic.ret_code); | |
1527 | if (reply.generic.ret_code != LTTNG_OK) { | |
1528 | ret = -1; | |
1529 | ERR("Relayd trace chunk close replied error %d", | |
1530 | reply.generic.ret_code); | |
1531 | } else { | |
1532 | ret = 0; | |
1533 | DBG("Relayd successfully checked trace chunk existence: chunk_id = %" PRIu64 | |
1534 | ", exists = %s", chunk_id, | |
1535 | reply.trace_chunk_exists ? "true" : "false"); | |
1536 | *chunk_exists = !!reply.trace_chunk_exists; | |
1537 | } | |
1538 | end: | |
1539 | return ret; | |
1540 | } | |
8614e600 MD |
1541 | |
1542 | int relayd_get_configuration(struct lttcomm_relayd_sock *sock, | |
1543 | uint64_t query_flags, | |
1544 | uint64_t *result_flags) | |
1545 | { | |
1546 | int ret = 0; | |
1547 | struct lttcomm_relayd_get_configuration msg = (typeof(msg)) { | |
1548 | .query_flags = htobe64(query_flags), | |
1549 | }; | |
1550 | struct lttcomm_relayd_get_configuration_reply reply = {}; | |
1551 | ||
1552 | if (!relayd_supports_get_configuration(sock)) { | |
1553 | DBG("Refusing to get relayd configuration (unsupported by relayd)"); | |
1554 | if (query_flags) { | |
1555 | ret = -1; | |
1556 | goto end; | |
1557 | } | |
1558 | *result_flags = 0; | |
1559 | goto end; | |
1560 | } | |
1561 | ||
1562 | ret = send_command(sock, RELAYD_GET_CONFIGURATION, &msg, sizeof(msg), | |
1563 | 0); | |
1564 | if (ret < 0) { | |
1565 | ERR("Failed to send get configuration command to relay daemon"); | |
1566 | goto end; | |
1567 | } | |
1568 | ||
1569 | ret = recv_reply(sock, &reply, sizeof(reply)); | |
1570 | if (ret < 0) { | |
1571 | ERR("Failed to receive relay daemon get configuration command reply"); | |
1572 | goto end; | |
1573 | } | |
1574 | ||
1575 | reply.generic.ret_code = be32toh(reply.generic.ret_code); | |
1576 | if (reply.generic.ret_code != LTTNG_OK) { | |
1577 | ret = -1; | |
1578 | ERR("Relayd get configuration replied error %d", | |
1579 | reply.generic.ret_code); | |
1580 | } else { | |
1581 | reply.relayd_configuration_flags = | |
1582 | be64toh(reply.relayd_configuration_flags); | |
1583 | ret = 0; | |
1584 | DBG("Relayd successfully got configuration: query_flags = %" PRIu64 | |
1585 | ", results_flags = %" PRIu64, query_flags, | |
1586 | reply.relayd_configuration_flags); | |
1587 | *result_flags = reply.relayd_configuration_flags; | |
1588 | } | |
1589 | end: | |
1590 | return ret; | |
1591 | } |