Fix: sessiond: consumer.c: rotation error handling
[lttng-tools.git] / src / common / kernel-consumer / kernel-consumer.c
CommitLineData
3bd1e081
MD
1/*
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
b3530820 4 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3bd1e081 5 *
d14d33bf
AM
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2 only,
8 * as published by the Free Software Foundation.
3bd1e081
MD
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
d14d33bf
AM
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3bd1e081
MD
18 */
19
6c1c0768 20#define _LGPL_SOURCE
3bd1e081 21#include <assert.h>
3bd1e081
MD
22#include <poll.h>
23#include <pthread.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/mman.h>
27#include <sys/socket.h>
28#include <sys/types.h>
77c7c900 29#include <inttypes.h>
3bd1e081 30#include <unistd.h>
dbb5dfe6 31#include <sys/stat.h>
3bd1e081 32
51a9e1c7 33#include <bin/lttng-consumerd/health-consumerd.h>
990570ed 34#include <common/common.h>
10a8a223 35#include <common/kernel-ctl/kernel-ctl.h>
10a8a223 36#include <common/sessiond-comm/sessiond-comm.h>
00e2e675 37#include <common/sessiond-comm/relayd.h>
dbb5dfe6 38#include <common/compat/fcntl.h>
f263b7fd 39#include <common/compat/endian.h>
acdb9057 40#include <common/pipe.h>
00e2e675 41#include <common/relayd/relayd.h>
fe4477ee 42#include <common/utils.h>
c8fea79c 43#include <common/consumer/consumer-stream.h>
309167d2 44#include <common/index/index.h>
c8fea79c 45#include <common/consumer/consumer-timer.h>
0857097f 46
10a8a223 47#include "kernel-consumer.h"
3bd1e081
MD
48
49extern struct lttng_consumer_global_data consumer_data;
50extern int consumer_poll_timeout;
3bd1e081 51
3bd1e081
MD
52/*
53 * Take a snapshot for a specific fd
54 *
55 * Returns 0 on success, < 0 on error
56 */
ffe60014 57int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream *stream)
3bd1e081
MD
58{
59 int ret = 0;
60 int infd = stream->wait_fd;
61
62 ret = kernctl_snapshot(infd);
d2d2f190
JD
63 /*
64 * -EAGAIN is not an error, it just means that there is no data to
65 * be read.
66 */
67 if (ret != 0 && ret != -EAGAIN) {
5a510c9f 68 PERROR("Getting sub-buffer snapshot.");
3bd1e081
MD
69 }
70
71 return ret;
72}
73
e9404c27
JG
74/*
75 * Sample consumed and produced positions for a specific fd.
76 *
77 * Returns 0 on success, < 0 on error.
78 */
79int lttng_kconsumer_sample_snapshot_positions(
80 struct lttng_consumer_stream *stream)
81{
82 assert(stream);
83
84 return kernctl_snapshot_sample_positions(stream->wait_fd);
85}
86
3bd1e081
MD
87/*
88 * Get the produced position
89 *
90 * Returns 0 on success, < 0 on error
91 */
ffe60014 92int lttng_kconsumer_get_produced_snapshot(struct lttng_consumer_stream *stream,
3bd1e081
MD
93 unsigned long *pos)
94{
95 int ret;
96 int infd = stream->wait_fd;
97
98 ret = kernctl_snapshot_get_produced(infd, pos);
99 if (ret != 0) {
5a510c9f 100 PERROR("kernctl_snapshot_get_produced");
3bd1e081
MD
101 }
102
103 return ret;
104}
105
07b86b52
JD
106/*
107 * Get the consumerd position
108 *
109 * Returns 0 on success, < 0 on error
110 */
111int lttng_kconsumer_get_consumed_snapshot(struct lttng_consumer_stream *stream,
112 unsigned long *pos)
113{
114 int ret;
115 int infd = stream->wait_fd;
116
117 ret = kernctl_snapshot_get_consumed(infd, pos);
118 if (ret != 0) {
5a510c9f 119 PERROR("kernctl_snapshot_get_consumed");
07b86b52
JD
120 }
121
122 return ret;
123}
124
07b86b52
JD
125/*
126 * Take a snapshot of all the stream of a channel
127 *
128 * Returns 0 on success, < 0 on error
129 */
130int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
d07ceecd 131 uint64_t relayd_id, uint64_t nb_packets_per_stream,
5c786ded 132 struct lttng_consumer_local_data *ctx)
07b86b52
JD
133{
134 int ret;
07b86b52
JD
135 struct lttng_consumer_channel *channel;
136 struct lttng_consumer_stream *stream;
137
6a00837f 138 DBG("Kernel consumer snapshot channel %" PRIu64, key);
07b86b52
JD
139
140 rcu_read_lock();
141
142 channel = consumer_find_channel(key);
143 if (!channel) {
6a00837f 144 ERR("No channel found for key %" PRIu64, key);
07b86b52
JD
145 ret = -1;
146 goto end;
147 }
148
149 /* Splice is not supported yet for channel snapshot. */
150 if (channel->output != CONSUMER_CHANNEL_MMAP) {
151 ERR("Unsupported output %d", channel->output);
152 ret = -1;
153 goto end;
154 }
155
10a50311 156 cds_list_for_each_entry(stream, &channel->streams.head, send_node) {
923333cd 157 unsigned long consumed_pos, produced_pos;
9ce5646a
MD
158
159 health_code_update();
160
07b86b52
JD
161 /*
162 * Lock stream because we are about to change its state.
163 */
164 pthread_mutex_lock(&stream->lock);
165
29decac3
DG
166 /*
167 * Assign the received relayd ID so we can use it for streaming. The streams
168 * are not visible to anyone so this is OK to change it.
169 */
07b86b52
JD
170 stream->net_seq_idx = relayd_id;
171 channel->relayd_id = relayd_id;
172 if (relayd_id != (uint64_t) -1ULL) {
10a50311 173 ret = consumer_send_relayd_stream(stream, path);
07b86b52
JD
174 if (ret < 0) {
175 ERR("sending stream to relayd");
176 goto end_unlock;
177 }
07b86b52
JD
178 } else {
179 ret = utils_create_stream_file(path, stream->name,
10a50311
JD
180 stream->chan->tracefile_size,
181 stream->tracefile_count_current,
309167d2 182 stream->uid, stream->gid, NULL);
07b86b52
JD
183 if (ret < 0) {
184 ERR("utils_create_stream_file");
185 goto end_unlock;
186 }
187
188 stream->out_fd = ret;
189 stream->tracefile_size_current = 0;
190
81ea21bf
MD
191 DBG("Kernel consumer snapshot stream %s/%s (%" PRIu64 ")",
192 path, stream->name, stream->key);
07b86b52
JD
193 }
194
f22dd891 195 ret = kernctl_buffer_flush_empty(stream->wait_fd);
07b86b52 196 if (ret < 0) {
f22dd891
MD
197 /*
198 * Doing a buffer flush which does not take into
199 * account empty packets. This is not perfect
200 * for stream intersection, but required as a
201 * fall-back when "flush_empty" is not
202 * implemented by lttng-modules.
203 */
204 ret = kernctl_buffer_flush(stream->wait_fd);
205 if (ret < 0) {
206 ERR("Failed to flush kernel stream");
207 goto end_unlock;
208 }
07b86b52
JD
209 goto end_unlock;
210 }
211
212 ret = lttng_kconsumer_take_snapshot(stream);
213 if (ret < 0) {
214 ERR("Taking kernel snapshot");
215 goto end_unlock;
216 }
217
218 ret = lttng_kconsumer_get_produced_snapshot(stream, &produced_pos);
219 if (ret < 0) {
220 ERR("Produced kernel snapshot position");
221 goto end_unlock;
222 }
223
224 ret = lttng_kconsumer_get_consumed_snapshot(stream, &consumed_pos);
225 if (ret < 0) {
226 ERR("Consumerd kernel snapshot position");
227 goto end_unlock;
228 }
229
230 if (stream->max_sb_size == 0) {
231 ret = kernctl_get_max_subbuf_size(stream->wait_fd,
232 &stream->max_sb_size);
233 if (ret < 0) {
234 ERR("Getting kernel max_sb_size");
235 goto end_unlock;
236 }
237 }
238
d07ceecd
MD
239 consumed_pos = consumer_get_consume_start_pos(consumed_pos,
240 produced_pos, nb_packets_per_stream,
241 stream->max_sb_size);
5c786ded 242
07b86b52
JD
243 while (consumed_pos < produced_pos) {
244 ssize_t read_len;
245 unsigned long len, padded_len;
246
9ce5646a
MD
247 health_code_update();
248
07b86b52
JD
249 DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos);
250
251 ret = kernctl_get_subbuf(stream->wait_fd, &consumed_pos);
252 if (ret < 0) {
32af2c95 253 if (ret != -EAGAIN) {
07b86b52
JD
254 PERROR("kernctl_get_subbuf snapshot");
255 goto end_unlock;
256 }
257 DBG("Kernel consumer get subbuf failed. Skipping it.");
258 consumed_pos += stream->max_sb_size;
ddc93ee4 259 stream->chan->lost_packets++;
07b86b52
JD
260 continue;
261 }
262
263 ret = kernctl_get_subbuf_size(stream->wait_fd, &len);
264 if (ret < 0) {
265 ERR("Snapshot kernctl_get_subbuf_size");
29decac3 266 goto error_put_subbuf;
07b86b52
JD
267 }
268
269 ret = kernctl_get_padded_subbuf_size(stream->wait_fd, &padded_len);
270 if (ret < 0) {
271 ERR("Snapshot kernctl_get_padded_subbuf_size");
29decac3 272 goto error_put_subbuf;
07b86b52
JD
273 }
274
275 read_len = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, len,
309167d2 276 padded_len - len, NULL);
07b86b52 277 /*
29decac3
DG
278 * We write the padded len in local tracefiles but the data len
279 * when using a relay. Display the error but continue processing
280 * to try to release the subbuffer.
07b86b52
JD
281 */
282 if (relayd_id != (uint64_t) -1ULL) {
283 if (read_len != len) {
284 ERR("Error sending to the relay (ret: %zd != len: %lu)",
285 read_len, len);
286 }
287 } else {
288 if (read_len != padded_len) {
289 ERR("Error writing to tracefile (ret: %zd != len: %lu)",
290 read_len, padded_len);
291 }
292 }
293
294 ret = kernctl_put_subbuf(stream->wait_fd);
295 if (ret < 0) {
296 ERR("Snapshot kernctl_put_subbuf");
297 goto end_unlock;
298 }
299 consumed_pos += stream->max_sb_size;
300 }
301
302 if (relayd_id == (uint64_t) -1ULL) {
fdf9986c
MD
303 if (stream->out_fd >= 0) {
304 ret = close(stream->out_fd);
305 if (ret < 0) {
306 PERROR("Kernel consumer snapshot close out_fd");
307 goto end_unlock;
308 }
309 stream->out_fd = -1;
07b86b52 310 }
07b86b52
JD
311 } else {
312 close_relayd_stream(stream);
313 stream->net_seq_idx = (uint64_t) -1ULL;
314 }
315 pthread_mutex_unlock(&stream->lock);
316 }
317
318 /* All good! */
319 ret = 0;
320 goto end;
321
29decac3
DG
322error_put_subbuf:
323 ret = kernctl_put_subbuf(stream->wait_fd);
324 if (ret < 0) {
325 ERR("Snapshot kernctl_put_subbuf error path");
326 }
07b86b52
JD
327end_unlock:
328 pthread_mutex_unlock(&stream->lock);
329end:
330 rcu_read_unlock();
331 return ret;
332}
333
334/*
335 * Read the whole metadata available for a snapshot.
336 *
337 * Returns 0 on success, < 0 on error
338 */
fa27abe8 339static int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path,
e2039c7a 340 uint64_t relayd_id, struct lttng_consumer_local_data *ctx)
07b86b52 341{
d771f832
DG
342 int ret, use_relayd = 0;
343 ssize_t ret_read;
07b86b52
JD
344 struct lttng_consumer_channel *metadata_channel;
345 struct lttng_consumer_stream *metadata_stream;
d771f832
DG
346
347 assert(ctx);
07b86b52
JD
348
349 DBG("Kernel consumer snapshot metadata with key %" PRIu64 " at path %s",
350 key, path);
351
352 rcu_read_lock();
353
354 metadata_channel = consumer_find_channel(key);
355 if (!metadata_channel) {
d771f832 356 ERR("Kernel snapshot metadata not found for key %" PRIu64, key);
07b86b52 357 ret = -1;
fa27abe8 358 goto error_no_channel;
07b86b52
JD
359 }
360
361 metadata_stream = metadata_channel->metadata_stream;
362 assert(metadata_stream);
fa27abe8 363 pthread_mutex_lock(&metadata_stream->lock);
07b86b52 364
d771f832 365 /* Flag once that we have a valid relayd for the stream. */
e2039c7a 366 if (relayd_id != (uint64_t) -1ULL) {
d771f832
DG
367 use_relayd = 1;
368 }
369
370 if (use_relayd) {
10a50311 371 ret = consumer_send_relayd_stream(metadata_stream, path);
e2039c7a 372 if (ret < 0) {
fa27abe8 373 goto error_snapshot;
e2039c7a 374 }
e2039c7a
JD
375 } else {
376 ret = utils_create_stream_file(path, metadata_stream->name,
377 metadata_stream->chan->tracefile_size,
378 metadata_stream->tracefile_count_current,
309167d2 379 metadata_stream->uid, metadata_stream->gid, NULL);
e2039c7a 380 if (ret < 0) {
fa27abe8 381 goto error_snapshot;
e2039c7a
JD
382 }
383 metadata_stream->out_fd = ret;
07b86b52 384 }
07b86b52 385
d771f832 386 do {
9ce5646a
MD
387 health_code_update();
388
02d02e31 389 ret_read = lttng_kconsumer_read_subbuffer(metadata_stream, ctx, NULL);
d771f832 390 if (ret_read < 0) {
56591bac 391 if (ret_read != -EAGAIN) {
6a00837f 392 ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
d771f832 393 ret_read);
fa27abe8
JG
394 ret = ret_read;
395 goto error_snapshot;
07b86b52 396 }
d771f832 397 /* ret_read is negative at this point so we will exit the loop. */
07b86b52
JD
398 continue;
399 }
d771f832 400 } while (ret_read >= 0);
07b86b52 401
d771f832
DG
402 if (use_relayd) {
403 close_relayd_stream(metadata_stream);
404 metadata_stream->net_seq_idx = (uint64_t) -1ULL;
405 } else {
fdf9986c
MD
406 if (metadata_stream->out_fd >= 0) {
407 ret = close(metadata_stream->out_fd);
408 if (ret < 0) {
409 PERROR("Kernel consumer snapshot metadata close out_fd");
410 /*
411 * Don't go on error here since the snapshot was successful at this
412 * point but somehow the close failed.
413 */
414 }
415 metadata_stream->out_fd = -1;
e2039c7a 416 }
e2039c7a
JD
417 }
418
07b86b52 419 ret = 0;
fa27abe8
JG
420error_snapshot:
421 pthread_mutex_unlock(&metadata_stream->lock);
cf53a8a6
JD
422 cds_list_del(&metadata_stream->send_node);
423 consumer_stream_destroy(metadata_stream, NULL);
424 metadata_channel->metadata_stream = NULL;
fa27abe8 425error_no_channel:
07b86b52
JD
426 rcu_read_unlock();
427 return ret;
428}
429
1803a064
MD
430/*
431 * Receive command from session daemon and process it.
432 *
433 * Return 1 on success else a negative value or 0.
434 */
3bd1e081
MD
435int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
436 int sock, struct pollfd *consumer_sockpoll)
437{
438 ssize_t ret;
0c759fc9 439 enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS;
3bd1e081
MD
440 struct lttcomm_consumer_msg msg;
441
9ce5646a
MD
442 health_code_update();
443
3bd1e081
MD
444 ret = lttcomm_recv_unix_sock(sock, &msg, sizeof(msg));
445 if (ret != sizeof(msg)) {
1803a064 446 if (ret > 0) {
c6857fcf 447 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_ERROR_RECV_CMD);
1803a064
MD
448 ret = -1;
449 }
3bd1e081
MD
450 return ret;
451 }
9ce5646a
MD
452
453 health_code_update();
454
84382d49
MD
455 /* Deprecated command */
456 assert(msg.cmd_type != LTTNG_CONSUMER_STOP);
3bd1e081 457
9ce5646a
MD
458 health_code_update();
459
b0b335c8
MD
460 /* relayd needs RCU read-side protection */
461 rcu_read_lock();
462
3bd1e081 463 switch (msg.cmd_type) {
00e2e675
DG
464 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET:
465 {
f50f23d9 466 /* Session daemon status message are handled in the following call. */
2527bf85 467 consumer_add_relayd_socket(msg.u.relayd_sock.net_index,
7735ef9e 468 msg.u.relayd_sock.type, ctx, sock, consumer_sockpoll,
d3e2ba59 469 &msg.u.relayd_sock.sock, msg.u.relayd_sock.session_id,
2527bf85 470 msg.u.relayd_sock.relayd_session_id);
00e2e675
DG
471 goto end_nosignal;
472 }
3bd1e081
MD
473 case LTTNG_CONSUMER_ADD_CHANNEL:
474 {
475 struct lttng_consumer_channel *new_channel;
e43c41c5 476 int ret_recv;
3bd1e081 477
9ce5646a
MD
478 health_code_update();
479
f50f23d9
DG
480 /* First send a status message before receiving the fds. */
481 ret = consumer_send_status_msg(sock, ret_code);
482 if (ret < 0) {
483 /* Somehow, the session daemon is not responding anymore. */
1803a064 484 goto error_fatal;
f50f23d9 485 }
9ce5646a
MD
486
487 health_code_update();
488
d88aee68 489 DBG("consumer_add_channel %" PRIu64, msg.u.channel.channel_key);
3bd1e081 490 new_channel = consumer_allocate_channel(msg.u.channel.channel_key,
ffe60014
DG
491 msg.u.channel.session_id, msg.u.channel.pathname,
492 msg.u.channel.name, msg.u.channel.uid, msg.u.channel.gid,
1624d5b7
JD
493 msg.u.channel.relayd_id, msg.u.channel.output,
494 msg.u.channel.tracefile_size,
1950109e 495 msg.u.channel.tracefile_count, 0,
ecc48a90 496 msg.u.channel.monitor,
d7ba1388 497 msg.u.channel.live_timer_interval,
3d071855 498 NULL, NULL);
3bd1e081 499 if (new_channel == NULL) {
f73fabfd 500 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR);
3bd1e081
MD
501 goto end_nosignal;
502 }
ffe60014 503 new_channel->nb_init_stream_left = msg.u.channel.nb_init_streams;
95a1109b
JD
504 switch (msg.u.channel.output) {
505 case LTTNG_EVENT_SPLICE:
506 new_channel->output = CONSUMER_CHANNEL_SPLICE;
507 break;
508 case LTTNG_EVENT_MMAP:
509 new_channel->output = CONSUMER_CHANNEL_MMAP;
510 break;
511 default:
512 ERR("Channel output unknown %d", msg.u.channel.output);
513 goto end_nosignal;
514 }
ffe60014
DG
515
516 /* Translate and save channel type. */
517 switch (msg.u.channel.type) {
518 case CONSUMER_CHANNEL_TYPE_DATA:
519 case CONSUMER_CHANNEL_TYPE_METADATA:
520 new_channel->type = msg.u.channel.type;
521 break;
522 default:
523 assert(0);
524 goto end_nosignal;
525 };
526
9ce5646a
MD
527 health_code_update();
528
3bd1e081 529 if (ctx->on_recv_channel != NULL) {
e43c41c5
JD
530 ret_recv = ctx->on_recv_channel(new_channel);
531 if (ret_recv == 0) {
532 ret = consumer_add_channel(new_channel, ctx);
533 } else if (ret_recv < 0) {
3bd1e081
MD
534 goto end_nosignal;
535 }
536 } else {
e43c41c5 537 ret = consumer_add_channel(new_channel, ctx);
3bd1e081 538 }
e9404c27
JG
539 if (msg.u.channel.type == CONSUMER_CHANNEL_TYPE_DATA && !ret) {
540 int monitor_start_ret;
541
542 DBG("Consumer starting monitor timer");
94d49140
JD
543 consumer_timer_live_start(new_channel,
544 msg.u.channel.live_timer_interval);
e9404c27
JG
545 monitor_start_ret = consumer_timer_monitor_start(
546 new_channel,
547 msg.u.channel.monitor_timer_interval);
548 if (monitor_start_ret < 0) {
549 ERR("Starting channel monitoring timer failed");
550 goto end_nosignal;
551 }
552
94d49140 553 }
e43c41c5 554
9ce5646a
MD
555 health_code_update();
556
e43c41c5 557 /* If we received an error in add_channel, we need to report it. */
821fffb2 558 if (ret < 0) {
1803a064
MD
559 ret = consumer_send_status_msg(sock, ret);
560 if (ret < 0) {
561 goto error_fatal;
562 }
e43c41c5
JD
563 goto end_nosignal;
564 }
565
3bd1e081
MD
566 goto end_nosignal;
567 }
568 case LTTNG_CONSUMER_ADD_STREAM:
569 {
dae10966
DG
570 int fd;
571 struct lttng_pipe *stream_pipe;
00e2e675 572 struct lttng_consumer_stream *new_stream;
ffe60014 573 struct lttng_consumer_channel *channel;
c80048c6 574 int alloc_ret = 0;
3bd1e081 575
ffe60014
DG
576 /*
577 * Get stream's channel reference. Needed when adding the stream to the
578 * global hash table.
579 */
580 channel = consumer_find_channel(msg.u.stream.channel_key);
581 if (!channel) {
582 /*
583 * We could not find the channel. Can happen if cpu hotplug
584 * happens while tearing down.
585 */
d88aee68 586 ERR("Unable to find channel key %" PRIu64, msg.u.stream.channel_key);
e462382a 587 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
ffe60014
DG
588 }
589
9ce5646a
MD
590 health_code_update();
591
f50f23d9
DG
592 /* First send a status message before receiving the fds. */
593 ret = consumer_send_status_msg(sock, ret_code);
1803a064 594 if (ret < 0) {
d771f832 595 /* Somehow, the session daemon is not responding anymore. */
1803a064
MD
596 goto error_fatal;
597 }
9ce5646a
MD
598
599 health_code_update();
600
0c759fc9 601 if (ret_code != LTTCOMM_CONSUMERD_SUCCESS) {
d771f832 602 /* Channel was not found. */
f50f23d9
DG
603 goto end_nosignal;
604 }
605
d771f832 606 /* Blocking call */
9ce5646a
MD
607 health_poll_entry();
608 ret = lttng_consumer_poll_socket(consumer_sockpoll);
609 health_poll_exit();
84382d49
MD
610 if (ret) {
611 goto error_fatal;
3bd1e081 612 }
00e2e675 613
9ce5646a
MD
614 health_code_update();
615
00e2e675 616 /* Get stream file descriptor from socket */
f2fc6720
MD
617 ret = lttcomm_recv_fds_unix_sock(sock, &fd, 1);
618 if (ret != sizeof(fd)) {
f73fabfd 619 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_ERROR_RECV_FD);
3f8e211f 620 rcu_read_unlock();
3bd1e081
MD
621 return ret;
622 }
3bd1e081 623
9ce5646a
MD
624 health_code_update();
625
f50f23d9
DG
626 /*
627 * Send status code to session daemon only if the recv works. If the
628 * above recv() failed, the session daemon is notified through the
629 * error socket and the teardown is eventually done.
630 */
631 ret = consumer_send_status_msg(sock, ret_code);
632 if (ret < 0) {
633 /* Somehow, the session daemon is not responding anymore. */
634 goto end_nosignal;
635 }
636
9ce5646a
MD
637 health_code_update();
638
ffe60014
DG
639 new_stream = consumer_allocate_stream(channel->key,
640 fd,
641 LTTNG_CONSUMER_ACTIVE_STREAM,
642 channel->name,
643 channel->uid,
644 channel->gid,
645 channel->relayd_id,
646 channel->session_id,
647 msg.u.stream.cpu,
648 &alloc_ret,
4891ece8 649 channel->type,
e098433c
JG
650 channel->monitor,
651 msg.u.stream.trace_archive_id);
3bd1e081 652 if (new_stream == NULL) {
c80048c6
MD
653 switch (alloc_ret) {
654 case -ENOMEM:
655 case -EINVAL:
656 default:
657 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR);
658 break;
c80048c6 659 }
3f8e211f 660 goto end_nosignal;
3bd1e081 661 }
d771f832 662
ffe60014
DG
663 new_stream->chan = channel;
664 new_stream->wait_fd = fd;
d9a2e16e
JD
665 consumer_stream_update_channel_attributes(new_stream,
666 channel);
07b86b52
JD
667 switch (channel->output) {
668 case CONSUMER_CHANNEL_SPLICE:
669 new_stream->output = LTTNG_EVENT_SPLICE;
a2361a61
JD
670 ret = utils_create_pipe(new_stream->splice_pipe);
671 if (ret < 0) {
672 goto end_nosignal;
673 }
07b86b52
JD
674 break;
675 case CONSUMER_CHANNEL_MMAP:
676 new_stream->output = LTTNG_EVENT_MMAP;
677 break;
678 default:
679 ERR("Stream output unknown %d", channel->output);
680 goto end_nosignal;
681 }
00e2e675 682
a0c83db9
DG
683 /*
684 * We've just assigned the channel to the stream so increment the
07b86b52
JD
685 * refcount right now. We don't need to increment the refcount for
686 * streams in no monitor because we handle manually the cleanup of
687 * those. It is very important to make sure there is NO prior
688 * consumer_del_stream() calls or else the refcount will be unbalanced.
a0c83db9 689 */
07b86b52
JD
690 if (channel->monitor) {
691 uatomic_inc(&new_stream->chan->refcount);
692 }
9d9353f9 693
fb3a43a9
DG
694 /*
695 * The buffer flush is done on the session daemon side for the kernel
696 * so no need for the stream "hangup_flush_done" variable to be
697 * tracked. This is important for a kernel stream since we don't rely
698 * on the flush state of the stream to read data. It's not the case for
699 * user space tracing.
700 */
701 new_stream->hangup_flush_done = 0;
702
9ce5646a
MD
703 health_code_update();
704
633d0084
DG
705 if (ctx->on_recv_stream) {
706 ret = ctx->on_recv_stream(new_stream);
707 if (ret < 0) {
d771f832 708 consumer_stream_free(new_stream);
633d0084 709 goto end_nosignal;
fb3a43a9 710 }
633d0084 711 }
fb3a43a9 712
9ce5646a
MD
713 health_code_update();
714
07b86b52
JD
715 if (new_stream->metadata_flag) {
716 channel->metadata_stream = new_stream;
717 }
718
2bba9e53
DG
719 /* Do not monitor this stream. */
720 if (!channel->monitor) {
5eecee74 721 DBG("Kernel consumer add stream %s in no monitor mode with "
6dc3064a 722 "relayd id %" PRIu64, new_stream->name,
5eecee74 723 new_stream->net_seq_idx);
10a50311 724 cds_list_add(&new_stream->send_node, &channel->streams.head);
6dc3064a
DG
725 break;
726 }
727
e1b71bdc
DG
728 /* Send stream to relayd if the stream has an ID. */
729 if (new_stream->net_seq_idx != (uint64_t) -1ULL) {
194ee077
DG
730 ret = consumer_send_relayd_stream(new_stream,
731 new_stream->chan->pathname);
e1b71bdc
DG
732 if (ret < 0) {
733 consumer_stream_free(new_stream);
734 goto end_nosignal;
735 }
001b7e62
MD
736
737 /*
738 * If adding an extra stream to an already
739 * existing channel (e.g. cpu hotplug), we need
740 * to send the "streams_sent" command to relayd.
741 */
742 if (channel->streams_sent_to_relayd) {
743 ret = consumer_send_relayd_streams_sent(
744 new_stream->net_seq_idx);
745 if (ret < 0) {
746 goto end_nosignal;
747 }
748 }
e2039c7a
JD
749 }
750
50f8ae69 751 /* Get the right pipe where the stream will be sent. */
633d0084 752 if (new_stream->metadata_flag) {
66d583dc 753 consumer_add_metadata_stream(new_stream);
dae10966 754 stream_pipe = ctx->consumer_metadata_pipe;
3bd1e081 755 } else {
66d583dc 756 consumer_add_data_stream(new_stream);
dae10966 757 stream_pipe = ctx->consumer_data_pipe;
50f8ae69
DG
758 }
759
66d583dc 760 /* Visible to other threads */
5ab66908
MD
761 new_stream->globally_visible = 1;
762
9ce5646a
MD
763 health_code_update();
764
dae10966 765 ret = lttng_pipe_write(stream_pipe, &new_stream, sizeof(new_stream));
50f8ae69 766 if (ret < 0) {
dae10966 767 ERR("Consumer write %s stream to pipe %d",
50f8ae69 768 new_stream->metadata_flag ? "metadata" : "data",
dae10966 769 lttng_pipe_get_writefd(stream_pipe));
5ab66908
MD
770 if (new_stream->metadata_flag) {
771 consumer_del_stream_for_metadata(new_stream);
772 } else {
773 consumer_del_stream_for_data(new_stream);
774 }
50f8ae69 775 goto end_nosignal;
3bd1e081 776 }
00e2e675 777
02d02e31
JD
778 DBG("Kernel consumer ADD_STREAM %s (fd: %d) %s with relayd id %" PRIu64,
779 new_stream->name, fd, new_stream->chan->pathname, new_stream->relayd_stream_id);
3bd1e081
MD
780 break;
781 }
a4baae1b
JD
782 case LTTNG_CONSUMER_STREAMS_SENT:
783 {
784 struct lttng_consumer_channel *channel;
785
786 /*
787 * Get stream's channel reference. Needed when adding the stream to the
788 * global hash table.
789 */
790 channel = consumer_find_channel(msg.u.sent_streams.channel_key);
791 if (!channel) {
792 /*
793 * We could not find the channel. Can happen if cpu hotplug
794 * happens while tearing down.
795 */
796 ERR("Unable to find channel key %" PRIu64,
797 msg.u.sent_streams.channel_key);
e462382a 798 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
a4baae1b
JD
799 }
800
801 health_code_update();
802
803 /*
804 * Send status code to session daemon.
805 */
806 ret = consumer_send_status_msg(sock, ret_code);
f261ad0a 807 if (ret < 0 || ret_code != LTTCOMM_CONSUMERD_SUCCESS) {
a4baae1b
JD
808 /* Somehow, the session daemon is not responding anymore. */
809 goto end_nosignal;
810 }
811
812 health_code_update();
813
814 /*
815 * We should not send this message if we don't monitor the
816 * streams in this channel.
817 */
818 if (!channel->monitor) {
819 break;
820 }
821
822 health_code_update();
823 /* Send stream to relayd if the stream has an ID. */
824 if (msg.u.sent_streams.net_seq_idx != (uint64_t) -1ULL) {
825 ret = consumer_send_relayd_streams_sent(
826 msg.u.sent_streams.net_seq_idx);
827 if (ret < 0) {
828 goto end_nosignal;
829 }
001b7e62 830 channel->streams_sent_to_relayd = true;
a4baae1b
JD
831 }
832 break;
833 }
3bd1e081
MD
834 case LTTNG_CONSUMER_UPDATE_STREAM:
835 {
3f8e211f
DG
836 rcu_read_unlock();
837 return -ENOSYS;
838 }
839 case LTTNG_CONSUMER_DESTROY_RELAYD:
840 {
a6ba4fe1 841 uint64_t index = msg.u.destroy_relayd.net_seq_idx;
3f8e211f
DG
842 struct consumer_relayd_sock_pair *relayd;
843
a6ba4fe1 844 DBG("Kernel consumer destroying relayd %" PRIu64, index);
3f8e211f
DG
845
846 /* Get relayd reference if exists. */
a6ba4fe1 847 relayd = consumer_find_relayd(index);
3f8e211f 848 if (relayd == NULL) {
3448e266 849 DBG("Unable to find relayd %" PRIu64, index);
e462382a 850 ret_code = LTTCOMM_CONSUMERD_RELAYD_FAIL;
3bd1e081 851 }
3f8e211f 852
a6ba4fe1
DG
853 /*
854 * Each relayd socket pair has a refcount of stream attached to it
855 * which tells if the relayd is still active or not depending on the
856 * refcount value.
857 *
858 * This will set the destroy flag of the relayd object and destroy it
859 * if the refcount reaches zero when called.
860 *
861 * The destroy can happen either here or when a stream fd hangs up.
862 */
f50f23d9
DG
863 if (relayd) {
864 consumer_flag_relayd_for_destroy(relayd);
865 }
866
9ce5646a
MD
867 health_code_update();
868
f50f23d9
DG
869 ret = consumer_send_status_msg(sock, ret_code);
870 if (ret < 0) {
871 /* Somehow, the session daemon is not responding anymore. */
1803a064 872 goto error_fatal;
f50f23d9 873 }
3f8e211f 874
3f8e211f 875 goto end_nosignal;
3bd1e081 876 }
6d805429 877 case LTTNG_CONSUMER_DATA_PENDING:
53632229 878 {
c8f59ee5 879 int32_t ret;
6d805429 880 uint64_t id = msg.u.data_pending.session_id;
c8f59ee5 881
6d805429 882 DBG("Kernel consumer data pending command for id %" PRIu64, id);
c8f59ee5 883
6d805429 884 ret = consumer_data_pending(id);
c8f59ee5 885
9ce5646a
MD
886 health_code_update();
887
c8f59ee5
DG
888 /* Send back returned value to session daemon */
889 ret = lttcomm_send_unix_sock(sock, &ret, sizeof(ret));
890 if (ret < 0) {
6d805429 891 PERROR("send data pending ret code");
1803a064 892 goto error_fatal;
c8f59ee5 893 }
f50f23d9
DG
894
895 /*
896 * No need to send back a status message since the data pending
897 * returned value is the response.
898 */
c8f59ee5 899 break;
53632229 900 }
6dc3064a
DG
901 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL:
902 {
07b86b52
JD
903 if (msg.u.snapshot_channel.metadata == 1) {
904 ret = lttng_kconsumer_snapshot_metadata(msg.u.snapshot_channel.key,
e2039c7a
JD
905 msg.u.snapshot_channel.pathname,
906 msg.u.snapshot_channel.relayd_id, ctx);
07b86b52
JD
907 if (ret < 0) {
908 ERR("Snapshot metadata failed");
e462382a 909 ret_code = LTTCOMM_CONSUMERD_ERROR_METADATA;
07b86b52
JD
910 }
911 } else {
912 ret = lttng_kconsumer_snapshot_channel(msg.u.snapshot_channel.key,
913 msg.u.snapshot_channel.pathname,
5c786ded 914 msg.u.snapshot_channel.relayd_id,
d07ceecd 915 msg.u.snapshot_channel.nb_packets_per_stream,
5c786ded 916 ctx);
07b86b52
JD
917 if (ret < 0) {
918 ERR("Snapshot channel failed");
e462382a 919 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
07b86b52
JD
920 }
921 }
922
9ce5646a
MD
923 health_code_update();
924
6dc3064a
DG
925 ret = consumer_send_status_msg(sock, ret_code);
926 if (ret < 0) {
927 /* Somehow, the session daemon is not responding anymore. */
928 goto end_nosignal;
929 }
930 break;
931 }
07b86b52
JD
932 case LTTNG_CONSUMER_DESTROY_CHANNEL:
933 {
934 uint64_t key = msg.u.destroy_channel.key;
935 struct lttng_consumer_channel *channel;
936
937 channel = consumer_find_channel(key);
938 if (!channel) {
939 ERR("Kernel consumer destroy channel %" PRIu64 " not found", key);
e462382a 940 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
07b86b52
JD
941 }
942
9ce5646a
MD
943 health_code_update();
944
07b86b52
JD
945 ret = consumer_send_status_msg(sock, ret_code);
946 if (ret < 0) {
947 /* Somehow, the session daemon is not responding anymore. */
948 goto end_nosignal;
949 }
950
9ce5646a
MD
951 health_code_update();
952
15dc512a
DG
953 /* Stop right now if no channel was found. */
954 if (!channel) {
955 goto end_nosignal;
956 }
957
07b86b52
JD
958 /*
959 * This command should ONLY be issued for channel with streams set in
960 * no monitor mode.
961 */
962 assert(!channel->monitor);
963
964 /*
965 * The refcount should ALWAYS be 0 in the case of a channel in no
966 * monitor mode.
967 */
968 assert(!uatomic_sub_return(&channel->refcount, 1));
969
970 consumer_del_channel(channel);
971
972 goto end_nosignal;
973 }
fb83fe64
JD
974 case LTTNG_CONSUMER_DISCARDED_EVENTS:
975 {
66ab32be
JD
976 ssize_t ret;
977 uint64_t count;
fb83fe64
JD
978 struct lttng_consumer_channel *channel;
979 uint64_t id = msg.u.discarded_events.session_id;
980 uint64_t key = msg.u.discarded_events.channel_key;
981
e5742757
MD
982 DBG("Kernel consumer discarded events command for session id %"
983 PRIu64 ", channel key %" PRIu64, id, key);
984
fb83fe64
JD
985 channel = consumer_find_channel(key);
986 if (!channel) {
987 ERR("Kernel consumer discarded events channel %"
988 PRIu64 " not found", key);
66ab32be 989 count = 0;
e5742757 990 } else {
66ab32be 991 count = channel->discarded_events;
fb83fe64
JD
992 }
993
fb83fe64
JD
994 health_code_update();
995
996 /* Send back returned value to session daemon */
66ab32be 997 ret = lttcomm_send_unix_sock(sock, &count, sizeof(count));
fb83fe64
JD
998 if (ret < 0) {
999 PERROR("send discarded events");
1000 goto error_fatal;
1001 }
1002
1003 break;
1004 }
1005 case LTTNG_CONSUMER_LOST_PACKETS:
1006 {
66ab32be
JD
1007 ssize_t ret;
1008 uint64_t count;
fb83fe64
JD
1009 struct lttng_consumer_channel *channel;
1010 uint64_t id = msg.u.lost_packets.session_id;
1011 uint64_t key = msg.u.lost_packets.channel_key;
1012
e5742757
MD
1013 DBG("Kernel consumer lost packets command for session id %"
1014 PRIu64 ", channel key %" PRIu64, id, key);
1015
fb83fe64
JD
1016 channel = consumer_find_channel(key);
1017 if (!channel) {
1018 ERR("Kernel consumer lost packets channel %"
1019 PRIu64 " not found", key);
66ab32be 1020 count = 0;
e5742757 1021 } else {
66ab32be 1022 count = channel->lost_packets;
fb83fe64
JD
1023 }
1024
fb83fe64
JD
1025 health_code_update();
1026
1027 /* Send back returned value to session daemon */
66ab32be 1028 ret = lttcomm_send_unix_sock(sock, &count, sizeof(count));
fb83fe64
JD
1029 if (ret < 0) {
1030 PERROR("send lost packets");
1031 goto error_fatal;
1032 }
1033
1034 break;
1035 }
b3530820
JG
1036 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE:
1037 {
1038 int channel_monitor_pipe;
1039
1040 ret_code = LTTCOMM_CONSUMERD_SUCCESS;
1041 /* Successfully received the command's type. */
1042 ret = consumer_send_status_msg(sock, ret_code);
1043 if (ret < 0) {
1044 goto error_fatal;
1045 }
1046
1047 ret = lttcomm_recv_fds_unix_sock(sock, &channel_monitor_pipe,
1048 1);
1049 if (ret != sizeof(channel_monitor_pipe)) {
1050 ERR("Failed to receive channel monitor pipe");
1051 goto error_fatal;
1052 }
1053
1054 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe);
1055 ret = consumer_timer_thread_set_channel_monitor_pipe(
1056 channel_monitor_pipe);
1057 if (!ret) {
1058 int flags;
1059
1060 ret_code = LTTCOMM_CONSUMERD_SUCCESS;
1061 /* Set the pipe as non-blocking. */
1062 ret = fcntl(channel_monitor_pipe, F_GETFL, 0);
1063 if (ret == -1) {
1064 PERROR("fcntl get flags of the channel monitoring pipe");
1065 goto error_fatal;
1066 }
1067 flags = ret;
1068
1069 ret = fcntl(channel_monitor_pipe, F_SETFL,
1070 flags | O_NONBLOCK);
1071 if (ret == -1) {
1072 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
1073 goto error_fatal;
1074 }
1075 DBG("Channel monitor pipe set as non-blocking");
1076 } else {
1077 ret_code = LTTCOMM_CONSUMERD_ALREADY_SET;
1078 }
1079 ret = consumer_send_status_msg(sock, ret_code);
1080 if (ret < 0) {
1081 goto error_fatal;
1082 }
1083 break;
1084 }
b99a8d42
JD
1085 case LTTNG_CONSUMER_ROTATE_CHANNEL:
1086 {
92b7a7f8
MD
1087 struct lttng_consumer_channel *channel;
1088 uint64_t key = msg.u.rotate_channel.key;
b99a8d42 1089
92b7a7f8 1090 DBG("Consumer rotate channel %" PRIu64, key);
b99a8d42 1091
92b7a7f8
MD
1092 channel = consumer_find_channel(key);
1093 if (!channel) {
1094 ERR("Channel %" PRIu64 " not found", key);
1095 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
1096 } else {
1097 /*
1098 * Sample the rotate position of all the streams in this channel.
1099 */
1100 ret = lttng_consumer_rotate_channel(channel, key,
1101 msg.u.rotate_channel.pathname,
1102 msg.u.rotate_channel.relayd_id,
1103 msg.u.rotate_channel.metadata,
1104 msg.u.rotate_channel.new_chunk_id,
1105 ctx);
1106 if (ret < 0) {
1107 ERR("Rotate channel failed");
1108 ret_code = LTTCOMM_CONSUMERD_ROTATION_FAIL;
1109 }
b99a8d42 1110
92b7a7f8
MD
1111 health_code_update();
1112 }
b99a8d42
JD
1113 ret = consumer_send_status_msg(sock, ret_code);
1114 if (ret < 0) {
1115 /* Somehow, the session daemon is not responding anymore. */
1116 goto end_nosignal;
1117 }
92b7a7f8
MD
1118 if (channel) {
1119 /* Rotate the streams that are ready right now. */
1120 ret = lttng_consumer_rotate_ready_streams(
1121 channel, key, ctx);
1122 if (ret < 0) {
1123 ERR("Rotate ready streams failed");
1124 }
b99a8d42
JD
1125 }
1126
1127 break;
1128 }
00fb02ac
JD
1129 case LTTNG_CONSUMER_ROTATE_RENAME:
1130 {
1131 DBG("Consumer rename session %" PRIu64 " after rotation, old path = \"%s\", new path = \"%s\"",
1132 msg.u.rotate_rename.session_id,
1133 msg.u.rotate_rename.old_path,
1134 msg.u.rotate_rename.new_path);
1135 ret = lttng_consumer_rotate_rename(msg.u.rotate_rename.old_path,
1136 msg.u.rotate_rename.new_path,
1137 msg.u.rotate_rename.uid,
1138 msg.u.rotate_rename.gid,
1139 msg.u.rotate_rename.relayd_id);
1140 if (ret < 0) {
1141 ERR("Rotate rename failed");
92b7a7f8 1142 ret_code = LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED;
00fb02ac
JD
1143 }
1144
1145 health_code_update();
1146
1147 ret = consumer_send_status_msg(sock, ret_code);
1148 if (ret < 0) {
1149 /* Somehow, the session daemon is not responding anymore. */
1150 goto end_nosignal;
1151 }
1152 break;
1153 }
92816cc3 1154 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL:
d88744a4 1155 {
19990ed5 1156 int pending;
d88744a4
JD
1157 uint32_t pending_reply;
1158
92816cc3
JG
1159 DBG("Perform local check of pending rotation for session id %" PRIu64,
1160 msg.u.check_rotation_pending_local.session_id);
1161 pending = lttng_consumer_check_rotation_pending_local(
1162 msg.u.check_rotation_pending_local.session_id,
1163 msg.u.check_rotation_pending_local.chunk_id);
19990ed5 1164 if (pending < 0) {
92816cc3 1165 ERR("Local rotation pending check failed with code %i", pending);
92b7a7f8 1166 ret_code = LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED;
d88744a4 1167 } else {
19990ed5 1168 pending_reply = !!pending;
d88744a4
JD
1169 }
1170
1171 health_code_update();
1172
1173 ret = consumer_send_status_msg(sock, ret_code);
1174 if (ret < 0) {
1175 /* Somehow, the session daemon is not responding anymore. */
1176 goto end_nosignal;
1177 }
1178
19990ed5
JG
1179 if (pending < 0) {
1180 /*
1181 * An error occured while running the command;
1182 * don't send the 'pending' flag as the sessiond
1183 * will not read it.
1184 */
1185 break;
1186 }
1187
d88744a4
JD
1188 /* Send back returned value to session daemon */
1189 ret = lttcomm_send_unix_sock(sock, &pending_reply,
1190 sizeof(pending_reply));
1191 if (ret < 0) {
92816cc3
JG
1192 PERROR("Failed to send rotation pending return code");
1193 goto error_fatal;
1194 }
1195 break;
1196 }
1197 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY:
1198 {
1199 int pending;
1200 uint32_t pending_reply;
1201
1202 DBG("Perform relayd check of pending rotation for session id %" PRIu64,
1203 msg.u.check_rotation_pending_relay.session_id);
1204 pending = lttng_consumer_check_rotation_pending_relay(
1205 msg.u.check_rotation_pending_relay.session_id,
1206 msg.u.check_rotation_pending_relay.relayd_id,
1207 msg.u.check_rotation_pending_relay.chunk_id);
1208 if (pending < 0) {
1209 ERR("Relayd rotation pending check failed with code %i", pending);
92b7a7f8 1210 ret_code = LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED;
92816cc3
JG
1211 } else {
1212 pending_reply = !!pending;
1213 }
1214
1215 health_code_update();
1216
1217 ret = consumer_send_status_msg(sock, ret_code);
1218 if (ret < 0) {
1219 /* Somehow, the session daemon is not responding anymore. */
1220 goto end_nosignal;
1221 }
1222
1223 if (pending < 0) {
1224 /*
1225 * An error occured while running the command;
1226 * don't send the 'pending' flag as the sessiond
1227 * will not read it.
1228 */
1229 break;
1230 }
1231
1232 /* Send back returned value to session daemon */
1233 ret = lttcomm_send_unix_sock(sock, &pending_reply,
1234 sizeof(pending_reply));
1235 if (ret < 0) {
1236 PERROR("Failed to send rotation pending return code");
d88744a4
JD
1237 goto error_fatal;
1238 }
1239 break;
1240 }
a1ae2ea5
JD
1241 case LTTNG_CONSUMER_MKDIR:
1242 {
1243 DBG("Consumer mkdir %s in session %" PRIu64,
1244 msg.u.mkdir.path,
1245 msg.u.mkdir.session_id);
1246 ret = lttng_consumer_mkdir(msg.u.mkdir.path,
1247 msg.u.mkdir.uid,
1248 msg.u.mkdir.gid,
1249 msg.u.mkdir.relayd_id);
1250 if (ret < 0) {
1251 ERR("consumer mkdir failed");
92b7a7f8 1252 ret_code = LTTCOMM_CONSUMERD_MKDIR_FAILED;
a1ae2ea5
JD
1253 }
1254
1255 health_code_update();
1256
1257 ret = consumer_send_status_msg(sock, ret_code);
1258 if (ret < 0) {
1259 /* Somehow, the session daemon is not responding anymore. */
1260 goto end_nosignal;
1261 }
1262 break;
1263 }
3bd1e081 1264 default:
3f8e211f 1265 goto end_nosignal;
3bd1e081 1266 }
3f8e211f 1267
3bd1e081 1268end_nosignal:
b0b335c8 1269 rcu_read_unlock();
4cbc1a04
DG
1270
1271 /*
1272 * Return 1 to indicate success since the 0 value can be a socket
1273 * shutdown during the recv() or send() call.
1274 */
9ce5646a 1275 health_code_update();
4cbc1a04 1276 return 1;
1803a064
MD
1277
1278error_fatal:
1279 rcu_read_unlock();
1280 /* This will issue a consumer stop. */
1281 return -1;
3bd1e081 1282}
d41f73b7 1283
309167d2
JD
1284/*
1285 * Populate index values of a kernel stream. Values are set in big endian order.
1286 *
1287 * Return 0 on success or else a negative value.
1288 */
50adc264 1289static int get_index_values(struct ctf_packet_index *index, int infd)
309167d2
JD
1290{
1291 int ret;
1292
1293 ret = kernctl_get_timestamp_begin(infd, &index->timestamp_begin);
1294 if (ret < 0) {
1295 PERROR("kernctl_get_timestamp_begin");
1296 goto error;
1297 }
1298 index->timestamp_begin = htobe64(index->timestamp_begin);
1299
1300 ret = kernctl_get_timestamp_end(infd, &index->timestamp_end);
1301 if (ret < 0) {
1302 PERROR("kernctl_get_timestamp_end");
1303 goto error;
1304 }
1305 index->timestamp_end = htobe64(index->timestamp_end);
1306
1307 ret = kernctl_get_events_discarded(infd, &index->events_discarded);
1308 if (ret < 0) {
1309 PERROR("kernctl_get_events_discarded");
1310 goto error;
1311 }
1312 index->events_discarded = htobe64(index->events_discarded);
1313
1314 ret = kernctl_get_content_size(infd, &index->content_size);
1315 if (ret < 0) {
1316 PERROR("kernctl_get_content_size");
1317 goto error;
1318 }
1319 index->content_size = htobe64(index->content_size);
1320
1321 ret = kernctl_get_packet_size(infd, &index->packet_size);
1322 if (ret < 0) {
1323 PERROR("kernctl_get_packet_size");
1324 goto error;
1325 }
1326 index->packet_size = htobe64(index->packet_size);
1327
1328 ret = kernctl_get_stream_id(infd, &index->stream_id);
1329 if (ret < 0) {
1330 PERROR("kernctl_get_stream_id");
1331 goto error;
1332 }
1333 index->stream_id = htobe64(index->stream_id);
1334
234cd636
JD
1335 ret = kernctl_get_instance_id(infd, &index->stream_instance_id);
1336 if (ret < 0) {
f0b03c22
MD
1337 if (ret == -ENOTTY) {
1338 /* Command not implemented by lttng-modules. */
1339 index->stream_instance_id = -1ULL;
f0b03c22
MD
1340 } else {
1341 PERROR("kernctl_get_instance_id");
1342 goto error;
1343 }
234cd636
JD
1344 }
1345 index->stream_instance_id = htobe64(index->stream_instance_id);
1346
1347 ret = kernctl_get_sequence_number(infd, &index->packet_seq_num);
1348 if (ret < 0) {
f0b03c22
MD
1349 if (ret == -ENOTTY) {
1350 /* Command not implemented by lttng-modules. */
1351 index->packet_seq_num = -1ULL;
1352 ret = 0;
1353 } else {
1354 PERROR("kernctl_get_sequence_number");
1355 goto error;
1356 }
234cd636
JD
1357 }
1358 index->packet_seq_num = htobe64(index->packet_seq_num);
1359
309167d2
JD
1360error:
1361 return ret;
1362}
94d49140
JD
1363/*
1364 * Sync metadata meaning request them to the session daemon and snapshot to the
1365 * metadata thread can consumer them.
1366 *
1367 * Metadata stream lock MUST be acquired.
1368 *
1369 * Return 0 if new metadatda is available, EAGAIN if the metadata stream
1370 * is empty or a negative value on error.
1371 */
1372int lttng_kconsumer_sync_metadata(struct lttng_consumer_stream *metadata)
1373{
1374 int ret;
1375
1376 assert(metadata);
1377
1378 ret = kernctl_buffer_flush(metadata->wait_fd);
1379 if (ret < 0) {
1380 ERR("Failed to flush kernel stream");
1381 goto end;
1382 }
1383
1384 ret = kernctl_snapshot(metadata->wait_fd);
1385 if (ret < 0) {
32af2c95 1386 if (ret != -EAGAIN) {
94d49140
JD
1387 ERR("Sync metadata, taking kernel snapshot failed.");
1388 goto end;
1389 }
1390 DBG("Sync metadata, no new kernel metadata");
1391 /* No new metadata, exit. */
1392 ret = ENODATA;
1393 goto end;
1394 }
1395
1396end:
1397 return ret;
1398}
309167d2 1399
fb83fe64
JD
1400static
1401int update_stream_stats(struct lttng_consumer_stream *stream)
1402{
1403 int ret;
1404 uint64_t seq, discarded;
1405
1406 ret = kernctl_get_sequence_number(stream->wait_fd, &seq);
1407 if (ret < 0) {
f0b03c22
MD
1408 if (ret == -ENOTTY) {
1409 /* Command not implemented by lttng-modules. */
1410 seq = -1ULL;
f0b03c22
MD
1411 } else {
1412 PERROR("kernctl_get_sequence_number");
1413 goto end;
1414 }
fb83fe64
JD
1415 }
1416
1417 /*
1418 * Start the sequence when we extract the first packet in case we don't
1419 * start at 0 (for example if a consumer is not connected to the
1420 * session immediately after the beginning).
1421 */
1422 if (stream->last_sequence_number == -1ULL) {
1423 stream->last_sequence_number = seq;
1424 } else if (seq > stream->last_sequence_number) {
1425 stream->chan->lost_packets += seq -
1426 stream->last_sequence_number - 1;
1427 } else {
1428 /* seq <= last_sequence_number */
1429 ERR("Sequence number inconsistent : prev = %" PRIu64
1430 ", current = %" PRIu64,
1431 stream->last_sequence_number, seq);
1432 ret = -1;
1433 goto end;
1434 }
1435 stream->last_sequence_number = seq;
1436
1437 ret = kernctl_get_events_discarded(stream->wait_fd, &discarded);
1438 if (ret < 0) {
1439 PERROR("kernctl_get_events_discarded");
1440 goto end;
1441 }
1442 if (discarded < stream->last_discarded_events) {
1443 /*
83f4233d
MJ
1444 * Overflow has occurred. We assume only one wrap-around
1445 * has occurred.
fb83fe64
JD
1446 */
1447 stream->chan->discarded_events += (1ULL << (CAA_BITS_PER_LONG - 1)) -
1448 stream->last_discarded_events + discarded;
1449 } else {
1450 stream->chan->discarded_events += discarded -
1451 stream->last_discarded_events;
1452 }
1453 stream->last_discarded_events = discarded;
1454 ret = 0;
1455
1456end:
1457 return ret;
1458}
1459
93ec662e
JD
1460/*
1461 * Check if the local version of the metadata stream matches with the version
1462 * of the metadata stream in the kernel. If it was updated, set the reset flag
1463 * on the stream.
1464 */
1465static
1466int metadata_stream_check_version(int infd, struct lttng_consumer_stream *stream)
1467{
1468 int ret;
1469 uint64_t cur_version;
1470
1471 ret = kernctl_get_metadata_version(infd, &cur_version);
1472 if (ret < 0) {
f0b03c22
MD
1473 if (ret == -ENOTTY) {
1474 /*
1475 * LTTng-modules does not implement this
1476 * command.
1477 */
1478 ret = 0;
1479 goto end;
1480 }
93ec662e
JD
1481 ERR("Failed to get the metadata version");
1482 goto end;
1483 }
1484
1485 if (stream->metadata_version == cur_version) {
1486 ret = 0;
1487 goto end;
1488 }
1489
1490 DBG("New metadata version detected");
1491 stream->metadata_version = cur_version;
1492 stream->reset_metadata_flag = 1;
1493 ret = 0;
1494
1495end:
1496 return ret;
1497}
1498
d41f73b7
MD
1499/*
1500 * Consume data on a file descriptor and write it on a trace file.
1501 */
4078b776 1502ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
02d02e31 1503 struct lttng_consumer_local_data *ctx, bool *rotated)
d41f73b7 1504{
1d4dfdef 1505 unsigned long len, subbuf_size, padding;
02d02e31 1506 int err, write_index = 1, rotation_ret;
4078b776 1507 ssize_t ret = 0;
d41f73b7 1508 int infd = stream->wait_fd;
50adc264 1509 struct ctf_packet_index index;
d41f73b7
MD
1510
1511 DBG("In read_subbuffer (infd : %d)", infd);
309167d2 1512
02d02e31
JD
1513 /*
1514 * If the stream was flagged to be ready for rotation before we extract the
1515 * next packet, rotate it now.
1516 */
1517 if (stream->rotate_ready) {
1518 DBG("Rotate stream before extracting data");
1519 rotation_ret = lttng_consumer_rotate_stream(ctx, stream, rotated);
1520 if (rotation_ret < 0) {
1521 ERR("Stream rotation error");
1522 ret = -1;
1523 goto error;
1524 }
1525 }
1526
d41f73b7
MD
1527 /* Get the next subbuffer */
1528 err = kernctl_get_next_subbuf(infd);
1529 if (err != 0) {
d41f73b7
MD
1530 /*
1531 * This is a debug message even for single-threaded consumer,
1532 * because poll() have more relaxed criterions than get subbuf,
1533 * so get_subbuf may fail for short race windows where poll()
1534 * would issue wakeups.
1535 */
1536 DBG("Reserving sub buffer failed (everything is normal, "
1537 "it is due to concurrency)");
32af2c95 1538 ret = err;
02d02e31 1539 goto error;
d41f73b7
MD
1540 }
1541
1d4dfdef
DG
1542 /* Get the full subbuffer size including padding */
1543 err = kernctl_get_padded_subbuf_size(infd, &len);
1544 if (err != 0) {
5a510c9f 1545 PERROR("Getting sub-buffer len failed.");
8265f19e
MD
1546 err = kernctl_put_subbuf(infd);
1547 if (err != 0) {
32af2c95 1548 if (err == -EFAULT) {
5a510c9f 1549 PERROR("Error in unreserving sub buffer\n");
32af2c95 1550 } else if (err == -EIO) {
8265f19e 1551 /* Should never happen with newer LTTng versions */
5a510c9f 1552 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
8265f19e 1553 }
32af2c95 1554 ret = err;
02d02e31 1555 goto error;
8265f19e 1556 }
32af2c95 1557 ret = err;
02d02e31 1558 goto error;
1d4dfdef
DG
1559 }
1560
1c20f0e2 1561 if (!stream->metadata_flag) {
309167d2
JD
1562 ret = get_index_values(&index, infd);
1563 if (ret < 0) {
8265f19e
MD
1564 err = kernctl_put_subbuf(infd);
1565 if (err != 0) {
32af2c95 1566 if (err == -EFAULT) {
5a510c9f 1567 PERROR("Error in unreserving sub buffer\n");
32af2c95 1568 } else if (err == -EIO) {
8265f19e 1569 /* Should never happen with newer LTTng versions */
5a510c9f 1570 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
8265f19e 1571 }
32af2c95 1572 ret = err;
02d02e31 1573 goto error;
8265f19e 1574 }
02d02e31 1575 goto error;
309167d2 1576 }
fb83fe64
JD
1577 ret = update_stream_stats(stream);
1578 if (ret < 0) {
7b87473d
MD
1579 err = kernctl_put_subbuf(infd);
1580 if (err != 0) {
1581 if (err == -EFAULT) {
1582 PERROR("Error in unreserving sub buffer\n");
1583 } else if (err == -EIO) {
1584 /* Should never happen with newer LTTng versions */
1585 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1586 }
1587 ret = err;
02d02e31 1588 goto error;
7b87473d 1589 }
02d02e31 1590 goto error;
fb83fe64 1591 }
1c20f0e2
JD
1592 } else {
1593 write_index = 0;
93ec662e
JD
1594 ret = metadata_stream_check_version(infd, stream);
1595 if (ret < 0) {
7b87473d
MD
1596 err = kernctl_put_subbuf(infd);
1597 if (err != 0) {
1598 if (err == -EFAULT) {
1599 PERROR("Error in unreserving sub buffer\n");
1600 } else if (err == -EIO) {
1601 /* Should never happen with newer LTTng versions */
1602 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1603 }
1604 ret = err;
02d02e31 1605 goto error;
7b87473d 1606 }
02d02e31 1607 goto error;
93ec662e 1608 }
309167d2
JD
1609 }
1610
ffe60014 1611 switch (stream->chan->output) {
07b86b52 1612 case CONSUMER_CHANNEL_SPLICE:
1d4dfdef
DG
1613 /*
1614 * XXX: The lttng-modules splice "actor" does not handle copying
1615 * partial pages hence only using the subbuffer size without the
1616 * padding makes the splice fail.
1617 */
1618 subbuf_size = len;
1619 padding = 0;
1620
1621 /* splice the subbuffer to the tracefile */
91dfef6e 1622 ret = lttng_consumer_on_read_subbuffer_splice(ctx, stream, subbuf_size,
309167d2 1623 padding, &index);
91dfef6e
DG
1624 /*
1625 * XXX: Splice does not support network streaming so the return value
1626 * is simply checked against subbuf_size and not like the mmap() op.
1627 */
1d4dfdef
DG
1628 if (ret != subbuf_size) {
1629 /*
1630 * display the error but continue processing to try
1631 * to release the subbuffer
1632 */
1633 ERR("Error splicing to tracefile (ret: %zd != len: %lu)",
1634 ret, subbuf_size);
309167d2 1635 write_index = 0;
1d4dfdef
DG
1636 }
1637 break;
07b86b52 1638 case CONSUMER_CHANNEL_MMAP:
1d4dfdef
DG
1639 /* Get subbuffer size without padding */
1640 err = kernctl_get_subbuf_size(infd, &subbuf_size);
1641 if (err != 0) {
5a510c9f 1642 PERROR("Getting sub-buffer len failed.");
8265f19e
MD
1643 err = kernctl_put_subbuf(infd);
1644 if (err != 0) {
32af2c95 1645 if (err == -EFAULT) {
5a510c9f 1646 PERROR("Error in unreserving sub buffer\n");
32af2c95 1647 } else if (err == -EIO) {
8265f19e 1648 /* Should never happen with newer LTTng versions */
5a510c9f 1649 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
8265f19e 1650 }
32af2c95 1651 ret = err;
02d02e31 1652 goto error;
8265f19e 1653 }
32af2c95 1654 ret = err;
02d02e31 1655 goto error;
1d4dfdef 1656 }
47e81c02 1657
1d4dfdef
DG
1658 /* Make sure the tracer is not gone mad on us! */
1659 assert(len >= subbuf_size);
1660
1661 padding = len - subbuf_size;
1662
1663 /* write the subbuffer to the tracefile */
91dfef6e 1664 ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, subbuf_size,
309167d2 1665 padding, &index);
91dfef6e
DG
1666 /*
1667 * The mmap operation should write subbuf_size amount of data when
1668 * network streaming or the full padding (len) size when we are _not_
1669 * streaming.
1670 */
d88aee68
DG
1671 if ((ret != subbuf_size && stream->net_seq_idx != (uint64_t) -1ULL) ||
1672 (ret != len && stream->net_seq_idx == (uint64_t) -1ULL)) {
1d4dfdef 1673 /*
91dfef6e 1674 * Display the error but continue processing to try to release the
2336629e
DG
1675 * subbuffer. This is a DBG statement since this is possible to
1676 * happen without being a critical error.
1d4dfdef 1677 */
2336629e 1678 DBG("Error writing to tracefile "
91dfef6e
DG
1679 "(ret: %zd != len: %lu != subbuf_size: %lu)",
1680 ret, len, subbuf_size);
309167d2 1681 write_index = 0;
1d4dfdef
DG
1682 }
1683 break;
1684 default:
1685 ERR("Unknown output method");
56591bac 1686 ret = -EPERM;
d41f73b7
MD
1687 }
1688
1689 err = kernctl_put_next_subbuf(infd);
1690 if (err != 0) {
32af2c95 1691 if (err == -EFAULT) {
5a510c9f 1692 PERROR("Error in unreserving sub buffer\n");
32af2c95 1693 } else if (err == -EIO) {
d41f73b7 1694 /* Should never happen with newer LTTng versions */
5a510c9f 1695 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
d41f73b7 1696 }
32af2c95 1697 ret = err;
02d02e31 1698 goto error;
d41f73b7
MD
1699 }
1700
309167d2 1701 /* Write index if needed. */
1c20f0e2 1702 if (!write_index) {
02d02e31 1703 goto rotate;
1c20f0e2
JD
1704 }
1705
94d49140
JD
1706 if (stream->chan->live_timer_interval && !stream->metadata_flag) {
1707 /*
1708 * In live, block until all the metadata is sent.
1709 */
c585821b
MD
1710 pthread_mutex_lock(&stream->metadata_timer_lock);
1711 assert(!stream->missed_metadata_flush);
1712 stream->waiting_on_metadata = true;
1713 pthread_mutex_unlock(&stream->metadata_timer_lock);
1714
94d49140 1715 err = consumer_stream_sync_metadata(ctx, stream->session_id);
c585821b
MD
1716
1717 pthread_mutex_lock(&stream->metadata_timer_lock);
1718 stream->waiting_on_metadata = false;
1719 if (stream->missed_metadata_flush) {
1720 stream->missed_metadata_flush = false;
1721 pthread_mutex_unlock(&stream->metadata_timer_lock);
1722 (void) consumer_flush_kernel_index(stream);
1723 } else {
1724 pthread_mutex_unlock(&stream->metadata_timer_lock);
1725 }
94d49140 1726 if (err < 0) {
02d02e31 1727 goto error;
94d49140
JD
1728 }
1729 }
1730
1c20f0e2
JD
1731 err = consumer_stream_write_index(stream, &index);
1732 if (err < 0) {
02d02e31 1733 goto error;
309167d2
JD
1734 }
1735
02d02e31
JD
1736rotate:
1737 /*
1738 * After extracting the packet, we check if the stream is now ready to be
1739 * rotated and perform the action immediately.
1740 */
1741 rotation_ret = lttng_consumer_stream_is_rotate_ready(stream);
1742 if (rotation_ret == 1) {
1743 rotation_ret = lttng_consumer_rotate_stream(ctx, stream, rotated);
1744 if (rotation_ret < 0) {
1745 ERR("Stream rotation error");
1746 ret = -1;
1747 goto error;
1748 }
1749 } else if (rotation_ret < 0) {
1750 ERR("Checking if stream is ready to rotate");
1751 ret = -1;
1752 goto error;
1753 }
1754
1755error:
d41f73b7
MD
1756 return ret;
1757}
1758
1759int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream)
1760{
1761 int ret;
ffe60014
DG
1762
1763 assert(stream);
1764
2bba9e53
DG
1765 /*
1766 * Don't create anything if this is set for streaming or should not be
1767 * monitored.
1768 */
1769 if (stream->net_seq_idx == (uint64_t) -1ULL && stream->chan->monitor) {
fe4477ee
JD
1770 ret = utils_create_stream_file(stream->chan->pathname, stream->name,
1771 stream->chan->tracefile_size, stream->tracefile_count_current,
309167d2 1772 stream->uid, stream->gid, NULL);
fe4477ee
JD
1773 if (ret < 0) {
1774 goto error;
1775 }
1776 stream->out_fd = ret;
1777 stream->tracefile_size_current = 0;
309167d2
JD
1778
1779 if (!stream->metadata_flag) {
f8f3885c
MD
1780 struct lttng_index_file *index_file;
1781
1782 index_file = lttng_index_file_create(stream->chan->pathname,
309167d2
JD
1783 stream->name, stream->uid, stream->gid,
1784 stream->chan->tracefile_size,
f8f3885c
MD
1785 stream->tracefile_count_current,
1786 CTF_INDEX_MAJOR, CTF_INDEX_MINOR);
1787 if (!index_file) {
309167d2
JD
1788 goto error;
1789 }
1b47ae58 1790 assert(!stream->index_file);
f8f3885c 1791 stream->index_file = index_file;
309167d2 1792 }
ffe60014 1793 }
d41f73b7 1794
d41f73b7
MD
1795 if (stream->output == LTTNG_EVENT_MMAP) {
1796 /* get the len of the mmap region */
1797 unsigned long mmap_len;
1798
1799 ret = kernctl_get_mmap_len(stream->wait_fd, &mmap_len);
1800 if (ret != 0) {
ffe60014 1801 PERROR("kernctl_get_mmap_len");
d41f73b7
MD
1802 goto error_close_fd;
1803 }
1804 stream->mmap_len = (size_t) mmap_len;
1805
ffe60014
DG
1806 stream->mmap_base = mmap(NULL, stream->mmap_len, PROT_READ,
1807 MAP_PRIVATE, stream->wait_fd, 0);
d41f73b7 1808 if (stream->mmap_base == MAP_FAILED) {
ffe60014 1809 PERROR("Error mmaping");
d41f73b7
MD
1810 ret = -1;
1811 goto error_close_fd;
1812 }
1813 }
1814
1815 /* we return 0 to let the library handle the FD internally */
1816 return 0;
1817
1818error_close_fd:
2f225ce2 1819 if (stream->out_fd >= 0) {
d41f73b7
MD
1820 int err;
1821
1822 err = close(stream->out_fd);
1823 assert(!err);
2f225ce2 1824 stream->out_fd = -1;
d41f73b7
MD
1825 }
1826error:
1827 return ret;
1828}
1829
ca22feea
DG
1830/*
1831 * Check if data is still being extracted from the buffers for a specific
4e9a4686
DG
1832 * stream. Consumer data lock MUST be acquired before calling this function
1833 * and the stream lock.
ca22feea 1834 *
6d805429 1835 * Return 1 if the traced data are still getting read else 0 meaning that the
ca22feea
DG
1836 * data is available for trace viewer reading.
1837 */
6d805429 1838int lttng_kconsumer_data_pending(struct lttng_consumer_stream *stream)
ca22feea
DG
1839{
1840 int ret;
1841
1842 assert(stream);
1843
873b9e9a
MD
1844 if (stream->endpoint_status != CONSUMER_ENDPOINT_ACTIVE) {
1845 ret = 0;
1846 goto end;
1847 }
1848
ca22feea
DG
1849 ret = kernctl_get_next_subbuf(stream->wait_fd);
1850 if (ret == 0) {
1851 /* There is still data so let's put back this subbuffer. */
1852 ret = kernctl_put_subbuf(stream->wait_fd);
1853 assert(ret == 0);
6d805429 1854 ret = 1; /* Data is pending */
4e9a4686 1855 goto end;
ca22feea
DG
1856 }
1857
6d805429
DG
1858 /* Data is NOT pending and ready to be read. */
1859 ret = 0;
ca22feea 1860
6efae65e
DG
1861end:
1862 return ret;
ca22feea 1863}
This page took 0.151349 seconds and 4 git commands to generate.