Commit | Line | Data |
---|---|---|
3bd1e081 MD |
1 | /* |
2 | * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca> | |
3 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | * | |
d14d33bf AM |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License, version 2 only, | |
7 | * as published by the Free Software Foundation. | |
3bd1e081 MD |
8 | * |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
d14d33bf AM |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
3bd1e081 MD |
17 | */ |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <assert.h> | |
3bd1e081 MD |
21 | #include <poll.h> |
22 | #include <pthread.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include <sys/mman.h> | |
26 | #include <sys/socket.h> | |
27 | #include <sys/types.h> | |
77c7c900 | 28 | #include <inttypes.h> |
3bd1e081 | 29 | #include <unistd.h> |
dbb5dfe6 | 30 | #include <sys/stat.h> |
3bd1e081 | 31 | |
990570ed | 32 | #include <common/common.h> |
10a8a223 | 33 | #include <common/kernel-ctl/kernel-ctl.h> |
10a8a223 | 34 | #include <common/sessiond-comm/sessiond-comm.h> |
00e2e675 | 35 | #include <common/sessiond-comm/relayd.h> |
dbb5dfe6 | 36 | #include <common/compat/fcntl.h> |
acdb9057 | 37 | #include <common/pipe.h> |
00e2e675 | 38 | #include <common/relayd/relayd.h> |
fe4477ee | 39 | #include <common/utils.h> |
07b86b52 | 40 | #include <common/consumer-stream.h> |
0857097f | 41 | |
10a8a223 | 42 | #include "kernel-consumer.h" |
3bd1e081 MD |
43 | |
44 | extern struct lttng_consumer_global_data consumer_data; | |
45 | extern int consumer_poll_timeout; | |
46 | extern volatile int consumer_quit; | |
47 | ||
3bd1e081 MD |
48 | /* |
49 | * Take a snapshot for a specific fd | |
50 | * | |
51 | * Returns 0 on success, < 0 on error | |
52 | */ | |
ffe60014 | 53 | int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream *stream) |
3bd1e081 MD |
54 | { |
55 | int ret = 0; | |
56 | int infd = stream->wait_fd; | |
57 | ||
58 | ret = kernctl_snapshot(infd); | |
59 | if (ret != 0) { | |
3bd1e081 | 60 | perror("Getting sub-buffer snapshot."); |
56591bac | 61 | ret = -errno; |
3bd1e081 MD |
62 | } |
63 | ||
64 | return ret; | |
65 | } | |
66 | ||
67 | /* | |
68 | * Get the produced position | |
69 | * | |
70 | * Returns 0 on success, < 0 on error | |
71 | */ | |
ffe60014 | 72 | int lttng_kconsumer_get_produced_snapshot(struct lttng_consumer_stream *stream, |
3bd1e081 MD |
73 | unsigned long *pos) |
74 | { | |
75 | int ret; | |
76 | int infd = stream->wait_fd; | |
77 | ||
78 | ret = kernctl_snapshot_get_produced(infd, pos); | |
79 | if (ret != 0) { | |
3bd1e081 | 80 | perror("kernctl_snapshot_get_produced"); |
56591bac | 81 | ret = -errno; |
3bd1e081 MD |
82 | } |
83 | ||
84 | return ret; | |
85 | } | |
86 | ||
07b86b52 JD |
87 | /* |
88 | * Get the consumerd position | |
89 | * | |
90 | * Returns 0 on success, < 0 on error | |
91 | */ | |
92 | int lttng_kconsumer_get_consumed_snapshot(struct lttng_consumer_stream *stream, | |
93 | unsigned long *pos) | |
94 | { | |
95 | int ret; | |
96 | int infd = stream->wait_fd; | |
97 | ||
98 | ret = kernctl_snapshot_get_consumed(infd, pos); | |
99 | if (ret != 0) { | |
07b86b52 | 100 | perror("kernctl_snapshot_get_consumed"); |
56591bac | 101 | ret = -errno; |
07b86b52 JD |
102 | } |
103 | ||
104 | return ret; | |
105 | } | |
106 | ||
07b86b52 JD |
107 | /* |
108 | * Take a snapshot of all the stream of a channel | |
109 | * | |
110 | * Returns 0 on success, < 0 on error | |
111 | */ | |
112 | int lttng_kconsumer_snapshot_channel(uint64_t key, char *path, | |
5c786ded JD |
113 | uint64_t relayd_id, uint64_t max_stream_size, |
114 | struct lttng_consumer_local_data *ctx) | |
07b86b52 JD |
115 | { |
116 | int ret; | |
117 | unsigned long consumed_pos, produced_pos; | |
118 | struct lttng_consumer_channel *channel; | |
119 | struct lttng_consumer_stream *stream; | |
120 | ||
6a00837f | 121 | DBG("Kernel consumer snapshot channel %" PRIu64, key); |
07b86b52 JD |
122 | |
123 | rcu_read_lock(); | |
124 | ||
125 | channel = consumer_find_channel(key); | |
126 | if (!channel) { | |
6a00837f | 127 | ERR("No channel found for key %" PRIu64, key); |
07b86b52 JD |
128 | ret = -1; |
129 | goto end; | |
130 | } | |
131 | ||
132 | /* Splice is not supported yet for channel snapshot. */ | |
133 | if (channel->output != CONSUMER_CHANNEL_MMAP) { | |
134 | ERR("Unsupported output %d", channel->output); | |
135 | ret = -1; | |
136 | goto end; | |
137 | } | |
138 | ||
10a50311 | 139 | cds_list_for_each_entry(stream, &channel->streams.head, send_node) { |
07b86b52 JD |
140 | /* |
141 | * Lock stream because we are about to change its state. | |
142 | */ | |
143 | pthread_mutex_lock(&stream->lock); | |
144 | ||
29decac3 DG |
145 | /* |
146 | * Assign the received relayd ID so we can use it for streaming. The streams | |
147 | * are not visible to anyone so this is OK to change it. | |
148 | */ | |
07b86b52 JD |
149 | stream->net_seq_idx = relayd_id; |
150 | channel->relayd_id = relayd_id; | |
151 | if (relayd_id != (uint64_t) -1ULL) { | |
10a50311 | 152 | ret = consumer_send_relayd_stream(stream, path); |
07b86b52 JD |
153 | if (ret < 0) { |
154 | ERR("sending stream to relayd"); | |
155 | goto end_unlock; | |
156 | } | |
07b86b52 JD |
157 | } else { |
158 | ret = utils_create_stream_file(path, stream->name, | |
10a50311 JD |
159 | stream->chan->tracefile_size, |
160 | stream->tracefile_count_current, | |
07b86b52 JD |
161 | stream->uid, stream->gid); |
162 | if (ret < 0) { | |
163 | ERR("utils_create_stream_file"); | |
164 | goto end_unlock; | |
165 | } | |
166 | ||
167 | stream->out_fd = ret; | |
168 | stream->tracefile_size_current = 0; | |
169 | ||
81ea21bf MD |
170 | DBG("Kernel consumer snapshot stream %s/%s (%" PRIu64 ")", |
171 | path, stream->name, stream->key); | |
07b86b52 JD |
172 | } |
173 | ||
174 | ret = kernctl_buffer_flush(stream->wait_fd); | |
175 | if (ret < 0) { | |
10a50311 | 176 | ERR("Failed to flush kernel stream"); |
56591bac | 177 | ret = -errno; |
07b86b52 JD |
178 | goto end_unlock; |
179 | } | |
180 | ||
181 | ret = lttng_kconsumer_take_snapshot(stream); | |
182 | if (ret < 0) { | |
183 | ERR("Taking kernel snapshot"); | |
184 | goto end_unlock; | |
185 | } | |
186 | ||
187 | ret = lttng_kconsumer_get_produced_snapshot(stream, &produced_pos); | |
188 | if (ret < 0) { | |
189 | ERR("Produced kernel snapshot position"); | |
190 | goto end_unlock; | |
191 | } | |
192 | ||
193 | ret = lttng_kconsumer_get_consumed_snapshot(stream, &consumed_pos); | |
194 | if (ret < 0) { | |
195 | ERR("Consumerd kernel snapshot position"); | |
196 | goto end_unlock; | |
197 | } | |
198 | ||
199 | if (stream->max_sb_size == 0) { | |
200 | ret = kernctl_get_max_subbuf_size(stream->wait_fd, | |
201 | &stream->max_sb_size); | |
202 | if (ret < 0) { | |
203 | ERR("Getting kernel max_sb_size"); | |
56591bac | 204 | ret = -errno; |
07b86b52 JD |
205 | goto end_unlock; |
206 | } | |
207 | } | |
208 | ||
5c786ded JD |
209 | /* |
210 | * The original value is sent back if max stream size is larger than | |
211 | * the possible size of the snapshot. Also, we asume that the session | |
212 | * daemon should never send a maximum stream size that is lower than | |
213 | * subbuffer size. | |
214 | */ | |
215 | consumed_pos = consumer_get_consumed_maxsize(consumed_pos, | |
216 | produced_pos, max_stream_size); | |
217 | ||
07b86b52 JD |
218 | while (consumed_pos < produced_pos) { |
219 | ssize_t read_len; | |
220 | unsigned long len, padded_len; | |
221 | ||
222 | DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos); | |
223 | ||
224 | ret = kernctl_get_subbuf(stream->wait_fd, &consumed_pos); | |
225 | if (ret < 0) { | |
226 | if (errno != EAGAIN) { | |
227 | PERROR("kernctl_get_subbuf snapshot"); | |
56591bac | 228 | ret = -errno; |
07b86b52 JD |
229 | goto end_unlock; |
230 | } | |
231 | DBG("Kernel consumer get subbuf failed. Skipping it."); | |
232 | consumed_pos += stream->max_sb_size; | |
233 | continue; | |
234 | } | |
235 | ||
236 | ret = kernctl_get_subbuf_size(stream->wait_fd, &len); | |
237 | if (ret < 0) { | |
238 | ERR("Snapshot kernctl_get_subbuf_size"); | |
56591bac | 239 | ret = -errno; |
29decac3 | 240 | goto error_put_subbuf; |
07b86b52 JD |
241 | } |
242 | ||
243 | ret = kernctl_get_padded_subbuf_size(stream->wait_fd, &padded_len); | |
244 | if (ret < 0) { | |
245 | ERR("Snapshot kernctl_get_padded_subbuf_size"); | |
56591bac | 246 | ret = -errno; |
29decac3 | 247 | goto error_put_subbuf; |
07b86b52 JD |
248 | } |
249 | ||
250 | read_len = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, len, | |
251 | padded_len - len); | |
252 | /* | |
29decac3 DG |
253 | * We write the padded len in local tracefiles but the data len |
254 | * when using a relay. Display the error but continue processing | |
255 | * to try to release the subbuffer. | |
07b86b52 JD |
256 | */ |
257 | if (relayd_id != (uint64_t) -1ULL) { | |
258 | if (read_len != len) { | |
259 | ERR("Error sending to the relay (ret: %zd != len: %lu)", | |
260 | read_len, len); | |
261 | } | |
262 | } else { | |
263 | if (read_len != padded_len) { | |
264 | ERR("Error writing to tracefile (ret: %zd != len: %lu)", | |
265 | read_len, padded_len); | |
266 | } | |
267 | } | |
268 | ||
269 | ret = kernctl_put_subbuf(stream->wait_fd); | |
270 | if (ret < 0) { | |
271 | ERR("Snapshot kernctl_put_subbuf"); | |
56591bac | 272 | ret = -errno; |
07b86b52 JD |
273 | goto end_unlock; |
274 | } | |
275 | consumed_pos += stream->max_sb_size; | |
276 | } | |
277 | ||
278 | if (relayd_id == (uint64_t) -1ULL) { | |
fdf9986c MD |
279 | if (stream->out_fd >= 0) { |
280 | ret = close(stream->out_fd); | |
281 | if (ret < 0) { | |
282 | PERROR("Kernel consumer snapshot close out_fd"); | |
283 | goto end_unlock; | |
284 | } | |
285 | stream->out_fd = -1; | |
07b86b52 | 286 | } |
07b86b52 JD |
287 | } else { |
288 | close_relayd_stream(stream); | |
289 | stream->net_seq_idx = (uint64_t) -1ULL; | |
290 | } | |
291 | pthread_mutex_unlock(&stream->lock); | |
292 | } | |
293 | ||
294 | /* All good! */ | |
295 | ret = 0; | |
296 | goto end; | |
297 | ||
29decac3 DG |
298 | error_put_subbuf: |
299 | ret = kernctl_put_subbuf(stream->wait_fd); | |
300 | if (ret < 0) { | |
56591bac | 301 | ret = -errno; |
29decac3 DG |
302 | ERR("Snapshot kernctl_put_subbuf error path"); |
303 | } | |
07b86b52 JD |
304 | end_unlock: |
305 | pthread_mutex_unlock(&stream->lock); | |
306 | end: | |
307 | rcu_read_unlock(); | |
308 | return ret; | |
309 | } | |
310 | ||
311 | /* | |
312 | * Read the whole metadata available for a snapshot. | |
313 | * | |
314 | * Returns 0 on success, < 0 on error | |
315 | */ | |
316 | int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path, | |
e2039c7a | 317 | uint64_t relayd_id, struct lttng_consumer_local_data *ctx) |
07b86b52 | 318 | { |
d771f832 DG |
319 | int ret, use_relayd = 0; |
320 | ssize_t ret_read; | |
07b86b52 JD |
321 | struct lttng_consumer_channel *metadata_channel; |
322 | struct lttng_consumer_stream *metadata_stream; | |
d771f832 DG |
323 | |
324 | assert(ctx); | |
07b86b52 JD |
325 | |
326 | DBG("Kernel consumer snapshot metadata with key %" PRIu64 " at path %s", | |
327 | key, path); | |
328 | ||
329 | rcu_read_lock(); | |
330 | ||
331 | metadata_channel = consumer_find_channel(key); | |
332 | if (!metadata_channel) { | |
d771f832 | 333 | ERR("Kernel snapshot metadata not found for key %" PRIu64, key); |
07b86b52 | 334 | ret = -1; |
d771f832 | 335 | goto error; |
07b86b52 JD |
336 | } |
337 | ||
338 | metadata_stream = metadata_channel->metadata_stream; | |
339 | assert(metadata_stream); | |
340 | ||
d771f832 | 341 | /* Flag once that we have a valid relayd for the stream. */ |
e2039c7a | 342 | if (relayd_id != (uint64_t) -1ULL) { |
d771f832 DG |
343 | use_relayd = 1; |
344 | } | |
345 | ||
346 | if (use_relayd) { | |
10a50311 | 347 | ret = consumer_send_relayd_stream(metadata_stream, path); |
e2039c7a | 348 | if (ret < 0) { |
d771f832 | 349 | goto error; |
e2039c7a | 350 | } |
e2039c7a JD |
351 | } else { |
352 | ret = utils_create_stream_file(path, metadata_stream->name, | |
353 | metadata_stream->chan->tracefile_size, | |
354 | metadata_stream->tracefile_count_current, | |
355 | metadata_stream->uid, metadata_stream->gid); | |
356 | if (ret < 0) { | |
d771f832 | 357 | goto error; |
e2039c7a JD |
358 | } |
359 | metadata_stream->out_fd = ret; | |
07b86b52 | 360 | } |
07b86b52 | 361 | |
d771f832 DG |
362 | do { |
363 | ret_read = lttng_kconsumer_read_subbuffer(metadata_stream, ctx); | |
364 | if (ret_read < 0) { | |
56591bac | 365 | if (ret_read != -EAGAIN) { |
6a00837f | 366 | ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)", |
d771f832 DG |
367 | ret_read); |
368 | goto error; | |
07b86b52 | 369 | } |
d771f832 | 370 | /* ret_read is negative at this point so we will exit the loop. */ |
07b86b52 JD |
371 | continue; |
372 | } | |
d771f832 | 373 | } while (ret_read >= 0); |
07b86b52 | 374 | |
d771f832 DG |
375 | if (use_relayd) { |
376 | close_relayd_stream(metadata_stream); | |
377 | metadata_stream->net_seq_idx = (uint64_t) -1ULL; | |
378 | } else { | |
fdf9986c MD |
379 | if (metadata_stream->out_fd >= 0) { |
380 | ret = close(metadata_stream->out_fd); | |
381 | if (ret < 0) { | |
382 | PERROR("Kernel consumer snapshot metadata close out_fd"); | |
383 | /* | |
384 | * Don't go on error here since the snapshot was successful at this | |
385 | * point but somehow the close failed. | |
386 | */ | |
387 | } | |
388 | metadata_stream->out_fd = -1; | |
e2039c7a | 389 | } |
e2039c7a JD |
390 | } |
391 | ||
07b86b52 | 392 | ret = 0; |
d771f832 | 393 | |
cf53a8a6 JD |
394 | cds_list_del(&metadata_stream->send_node); |
395 | consumer_stream_destroy(metadata_stream, NULL); | |
396 | metadata_channel->metadata_stream = NULL; | |
d771f832 | 397 | error: |
07b86b52 JD |
398 | rcu_read_unlock(); |
399 | return ret; | |
400 | } | |
401 | ||
1803a064 MD |
402 | /* |
403 | * Receive command from session daemon and process it. | |
404 | * | |
405 | * Return 1 on success else a negative value or 0. | |
406 | */ | |
3bd1e081 MD |
407 | int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, |
408 | int sock, struct pollfd *consumer_sockpoll) | |
409 | { | |
410 | ssize_t ret; | |
f50f23d9 | 411 | enum lttng_error_code ret_code = LTTNG_OK; |
3bd1e081 MD |
412 | struct lttcomm_consumer_msg msg; |
413 | ||
414 | ret = lttcomm_recv_unix_sock(sock, &msg, sizeof(msg)); | |
415 | if (ret != sizeof(msg)) { | |
1803a064 | 416 | if (ret > 0) { |
c6857fcf | 417 | lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_ERROR_RECV_CMD); |
1803a064 MD |
418 | ret = -1; |
419 | } | |
3bd1e081 MD |
420 | return ret; |
421 | } | |
422 | if (msg.cmd_type == LTTNG_CONSUMER_STOP) { | |
f50f23d9 DG |
423 | /* |
424 | * Notify the session daemon that the command is completed. | |
425 | * | |
426 | * On transport layer error, the function call will print an error | |
427 | * message so handling the returned code is a bit useless since we | |
428 | * return an error code anyway. | |
429 | */ | |
430 | (void) consumer_send_status_msg(sock, ret_code); | |
3bd1e081 MD |
431 | return -ENOENT; |
432 | } | |
433 | ||
b0b335c8 MD |
434 | /* relayd needs RCU read-side protection */ |
435 | rcu_read_lock(); | |
436 | ||
3bd1e081 | 437 | switch (msg.cmd_type) { |
00e2e675 DG |
438 | case LTTNG_CONSUMER_ADD_RELAYD_SOCKET: |
439 | { | |
f50f23d9 | 440 | /* Session daemon status message are handled in the following call. */ |
7735ef9e DG |
441 | ret = consumer_add_relayd_socket(msg.u.relayd_sock.net_index, |
442 | msg.u.relayd_sock.type, ctx, sock, consumer_sockpoll, | |
46e6455f | 443 | &msg.u.relayd_sock.sock, msg.u.relayd_sock.session_id); |
00e2e675 DG |
444 | goto end_nosignal; |
445 | } | |
3bd1e081 MD |
446 | case LTTNG_CONSUMER_ADD_CHANNEL: |
447 | { | |
448 | struct lttng_consumer_channel *new_channel; | |
e43c41c5 | 449 | int ret_recv; |
3bd1e081 | 450 | |
f50f23d9 DG |
451 | /* First send a status message before receiving the fds. */ |
452 | ret = consumer_send_status_msg(sock, ret_code); | |
453 | if (ret < 0) { | |
454 | /* Somehow, the session daemon is not responding anymore. */ | |
1803a064 | 455 | goto error_fatal; |
f50f23d9 | 456 | } |
d88aee68 | 457 | DBG("consumer_add_channel %" PRIu64, msg.u.channel.channel_key); |
3bd1e081 | 458 | new_channel = consumer_allocate_channel(msg.u.channel.channel_key, |
ffe60014 DG |
459 | msg.u.channel.session_id, msg.u.channel.pathname, |
460 | msg.u.channel.name, msg.u.channel.uid, msg.u.channel.gid, | |
1624d5b7 JD |
461 | msg.u.channel.relayd_id, msg.u.channel.output, |
462 | msg.u.channel.tracefile_size, | |
1950109e | 463 | msg.u.channel.tracefile_count, 0, |
2bba9e53 | 464 | msg.u.channel.monitor); |
3bd1e081 | 465 | if (new_channel == NULL) { |
f73fabfd | 466 | lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR); |
3bd1e081 MD |
467 | goto end_nosignal; |
468 | } | |
ffe60014 | 469 | new_channel->nb_init_stream_left = msg.u.channel.nb_init_streams; |
95a1109b JD |
470 | switch (msg.u.channel.output) { |
471 | case LTTNG_EVENT_SPLICE: | |
472 | new_channel->output = CONSUMER_CHANNEL_SPLICE; | |
473 | break; | |
474 | case LTTNG_EVENT_MMAP: | |
475 | new_channel->output = CONSUMER_CHANNEL_MMAP; | |
476 | break; | |
477 | default: | |
478 | ERR("Channel output unknown %d", msg.u.channel.output); | |
479 | goto end_nosignal; | |
480 | } | |
ffe60014 DG |
481 | |
482 | /* Translate and save channel type. */ | |
483 | switch (msg.u.channel.type) { | |
484 | case CONSUMER_CHANNEL_TYPE_DATA: | |
485 | case CONSUMER_CHANNEL_TYPE_METADATA: | |
486 | new_channel->type = msg.u.channel.type; | |
487 | break; | |
488 | default: | |
489 | assert(0); | |
490 | goto end_nosignal; | |
491 | }; | |
492 | ||
3bd1e081 | 493 | if (ctx->on_recv_channel != NULL) { |
e43c41c5 JD |
494 | ret_recv = ctx->on_recv_channel(new_channel); |
495 | if (ret_recv == 0) { | |
496 | ret = consumer_add_channel(new_channel, ctx); | |
497 | } else if (ret_recv < 0) { | |
3bd1e081 MD |
498 | goto end_nosignal; |
499 | } | |
500 | } else { | |
e43c41c5 | 501 | ret = consumer_add_channel(new_channel, ctx); |
3bd1e081 | 502 | } |
e43c41c5 JD |
503 | |
504 | /* If we received an error in add_channel, we need to report it. */ | |
821fffb2 | 505 | if (ret < 0) { |
1803a064 MD |
506 | ret = consumer_send_status_msg(sock, ret); |
507 | if (ret < 0) { | |
508 | goto error_fatal; | |
509 | } | |
e43c41c5 JD |
510 | goto end_nosignal; |
511 | } | |
512 | ||
3bd1e081 MD |
513 | goto end_nosignal; |
514 | } | |
515 | case LTTNG_CONSUMER_ADD_STREAM: | |
516 | { | |
dae10966 DG |
517 | int fd; |
518 | struct lttng_pipe *stream_pipe; | |
00e2e675 | 519 | struct lttng_consumer_stream *new_stream; |
ffe60014 | 520 | struct lttng_consumer_channel *channel; |
c80048c6 | 521 | int alloc_ret = 0; |
3bd1e081 | 522 | |
ffe60014 DG |
523 | /* |
524 | * Get stream's channel reference. Needed when adding the stream to the | |
525 | * global hash table. | |
526 | */ | |
527 | channel = consumer_find_channel(msg.u.stream.channel_key); | |
528 | if (!channel) { | |
529 | /* | |
530 | * We could not find the channel. Can happen if cpu hotplug | |
531 | * happens while tearing down. | |
532 | */ | |
d88aee68 | 533 | ERR("Unable to find channel key %" PRIu64, msg.u.stream.channel_key); |
ffe60014 DG |
534 | ret_code = LTTNG_ERR_KERN_CHAN_NOT_FOUND; |
535 | } | |
536 | ||
f50f23d9 DG |
537 | /* First send a status message before receiving the fds. */ |
538 | ret = consumer_send_status_msg(sock, ret_code); | |
1803a064 | 539 | if (ret < 0) { |
d771f832 | 540 | /* Somehow, the session daemon is not responding anymore. */ |
1803a064 MD |
541 | goto error_fatal; |
542 | } | |
543 | if (ret_code != LTTNG_OK) { | |
d771f832 | 544 | /* Channel was not found. */ |
f50f23d9 DG |
545 | goto end_nosignal; |
546 | } | |
547 | ||
d771f832 | 548 | /* Blocking call */ |
3bd1e081 | 549 | if (lttng_consumer_poll_socket(consumer_sockpoll) < 0) { |
3f8e211f | 550 | rcu_read_unlock(); |
3bd1e081 MD |
551 | return -EINTR; |
552 | } | |
00e2e675 DG |
553 | |
554 | /* Get stream file descriptor from socket */ | |
f2fc6720 MD |
555 | ret = lttcomm_recv_fds_unix_sock(sock, &fd, 1); |
556 | if (ret != sizeof(fd)) { | |
f73fabfd | 557 | lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_ERROR_RECV_FD); |
3f8e211f | 558 | rcu_read_unlock(); |
3bd1e081 MD |
559 | return ret; |
560 | } | |
3bd1e081 | 561 | |
f50f23d9 DG |
562 | /* |
563 | * Send status code to session daemon only if the recv works. If the | |
564 | * above recv() failed, the session daemon is notified through the | |
565 | * error socket and the teardown is eventually done. | |
566 | */ | |
567 | ret = consumer_send_status_msg(sock, ret_code); | |
568 | if (ret < 0) { | |
569 | /* Somehow, the session daemon is not responding anymore. */ | |
570 | goto end_nosignal; | |
571 | } | |
572 | ||
ffe60014 DG |
573 | new_stream = consumer_allocate_stream(channel->key, |
574 | fd, | |
575 | LTTNG_CONSUMER_ACTIVE_STREAM, | |
576 | channel->name, | |
577 | channel->uid, | |
578 | channel->gid, | |
579 | channel->relayd_id, | |
580 | channel->session_id, | |
581 | msg.u.stream.cpu, | |
582 | &alloc_ret, | |
4891ece8 DG |
583 | channel->type, |
584 | channel->monitor); | |
3bd1e081 | 585 | if (new_stream == NULL) { |
c80048c6 MD |
586 | switch (alloc_ret) { |
587 | case -ENOMEM: | |
588 | case -EINVAL: | |
589 | default: | |
590 | lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR); | |
591 | break; | |
c80048c6 | 592 | } |
3f8e211f | 593 | goto end_nosignal; |
3bd1e081 | 594 | } |
d771f832 | 595 | |
ffe60014 DG |
596 | new_stream->chan = channel; |
597 | new_stream->wait_fd = fd; | |
07b86b52 JD |
598 | switch (channel->output) { |
599 | case CONSUMER_CHANNEL_SPLICE: | |
600 | new_stream->output = LTTNG_EVENT_SPLICE; | |
601 | break; | |
602 | case CONSUMER_CHANNEL_MMAP: | |
603 | new_stream->output = LTTNG_EVENT_MMAP; | |
604 | break; | |
605 | default: | |
606 | ERR("Stream output unknown %d", channel->output); | |
607 | goto end_nosignal; | |
608 | } | |
00e2e675 | 609 | |
a0c83db9 DG |
610 | /* |
611 | * We've just assigned the channel to the stream so increment the | |
07b86b52 JD |
612 | * refcount right now. We don't need to increment the refcount for |
613 | * streams in no monitor because we handle manually the cleanup of | |
614 | * those. It is very important to make sure there is NO prior | |
615 | * consumer_del_stream() calls or else the refcount will be unbalanced. | |
a0c83db9 | 616 | */ |
07b86b52 JD |
617 | if (channel->monitor) { |
618 | uatomic_inc(&new_stream->chan->refcount); | |
619 | } | |
9d9353f9 | 620 | |
fb3a43a9 DG |
621 | /* |
622 | * The buffer flush is done on the session daemon side for the kernel | |
623 | * so no need for the stream "hangup_flush_done" variable to be | |
624 | * tracked. This is important for a kernel stream since we don't rely | |
625 | * on the flush state of the stream to read data. It's not the case for | |
626 | * user space tracing. | |
627 | */ | |
628 | new_stream->hangup_flush_done = 0; | |
629 | ||
633d0084 DG |
630 | if (ctx->on_recv_stream) { |
631 | ret = ctx->on_recv_stream(new_stream); | |
632 | if (ret < 0) { | |
d771f832 | 633 | consumer_stream_free(new_stream); |
633d0084 | 634 | goto end_nosignal; |
fb3a43a9 | 635 | } |
633d0084 | 636 | } |
fb3a43a9 | 637 | |
07b86b52 JD |
638 | if (new_stream->metadata_flag) { |
639 | channel->metadata_stream = new_stream; | |
640 | } | |
641 | ||
2bba9e53 DG |
642 | /* Do not monitor this stream. */ |
643 | if (!channel->monitor) { | |
5eecee74 | 644 | DBG("Kernel consumer add stream %s in no monitor mode with " |
6dc3064a | 645 | "relayd id %" PRIu64, new_stream->name, |
5eecee74 | 646 | new_stream->net_seq_idx); |
10a50311 | 647 | cds_list_add(&new_stream->send_node, &channel->streams.head); |
6dc3064a DG |
648 | break; |
649 | } | |
650 | ||
e1b71bdc DG |
651 | /* Send stream to relayd if the stream has an ID. */ |
652 | if (new_stream->net_seq_idx != (uint64_t) -1ULL) { | |
194ee077 DG |
653 | ret = consumer_send_relayd_stream(new_stream, |
654 | new_stream->chan->pathname); | |
e1b71bdc DG |
655 | if (ret < 0) { |
656 | consumer_stream_free(new_stream); | |
657 | goto end_nosignal; | |
658 | } | |
e2039c7a JD |
659 | } |
660 | ||
50f8ae69 | 661 | /* Get the right pipe where the stream will be sent. */ |
633d0084 | 662 | if (new_stream->metadata_flag) { |
5ab66908 MD |
663 | ret = consumer_add_metadata_stream(new_stream); |
664 | if (ret) { | |
665 | ERR("Consumer add metadata stream %" PRIu64 " failed. Continuing", | |
666 | new_stream->key); | |
667 | consumer_stream_free(new_stream); | |
668 | goto end_nosignal; | |
669 | } | |
dae10966 | 670 | stream_pipe = ctx->consumer_metadata_pipe; |
3bd1e081 | 671 | } else { |
5ab66908 MD |
672 | ret = consumer_add_data_stream(new_stream); |
673 | if (ret) { | |
674 | ERR("Consumer add stream %" PRIu64 " failed. Continuing", | |
675 | new_stream->key); | |
676 | consumer_stream_free(new_stream); | |
677 | goto end_nosignal; | |
678 | } | |
dae10966 | 679 | stream_pipe = ctx->consumer_data_pipe; |
50f8ae69 DG |
680 | } |
681 | ||
5ab66908 MD |
682 | /* Vitible to other threads */ |
683 | new_stream->globally_visible = 1; | |
684 | ||
dae10966 | 685 | ret = lttng_pipe_write(stream_pipe, &new_stream, sizeof(new_stream)); |
50f8ae69 | 686 | if (ret < 0) { |
dae10966 | 687 | ERR("Consumer write %s stream to pipe %d", |
50f8ae69 | 688 | new_stream->metadata_flag ? "metadata" : "data", |
dae10966 | 689 | lttng_pipe_get_writefd(stream_pipe)); |
5ab66908 MD |
690 | if (new_stream->metadata_flag) { |
691 | consumer_del_stream_for_metadata(new_stream); | |
692 | } else { | |
693 | consumer_del_stream_for_data(new_stream); | |
694 | } | |
50f8ae69 | 695 | goto end_nosignal; |
3bd1e081 | 696 | } |
00e2e675 | 697 | |
50f8ae69 | 698 | DBG("Kernel consumer ADD_STREAM %s (fd: %d) with relayd id %" PRIu64, |
ffe60014 | 699 | new_stream->name, fd, new_stream->relayd_stream_id); |
3bd1e081 MD |
700 | break; |
701 | } | |
702 | case LTTNG_CONSUMER_UPDATE_STREAM: | |
703 | { | |
3f8e211f DG |
704 | rcu_read_unlock(); |
705 | return -ENOSYS; | |
706 | } | |
707 | case LTTNG_CONSUMER_DESTROY_RELAYD: | |
708 | { | |
a6ba4fe1 | 709 | uint64_t index = msg.u.destroy_relayd.net_seq_idx; |
3f8e211f DG |
710 | struct consumer_relayd_sock_pair *relayd; |
711 | ||
a6ba4fe1 | 712 | DBG("Kernel consumer destroying relayd %" PRIu64, index); |
3f8e211f DG |
713 | |
714 | /* Get relayd reference if exists. */ | |
a6ba4fe1 | 715 | relayd = consumer_find_relayd(index); |
3f8e211f | 716 | if (relayd == NULL) { |
3448e266 | 717 | DBG("Unable to find relayd %" PRIu64, index); |
f50f23d9 | 718 | ret_code = LTTNG_ERR_NO_CONSUMER; |
3bd1e081 | 719 | } |
3f8e211f | 720 | |
a6ba4fe1 DG |
721 | /* |
722 | * Each relayd socket pair has a refcount of stream attached to it | |
723 | * which tells if the relayd is still active or not depending on the | |
724 | * refcount value. | |
725 | * | |
726 | * This will set the destroy flag of the relayd object and destroy it | |
727 | * if the refcount reaches zero when called. | |
728 | * | |
729 | * The destroy can happen either here or when a stream fd hangs up. | |
730 | */ | |
f50f23d9 DG |
731 | if (relayd) { |
732 | consumer_flag_relayd_for_destroy(relayd); | |
733 | } | |
734 | ||
735 | ret = consumer_send_status_msg(sock, ret_code); | |
736 | if (ret < 0) { | |
737 | /* Somehow, the session daemon is not responding anymore. */ | |
1803a064 | 738 | goto error_fatal; |
f50f23d9 | 739 | } |
3f8e211f | 740 | |
3f8e211f | 741 | goto end_nosignal; |
3bd1e081 | 742 | } |
6d805429 | 743 | case LTTNG_CONSUMER_DATA_PENDING: |
53632229 | 744 | { |
c8f59ee5 | 745 | int32_t ret; |
6d805429 | 746 | uint64_t id = msg.u.data_pending.session_id; |
c8f59ee5 | 747 | |
6d805429 | 748 | DBG("Kernel consumer data pending command for id %" PRIu64, id); |
c8f59ee5 | 749 | |
6d805429 | 750 | ret = consumer_data_pending(id); |
c8f59ee5 DG |
751 | |
752 | /* Send back returned value to session daemon */ | |
753 | ret = lttcomm_send_unix_sock(sock, &ret, sizeof(ret)); | |
754 | if (ret < 0) { | |
6d805429 | 755 | PERROR("send data pending ret code"); |
1803a064 | 756 | goto error_fatal; |
c8f59ee5 | 757 | } |
f50f23d9 DG |
758 | |
759 | /* | |
760 | * No need to send back a status message since the data pending | |
761 | * returned value is the response. | |
762 | */ | |
c8f59ee5 | 763 | break; |
53632229 | 764 | } |
6dc3064a DG |
765 | case LTTNG_CONSUMER_SNAPSHOT_CHANNEL: |
766 | { | |
07b86b52 JD |
767 | if (msg.u.snapshot_channel.metadata == 1) { |
768 | ret = lttng_kconsumer_snapshot_metadata(msg.u.snapshot_channel.key, | |
e2039c7a JD |
769 | msg.u.snapshot_channel.pathname, |
770 | msg.u.snapshot_channel.relayd_id, ctx); | |
07b86b52 JD |
771 | if (ret < 0) { |
772 | ERR("Snapshot metadata failed"); | |
773 | ret_code = LTTNG_ERR_KERN_META_FAIL; | |
774 | } | |
775 | } else { | |
776 | ret = lttng_kconsumer_snapshot_channel(msg.u.snapshot_channel.key, | |
777 | msg.u.snapshot_channel.pathname, | |
5c786ded JD |
778 | msg.u.snapshot_channel.relayd_id, |
779 | msg.u.snapshot_channel.max_stream_size, | |
780 | ctx); | |
07b86b52 JD |
781 | if (ret < 0) { |
782 | ERR("Snapshot channel failed"); | |
783 | ret_code = LTTNG_ERR_KERN_CHAN_FAIL; | |
784 | } | |
785 | } | |
786 | ||
6dc3064a DG |
787 | ret = consumer_send_status_msg(sock, ret_code); |
788 | if (ret < 0) { | |
789 | /* Somehow, the session daemon is not responding anymore. */ | |
790 | goto end_nosignal; | |
791 | } | |
792 | break; | |
793 | } | |
07b86b52 JD |
794 | case LTTNG_CONSUMER_DESTROY_CHANNEL: |
795 | { | |
796 | uint64_t key = msg.u.destroy_channel.key; | |
797 | struct lttng_consumer_channel *channel; | |
798 | ||
799 | channel = consumer_find_channel(key); | |
800 | if (!channel) { | |
801 | ERR("Kernel consumer destroy channel %" PRIu64 " not found", key); | |
802 | ret_code = LTTNG_ERR_KERN_CHAN_NOT_FOUND; | |
803 | } | |
804 | ||
805 | ret = consumer_send_status_msg(sock, ret_code); | |
806 | if (ret < 0) { | |
807 | /* Somehow, the session daemon is not responding anymore. */ | |
808 | goto end_nosignal; | |
809 | } | |
810 | ||
811 | /* | |
812 | * This command should ONLY be issued for channel with streams set in | |
813 | * no monitor mode. | |
814 | */ | |
815 | assert(!channel->monitor); | |
816 | ||
817 | /* | |
818 | * The refcount should ALWAYS be 0 in the case of a channel in no | |
819 | * monitor mode. | |
820 | */ | |
821 | assert(!uatomic_sub_return(&channel->refcount, 1)); | |
822 | ||
823 | consumer_del_channel(channel); | |
824 | ||
825 | goto end_nosignal; | |
826 | } | |
3bd1e081 | 827 | default: |
3f8e211f | 828 | goto end_nosignal; |
3bd1e081 | 829 | } |
3f8e211f | 830 | |
3bd1e081 | 831 | end_nosignal: |
b0b335c8 | 832 | rcu_read_unlock(); |
4cbc1a04 DG |
833 | |
834 | /* | |
835 | * Return 1 to indicate success since the 0 value can be a socket | |
836 | * shutdown during the recv() or send() call. | |
837 | */ | |
838 | return 1; | |
1803a064 MD |
839 | |
840 | error_fatal: | |
841 | rcu_read_unlock(); | |
842 | /* This will issue a consumer stop. */ | |
843 | return -1; | |
3bd1e081 | 844 | } |
d41f73b7 MD |
845 | |
846 | /* | |
847 | * Consume data on a file descriptor and write it on a trace file. | |
848 | */ | |
4078b776 | 849 | ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, |
d41f73b7 MD |
850 | struct lttng_consumer_local_data *ctx) |
851 | { | |
1d4dfdef | 852 | unsigned long len, subbuf_size, padding; |
d41f73b7 | 853 | int err; |
4078b776 | 854 | ssize_t ret = 0; |
d41f73b7 MD |
855 | int infd = stream->wait_fd; |
856 | ||
857 | DBG("In read_subbuffer (infd : %d)", infd); | |
858 | /* Get the next subbuffer */ | |
859 | err = kernctl_get_next_subbuf(infd); | |
860 | if (err != 0) { | |
d41f73b7 MD |
861 | /* |
862 | * This is a debug message even for single-threaded consumer, | |
863 | * because poll() have more relaxed criterions than get subbuf, | |
864 | * so get_subbuf may fail for short race windows where poll() | |
865 | * would issue wakeups. | |
866 | */ | |
867 | DBG("Reserving sub buffer failed (everything is normal, " | |
868 | "it is due to concurrency)"); | |
56591bac | 869 | ret = -errno; |
d41f73b7 MD |
870 | goto end; |
871 | } | |
872 | ||
1d4dfdef DG |
873 | /* Get the full subbuffer size including padding */ |
874 | err = kernctl_get_padded_subbuf_size(infd, &len); | |
875 | if (err != 0) { | |
1d4dfdef | 876 | perror("Getting sub-buffer len failed."); |
56591bac | 877 | ret = -errno; |
1d4dfdef DG |
878 | goto end; |
879 | } | |
880 | ||
ffe60014 | 881 | switch (stream->chan->output) { |
07b86b52 | 882 | case CONSUMER_CHANNEL_SPLICE: |
1d4dfdef DG |
883 | /* |
884 | * XXX: The lttng-modules splice "actor" does not handle copying | |
885 | * partial pages hence only using the subbuffer size without the | |
886 | * padding makes the splice fail. | |
887 | */ | |
888 | subbuf_size = len; | |
889 | padding = 0; | |
890 | ||
891 | /* splice the subbuffer to the tracefile */ | |
91dfef6e DG |
892 | ret = lttng_consumer_on_read_subbuffer_splice(ctx, stream, subbuf_size, |
893 | padding); | |
894 | /* | |
895 | * XXX: Splice does not support network streaming so the return value | |
896 | * is simply checked against subbuf_size and not like the mmap() op. | |
897 | */ | |
1d4dfdef DG |
898 | if (ret != subbuf_size) { |
899 | /* | |
900 | * display the error but continue processing to try | |
901 | * to release the subbuffer | |
902 | */ | |
903 | ERR("Error splicing to tracefile (ret: %zd != len: %lu)", | |
904 | ret, subbuf_size); | |
905 | } | |
906 | break; | |
07b86b52 | 907 | case CONSUMER_CHANNEL_MMAP: |
1d4dfdef DG |
908 | /* Get subbuffer size without padding */ |
909 | err = kernctl_get_subbuf_size(infd, &subbuf_size); | |
910 | if (err != 0) { | |
1d4dfdef | 911 | perror("Getting sub-buffer len failed."); |
56591bac | 912 | ret = -errno; |
1d4dfdef DG |
913 | goto end; |
914 | } | |
47e81c02 | 915 | |
1d4dfdef DG |
916 | /* Make sure the tracer is not gone mad on us! */ |
917 | assert(len >= subbuf_size); | |
918 | ||
919 | padding = len - subbuf_size; | |
920 | ||
921 | /* write the subbuffer to the tracefile */ | |
91dfef6e DG |
922 | ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, subbuf_size, |
923 | padding); | |
924 | /* | |
925 | * The mmap operation should write subbuf_size amount of data when | |
926 | * network streaming or the full padding (len) size when we are _not_ | |
927 | * streaming. | |
928 | */ | |
d88aee68 DG |
929 | if ((ret != subbuf_size && stream->net_seq_idx != (uint64_t) -1ULL) || |
930 | (ret != len && stream->net_seq_idx == (uint64_t) -1ULL)) { | |
1d4dfdef | 931 | /* |
91dfef6e DG |
932 | * Display the error but continue processing to try to release the |
933 | * subbuffer | |
1d4dfdef | 934 | */ |
91dfef6e DG |
935 | ERR("Error writing to tracefile " |
936 | "(ret: %zd != len: %lu != subbuf_size: %lu)", | |
937 | ret, len, subbuf_size); | |
1d4dfdef DG |
938 | } |
939 | break; | |
940 | default: | |
941 | ERR("Unknown output method"); | |
56591bac | 942 | ret = -EPERM; |
d41f73b7 MD |
943 | } |
944 | ||
945 | err = kernctl_put_next_subbuf(infd); | |
946 | if (err != 0) { | |
d41f73b7 MD |
947 | if (errno == EFAULT) { |
948 | perror("Error in unreserving sub buffer\n"); | |
949 | } else if (errno == EIO) { | |
950 | /* Should never happen with newer LTTng versions */ | |
951 | perror("Reader has been pushed by the writer, last sub-buffer corrupted."); | |
952 | } | |
56591bac | 953 | ret = -errno; |
d41f73b7 MD |
954 | goto end; |
955 | } | |
956 | ||
957 | end: | |
958 | return ret; | |
959 | } | |
960 | ||
961 | int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream) | |
962 | { | |
963 | int ret; | |
ffe60014 DG |
964 | |
965 | assert(stream); | |
966 | ||
2bba9e53 DG |
967 | /* |
968 | * Don't create anything if this is set for streaming or should not be | |
969 | * monitored. | |
970 | */ | |
971 | if (stream->net_seq_idx == (uint64_t) -1ULL && stream->chan->monitor) { | |
fe4477ee JD |
972 | ret = utils_create_stream_file(stream->chan->pathname, stream->name, |
973 | stream->chan->tracefile_size, stream->tracefile_count_current, | |
974 | stream->uid, stream->gid); | |
975 | if (ret < 0) { | |
976 | goto error; | |
977 | } | |
978 | stream->out_fd = ret; | |
979 | stream->tracefile_size_current = 0; | |
ffe60014 | 980 | } |
d41f73b7 | 981 | |
d41f73b7 MD |
982 | if (stream->output == LTTNG_EVENT_MMAP) { |
983 | /* get the len of the mmap region */ | |
984 | unsigned long mmap_len; | |
985 | ||
986 | ret = kernctl_get_mmap_len(stream->wait_fd, &mmap_len); | |
987 | if (ret != 0) { | |
ffe60014 | 988 | PERROR("kernctl_get_mmap_len"); |
56591bac | 989 | ret = -errno; |
d41f73b7 MD |
990 | goto error_close_fd; |
991 | } | |
992 | stream->mmap_len = (size_t) mmap_len; | |
993 | ||
ffe60014 DG |
994 | stream->mmap_base = mmap(NULL, stream->mmap_len, PROT_READ, |
995 | MAP_PRIVATE, stream->wait_fd, 0); | |
d41f73b7 | 996 | if (stream->mmap_base == MAP_FAILED) { |
ffe60014 | 997 | PERROR("Error mmaping"); |
d41f73b7 MD |
998 | ret = -1; |
999 | goto error_close_fd; | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | /* we return 0 to let the library handle the FD internally */ | |
1004 | return 0; | |
1005 | ||
1006 | error_close_fd: | |
2f225ce2 | 1007 | if (stream->out_fd >= 0) { |
d41f73b7 MD |
1008 | int err; |
1009 | ||
1010 | err = close(stream->out_fd); | |
1011 | assert(!err); | |
2f225ce2 | 1012 | stream->out_fd = -1; |
d41f73b7 MD |
1013 | } |
1014 | error: | |
1015 | return ret; | |
1016 | } | |
1017 | ||
ca22feea DG |
1018 | /* |
1019 | * Check if data is still being extracted from the buffers for a specific | |
4e9a4686 DG |
1020 | * stream. Consumer data lock MUST be acquired before calling this function |
1021 | * and the stream lock. | |
ca22feea | 1022 | * |
6d805429 | 1023 | * Return 1 if the traced data are still getting read else 0 meaning that the |
ca22feea DG |
1024 | * data is available for trace viewer reading. |
1025 | */ | |
6d805429 | 1026 | int lttng_kconsumer_data_pending(struct lttng_consumer_stream *stream) |
ca22feea DG |
1027 | { |
1028 | int ret; | |
1029 | ||
1030 | assert(stream); | |
1031 | ||
873b9e9a MD |
1032 | if (stream->endpoint_status != CONSUMER_ENDPOINT_ACTIVE) { |
1033 | ret = 0; | |
1034 | goto end; | |
1035 | } | |
1036 | ||
ca22feea DG |
1037 | ret = kernctl_get_next_subbuf(stream->wait_fd); |
1038 | if (ret == 0) { | |
1039 | /* There is still data so let's put back this subbuffer. */ | |
1040 | ret = kernctl_put_subbuf(stream->wait_fd); | |
1041 | assert(ret == 0); | |
6d805429 | 1042 | ret = 1; /* Data is pending */ |
4e9a4686 | 1043 | goto end; |
ca22feea DG |
1044 | } |
1045 | ||
6d805429 DG |
1046 | /* Data is NOT pending and ready to be read. */ |
1047 | ret = 0; | |
ca22feea | 1048 | |
6efae65e DG |
1049 | end: |
1050 | return ret; | |
ca22feea | 1051 | } |