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