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