591c58fc5674100908f5fbcd847fa68db874f4d2
[lttng-tools.git] / src / common / ust-consumer / ust-consumer.cpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 */
9
10 #define _LGPL_SOURCE
11 #include <lttng/ust-ctl.h>
12 #include <lttng/ust-sigbus.h>
13 #include <poll.h>
14 #include <pthread.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <sys/mman.h>
18 #include <sys/socket.h>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include <inttypes.h>
22 #include <unistd.h>
23 #include <urcu/list.h>
24 #include <signal.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27
28 #include <bin/lttng-consumerd/health-consumerd.h>
29 #include <common/common.h>
30 #include <common/sessiond-comm/sessiond-comm.h>
31 #include <common/relayd/relayd.h>
32 #include <common/compat/fcntl.h>
33 #include <common/compat/endian.h>
34 #include <common/consumer/consumer-metadata-cache.h>
35 #include <common/consumer/consumer-stream.h>
36 #include <common/consumer/consumer-timer.h>
37 #include <common/utils.h>
38 #include <common/index/index.h>
39 #include <common/consumer/consumer.h>
40 #include <common/shm.h>
41 #include <common/optional.h>
42
43 #include "ust-consumer.h"
44
45 #define INT_MAX_STR_LEN 12 /* includes \0 */
46
47 extern struct lttng_consumer_global_data the_consumer_data;
48 extern int consumer_poll_timeout;
49
50 LTTNG_EXPORT DEFINE_LTTNG_UST_SIGBUS_STATE();
51
52 /*
53 * Free channel object and all streams associated with it. This MUST be used
54 * only and only if the channel has _NEVER_ been added to the global channel
55 * hash table.
56 */
57 static void destroy_channel(struct lttng_consumer_channel *channel)
58 {
59 struct lttng_consumer_stream *stream, *stmp;
60
61 LTTNG_ASSERT(channel);
62
63 DBG("UST consumer cleaning stream list");
64
65 cds_list_for_each_entry_safe(stream, stmp, &channel->streams.head,
66 send_node) {
67
68 health_code_update();
69
70 cds_list_del(&stream->send_node);
71 lttng_ust_ctl_destroy_stream(stream->ustream);
72 lttng_trace_chunk_put(stream->trace_chunk);
73 free(stream);
74 }
75
76 /*
77 * If a channel is available meaning that was created before the streams
78 * were, delete it.
79 */
80 if (channel->uchan) {
81 lttng_ustconsumer_del_channel(channel);
82 lttng_ustconsumer_free_channel(channel);
83 }
84
85 if (channel->trace_chunk) {
86 lttng_trace_chunk_put(channel->trace_chunk);
87 }
88
89 free(channel);
90 }
91
92 /*
93 * Add channel to internal consumer state.
94 *
95 * Returns 0 on success or else a negative value.
96 */
97 static int add_channel(struct lttng_consumer_channel *channel,
98 struct lttng_consumer_local_data *ctx)
99 {
100 int ret = 0;
101
102 LTTNG_ASSERT(channel);
103 LTTNG_ASSERT(ctx);
104
105 if (ctx->on_recv_channel != NULL) {
106 ret = ctx->on_recv_channel(channel);
107 if (ret == 0) {
108 ret = consumer_add_channel(channel, ctx);
109 } else if (ret < 0) {
110 /* Most likely an ENOMEM. */
111 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR);
112 goto error;
113 }
114 } else {
115 ret = consumer_add_channel(channel, ctx);
116 }
117
118 DBG("UST consumer channel added (key: %" PRIu64 ")", channel->key);
119
120 error:
121 return ret;
122 }
123
124 /*
125 * Allocate and return a consumer stream object. If _alloc_ret is not NULL, the
126 * error value if applicable is set in it else it is kept untouched.
127 *
128 * Return NULL on error else the newly allocated stream object.
129 */
130 static struct lttng_consumer_stream *allocate_stream(int cpu, int key,
131 struct lttng_consumer_channel *channel,
132 struct lttng_consumer_local_data *ctx, int *_alloc_ret)
133 {
134 int alloc_ret;
135 struct lttng_consumer_stream *stream = NULL;
136
137 LTTNG_ASSERT(channel);
138 LTTNG_ASSERT(ctx);
139
140 stream = consumer_stream_create(
141 channel,
142 channel->key,
143 key,
144 channel->name,
145 channel->relayd_id,
146 channel->session_id,
147 channel->trace_chunk,
148 cpu,
149 &alloc_ret,
150 channel->type,
151 channel->monitor);
152 if (stream == NULL) {
153 switch (alloc_ret) {
154 case -ENOENT:
155 /*
156 * We could not find the channel. Can happen if cpu hotplug
157 * happens while tearing down.
158 */
159 DBG3("Could not find channel");
160 break;
161 case -ENOMEM:
162 case -EINVAL:
163 default:
164 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR);
165 break;
166 }
167 goto error;
168 }
169
170 consumer_stream_update_channel_attributes(stream, channel);
171
172 error:
173 if (_alloc_ret) {
174 *_alloc_ret = alloc_ret;
175 }
176 return stream;
177 }
178
179 /*
180 * Send the given stream pointer to the corresponding thread.
181 *
182 * Returns 0 on success else a negative value.
183 */
184 static int send_stream_to_thread(struct lttng_consumer_stream *stream,
185 struct lttng_consumer_local_data *ctx)
186 {
187 int ret;
188 struct lttng_pipe *stream_pipe;
189
190 /* Get the right pipe where the stream will be sent. */
191 if (stream->metadata_flag) {
192 consumer_add_metadata_stream(stream);
193 stream_pipe = ctx->consumer_metadata_pipe;
194 } else {
195 consumer_add_data_stream(stream);
196 stream_pipe = ctx->consumer_data_pipe;
197 }
198
199 /*
200 * From this point on, the stream's ownership has been moved away from
201 * the channel and it becomes globally visible. Hence, remove it from
202 * the local stream list to prevent the stream from being both local and
203 * global.
204 */
205 stream->globally_visible = 1;
206 cds_list_del(&stream->send_node);
207
208 ret = lttng_pipe_write(stream_pipe, &stream, sizeof(stream));
209 if (ret < 0) {
210 ERR("Consumer write %s stream to pipe %d",
211 stream->metadata_flag ? "metadata" : "data",
212 lttng_pipe_get_writefd(stream_pipe));
213 if (stream->metadata_flag) {
214 consumer_del_stream_for_metadata(stream);
215 } else {
216 consumer_del_stream_for_data(stream);
217 }
218 goto error;
219 }
220
221 error:
222 return ret;
223 }
224
225 static
226 int get_stream_shm_path(char *stream_shm_path, const char *shm_path, int cpu)
227 {
228 char cpu_nr[INT_MAX_STR_LEN]; /* int max len */
229 int ret;
230
231 strncpy(stream_shm_path, shm_path, PATH_MAX);
232 stream_shm_path[PATH_MAX - 1] = '\0';
233 ret = snprintf(cpu_nr, INT_MAX_STR_LEN, "%i", cpu);
234 if (ret < 0) {
235 PERROR("snprintf");
236 goto end;
237 }
238 strncat(stream_shm_path, cpu_nr,
239 PATH_MAX - strlen(stream_shm_path) - 1);
240 ret = 0;
241 end:
242 return ret;
243 }
244
245 /*
246 * Create streams for the given channel using liblttng-ust-ctl.
247 * The channel lock must be acquired by the caller.
248 *
249 * Return 0 on success else a negative value.
250 */
251 static int create_ust_streams(struct lttng_consumer_channel *channel,
252 struct lttng_consumer_local_data *ctx)
253 {
254 int ret, cpu = 0;
255 struct lttng_ust_ctl_consumer_stream *ustream;
256 struct lttng_consumer_stream *stream;
257 pthread_mutex_t *current_stream_lock = NULL;
258
259 LTTNG_ASSERT(channel);
260 LTTNG_ASSERT(ctx);
261
262 /*
263 * While a stream is available from ustctl. When NULL is returned, we've
264 * reached the end of the possible stream for the channel.
265 */
266 while ((ustream = lttng_ust_ctl_create_stream(channel->uchan, cpu))) {
267 int wait_fd;
268 int ust_metadata_pipe[2];
269
270 health_code_update();
271
272 if (channel->type == CONSUMER_CHANNEL_TYPE_METADATA && channel->monitor) {
273 ret = utils_create_pipe_cloexec_nonblock(ust_metadata_pipe);
274 if (ret < 0) {
275 ERR("Create ust metadata poll pipe");
276 goto error;
277 }
278 wait_fd = ust_metadata_pipe[0];
279 } else {
280 wait_fd = lttng_ust_ctl_stream_get_wait_fd(ustream);
281 }
282
283 /* Allocate consumer stream object. */
284 stream = allocate_stream(cpu, wait_fd, channel, ctx, &ret);
285 if (!stream) {
286 goto error_alloc;
287 }
288 stream->ustream = ustream;
289 /*
290 * Store it so we can save multiple function calls afterwards since
291 * this value is used heavily in the stream threads. This is UST
292 * specific so this is why it's done after allocation.
293 */
294 stream->wait_fd = wait_fd;
295
296 /*
297 * Increment channel refcount since the channel reference has now been
298 * assigned in the allocation process above.
299 */
300 if (stream->chan->monitor) {
301 uatomic_inc(&stream->chan->refcount);
302 }
303
304 pthread_mutex_lock(&stream->lock);
305 current_stream_lock = &stream->lock;
306 /*
307 * Order is important this is why a list is used. On error, the caller
308 * should clean this list.
309 */
310 cds_list_add_tail(&stream->send_node, &channel->streams.head);
311
312 ret = lttng_ust_ctl_get_max_subbuf_size(stream->ustream,
313 &stream->max_sb_size);
314 if (ret < 0) {
315 ERR("lttng_ust_ctl_get_max_subbuf_size failed for stream %s",
316 stream->name);
317 goto error;
318 }
319
320 /* Do actions once stream has been received. */
321 if (ctx->on_recv_stream) {
322 ret = ctx->on_recv_stream(stream);
323 if (ret < 0) {
324 goto error;
325 }
326 }
327
328 DBG("UST consumer add stream %s (key: %" PRIu64 ") with relayd id %" PRIu64,
329 stream->name, stream->key, stream->relayd_stream_id);
330
331 /* Set next CPU stream. */
332 channel->streams.count = ++cpu;
333
334 /* Keep stream reference when creating metadata. */
335 if (channel->type == CONSUMER_CHANNEL_TYPE_METADATA) {
336 channel->metadata_stream = stream;
337 if (channel->monitor) {
338 /* Set metadata poll pipe if we created one */
339 memcpy(stream->ust_metadata_poll_pipe,
340 ust_metadata_pipe,
341 sizeof(ust_metadata_pipe));
342 }
343 }
344 pthread_mutex_unlock(&stream->lock);
345 current_stream_lock = NULL;
346 }
347
348 return 0;
349
350 error:
351 error_alloc:
352 if (current_stream_lock) {
353 pthread_mutex_unlock(current_stream_lock);
354 }
355 return ret;
356 }
357
358 static int open_ust_stream_fd(struct lttng_consumer_channel *channel, int cpu,
359 const struct lttng_credentials *session_credentials)
360 {
361 char shm_path[PATH_MAX];
362 int ret;
363
364 if (!channel->shm_path[0]) {
365 return shm_create_anonymous("ust-consumer");
366 }
367 ret = get_stream_shm_path(shm_path, channel->shm_path, cpu);
368 if (ret) {
369 goto error_shm_path;
370 }
371 return run_as_open(shm_path,
372 O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR,
373 lttng_credentials_get_uid(session_credentials),
374 lttng_credentials_get_gid(session_credentials));
375
376 error_shm_path:
377 return -1;
378 }
379
380 /*
381 * Create an UST channel with the given attributes and send it to the session
382 * daemon using the ust ctl API.
383 *
384 * Return 0 on success or else a negative value.
385 */
386 static int create_ust_channel(struct lttng_consumer_channel *channel,
387 struct lttng_ust_ctl_consumer_channel_attr *attr,
388 struct lttng_ust_ctl_consumer_channel **ust_chanp)
389 {
390 int ret, nr_stream_fds, i, j;
391 int *stream_fds;
392 struct lttng_ust_ctl_consumer_channel *ust_channel;
393
394 LTTNG_ASSERT(channel);
395 LTTNG_ASSERT(attr);
396 LTTNG_ASSERT(ust_chanp);
397 LTTNG_ASSERT(channel->buffer_credentials.is_set);
398
399 DBG3("Creating channel to ustctl with attr: [overwrite: %d, "
400 "subbuf_size: %" PRIu64 ", num_subbuf: %" PRIu64 ", "
401 "switch_timer_interval: %u, read_timer_interval: %u, "
402 "output: %d, type: %d", attr->overwrite, attr->subbuf_size,
403 attr->num_subbuf, attr->switch_timer_interval,
404 attr->read_timer_interval, attr->output, attr->type);
405
406 if (channel->type == CONSUMER_CHANNEL_TYPE_METADATA)
407 nr_stream_fds = 1;
408 else
409 nr_stream_fds = lttng_ust_ctl_get_nr_stream_per_channel();
410 stream_fds = (int *) zmalloc(nr_stream_fds * sizeof(*stream_fds));
411 if (!stream_fds) {
412 ret = -1;
413 goto error_alloc;
414 }
415 for (i = 0; i < nr_stream_fds; i++) {
416 stream_fds[i] = open_ust_stream_fd(channel, i,
417 &channel->buffer_credentials.value);
418 if (stream_fds[i] < 0) {
419 ret = -1;
420 goto error_open;
421 }
422 }
423 ust_channel = lttng_ust_ctl_create_channel(attr, stream_fds, nr_stream_fds);
424 if (!ust_channel) {
425 ret = -1;
426 goto error_create;
427 }
428 channel->nr_stream_fds = nr_stream_fds;
429 channel->stream_fds = stream_fds;
430 *ust_chanp = ust_channel;
431
432 return 0;
433
434 error_create:
435 error_open:
436 for (j = i - 1; j >= 0; j--) {
437 int closeret;
438
439 closeret = close(stream_fds[j]);
440 if (closeret) {
441 PERROR("close");
442 }
443 if (channel->shm_path[0]) {
444 char shm_path[PATH_MAX];
445
446 closeret = get_stream_shm_path(shm_path,
447 channel->shm_path, j);
448 if (closeret) {
449 ERR("Cannot get stream shm path");
450 }
451 closeret = run_as_unlink(shm_path,
452 lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
453 channel->buffer_credentials)),
454 lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
455 channel->buffer_credentials)));
456 if (closeret) {
457 PERROR("unlink %s", shm_path);
458 }
459 }
460 }
461 /* Try to rmdir all directories under shm_path root. */
462 if (channel->root_shm_path[0]) {
463 (void) run_as_rmdir_recursive(channel->root_shm_path,
464 lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
465 channel->buffer_credentials)),
466 lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
467 channel->buffer_credentials)),
468 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
469 }
470 free(stream_fds);
471 error_alloc:
472 return ret;
473 }
474
475 /*
476 * Send a single given stream to the session daemon using the sock.
477 *
478 * Return 0 on success else a negative value.
479 */
480 static int send_sessiond_stream(int sock, struct lttng_consumer_stream *stream)
481 {
482 int ret;
483
484 LTTNG_ASSERT(stream);
485 LTTNG_ASSERT(sock >= 0);
486
487 DBG("UST consumer sending stream %" PRIu64 " to sessiond", stream->key);
488
489 /* Send stream to session daemon. */
490 ret = lttng_ust_ctl_send_stream_to_sessiond(sock, stream->ustream);
491 if (ret < 0) {
492 goto error;
493 }
494
495 error:
496 return ret;
497 }
498
499 /*
500 * Send channel to sessiond and relayd if applicable.
501 *
502 * Return 0 on success or else a negative value.
503 */
504 static int send_channel_to_sessiond_and_relayd(int sock,
505 struct lttng_consumer_channel *channel,
506 struct lttng_consumer_local_data *ctx, int *relayd_error)
507 {
508 int ret, ret_code = LTTCOMM_CONSUMERD_SUCCESS;
509 struct lttng_consumer_stream *stream;
510 uint64_t net_seq_idx = -1ULL;
511
512 LTTNG_ASSERT(channel);
513 LTTNG_ASSERT(ctx);
514 LTTNG_ASSERT(sock >= 0);
515
516 DBG("UST consumer sending channel %s to sessiond", channel->name);
517
518 if (channel->relayd_id != (uint64_t) -1ULL) {
519 cds_list_for_each_entry(stream, &channel->streams.head, send_node) {
520
521 health_code_update();
522
523 /* Try to send the stream to the relayd if one is available. */
524 DBG("Sending stream %" PRIu64 " of channel \"%s\" to relayd",
525 stream->key, channel->name);
526 ret = consumer_send_relayd_stream(stream, stream->chan->pathname);
527 if (ret < 0) {
528 /*
529 * Flag that the relayd was the problem here probably due to a
530 * communicaton error on the socket.
531 */
532 if (relayd_error) {
533 *relayd_error = 1;
534 }
535 ret_code = LTTCOMM_CONSUMERD_RELAYD_FAIL;
536 }
537 if (net_seq_idx == -1ULL) {
538 net_seq_idx = stream->net_seq_idx;
539 }
540 }
541 }
542
543 /* Inform sessiond that we are about to send channel and streams. */
544 ret = consumer_send_status_msg(sock, ret_code);
545 if (ret < 0 || ret_code != LTTCOMM_CONSUMERD_SUCCESS) {
546 /*
547 * Either the session daemon is not responding or the relayd died so we
548 * stop now.
549 */
550 goto error;
551 }
552
553 /* Send channel to sessiond. */
554 ret = lttng_ust_ctl_send_channel_to_sessiond(sock, channel->uchan);
555 if (ret < 0) {
556 goto error;
557 }
558
559 ret = lttng_ust_ctl_channel_close_wakeup_fd(channel->uchan);
560 if (ret < 0) {
561 goto error;
562 }
563
564 /* The channel was sent successfully to the sessiond at this point. */
565 cds_list_for_each_entry(stream, &channel->streams.head, send_node) {
566
567 health_code_update();
568
569 /* Send stream to session daemon. */
570 ret = send_sessiond_stream(sock, stream);
571 if (ret < 0) {
572 goto error;
573 }
574 }
575
576 /* Tell sessiond there is no more stream. */
577 ret = lttng_ust_ctl_send_stream_to_sessiond(sock, NULL);
578 if (ret < 0) {
579 goto error;
580 }
581
582 DBG("UST consumer NULL stream sent to sessiond");
583
584 return 0;
585
586 error:
587 if (ret_code != LTTCOMM_CONSUMERD_SUCCESS) {
588 ret = -1;
589 }
590 return ret;
591 }
592
593 /*
594 * Creates a channel and streams and add the channel it to the channel internal
595 * state. The created stream must ONLY be sent once the GET_CHANNEL command is
596 * received.
597 *
598 * Return 0 on success or else, a negative value is returned and the channel
599 * MUST be destroyed by consumer_del_channel().
600 */
601 static int ask_channel(struct lttng_consumer_local_data *ctx,
602 struct lttng_consumer_channel *channel,
603 struct lttng_ust_ctl_consumer_channel_attr *attr)
604 {
605 int ret;
606
607 LTTNG_ASSERT(ctx);
608 LTTNG_ASSERT(channel);
609 LTTNG_ASSERT(attr);
610
611 /*
612 * This value is still used by the kernel consumer since for the kernel,
613 * the stream ownership is not IN the consumer so we need to have the
614 * number of left stream that needs to be initialized so we can know when
615 * to delete the channel (see consumer.c).
616 *
617 * As for the user space tracer now, the consumer creates and sends the
618 * stream to the session daemon which only sends them to the application
619 * once every stream of a channel is received making this value useless
620 * because we they will be added to the poll thread before the application
621 * receives them. This ensures that a stream can not hang up during
622 * initilization of a channel.
623 */
624 channel->nb_init_stream_left = 0;
625
626 /* The reply msg status is handled in the following call. */
627 ret = create_ust_channel(channel, attr, &channel->uchan);
628 if (ret < 0) {
629 goto end;
630 }
631
632 channel->wait_fd = lttng_ust_ctl_channel_get_wait_fd(channel->uchan);
633
634 /*
635 * For the snapshots (no monitor), we create the metadata streams
636 * on demand, not during the channel creation.
637 */
638 if (channel->type == CONSUMER_CHANNEL_TYPE_METADATA && !channel->monitor) {
639 ret = 0;
640 goto end;
641 }
642
643 /* Open all streams for this channel. */
644 pthread_mutex_lock(&channel->lock);
645 ret = create_ust_streams(channel, ctx);
646 pthread_mutex_unlock(&channel->lock);
647 if (ret < 0) {
648 goto end;
649 }
650
651 end:
652 return ret;
653 }
654
655 /*
656 * Send all stream of a channel to the right thread handling it.
657 *
658 * On error, return a negative value else 0 on success.
659 */
660 static int send_streams_to_thread(struct lttng_consumer_channel *channel,
661 struct lttng_consumer_local_data *ctx)
662 {
663 int ret = 0;
664 struct lttng_consumer_stream *stream, *stmp;
665
666 LTTNG_ASSERT(channel);
667 LTTNG_ASSERT(ctx);
668
669 /* Send streams to the corresponding thread. */
670 cds_list_for_each_entry_safe(stream, stmp, &channel->streams.head,
671 send_node) {
672
673 health_code_update();
674
675 /* Sending the stream to the thread. */
676 ret = send_stream_to_thread(stream, ctx);
677 if (ret < 0) {
678 /*
679 * If we are unable to send the stream to the thread, there is
680 * a big problem so just stop everything.
681 */
682 goto error;
683 }
684 }
685
686 error:
687 return ret;
688 }
689
690 /*
691 * Flush channel's streams using the given key to retrieve the channel.
692 *
693 * Return 0 on success else an LTTng error code.
694 */
695 static int flush_channel(uint64_t chan_key)
696 {
697 int ret = 0;
698 struct lttng_consumer_channel *channel;
699 struct lttng_consumer_stream *stream;
700 struct lttng_ht *ht;
701 struct lttng_ht_iter iter;
702
703 DBG("UST consumer flush channel key %" PRIu64, chan_key);
704
705 rcu_read_lock();
706 channel = consumer_find_channel(chan_key);
707 if (!channel) {
708 ERR("UST consumer flush channel %" PRIu64 " not found", chan_key);
709 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
710 goto error;
711 }
712
713 ht = the_consumer_data.stream_per_chan_id_ht;
714
715 /* For each stream of the channel id, flush it. */
716 cds_lfht_for_each_entry_duplicate(ht->ht,
717 ht->hash_fct(&channel->key, lttng_ht_seed), ht->match_fct,
718 &channel->key, &iter.iter, stream, node_channel_id.node) {
719
720 health_code_update();
721
722 pthread_mutex_lock(&stream->lock);
723
724 /*
725 * Protect against concurrent teardown of a stream.
726 */
727 if (cds_lfht_is_node_deleted(&stream->node.node)) {
728 goto next;
729 }
730
731 if (!stream->quiescent) {
732 ret = lttng_ust_ctl_flush_buffer(stream->ustream, 0);
733 if (ret) {
734 ERR("Failed to flush buffer while flushing channel: channel key = %" PRIu64 ", channel name = '%s'",
735 chan_key, channel->name);
736 ret = LTTNG_ERR_BUFFER_FLUSH_FAILED;
737 pthread_mutex_unlock(&stream->lock);
738 goto error;
739 }
740 stream->quiescent = true;
741 }
742 next:
743 pthread_mutex_unlock(&stream->lock);
744 }
745 error:
746 rcu_read_unlock();
747 return ret;
748 }
749
750 /*
751 * Clear quiescent state from channel's streams using the given key to
752 * retrieve the channel.
753 *
754 * Return 0 on success else an LTTng error code.
755 */
756 static int clear_quiescent_channel(uint64_t chan_key)
757 {
758 int ret = 0;
759 struct lttng_consumer_channel *channel;
760 struct lttng_consumer_stream *stream;
761 struct lttng_ht *ht;
762 struct lttng_ht_iter iter;
763
764 DBG("UST consumer clear quiescent channel key %" PRIu64, chan_key);
765
766 rcu_read_lock();
767 channel = consumer_find_channel(chan_key);
768 if (!channel) {
769 ERR("UST consumer clear quiescent channel %" PRIu64 " not found", chan_key);
770 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
771 goto error;
772 }
773
774 ht = the_consumer_data.stream_per_chan_id_ht;
775
776 /* For each stream of the channel id, clear quiescent state. */
777 cds_lfht_for_each_entry_duplicate(ht->ht,
778 ht->hash_fct(&channel->key, lttng_ht_seed), ht->match_fct,
779 &channel->key, &iter.iter, stream, node_channel_id.node) {
780
781 health_code_update();
782
783 pthread_mutex_lock(&stream->lock);
784 stream->quiescent = false;
785 pthread_mutex_unlock(&stream->lock);
786 }
787 error:
788 rcu_read_unlock();
789 return ret;
790 }
791
792 /*
793 * Close metadata stream wakeup_fd using the given key to retrieve the channel.
794 *
795 * Return 0 on success else an LTTng error code.
796 */
797 static int close_metadata(uint64_t chan_key)
798 {
799 int ret = 0;
800 struct lttng_consumer_channel *channel;
801 unsigned int channel_monitor;
802
803 DBG("UST consumer close metadata key %" PRIu64, chan_key);
804
805 channel = consumer_find_channel(chan_key);
806 if (!channel) {
807 /*
808 * This is possible if the metadata thread has issue a delete because
809 * the endpoint point of the stream hung up. There is no way the
810 * session daemon can know about it thus use a DBG instead of an actual
811 * error.
812 */
813 DBG("UST consumer close metadata %" PRIu64 " not found", chan_key);
814 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
815 goto error;
816 }
817
818 pthread_mutex_lock(&the_consumer_data.lock);
819 pthread_mutex_lock(&channel->lock);
820 channel_monitor = channel->monitor;
821 if (cds_lfht_is_node_deleted(&channel->node.node)) {
822 goto error_unlock;
823 }
824
825 lttng_ustconsumer_close_metadata(channel);
826 pthread_mutex_unlock(&channel->lock);
827 pthread_mutex_unlock(&the_consumer_data.lock);
828
829 /*
830 * The ownership of a metadata channel depends on the type of
831 * session to which it belongs. In effect, the monitor flag is checked
832 * to determine if this metadata channel is in "snapshot" mode or not.
833 *
834 * In the non-snapshot case, the metadata channel is created along with
835 * a single stream which will remain present until the metadata channel
836 * is destroyed (on the destruction of its session). In this case, the
837 * metadata stream in "monitored" by the metadata poll thread and holds
838 * the ownership of its channel.
839 *
840 * Closing the metadata will cause the metadata stream's "metadata poll
841 * pipe" to be closed. Closing this pipe will wake-up the metadata poll
842 * thread which will teardown the metadata stream which, in return,
843 * deletes the metadata channel.
844 *
845 * In the snapshot case, the metadata stream is created and destroyed
846 * on every snapshot record. Since the channel doesn't have an owner
847 * other than the session daemon, it is safe to destroy it immediately
848 * on reception of the CLOSE_METADATA command.
849 */
850 if (!channel_monitor) {
851 /*
852 * The channel and consumer_data locks must be
853 * released before this call since consumer_del_channel
854 * re-acquires the channel and consumer_data locks to teardown
855 * the channel and queue its reclamation by the "call_rcu"
856 * worker thread.
857 */
858 consumer_del_channel(channel);
859 }
860
861 return ret;
862 error_unlock:
863 pthread_mutex_unlock(&channel->lock);
864 pthread_mutex_unlock(&the_consumer_data.lock);
865 error:
866 return ret;
867 }
868
869 /*
870 * RCU read side lock MUST be acquired before calling this function.
871 *
872 * Return 0 on success else an LTTng error code.
873 */
874 static int setup_metadata(struct lttng_consumer_local_data *ctx, uint64_t key)
875 {
876 int ret;
877 struct lttng_consumer_channel *metadata;
878
879 DBG("UST consumer setup metadata key %" PRIu64, key);
880
881 metadata = consumer_find_channel(key);
882 if (!metadata) {
883 ERR("UST consumer push metadata %" PRIu64 " not found", key);
884 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
885 goto end;
886 }
887
888 /*
889 * In no monitor mode, the metadata channel has no stream(s) so skip the
890 * ownership transfer to the metadata thread.
891 */
892 if (!metadata->monitor) {
893 DBG("Metadata channel in no monitor");
894 ret = 0;
895 goto end;
896 }
897
898 /*
899 * Send metadata stream to relayd if one available. Availability is
900 * known if the stream is still in the list of the channel.
901 */
902 if (cds_list_empty(&metadata->streams.head)) {
903 ERR("Metadata channel key %" PRIu64 ", no stream available.", key);
904 ret = LTTCOMM_CONSUMERD_ERROR_METADATA;
905 goto error_no_stream;
906 }
907
908 /* Send metadata stream to relayd if needed. */
909 if (metadata->metadata_stream->net_seq_idx != (uint64_t) -1ULL) {
910 ret = consumer_send_relayd_stream(metadata->metadata_stream,
911 metadata->pathname);
912 if (ret < 0) {
913 ret = LTTCOMM_CONSUMERD_ERROR_METADATA;
914 goto error;
915 }
916 ret = consumer_send_relayd_streams_sent(
917 metadata->metadata_stream->net_seq_idx);
918 if (ret < 0) {
919 ret = LTTCOMM_CONSUMERD_RELAYD_FAIL;
920 goto error;
921 }
922 }
923
924 /*
925 * Ownership of metadata stream is passed along. Freeing is handled by
926 * the callee.
927 */
928 ret = send_streams_to_thread(metadata, ctx);
929 if (ret < 0) {
930 /*
931 * If we are unable to send the stream to the thread, there is
932 * a big problem so just stop everything.
933 */
934 ret = LTTCOMM_CONSUMERD_FATAL;
935 goto send_streams_error;
936 }
937 /* List MUST be empty after or else it could be reused. */
938 LTTNG_ASSERT(cds_list_empty(&metadata->streams.head));
939
940 ret = 0;
941 goto end;
942
943 error:
944 /*
945 * Delete metadata channel on error. At this point, the metadata stream can
946 * NOT be monitored by the metadata thread thus having the guarantee that
947 * the stream is still in the local stream list of the channel. This call
948 * will make sure to clean that list.
949 */
950 consumer_stream_destroy(metadata->metadata_stream, NULL);
951 cds_list_del(&metadata->metadata_stream->send_node);
952 metadata->metadata_stream = NULL;
953 send_streams_error:
954 error_no_stream:
955 end:
956 return ret;
957 }
958
959 /*
960 * Snapshot the whole metadata.
961 * RCU read-side lock must be held by the caller.
962 *
963 * Returns 0 on success, < 0 on error
964 */
965 static int snapshot_metadata(struct lttng_consumer_channel *metadata_channel,
966 uint64_t key, char *path, uint64_t relayd_id,
967 struct lttng_consumer_local_data *ctx)
968 {
969 int ret = 0;
970 struct lttng_consumer_stream *metadata_stream;
971
972 LTTNG_ASSERT(path);
973 LTTNG_ASSERT(ctx);
974
975 DBG("UST consumer snapshot metadata with key %" PRIu64 " at path %s",
976 key, path);
977
978 rcu_read_lock();
979
980 LTTNG_ASSERT(!metadata_channel->monitor);
981
982 health_code_update();
983
984 /*
985 * Ask the sessiond if we have new metadata waiting and update the
986 * consumer metadata cache.
987 */
988 ret = lttng_ustconsumer_request_metadata(ctx, metadata_channel, 0, 1);
989 if (ret < 0) {
990 goto error;
991 }
992
993 health_code_update();
994
995 /*
996 * The metadata stream is NOT created in no monitor mode when the channel
997 * is created on a sessiond ask channel command.
998 */
999 ret = create_ust_streams(metadata_channel, ctx);
1000 if (ret < 0) {
1001 goto error;
1002 }
1003
1004 metadata_stream = metadata_channel->metadata_stream;
1005 LTTNG_ASSERT(metadata_stream);
1006
1007 metadata_stream->read_subbuffer_ops.lock(metadata_stream);
1008 if (relayd_id != (uint64_t) -1ULL) {
1009 metadata_stream->net_seq_idx = relayd_id;
1010 ret = consumer_send_relayd_stream(metadata_stream, path);
1011 } else {
1012 ret = consumer_stream_create_output_files(metadata_stream,
1013 false);
1014 }
1015 if (ret < 0) {
1016 goto error_stream;
1017 }
1018
1019 do {
1020 health_code_update();
1021 ret = lttng_consumer_read_subbuffer(metadata_stream, ctx, true);
1022 if (ret < 0) {
1023 goto error_stream;
1024 }
1025 } while (ret > 0);
1026
1027 error_stream:
1028 metadata_stream->read_subbuffer_ops.unlock(metadata_stream);
1029 /*
1030 * Clean up the stream completely because the next snapshot will use a
1031 * new metadata stream.
1032 */
1033 consumer_stream_destroy(metadata_stream, NULL);
1034 cds_list_del(&metadata_stream->send_node);
1035 metadata_channel->metadata_stream = NULL;
1036
1037 error:
1038 rcu_read_unlock();
1039 return ret;
1040 }
1041
1042 static
1043 int get_current_subbuf_addr(struct lttng_consumer_stream *stream,
1044 const char **addr)
1045 {
1046 int ret;
1047 unsigned long mmap_offset;
1048 const char *mmap_base;
1049
1050 mmap_base = (const char *) lttng_ust_ctl_get_mmap_base(stream->ustream);
1051 if (!mmap_base) {
1052 ERR("Failed to get mmap base for stream `%s`",
1053 stream->name);
1054 ret = -EPERM;
1055 goto error;
1056 }
1057
1058 ret = lttng_ust_ctl_get_mmap_read_offset(stream->ustream, &mmap_offset);
1059 if (ret != 0) {
1060 ERR("Failed to get mmap offset for stream `%s`", stream->name);
1061 ret = -EINVAL;
1062 goto error;
1063 }
1064
1065 *addr = mmap_base + mmap_offset;
1066 error:
1067 return ret;
1068
1069 }
1070
1071 /*
1072 * Take a snapshot of all the stream of a channel.
1073 * RCU read-side lock and the channel lock must be held by the caller.
1074 *
1075 * Returns 0 on success, < 0 on error
1076 */
1077 static int snapshot_channel(struct lttng_consumer_channel *channel,
1078 uint64_t key, char *path, uint64_t relayd_id,
1079 uint64_t nb_packets_per_stream,
1080 struct lttng_consumer_local_data *ctx)
1081 {
1082 int ret;
1083 unsigned use_relayd = 0;
1084 unsigned long consumed_pos, produced_pos;
1085 struct lttng_consumer_stream *stream;
1086
1087 LTTNG_ASSERT(path);
1088 LTTNG_ASSERT(ctx);
1089
1090 rcu_read_lock();
1091
1092 if (relayd_id != (uint64_t) -1ULL) {
1093 use_relayd = 1;
1094 }
1095
1096 LTTNG_ASSERT(!channel->monitor);
1097 DBG("UST consumer snapshot channel %" PRIu64, key);
1098
1099 cds_list_for_each_entry(stream, &channel->streams.head, send_node) {
1100 health_code_update();
1101
1102 /* Lock stream because we are about to change its state. */
1103 pthread_mutex_lock(&stream->lock);
1104 LTTNG_ASSERT(channel->trace_chunk);
1105 if (!lttng_trace_chunk_get(channel->trace_chunk)) {
1106 /*
1107 * Can't happen barring an internal error as the channel
1108 * holds a reference to the trace chunk.
1109 */
1110 ERR("Failed to acquire reference to channel's trace chunk");
1111 ret = -1;
1112 goto error_unlock;
1113 }
1114 LTTNG_ASSERT(!stream->trace_chunk);
1115 stream->trace_chunk = channel->trace_chunk;
1116
1117 stream->net_seq_idx = relayd_id;
1118
1119 if (use_relayd) {
1120 ret = consumer_send_relayd_stream(stream, path);
1121 if (ret < 0) {
1122 goto error_unlock;
1123 }
1124 } else {
1125 ret = consumer_stream_create_output_files(stream,
1126 false);
1127 if (ret < 0) {
1128 goto error_unlock;
1129 }
1130 DBG("UST consumer snapshot stream (%" PRIu64 ")",
1131 stream->key);
1132 }
1133
1134 /*
1135 * If tracing is active, we want to perform a "full" buffer flush.
1136 * Else, if quiescent, it has already been done by the prior stop.
1137 */
1138 if (!stream->quiescent) {
1139 ret = lttng_ust_ctl_flush_buffer(stream->ustream, 0);
1140 if (ret < 0) {
1141 ERR("Failed to flush buffer during snapshot of channel: channel key = %" PRIu64 ", channel name = '%s'",
1142 channel->key, channel->name);
1143 goto error_unlock;
1144 }
1145 }
1146
1147 ret = lttng_ustconsumer_take_snapshot(stream);
1148 if (ret < 0) {
1149 ERR("Taking UST snapshot");
1150 goto error_unlock;
1151 }
1152
1153 ret = lttng_ustconsumer_get_produced_snapshot(stream, &produced_pos);
1154 if (ret < 0) {
1155 ERR("Produced UST snapshot position");
1156 goto error_unlock;
1157 }
1158
1159 ret = lttng_ustconsumer_get_consumed_snapshot(stream, &consumed_pos);
1160 if (ret < 0) {
1161 ERR("Consumerd UST snapshot position");
1162 goto error_unlock;
1163 }
1164
1165 /*
1166 * The original value is sent back if max stream size is larger than
1167 * the possible size of the snapshot. Also, we assume that the session
1168 * daemon should never send a maximum stream size that is lower than
1169 * subbuffer size.
1170 */
1171 consumed_pos = consumer_get_consume_start_pos(consumed_pos,
1172 produced_pos, nb_packets_per_stream,
1173 stream->max_sb_size);
1174
1175 while ((long) (consumed_pos - produced_pos) < 0) {
1176 ssize_t read_len;
1177 unsigned long len, padded_len;
1178 const char *subbuf_addr;
1179 struct lttng_buffer_view subbuf_view;
1180
1181 health_code_update();
1182
1183 DBG("UST consumer taking snapshot at pos %lu", consumed_pos);
1184
1185 ret = lttng_ust_ctl_get_subbuf(stream->ustream, &consumed_pos);
1186 if (ret < 0) {
1187 if (ret != -EAGAIN) {
1188 PERROR("lttng_ust_ctl_get_subbuf snapshot");
1189 goto error_close_stream;
1190 }
1191 DBG("UST consumer get subbuf failed. Skipping it.");
1192 consumed_pos += stream->max_sb_size;
1193 stream->chan->lost_packets++;
1194 continue;
1195 }
1196
1197 ret = lttng_ust_ctl_get_subbuf_size(stream->ustream, &len);
1198 if (ret < 0) {
1199 ERR("Snapshot lttng_ust_ctl_get_subbuf_size");
1200 goto error_put_subbuf;
1201 }
1202
1203 ret = lttng_ust_ctl_get_padded_subbuf_size(stream->ustream, &padded_len);
1204 if (ret < 0) {
1205 ERR("Snapshot lttng_ust_ctl_get_padded_subbuf_size");
1206 goto error_put_subbuf;
1207 }
1208
1209 ret = get_current_subbuf_addr(stream, &subbuf_addr);
1210 if (ret) {
1211 goto error_put_subbuf;
1212 }
1213
1214 subbuf_view = lttng_buffer_view_init(
1215 subbuf_addr, 0, padded_len);
1216 read_len = lttng_consumer_on_read_subbuffer_mmap(
1217 stream, &subbuf_view, padded_len - len);
1218 if (use_relayd) {
1219 if (read_len != len) {
1220 ret = -EPERM;
1221 goto error_put_subbuf;
1222 }
1223 } else {
1224 if (read_len != padded_len) {
1225 ret = -EPERM;
1226 goto error_put_subbuf;
1227 }
1228 }
1229
1230 ret = lttng_ust_ctl_put_subbuf(stream->ustream);
1231 if (ret < 0) {
1232 ERR("Snapshot lttng_ust_ctl_put_subbuf");
1233 goto error_close_stream;
1234 }
1235 consumed_pos += stream->max_sb_size;
1236 }
1237
1238 /* Simply close the stream so we can use it on the next snapshot. */
1239 consumer_stream_close(stream);
1240 pthread_mutex_unlock(&stream->lock);
1241 }
1242
1243 rcu_read_unlock();
1244 return 0;
1245
1246 error_put_subbuf:
1247 if (lttng_ust_ctl_put_subbuf(stream->ustream) < 0) {
1248 ERR("Snapshot lttng_ust_ctl_put_subbuf");
1249 }
1250 error_close_stream:
1251 consumer_stream_close(stream);
1252 error_unlock:
1253 pthread_mutex_unlock(&stream->lock);
1254 rcu_read_unlock();
1255 return ret;
1256 }
1257
1258 static
1259 void metadata_stream_reset_cache_consumed_position(
1260 struct lttng_consumer_stream *stream)
1261 {
1262 ASSERT_LOCKED(stream->lock);
1263
1264 DBG("Reset metadata cache of session %" PRIu64,
1265 stream->chan->session_id);
1266 stream->ust_metadata_pushed = 0;
1267 }
1268
1269 /*
1270 * Receive the metadata updates from the sessiond. Supports receiving
1271 * overlapping metadata, but is needs to always belong to a contiguous
1272 * range starting from 0.
1273 * Be careful about the locks held when calling this function: it needs
1274 * the metadata cache flush to concurrently progress in order to
1275 * complete.
1276 */
1277 int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset,
1278 uint64_t len, uint64_t version,
1279 struct lttng_consumer_channel *channel, int timer, int wait)
1280 {
1281 int ret, ret_code = LTTCOMM_CONSUMERD_SUCCESS;
1282 char *metadata_str;
1283 enum consumer_metadata_cache_write_status cache_write_status;
1284
1285 DBG("UST consumer push metadata key %" PRIu64 " of len %" PRIu64, key, len);
1286
1287 metadata_str = (char *) zmalloc(len * sizeof(char));
1288 if (!metadata_str) {
1289 PERROR("zmalloc metadata string");
1290 ret_code = LTTCOMM_CONSUMERD_ENOMEM;
1291 goto end;
1292 }
1293
1294 health_code_update();
1295
1296 /* Receive metadata string. */
1297 ret = lttcomm_recv_unix_sock(sock, metadata_str, len);
1298 if (ret < 0) {
1299 /* Session daemon is dead so return gracefully. */
1300 ret_code = ret;
1301 goto end_free;
1302 }
1303
1304 health_code_update();
1305
1306 pthread_mutex_lock(&channel->metadata_cache->lock);
1307 cache_write_status = consumer_metadata_cache_write(
1308 channel->metadata_cache, offset, len, version,
1309 metadata_str);
1310 pthread_mutex_unlock(&channel->metadata_cache->lock);
1311 switch (cache_write_status) {
1312 case CONSUMER_METADATA_CACHE_WRITE_STATUS_NO_CHANGE:
1313 /*
1314 * The write entirely overlapped with existing contents of the
1315 * same metadata version (same content); there is nothing to do.
1316 */
1317 break;
1318 case CONSUMER_METADATA_CACHE_WRITE_STATUS_INVALIDATED:
1319 /*
1320 * The metadata cache was invalidated (previously pushed
1321 * content has been overwritten). Reset the stream's consumed
1322 * metadata position to ensure the metadata poll thread consumes
1323 * the whole cache.
1324 */
1325
1326 /*
1327 * channel::metadata_stream can be null when the metadata
1328 * channel is under a snapshot session type. No need to update
1329 * the stream position in that scenario.
1330 */
1331 if (channel->metadata_stream != NULL) {
1332 pthread_mutex_lock(&channel->metadata_stream->lock);
1333 metadata_stream_reset_cache_consumed_position(
1334 channel->metadata_stream);
1335 pthread_mutex_unlock(&channel->metadata_stream->lock);
1336 } else {
1337 /* Validate we are in snapshot mode. */
1338 LTTNG_ASSERT(!channel->monitor);
1339 }
1340 /* Fall-through. */
1341 case CONSUMER_METADATA_CACHE_WRITE_STATUS_APPENDED_CONTENT:
1342 /*
1343 * In both cases, the metadata poll thread has new data to
1344 * consume.
1345 */
1346 ret = consumer_metadata_wakeup_pipe(channel);
1347 if (ret) {
1348 ret_code = LTTCOMM_CONSUMERD_ERROR_METADATA;
1349 goto end_free;
1350 }
1351 break;
1352 case CONSUMER_METADATA_CACHE_WRITE_STATUS_ERROR:
1353 /* Unable to handle metadata. Notify session daemon. */
1354 ret_code = LTTCOMM_CONSUMERD_ERROR_METADATA;
1355 /*
1356 * Skip metadata flush on write error since the offset and len might
1357 * not have been updated which could create an infinite loop below when
1358 * waiting for the metadata cache to be flushed.
1359 */
1360 goto end_free;
1361 default:
1362 abort();
1363 }
1364
1365 if (!wait) {
1366 goto end_free;
1367 }
1368 while (consumer_metadata_cache_flushed(channel, offset + len, timer)) {
1369 DBG("Waiting for metadata to be flushed");
1370
1371 health_code_update();
1372
1373 usleep(DEFAULT_METADATA_AVAILABILITY_WAIT_TIME);
1374 }
1375
1376 end_free:
1377 free(metadata_str);
1378 end:
1379 return ret_code;
1380 }
1381
1382 /*
1383 * Receive command from session daemon and process it.
1384 *
1385 * Return 1 on success else a negative value or 0.
1386 */
1387 int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
1388 int sock, struct pollfd *consumer_sockpoll)
1389 {
1390 int ret_func;
1391 enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS;
1392 struct lttcomm_consumer_msg msg;
1393 struct lttng_consumer_channel *channel = NULL;
1394
1395 health_code_update();
1396
1397 {
1398 ssize_t ret_recv;
1399
1400 ret_recv = lttcomm_recv_unix_sock(sock, &msg, sizeof(msg));
1401 if (ret_recv != sizeof(msg)) {
1402 DBG("Consumer received unexpected message size %zd (expects %zu)",
1403 ret_recv, sizeof(msg));
1404 /*
1405 * The ret value might 0 meaning an orderly shutdown but this is ok
1406 * since the caller handles this.
1407 */
1408 if (ret_recv > 0) {
1409 lttng_consumer_send_error(ctx,
1410 LTTCOMM_CONSUMERD_ERROR_RECV_CMD);
1411 ret_recv = -1;
1412 }
1413 return ret_recv;
1414 }
1415 }
1416
1417 health_code_update();
1418
1419 /* deprecated */
1420 LTTNG_ASSERT(msg.cmd_type != LTTNG_CONSUMER_STOP);
1421
1422 health_code_update();
1423
1424 /* relayd needs RCU read-side lock */
1425 rcu_read_lock();
1426
1427 switch (msg.cmd_type) {
1428 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET:
1429 {
1430 /* Session daemon status message are handled in the following call. */
1431 consumer_add_relayd_socket(msg.u.relayd_sock.net_index,
1432 msg.u.relayd_sock.type, ctx, sock, consumer_sockpoll,
1433 &msg.u.relayd_sock.sock, msg.u.relayd_sock.session_id,
1434 msg.u.relayd_sock.relayd_session_id);
1435 goto end_nosignal;
1436 }
1437 case LTTNG_CONSUMER_DESTROY_RELAYD:
1438 {
1439 uint64_t index = msg.u.destroy_relayd.net_seq_idx;
1440 struct consumer_relayd_sock_pair *relayd;
1441
1442 DBG("UST consumer destroying relayd %" PRIu64, index);
1443
1444 /* Get relayd reference if exists. */
1445 relayd = consumer_find_relayd(index);
1446 if (relayd == NULL) {
1447 DBG("Unable to find relayd %" PRIu64, index);
1448 ret_code = LTTCOMM_CONSUMERD_RELAYD_FAIL;
1449 }
1450
1451 /*
1452 * Each relayd socket pair has a refcount of stream attached to it
1453 * which tells if the relayd is still active or not depending on the
1454 * refcount value.
1455 *
1456 * This will set the destroy flag of the relayd object and destroy it
1457 * if the refcount reaches zero when called.
1458 *
1459 * The destroy can happen either here or when a stream fd hangs up.
1460 */
1461 if (relayd) {
1462 consumer_flag_relayd_for_destroy(relayd);
1463 }
1464
1465 goto end_msg_sessiond;
1466 }
1467 case LTTNG_CONSUMER_UPDATE_STREAM:
1468 {
1469 rcu_read_unlock();
1470 return -ENOSYS;
1471 }
1472 case LTTNG_CONSUMER_DATA_PENDING:
1473 {
1474 int is_data_pending;
1475 ssize_t ret_send;
1476 uint64_t id = msg.u.data_pending.session_id;
1477
1478 DBG("UST consumer data pending command for id %" PRIu64, id);
1479
1480 is_data_pending = consumer_data_pending(id);
1481
1482 /* Send back returned value to session daemon */
1483 ret_send = lttcomm_send_unix_sock(sock, &is_data_pending,
1484 sizeof(is_data_pending));
1485 if (ret_send < 0) {
1486 DBG("Error when sending the data pending ret code: %zd",
1487 ret_send);
1488 goto error_fatal;
1489 }
1490
1491 /*
1492 * No need to send back a status message since the data pending
1493 * returned value is the response.
1494 */
1495 break;
1496 }
1497 case LTTNG_CONSUMER_ASK_CHANNEL_CREATION:
1498 {
1499 int ret_ask_channel, ret_add_channel, ret_send;
1500 struct lttng_ust_ctl_consumer_channel_attr attr;
1501 const uint64_t chunk_id = msg.u.ask_channel.chunk_id.value;
1502 const struct lttng_credentials buffer_credentials = {
1503 .uid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.ask_channel.buffer_credentials.uid),
1504 .gid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.ask_channel.buffer_credentials.gid),
1505 };
1506
1507 /* Create a plain object and reserve a channel key. */
1508 channel = consumer_allocate_channel(
1509 msg.u.ask_channel.key,
1510 msg.u.ask_channel.session_id,
1511 msg.u.ask_channel.chunk_id.is_set ?
1512 &chunk_id : NULL,
1513 msg.u.ask_channel.pathname,
1514 msg.u.ask_channel.name,
1515 msg.u.ask_channel.relayd_id,
1516 (enum lttng_event_output) msg.u.ask_channel.output,
1517 msg.u.ask_channel.tracefile_size,
1518 msg.u.ask_channel.tracefile_count,
1519 msg.u.ask_channel.session_id_per_pid,
1520 msg.u.ask_channel.monitor,
1521 msg.u.ask_channel.live_timer_interval,
1522 msg.u.ask_channel.is_live,
1523 msg.u.ask_channel.root_shm_path,
1524 msg.u.ask_channel.shm_path);
1525 if (!channel) {
1526 goto end_channel_error;
1527 }
1528
1529 LTTNG_OPTIONAL_SET(&channel->buffer_credentials,
1530 buffer_credentials);
1531
1532 /*
1533 * Assign UST application UID to the channel. This value is ignored for
1534 * per PID buffers. This is specific to UST thus setting this after the
1535 * allocation.
1536 */
1537 channel->ust_app_uid = msg.u.ask_channel.ust_app_uid;
1538
1539 /* Build channel attributes from received message. */
1540 attr.subbuf_size = msg.u.ask_channel.subbuf_size;
1541 attr.num_subbuf = msg.u.ask_channel.num_subbuf;
1542 attr.overwrite = msg.u.ask_channel.overwrite;
1543 attr.switch_timer_interval = msg.u.ask_channel.switch_timer_interval;
1544 attr.read_timer_interval = msg.u.ask_channel.read_timer_interval;
1545 attr.chan_id = msg.u.ask_channel.chan_id;
1546 memcpy(attr.uuid, msg.u.ask_channel.uuid, sizeof(attr.uuid));
1547 attr.blocking_timeout= msg.u.ask_channel.blocking_timeout;
1548
1549 /* Match channel buffer type to the UST abi. */
1550 switch (msg.u.ask_channel.output) {
1551 case LTTNG_EVENT_MMAP:
1552 default:
1553 attr.output = LTTNG_UST_ABI_MMAP;
1554 break;
1555 }
1556
1557 /* Translate and save channel type. */
1558 switch (msg.u.ask_channel.type) {
1559 case LTTNG_UST_ABI_CHAN_PER_CPU:
1560 channel->type = CONSUMER_CHANNEL_TYPE_DATA;
1561 attr.type = LTTNG_UST_ABI_CHAN_PER_CPU;
1562 /*
1563 * Set refcount to 1 for owner. Below, we will
1564 * pass ownership to the
1565 * consumer_thread_channel_poll() thread.
1566 */
1567 channel->refcount = 1;
1568 break;
1569 case LTTNG_UST_ABI_CHAN_METADATA:
1570 channel->type = CONSUMER_CHANNEL_TYPE_METADATA;
1571 attr.type = LTTNG_UST_ABI_CHAN_METADATA;
1572 break;
1573 default:
1574 abort();
1575 goto error_fatal;
1576 };
1577
1578 health_code_update();
1579
1580 ret_ask_channel = ask_channel(ctx, channel, &attr);
1581 if (ret_ask_channel < 0) {
1582 goto end_channel_error;
1583 }
1584
1585 if (msg.u.ask_channel.type == LTTNG_UST_ABI_CHAN_METADATA) {
1586 int ret_allocate;
1587
1588 ret_allocate = consumer_metadata_cache_allocate(
1589 channel);
1590 if (ret_allocate < 0) {
1591 ERR("Allocating metadata cache");
1592 goto end_channel_error;
1593 }
1594 consumer_timer_switch_start(channel, attr.switch_timer_interval);
1595 attr.switch_timer_interval = 0;
1596 } else {
1597 int monitor_start_ret;
1598
1599 consumer_timer_live_start(channel,
1600 msg.u.ask_channel.live_timer_interval);
1601 monitor_start_ret = consumer_timer_monitor_start(
1602 channel,
1603 msg.u.ask_channel.monitor_timer_interval);
1604 if (monitor_start_ret < 0) {
1605 ERR("Starting channel monitoring timer failed");
1606 goto end_channel_error;
1607 }
1608 }
1609
1610 health_code_update();
1611
1612 /*
1613 * Add the channel to the internal state AFTER all streams were created
1614 * and successfully sent to session daemon. This way, all streams must
1615 * be ready before this channel is visible to the threads.
1616 * If add_channel succeeds, ownership of the channel is
1617 * passed to consumer_thread_channel_poll().
1618 */
1619 ret_add_channel = add_channel(channel, ctx);
1620 if (ret_add_channel < 0) {
1621 if (msg.u.ask_channel.type == LTTNG_UST_ABI_CHAN_METADATA) {
1622 if (channel->switch_timer_enabled == 1) {
1623 consumer_timer_switch_stop(channel);
1624 }
1625 consumer_metadata_cache_destroy(channel);
1626 }
1627 if (channel->live_timer_enabled == 1) {
1628 consumer_timer_live_stop(channel);
1629 }
1630 if (channel->monitor_timer_enabled == 1) {
1631 consumer_timer_monitor_stop(channel);
1632 }
1633 goto end_channel_error;
1634 }
1635
1636 health_code_update();
1637
1638 /*
1639 * Channel and streams are now created. Inform the session daemon that
1640 * everything went well and should wait to receive the channel and
1641 * streams with ustctl API.
1642 */
1643 ret_send = consumer_send_status_channel(sock, channel);
1644 if (ret_send < 0) {
1645 /*
1646 * There is probably a problem on the socket.
1647 */
1648 goto error_fatal;
1649 }
1650
1651 break;
1652 }
1653 case LTTNG_CONSUMER_GET_CHANNEL:
1654 {
1655 int ret, relayd_err = 0;
1656 uint64_t key = msg.u.get_channel.key;
1657 struct lttng_consumer_channel *found_channel;
1658
1659 found_channel = consumer_find_channel(key);
1660 if (!found_channel) {
1661 ERR("UST consumer get channel key %" PRIu64 " not found", key);
1662 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
1663 goto end_get_channel;
1664 }
1665
1666 health_code_update();
1667
1668 /* Send the channel to sessiond (and relayd, if applicable). */
1669 ret = send_channel_to_sessiond_and_relayd(
1670 sock, found_channel, ctx, &relayd_err);
1671 if (ret < 0) {
1672 if (relayd_err) {
1673 /*
1674 * We were unable to send to the relayd the stream so avoid
1675 * sending back a fatal error to the thread since this is OK
1676 * and the consumer can continue its work. The above call
1677 * has sent the error status message to the sessiond.
1678 */
1679 goto end_get_channel_nosignal;
1680 }
1681 /*
1682 * The communicaton was broken hence there is a bad state between
1683 * the consumer and sessiond so stop everything.
1684 */
1685 goto error_get_channel_fatal;
1686 }
1687
1688 health_code_update();
1689
1690 /*
1691 * In no monitor mode, the streams ownership is kept inside the channel
1692 * so don't send them to the data thread.
1693 */
1694 if (!found_channel->monitor) {
1695 goto end_get_channel;
1696 }
1697
1698 ret = send_streams_to_thread(found_channel, ctx);
1699 if (ret < 0) {
1700 /*
1701 * If we are unable to send the stream to the thread, there is
1702 * a big problem so just stop everything.
1703 */
1704 goto error_get_channel_fatal;
1705 }
1706 /* List MUST be empty after or else it could be reused. */
1707 LTTNG_ASSERT(cds_list_empty(&found_channel->streams.head));
1708 end_get_channel:
1709 goto end_msg_sessiond;
1710 error_get_channel_fatal:
1711 goto error_fatal;
1712 end_get_channel_nosignal:
1713 goto end_nosignal;
1714 }
1715 case LTTNG_CONSUMER_DESTROY_CHANNEL:
1716 {
1717 uint64_t key = msg.u.destroy_channel.key;
1718
1719 /*
1720 * Only called if streams have not been sent to stream
1721 * manager thread. However, channel has been sent to
1722 * channel manager thread.
1723 */
1724 notify_thread_del_channel(ctx, key);
1725 goto end_msg_sessiond;
1726 }
1727 case LTTNG_CONSUMER_CLOSE_METADATA:
1728 {
1729 int ret;
1730
1731 ret = close_metadata(msg.u.close_metadata.key);
1732 if (ret != 0) {
1733 ret_code = (lttcomm_return_code) ret;
1734 }
1735
1736 goto end_msg_sessiond;
1737 }
1738 case LTTNG_CONSUMER_FLUSH_CHANNEL:
1739 {
1740 int ret;
1741
1742 ret = flush_channel(msg.u.flush_channel.key);
1743 if (ret != 0) {
1744 ret_code = (lttcomm_return_code) ret;
1745 }
1746
1747 goto end_msg_sessiond;
1748 }
1749 case LTTNG_CONSUMER_CLEAR_QUIESCENT_CHANNEL:
1750 {
1751 int ret;
1752
1753 ret = clear_quiescent_channel(
1754 msg.u.clear_quiescent_channel.key);
1755 if (ret != 0) {
1756 ret_code = (lttcomm_return_code) ret;
1757 }
1758
1759 goto end_msg_sessiond;
1760 }
1761 case LTTNG_CONSUMER_PUSH_METADATA:
1762 {
1763 int ret;
1764 uint64_t len = msg.u.push_metadata.len;
1765 uint64_t key = msg.u.push_metadata.key;
1766 uint64_t offset = msg.u.push_metadata.target_offset;
1767 uint64_t version = msg.u.push_metadata.version;
1768 struct lttng_consumer_channel *found_channel;
1769
1770 DBG("UST consumer push metadata key %" PRIu64 " of len %" PRIu64, key,
1771 len);
1772
1773 found_channel = consumer_find_channel(key);
1774 if (!found_channel) {
1775 /*
1776 * This is possible if the metadata creation on the consumer side
1777 * is in flight vis-a-vis a concurrent push metadata from the
1778 * session daemon. Simply return that the channel failed and the
1779 * session daemon will handle that message correctly considering
1780 * that this race is acceptable thus the DBG() statement here.
1781 */
1782 DBG("UST consumer push metadata %" PRIu64 " not found", key);
1783 ret_code = LTTCOMM_CONSUMERD_CHANNEL_FAIL;
1784 goto end_push_metadata_msg_sessiond;
1785 }
1786
1787 health_code_update();
1788
1789 if (!len) {
1790 /*
1791 * There is nothing to receive. We have simply
1792 * checked whether the channel can be found.
1793 */
1794 ret_code = LTTCOMM_CONSUMERD_SUCCESS;
1795 goto end_push_metadata_msg_sessiond;
1796 }
1797
1798 /* Tell session daemon we are ready to receive the metadata. */
1799 ret = consumer_send_status_msg(sock, LTTCOMM_CONSUMERD_SUCCESS);
1800 if (ret < 0) {
1801 /* Somehow, the session daemon is not responding anymore. */
1802 goto error_push_metadata_fatal;
1803 }
1804
1805 health_code_update();
1806
1807 /* Wait for more data. */
1808 health_poll_entry();
1809 ret = lttng_consumer_poll_socket(consumer_sockpoll);
1810 health_poll_exit();
1811 if (ret) {
1812 goto error_push_metadata_fatal;
1813 }
1814
1815 health_code_update();
1816
1817 ret = lttng_ustconsumer_recv_metadata(sock, key, offset, len,
1818 version, found_channel, 0, 1);
1819 if (ret < 0) {
1820 /* error receiving from sessiond */
1821 goto error_push_metadata_fatal;
1822 } else {
1823 ret_code = (lttcomm_return_code) ret;
1824 goto end_push_metadata_msg_sessiond;
1825 }
1826 end_push_metadata_msg_sessiond:
1827 goto end_msg_sessiond;
1828 error_push_metadata_fatal:
1829 goto error_fatal;
1830 }
1831 case LTTNG_CONSUMER_SETUP_METADATA:
1832 {
1833 int ret;
1834
1835 ret = setup_metadata(ctx, msg.u.setup_metadata.key);
1836 if (ret) {
1837 ret_code = (lttcomm_return_code) ret;
1838 }
1839 goto end_msg_sessiond;
1840 }
1841 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL:
1842 {
1843 struct lttng_consumer_channel *found_channel;
1844 uint64_t key = msg.u.snapshot_channel.key;
1845 int ret_send;
1846
1847 found_channel = consumer_find_channel(key);
1848 if (!found_channel) {
1849 DBG("UST snapshot channel not found for key %" PRIu64, key);
1850 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
1851 } else {
1852 if (msg.u.snapshot_channel.metadata) {
1853 int ret_snapshot;
1854
1855 ret_snapshot = snapshot_metadata(found_channel,
1856 key,
1857 msg.u.snapshot_channel.pathname,
1858 msg.u.snapshot_channel.relayd_id,
1859 ctx);
1860 if (ret_snapshot < 0) {
1861 ERR("Snapshot metadata failed");
1862 ret_code = LTTCOMM_CONSUMERD_SNAPSHOT_FAILED;
1863 }
1864 } else {
1865 int ret_snapshot;
1866
1867 ret_snapshot = snapshot_channel(found_channel,
1868 key,
1869 msg.u.snapshot_channel.pathname,
1870 msg.u.snapshot_channel.relayd_id,
1871 msg.u.snapshot_channel
1872 .nb_packets_per_stream,
1873 ctx);
1874 if (ret_snapshot < 0) {
1875 ERR("Snapshot channel failed");
1876 ret_code = LTTCOMM_CONSUMERD_SNAPSHOT_FAILED;
1877 }
1878 }
1879 }
1880 health_code_update();
1881 ret_send = consumer_send_status_msg(sock, ret_code);
1882 if (ret_send < 0) {
1883 /* Somehow, the session daemon is not responding anymore. */
1884 goto end_nosignal;
1885 }
1886 health_code_update();
1887 break;
1888 }
1889 case LTTNG_CONSUMER_DISCARDED_EVENTS:
1890 {
1891 int ret = 0;
1892 uint64_t discarded_events;
1893 struct lttng_ht_iter iter;
1894 struct lttng_ht *ht;
1895 struct lttng_consumer_stream *stream;
1896 uint64_t id = msg.u.discarded_events.session_id;
1897 uint64_t key = msg.u.discarded_events.channel_key;
1898
1899 DBG("UST consumer discarded events command for session id %"
1900 PRIu64, id);
1901 rcu_read_lock();
1902 pthread_mutex_lock(&the_consumer_data.lock);
1903
1904 ht = the_consumer_data.stream_list_ht;
1905
1906 /*
1907 * We only need a reference to the channel, but they are not
1908 * directly indexed, so we just use the first matching stream
1909 * to extract the information we need, we default to 0 if not
1910 * found (no events are dropped if the channel is not yet in
1911 * use).
1912 */
1913 discarded_events = 0;
1914 cds_lfht_for_each_entry_duplicate(ht->ht,
1915 ht->hash_fct(&id, lttng_ht_seed),
1916 ht->match_fct, &id,
1917 &iter.iter, stream, node_session_id.node) {
1918 if (stream->chan->key == key) {
1919 discarded_events = stream->chan->discarded_events;
1920 break;
1921 }
1922 }
1923 pthread_mutex_unlock(&the_consumer_data.lock);
1924 rcu_read_unlock();
1925
1926 DBG("UST consumer discarded events command for session id %"
1927 PRIu64 ", channel key %" PRIu64, id, key);
1928
1929 health_code_update();
1930
1931 /* Send back returned value to session daemon */
1932 ret = lttcomm_send_unix_sock(sock, &discarded_events, sizeof(discarded_events));
1933 if (ret < 0) {
1934 PERROR("send discarded events");
1935 goto error_fatal;
1936 }
1937
1938 break;
1939 }
1940 case LTTNG_CONSUMER_LOST_PACKETS:
1941 {
1942 int ret;
1943 uint64_t lost_packets;
1944 struct lttng_ht_iter iter;
1945 struct lttng_ht *ht;
1946 struct lttng_consumer_stream *stream;
1947 uint64_t id = msg.u.lost_packets.session_id;
1948 uint64_t key = msg.u.lost_packets.channel_key;
1949
1950 DBG("UST consumer lost packets command for session id %"
1951 PRIu64, id);
1952 rcu_read_lock();
1953 pthread_mutex_lock(&the_consumer_data.lock);
1954
1955 ht = the_consumer_data.stream_list_ht;
1956
1957 /*
1958 * We only need a reference to the channel, but they are not
1959 * directly indexed, so we just use the first matching stream
1960 * to extract the information we need, we default to 0 if not
1961 * found (no packets lost if the channel is not yet in use).
1962 */
1963 lost_packets = 0;
1964 cds_lfht_for_each_entry_duplicate(ht->ht,
1965 ht->hash_fct(&id, lttng_ht_seed),
1966 ht->match_fct, &id,
1967 &iter.iter, stream, node_session_id.node) {
1968 if (stream->chan->key == key) {
1969 lost_packets = stream->chan->lost_packets;
1970 break;
1971 }
1972 }
1973 pthread_mutex_unlock(&the_consumer_data.lock);
1974 rcu_read_unlock();
1975
1976 DBG("UST consumer lost packets command for session id %"
1977 PRIu64 ", channel key %" PRIu64, id, key);
1978
1979 health_code_update();
1980
1981 /* Send back returned value to session daemon */
1982 ret = lttcomm_send_unix_sock(sock, &lost_packets,
1983 sizeof(lost_packets));
1984 if (ret < 0) {
1985 PERROR("send lost packets");
1986 goto error_fatal;
1987 }
1988
1989 break;
1990 }
1991 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE:
1992 {
1993 int channel_monitor_pipe, ret_send,
1994 ret_set_channel_monitor_pipe;
1995 ssize_t ret_recv;
1996
1997 ret_code = LTTCOMM_CONSUMERD_SUCCESS;
1998 /* Successfully received the command's type. */
1999 ret_send = consumer_send_status_msg(sock, ret_code);
2000 if (ret_send < 0) {
2001 goto error_fatal;
2002 }
2003
2004 ret_recv = lttcomm_recv_fds_unix_sock(
2005 sock, &channel_monitor_pipe, 1);
2006 if (ret_recv != sizeof(channel_monitor_pipe)) {
2007 ERR("Failed to receive channel monitor pipe");
2008 goto error_fatal;
2009 }
2010
2011 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe);
2012 ret_set_channel_monitor_pipe =
2013 consumer_timer_thread_set_channel_monitor_pipe(
2014 channel_monitor_pipe);
2015 if (!ret_set_channel_monitor_pipe) {
2016 int flags;
2017 int ret_fcntl;
2018
2019 ret_code = LTTCOMM_CONSUMERD_SUCCESS;
2020 /* Set the pipe as non-blocking. */
2021 ret_fcntl = fcntl(channel_monitor_pipe, F_GETFL, 0);
2022 if (ret_fcntl == -1) {
2023 PERROR("fcntl get flags of the channel monitoring pipe");
2024 goto error_fatal;
2025 }
2026 flags = ret_fcntl;
2027
2028 ret_fcntl = fcntl(channel_monitor_pipe, F_SETFL,
2029 flags | O_NONBLOCK);
2030 if (ret_fcntl == -1) {
2031 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
2032 goto error_fatal;
2033 }
2034 DBG("Channel monitor pipe set as non-blocking");
2035 } else {
2036 ret_code = LTTCOMM_CONSUMERD_ALREADY_SET;
2037 }
2038 goto end_msg_sessiond;
2039 }
2040 case LTTNG_CONSUMER_ROTATE_CHANNEL:
2041 {
2042 struct lttng_consumer_channel *found_channel;
2043 uint64_t key = msg.u.rotate_channel.key;
2044 int ret_send_status;
2045
2046 found_channel = consumer_find_channel(key);
2047 if (!found_channel) {
2048 DBG("Channel %" PRIu64 " not found", key);
2049 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
2050 } else {
2051 int rotate_channel;
2052
2053 /*
2054 * Sample the rotate position of all the streams in
2055 * this channel.
2056 */
2057 rotate_channel = lttng_consumer_rotate_channel(
2058 found_channel, key,
2059 msg.u.rotate_channel.relayd_id,
2060 msg.u.rotate_channel.metadata, ctx);
2061 if (rotate_channel < 0) {
2062 ERR("Rotate channel failed");
2063 ret_code = LTTCOMM_CONSUMERD_ROTATION_FAIL;
2064 }
2065
2066 health_code_update();
2067 }
2068
2069 ret_send_status = consumer_send_status_msg(sock, ret_code);
2070 if (ret_send_status < 0) {
2071 /* Somehow, the session daemon is not responding anymore. */
2072 goto end_rotate_channel_nosignal;
2073 }
2074
2075 /*
2076 * Rotate the streams that are ready right now.
2077 * FIXME: this is a second consecutive iteration over the
2078 * streams in a channel, there is probably a better way to
2079 * handle this, but it needs to be after the
2080 * consumer_send_status_msg() call.
2081 */
2082 if (found_channel) {
2083 int ret_rotate_read_streams;
2084
2085 ret_rotate_read_streams =
2086 lttng_consumer_rotate_ready_streams(
2087 found_channel, key,
2088 ctx);
2089 if (ret_rotate_read_streams < 0) {
2090 ERR("Rotate channel failed");
2091 }
2092 }
2093 break;
2094 end_rotate_channel_nosignal:
2095 goto end_nosignal;
2096 }
2097 case LTTNG_CONSUMER_CLEAR_CHANNEL:
2098 {
2099 struct lttng_consumer_channel *found_channel;
2100 uint64_t key = msg.u.clear_channel.key;
2101 int ret_send_status;
2102
2103 found_channel = consumer_find_channel(key);
2104 if (!found_channel) {
2105 DBG("Channel %" PRIu64 " not found", key);
2106 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
2107 } else {
2108 int ret_clear_channel;
2109
2110 ret_clear_channel = lttng_consumer_clear_channel(
2111 found_channel);
2112 if (ret_clear_channel) {
2113 ERR("Clear channel failed key %" PRIu64, key);
2114 ret_code = (lttcomm_return_code) ret_clear_channel;
2115 }
2116
2117 health_code_update();
2118 }
2119 ret_send_status = consumer_send_status_msg(sock, ret_code);
2120 if (ret_send_status < 0) {
2121 /* Somehow, the session daemon is not responding anymore. */
2122 goto end_nosignal;
2123 }
2124 break;
2125 }
2126 case LTTNG_CONSUMER_INIT:
2127 {
2128 int ret_send_status;
2129
2130 ret_code = lttng_consumer_init_command(ctx,
2131 msg.u.init.sessiond_uuid);
2132 health_code_update();
2133 ret_send_status = consumer_send_status_msg(sock, ret_code);
2134 if (ret_send_status < 0) {
2135 /* Somehow, the session daemon is not responding anymore. */
2136 goto end_nosignal;
2137 }
2138 break;
2139 }
2140 case LTTNG_CONSUMER_CREATE_TRACE_CHUNK:
2141 {
2142 const struct lttng_credentials credentials = {
2143 .uid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.create_trace_chunk.credentials.value.uid),
2144 .gid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.create_trace_chunk.credentials.value.gid),
2145 };
2146 const bool is_local_trace =
2147 !msg.u.create_trace_chunk.relayd_id.is_set;
2148 const uint64_t relayd_id =
2149 msg.u.create_trace_chunk.relayd_id.value;
2150 const char *chunk_override_name =
2151 *msg.u.create_trace_chunk.override_name ?
2152 msg.u.create_trace_chunk.override_name :
2153 NULL;
2154 struct lttng_directory_handle *chunk_directory_handle = NULL;
2155
2156 /*
2157 * The session daemon will only provide a chunk directory file
2158 * descriptor for local traces.
2159 */
2160 if (is_local_trace) {
2161 int chunk_dirfd;
2162 int ret_send_status;
2163 ssize_t ret_recv;
2164
2165 /* Acnowledge the reception of the command. */
2166 ret_send_status = consumer_send_status_msg(
2167 sock, LTTCOMM_CONSUMERD_SUCCESS);
2168 if (ret_send_status < 0) {
2169 /* Somehow, the session daemon is not responding anymore. */
2170 goto end_nosignal;
2171 }
2172
2173 /*
2174 * Receive trace chunk domain dirfd.
2175 */
2176 ret_recv = lttcomm_recv_fds_unix_sock(
2177 sock, &chunk_dirfd, 1);
2178 if (ret_recv != sizeof(chunk_dirfd)) {
2179 ERR("Failed to receive trace chunk domain directory file descriptor");
2180 goto error_fatal;
2181 }
2182
2183 DBG("Received trace chunk domain directory fd (%d)",
2184 chunk_dirfd);
2185 chunk_directory_handle = lttng_directory_handle_create_from_dirfd(
2186 chunk_dirfd);
2187 if (!chunk_directory_handle) {
2188 ERR("Failed to initialize chunk domain directory handle from directory file descriptor");
2189 if (close(chunk_dirfd)) {
2190 PERROR("Failed to close chunk directory file descriptor");
2191 }
2192 goto error_fatal;
2193 }
2194 }
2195
2196 ret_code = lttng_consumer_create_trace_chunk(
2197 !is_local_trace ? &relayd_id : NULL,
2198 msg.u.create_trace_chunk.session_id,
2199 msg.u.create_trace_chunk.chunk_id,
2200 (time_t) msg.u.create_trace_chunk
2201 .creation_timestamp,
2202 chunk_override_name,
2203 msg.u.create_trace_chunk.credentials.is_set ?
2204 &credentials :
2205 NULL,
2206 chunk_directory_handle);
2207 lttng_directory_handle_put(chunk_directory_handle);
2208 goto end_msg_sessiond;
2209 }
2210 case LTTNG_CONSUMER_CLOSE_TRACE_CHUNK:
2211 {
2212 enum lttng_trace_chunk_command_type close_command =
2213 (lttng_trace_chunk_command_type)
2214 msg.u.close_trace_chunk.close_command.value;
2215 const uint64_t relayd_id =
2216 msg.u.close_trace_chunk.relayd_id.value;
2217 struct lttcomm_consumer_close_trace_chunk_reply reply;
2218 char closed_trace_chunk_path[LTTNG_PATH_MAX] = {};
2219 int ret;
2220
2221 ret_code = lttng_consumer_close_trace_chunk(
2222 msg.u.close_trace_chunk.relayd_id.is_set ?
2223 &relayd_id :
2224 NULL,
2225 msg.u.close_trace_chunk.session_id,
2226 msg.u.close_trace_chunk.chunk_id,
2227 (time_t) msg.u.close_trace_chunk.close_timestamp,
2228 msg.u.close_trace_chunk.close_command.is_set ?
2229 &close_command :
2230 NULL, closed_trace_chunk_path);
2231 reply.ret_code = ret_code;
2232 reply.path_length = strlen(closed_trace_chunk_path) + 1;
2233 ret = lttcomm_send_unix_sock(sock, &reply, sizeof(reply));
2234 if (ret != sizeof(reply)) {
2235 goto error_fatal;
2236 }
2237 ret = lttcomm_send_unix_sock(sock, closed_trace_chunk_path,
2238 reply.path_length);
2239 if (ret != reply.path_length) {
2240 goto error_fatal;
2241 }
2242 goto end_nosignal;
2243 }
2244 case LTTNG_CONSUMER_TRACE_CHUNK_EXISTS:
2245 {
2246 const uint64_t relayd_id =
2247 msg.u.trace_chunk_exists.relayd_id.value;
2248
2249 ret_code = lttng_consumer_trace_chunk_exists(
2250 msg.u.trace_chunk_exists.relayd_id.is_set ?
2251 &relayd_id : NULL,
2252 msg.u.trace_chunk_exists.session_id,
2253 msg.u.trace_chunk_exists.chunk_id);
2254 goto end_msg_sessiond;
2255 }
2256 case LTTNG_CONSUMER_OPEN_CHANNEL_PACKETS:
2257 {
2258 const uint64_t key = msg.u.open_channel_packets.key;
2259 struct lttng_consumer_channel *found_channel =
2260 consumer_find_channel(key);
2261
2262 if (found_channel) {
2263 pthread_mutex_lock(&found_channel->lock);
2264 ret_code = lttng_consumer_open_channel_packets(
2265 found_channel);
2266 pthread_mutex_unlock(&found_channel->lock);
2267 } else {
2268 /*
2269 * The channel could have disappeared in per-pid
2270 * buffering mode.
2271 */
2272 DBG("Channel %" PRIu64 " not found", key);
2273 ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
2274 }
2275
2276 health_code_update();
2277 goto end_msg_sessiond;
2278 }
2279 default:
2280 break;
2281 }
2282
2283 end_nosignal:
2284 /*
2285 * Return 1 to indicate success since the 0 value can be a socket
2286 * shutdown during the recv() or send() call.
2287 */
2288 ret_func = 1;
2289 goto end;
2290
2291 end_msg_sessiond:
2292 /*
2293 * The returned value here is not useful since either way we'll return 1 to
2294 * the caller because the session daemon socket management is done
2295 * elsewhere. Returning a negative code or 0 will shutdown the consumer.
2296 */
2297 {
2298 int ret_send_status;
2299
2300 ret_send_status = consumer_send_status_msg(sock, ret_code);
2301 if (ret_send_status < 0) {
2302 goto error_fatal;
2303 }
2304 }
2305
2306 ret_func = 1;
2307 goto end;
2308
2309 end_channel_error:
2310 if (channel) {
2311 /*
2312 * Free channel here since no one has a reference to it. We don't
2313 * free after that because a stream can store this pointer.
2314 */
2315 destroy_channel(channel);
2316 }
2317 /* We have to send a status channel message indicating an error. */
2318 {
2319 int ret_send_status;
2320
2321 ret_send_status = consumer_send_status_channel(sock, NULL);
2322 if (ret_send_status < 0) {
2323 /* Stop everything if session daemon can not be notified. */
2324 goto error_fatal;
2325 }
2326 }
2327
2328 ret_func = 1;
2329 goto end;
2330
2331 error_fatal:
2332 /* This will issue a consumer stop. */
2333 ret_func = -1;
2334 goto end;
2335
2336 end:
2337 rcu_read_unlock();
2338 health_code_update();
2339 return ret_func;
2340 }
2341
2342 int lttng_ust_flush_buffer(struct lttng_consumer_stream *stream,
2343 int producer_active)
2344 {
2345 LTTNG_ASSERT(stream);
2346 LTTNG_ASSERT(stream->ustream);
2347
2348 return lttng_ust_ctl_flush_buffer(stream->ustream, producer_active);
2349 }
2350
2351 /*
2352 * Take a snapshot for a specific stream.
2353 *
2354 * Returns 0 on success, < 0 on error
2355 */
2356 int lttng_ustconsumer_take_snapshot(struct lttng_consumer_stream *stream)
2357 {
2358 LTTNG_ASSERT(stream);
2359 LTTNG_ASSERT(stream->ustream);
2360
2361 return lttng_ust_ctl_snapshot(stream->ustream);
2362 }
2363
2364 /*
2365 * Sample consumed and produced positions for a specific stream.
2366 *
2367 * Returns 0 on success, < 0 on error.
2368 */
2369 int lttng_ustconsumer_sample_snapshot_positions(
2370 struct lttng_consumer_stream *stream)
2371 {
2372 LTTNG_ASSERT(stream);
2373 LTTNG_ASSERT(stream->ustream);
2374
2375 return lttng_ust_ctl_snapshot_sample_positions(stream->ustream);
2376 }
2377
2378 /*
2379 * Get the produced position
2380 *
2381 * Returns 0 on success, < 0 on error
2382 */
2383 int lttng_ustconsumer_get_produced_snapshot(
2384 struct lttng_consumer_stream *stream, unsigned long *pos)
2385 {
2386 LTTNG_ASSERT(stream);
2387 LTTNG_ASSERT(stream->ustream);
2388 LTTNG_ASSERT(pos);
2389
2390 return lttng_ust_ctl_snapshot_get_produced(stream->ustream, pos);
2391 }
2392
2393 /*
2394 * Get the consumed position
2395 *
2396 * Returns 0 on success, < 0 on error
2397 */
2398 int lttng_ustconsumer_get_consumed_snapshot(
2399 struct lttng_consumer_stream *stream, unsigned long *pos)
2400 {
2401 LTTNG_ASSERT(stream);
2402 LTTNG_ASSERT(stream->ustream);
2403 LTTNG_ASSERT(pos);
2404
2405 return lttng_ust_ctl_snapshot_get_consumed(stream->ustream, pos);
2406 }
2407
2408 int lttng_ustconsumer_flush_buffer(struct lttng_consumer_stream *stream,
2409 int producer)
2410 {
2411 LTTNG_ASSERT(stream);
2412 LTTNG_ASSERT(stream->ustream);
2413
2414 return lttng_ust_ctl_flush_buffer(stream->ustream, producer);
2415 }
2416
2417 int lttng_ustconsumer_clear_buffer(struct lttng_consumer_stream *stream)
2418 {
2419 LTTNG_ASSERT(stream);
2420 LTTNG_ASSERT(stream->ustream);
2421
2422 return lttng_ust_ctl_clear_buffer(stream->ustream);
2423 }
2424
2425 int lttng_ustconsumer_get_current_timestamp(
2426 struct lttng_consumer_stream *stream, uint64_t *ts)
2427 {
2428 LTTNG_ASSERT(stream);
2429 LTTNG_ASSERT(stream->ustream);
2430 LTTNG_ASSERT(ts);
2431
2432 return lttng_ust_ctl_get_current_timestamp(stream->ustream, ts);
2433 }
2434
2435 int lttng_ustconsumer_get_sequence_number(
2436 struct lttng_consumer_stream *stream, uint64_t *seq)
2437 {
2438 LTTNG_ASSERT(stream);
2439 LTTNG_ASSERT(stream->ustream);
2440 LTTNG_ASSERT(seq);
2441
2442 return lttng_ust_ctl_get_sequence_number(stream->ustream, seq);
2443 }
2444
2445 /*
2446 * Called when the stream signals the consumer that it has hung up.
2447 */
2448 void lttng_ustconsumer_on_stream_hangup(struct lttng_consumer_stream *stream)
2449 {
2450 LTTNG_ASSERT(stream);
2451 LTTNG_ASSERT(stream->ustream);
2452
2453 pthread_mutex_lock(&stream->lock);
2454 if (!stream->quiescent) {
2455 if (lttng_ust_ctl_flush_buffer(stream->ustream, 0) < 0) {
2456 ERR("Failed to flush buffer on stream hang-up");
2457 } else {
2458 stream->quiescent = true;
2459 }
2460 }
2461 pthread_mutex_unlock(&stream->lock);
2462 stream->hangup_flush_done = 1;
2463 }
2464
2465 void lttng_ustconsumer_del_channel(struct lttng_consumer_channel *chan)
2466 {
2467 int i;
2468
2469 LTTNG_ASSERT(chan);
2470 LTTNG_ASSERT(chan->uchan);
2471 LTTNG_ASSERT(chan->buffer_credentials.is_set);
2472
2473 if (chan->switch_timer_enabled == 1) {
2474 consumer_timer_switch_stop(chan);
2475 }
2476 for (i = 0; i < chan->nr_stream_fds; i++) {
2477 int ret;
2478
2479 ret = close(chan->stream_fds[i]);
2480 if (ret) {
2481 PERROR("close");
2482 }
2483 if (chan->shm_path[0]) {
2484 char shm_path[PATH_MAX];
2485
2486 ret = get_stream_shm_path(shm_path, chan->shm_path, i);
2487 if (ret) {
2488 ERR("Cannot get stream shm path");
2489 }
2490 ret = run_as_unlink(shm_path,
2491 lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
2492 chan->buffer_credentials)),
2493 lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
2494 chan->buffer_credentials)));
2495 if (ret) {
2496 PERROR("unlink %s", shm_path);
2497 }
2498 }
2499 }
2500 }
2501
2502 void lttng_ustconsumer_free_channel(struct lttng_consumer_channel *chan)
2503 {
2504 LTTNG_ASSERT(chan);
2505 LTTNG_ASSERT(chan->uchan);
2506 LTTNG_ASSERT(chan->buffer_credentials.is_set);
2507
2508 consumer_metadata_cache_destroy(chan);
2509 lttng_ust_ctl_destroy_channel(chan->uchan);
2510 /* Try to rmdir all directories under shm_path root. */
2511 if (chan->root_shm_path[0]) {
2512 (void) run_as_rmdir_recursive(chan->root_shm_path,
2513 lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
2514 chan->buffer_credentials)),
2515 lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
2516 chan->buffer_credentials)),
2517 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
2518 }
2519 free(chan->stream_fds);
2520 }
2521
2522 void lttng_ustconsumer_del_stream(struct lttng_consumer_stream *stream)
2523 {
2524 LTTNG_ASSERT(stream);
2525 LTTNG_ASSERT(stream->ustream);
2526
2527 if (stream->chan->switch_timer_enabled == 1) {
2528 consumer_timer_switch_stop(stream->chan);
2529 }
2530 lttng_ust_ctl_destroy_stream(stream->ustream);
2531 }
2532
2533 int lttng_ustconsumer_get_wakeup_fd(struct lttng_consumer_stream *stream)
2534 {
2535 LTTNG_ASSERT(stream);
2536 LTTNG_ASSERT(stream->ustream);
2537
2538 return lttng_ust_ctl_stream_get_wakeup_fd(stream->ustream);
2539 }
2540
2541 int lttng_ustconsumer_close_wakeup_fd(struct lttng_consumer_stream *stream)
2542 {
2543 LTTNG_ASSERT(stream);
2544 LTTNG_ASSERT(stream->ustream);
2545
2546 return lttng_ust_ctl_stream_close_wakeup_fd(stream->ustream);
2547 }
2548
2549 /*
2550 * Write up to one packet from the metadata cache to the channel.
2551 *
2552 * Returns the number of bytes pushed from the cache into the ring buffer, or a
2553 * negative value on error.
2554 */
2555 static
2556 int commit_one_metadata_packet(struct lttng_consumer_stream *stream)
2557 {
2558 ssize_t write_len;
2559 int ret;
2560
2561 pthread_mutex_lock(&stream->chan->metadata_cache->lock);
2562 if (stream->chan->metadata_cache->contents.size ==
2563 stream->ust_metadata_pushed) {
2564 /*
2565 * In the context of a user space metadata channel, a
2566 * change in version can be detected in two ways:
2567 * 1) During the pre-consume of the `read_subbuffer` loop,
2568 * 2) When populating the metadata ring buffer (i.e. here).
2569 *
2570 * This function is invoked when there is no metadata
2571 * available in the ring-buffer. If all data was consumed
2572 * up to the size of the metadata cache, there is no metadata
2573 * to insert in the ring-buffer.
2574 *
2575 * However, the metadata version could still have changed (a
2576 * regeneration without any new data will yield the same cache
2577 * size).
2578 *
2579 * The cache's version is checked for a version change and the
2580 * consumed position is reset if one occurred.
2581 *
2582 * This check is only necessary for the user space domain as
2583 * it has to manage the cache explicitly. If this reset was not
2584 * performed, no metadata would be consumed (and no reset would
2585 * occur as part of the pre-consume) until the metadata size
2586 * exceeded the cache size.
2587 */
2588 if (stream->metadata_version !=
2589 stream->chan->metadata_cache->version) {
2590 metadata_stream_reset_cache_consumed_position(stream);
2591 consumer_stream_metadata_set_version(stream,
2592 stream->chan->metadata_cache->version);
2593 } else {
2594 ret = 0;
2595 goto end;
2596 }
2597 }
2598
2599 write_len = lttng_ust_ctl_write_one_packet_to_channel(stream->chan->uchan,
2600 &stream->chan->metadata_cache->contents.data[stream->ust_metadata_pushed],
2601 stream->chan->metadata_cache->contents.size -
2602 stream->ust_metadata_pushed);
2603 LTTNG_ASSERT(write_len != 0);
2604 if (write_len < 0) {
2605 ERR("Writing one metadata packet");
2606 ret = write_len;
2607 goto end;
2608 }
2609 stream->ust_metadata_pushed += write_len;
2610
2611 LTTNG_ASSERT(stream->chan->metadata_cache->contents.size >=
2612 stream->ust_metadata_pushed);
2613 ret = write_len;
2614
2615 /*
2616 * Switch packet (but don't open the next one) on every commit of
2617 * a metadata packet. Since the subbuffer is fully filled (with padding,
2618 * if needed), the stream is "quiescent" after this commit.
2619 */
2620 if (lttng_ust_ctl_flush_buffer(stream->ustream, 1)) {
2621 ERR("Failed to flush buffer while committing one metadata packet");
2622 ret = -EIO;
2623 } else {
2624 stream->quiescent = true;
2625 }
2626 end:
2627 pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
2628 return ret;
2629 }
2630
2631
2632 /*
2633 * Sync metadata meaning request them to the session daemon and snapshot to the
2634 * metadata thread can consumer them.
2635 *
2636 * Metadata stream lock is held here, but we need to release it when
2637 * interacting with sessiond, else we cause a deadlock with live
2638 * awaiting on metadata to be pushed out.
2639 *
2640 * The RCU read side lock must be held by the caller.
2641 */
2642 enum sync_metadata_status lttng_ustconsumer_sync_metadata(
2643 struct lttng_consumer_local_data *ctx,
2644 struct lttng_consumer_stream *metadata_stream)
2645 {
2646 int ret;
2647 enum sync_metadata_status status;
2648 struct lttng_consumer_channel *metadata_channel;
2649
2650 LTTNG_ASSERT(ctx);
2651 LTTNG_ASSERT(metadata_stream);
2652
2653 metadata_channel = metadata_stream->chan;
2654 pthread_mutex_unlock(&metadata_stream->lock);
2655 /*
2656 * Request metadata from the sessiond, but don't wait for the flush
2657 * because we locked the metadata thread.
2658 */
2659 ret = lttng_ustconsumer_request_metadata(ctx, metadata_channel, 0, 0);
2660 pthread_mutex_lock(&metadata_stream->lock);
2661 if (ret < 0) {
2662 status = SYNC_METADATA_STATUS_ERROR;
2663 goto end;
2664 }
2665
2666 /*
2667 * The metadata stream and channel can be deleted while the
2668 * metadata stream lock was released. The streamed is checked
2669 * for deletion before we use it further.
2670 *
2671 * Note that it is safe to access a logically-deleted stream since its
2672 * existence is still guaranteed by the RCU read side lock. However,
2673 * it should no longer be used. The close/deletion of the metadata
2674 * channel and stream already guarantees that all metadata has been
2675 * consumed. Therefore, there is nothing left to do in this function.
2676 */
2677 if (consumer_stream_is_deleted(metadata_stream)) {
2678 DBG("Metadata stream %" PRIu64 " was deleted during the metadata synchronization",
2679 metadata_stream->key);
2680 status = SYNC_METADATA_STATUS_NO_DATA;
2681 goto end;
2682 }
2683
2684 ret = commit_one_metadata_packet(metadata_stream);
2685 if (ret < 0) {
2686 status = SYNC_METADATA_STATUS_ERROR;
2687 goto end;
2688 } else if (ret > 0) {
2689 status = SYNC_METADATA_STATUS_NEW_DATA;
2690 } else /* ret == 0 */ {
2691 status = SYNC_METADATA_STATUS_NO_DATA;
2692 goto end;
2693 }
2694
2695 ret = lttng_ust_ctl_snapshot(metadata_stream->ustream);
2696 if (ret < 0) {
2697 ERR("Failed to take a snapshot of the metadata ring-buffer positions, ret = %d", ret);
2698 status = SYNC_METADATA_STATUS_ERROR;
2699 goto end;
2700 }
2701
2702 end:
2703 return status;
2704 }
2705
2706 /*
2707 * Return 0 on success else a negative value.
2708 */
2709 static int notify_if_more_data(struct lttng_consumer_stream *stream,
2710 struct lttng_consumer_local_data *ctx)
2711 {
2712 int ret;
2713 struct lttng_ust_ctl_consumer_stream *ustream;
2714
2715 LTTNG_ASSERT(stream);
2716 LTTNG_ASSERT(ctx);
2717
2718 ustream = stream->ustream;
2719
2720 /*
2721 * First, we are going to check if there is a new subbuffer available
2722 * before reading the stream wait_fd.
2723 */
2724 /* Get the next subbuffer */
2725 ret = lttng_ust_ctl_get_next_subbuf(ustream);
2726 if (ret) {
2727 /* No more data found, flag the stream. */
2728 stream->has_data = 0;
2729 ret = 0;
2730 goto end;
2731 }
2732
2733 ret = lttng_ust_ctl_put_subbuf(ustream);
2734 LTTNG_ASSERT(!ret);
2735
2736 /* This stream still has data. Flag it and wake up the data thread. */
2737 stream->has_data = 1;
2738
2739 if (stream->monitor && !stream->hangup_flush_done && !ctx->has_wakeup) {
2740 ssize_t writelen;
2741
2742 writelen = lttng_pipe_write(ctx->consumer_wakeup_pipe, "!", 1);
2743 if (writelen < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
2744 ret = writelen;
2745 goto end;
2746 }
2747
2748 /* The wake up pipe has been notified. */
2749 ctx->has_wakeup = 1;
2750 }
2751 ret = 0;
2752
2753 end:
2754 return ret;
2755 }
2756
2757 static int consumer_stream_ust_on_wake_up(struct lttng_consumer_stream *stream)
2758 {
2759 int ret = 0;
2760
2761 /*
2762 * We can consume the 1 byte written into the wait_fd by
2763 * UST. Don't trigger error if we cannot read this one byte
2764 * (read returns 0), or if the error is EAGAIN or EWOULDBLOCK.
2765 *
2766 * This is only done when the stream is monitored by a thread,
2767 * before the flush is done after a hangup and if the stream
2768 * is not flagged with data since there might be nothing to
2769 * consume in the wait fd but still have data available
2770 * flagged by the consumer wake up pipe.
2771 */
2772 if (stream->monitor && !stream->hangup_flush_done && !stream->has_data) {
2773 char dummy;
2774 ssize_t readlen;
2775
2776 readlen = lttng_read(stream->wait_fd, &dummy, 1);
2777 if (readlen < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
2778 ret = readlen;
2779 }
2780 }
2781
2782 return ret;
2783 }
2784
2785 static int extract_common_subbuffer_info(struct lttng_consumer_stream *stream,
2786 struct stream_subbuffer *subbuf)
2787 {
2788 int ret;
2789
2790 ret = lttng_ust_ctl_get_subbuf_size(
2791 stream->ustream, &subbuf->info.data.subbuf_size);
2792 if (ret) {
2793 goto end;
2794 }
2795
2796 ret = lttng_ust_ctl_get_padded_subbuf_size(
2797 stream->ustream, &subbuf->info.data.padded_subbuf_size);
2798 if (ret) {
2799 goto end;
2800 }
2801
2802 end:
2803 return ret;
2804 }
2805
2806 static int extract_metadata_subbuffer_info(struct lttng_consumer_stream *stream,
2807 struct stream_subbuffer *subbuf)
2808 {
2809 int ret;
2810
2811 ret = extract_common_subbuffer_info(stream, subbuf);
2812 if (ret) {
2813 goto end;
2814 }
2815
2816 subbuf->info.metadata.version = stream->metadata_version;
2817
2818 end:
2819 return ret;
2820 }
2821
2822 static int extract_data_subbuffer_info(struct lttng_consumer_stream *stream,
2823 struct stream_subbuffer *subbuf)
2824 {
2825 int ret;
2826
2827 ret = extract_common_subbuffer_info(stream, subbuf);
2828 if (ret) {
2829 goto end;
2830 }
2831
2832 ret = lttng_ust_ctl_get_packet_size(
2833 stream->ustream, &subbuf->info.data.packet_size);
2834 if (ret < 0) {
2835 PERROR("Failed to get sub-buffer packet size");
2836 goto end;
2837 }
2838
2839 ret = lttng_ust_ctl_get_content_size(
2840 stream->ustream, &subbuf->info.data.content_size);
2841 if (ret < 0) {
2842 PERROR("Failed to get sub-buffer content size");
2843 goto end;
2844 }
2845
2846 ret = lttng_ust_ctl_get_timestamp_begin(
2847 stream->ustream, &subbuf->info.data.timestamp_begin);
2848 if (ret < 0) {
2849 PERROR("Failed to get sub-buffer begin timestamp");
2850 goto end;
2851 }
2852
2853 ret = lttng_ust_ctl_get_timestamp_end(
2854 stream->ustream, &subbuf->info.data.timestamp_end);
2855 if (ret < 0) {
2856 PERROR("Failed to get sub-buffer end timestamp");
2857 goto end;
2858 }
2859
2860 ret = lttng_ust_ctl_get_events_discarded(
2861 stream->ustream, &subbuf->info.data.events_discarded);
2862 if (ret) {
2863 PERROR("Failed to get sub-buffer events discarded count");
2864 goto end;
2865 }
2866
2867 ret = lttng_ust_ctl_get_sequence_number(stream->ustream,
2868 &subbuf->info.data.sequence_number.value);
2869 if (ret) {
2870 /* May not be supported by older LTTng-modules. */
2871 if (ret != -ENOTTY) {
2872 PERROR("Failed to get sub-buffer sequence number");
2873 goto end;
2874 }
2875 } else {
2876 subbuf->info.data.sequence_number.is_set = true;
2877 }
2878
2879 ret = lttng_ust_ctl_get_stream_id(
2880 stream->ustream, &subbuf->info.data.stream_id);
2881 if (ret < 0) {
2882 PERROR("Failed to get stream id");
2883 goto end;
2884 }
2885
2886 ret = lttng_ust_ctl_get_instance_id(stream->ustream,
2887 &subbuf->info.data.stream_instance_id.value);
2888 if (ret) {
2889 /* May not be supported by older LTTng-modules. */
2890 if (ret != -ENOTTY) {
2891 PERROR("Failed to get stream instance id");
2892 goto end;
2893 }
2894 } else {
2895 subbuf->info.data.stream_instance_id.is_set = true;
2896 }
2897 end:
2898 return ret;
2899 }
2900
2901 static int get_next_subbuffer_common(struct lttng_consumer_stream *stream,
2902 struct stream_subbuffer *subbuffer)
2903 {
2904 int ret;
2905 const char *addr;
2906
2907 ret = stream->read_subbuffer_ops.extract_subbuffer_info(
2908 stream, subbuffer);
2909 if (ret) {
2910 goto end;
2911 }
2912
2913 ret = get_current_subbuf_addr(stream, &addr);
2914 if (ret) {
2915 goto end;
2916 }
2917
2918 subbuffer->buffer.buffer = lttng_buffer_view_init(
2919 addr, 0, subbuffer->info.data.padded_subbuf_size);
2920 LTTNG_ASSERT(subbuffer->buffer.buffer.data != NULL);
2921 end:
2922 return ret;
2923 }
2924
2925 static enum get_next_subbuffer_status get_next_subbuffer(
2926 struct lttng_consumer_stream *stream,
2927 struct stream_subbuffer *subbuffer)
2928 {
2929 int ret;
2930 enum get_next_subbuffer_status status;
2931
2932 ret = lttng_ust_ctl_get_next_subbuf(stream->ustream);
2933 switch (ret) {
2934 case 0:
2935 status = GET_NEXT_SUBBUFFER_STATUS_OK;
2936 break;
2937 case -ENODATA:
2938 case -EAGAIN:
2939 /*
2940 * The caller only expects -ENODATA when there is no data to
2941 * read, but the kernel tracer returns -EAGAIN when there is
2942 * currently no data for a non-finalized stream, and -ENODATA
2943 * when there is no data for a finalized stream. Those can be
2944 * combined into a -ENODATA return value.
2945 */
2946 status = GET_NEXT_SUBBUFFER_STATUS_NO_DATA;
2947 goto end;
2948 default:
2949 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
2950 goto end;
2951 }
2952
2953 ret = get_next_subbuffer_common(stream, subbuffer);
2954 if (ret) {
2955 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
2956 goto end;
2957 }
2958 end:
2959 return status;
2960 }
2961
2962 static enum get_next_subbuffer_status get_next_subbuffer_metadata(
2963 struct lttng_consumer_stream *stream,
2964 struct stream_subbuffer *subbuffer)
2965 {
2966 int ret;
2967 bool cache_empty;
2968 bool got_subbuffer;
2969 bool coherent;
2970 bool buffer_empty;
2971 unsigned long consumed_pos, produced_pos;
2972 enum get_next_subbuffer_status status;
2973
2974 do {
2975 ret = lttng_ust_ctl_get_next_subbuf(stream->ustream);
2976 if (ret == 0) {
2977 got_subbuffer = true;
2978 } else {
2979 got_subbuffer = false;
2980 if (ret != -EAGAIN) {
2981 /* Fatal error. */
2982 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
2983 goto end;
2984 }
2985 }
2986
2987 /*
2988 * Determine if the cache is empty and ensure that a sub-buffer
2989 * is made available if the cache is not empty.
2990 */
2991 if (!got_subbuffer) {
2992 ret = commit_one_metadata_packet(stream);
2993 if (ret < 0 && ret != -ENOBUFS) {
2994 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
2995 goto end;
2996 } else if (ret == 0) {
2997 /* Not an error, the cache is empty. */
2998 cache_empty = true;
2999 status = GET_NEXT_SUBBUFFER_STATUS_NO_DATA;
3000 goto end;
3001 } else {
3002 cache_empty = false;
3003 }
3004 } else {
3005 pthread_mutex_lock(&stream->chan->metadata_cache->lock);
3006 cache_empty = stream->chan->metadata_cache->contents.size ==
3007 stream->ust_metadata_pushed;
3008 pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
3009 }
3010 } while (!got_subbuffer);
3011
3012 /* Populate sub-buffer infos and view. */
3013 ret = get_next_subbuffer_common(stream, subbuffer);
3014 if (ret) {
3015 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
3016 goto end;
3017 }
3018
3019 ret = lttng_ustconsumer_sample_snapshot_positions(stream);
3020 if (ret < 0) {
3021 /*
3022 * -EAGAIN is not expected since we got a sub-buffer and haven't
3023 * pushed the consumption position yet (on put_next).
3024 */
3025 PERROR("Failed to take a snapshot of metadata buffer positions");
3026 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
3027 goto end;
3028 }
3029
3030 ret = lttng_ustconsumer_get_consumed_snapshot(stream, &consumed_pos);
3031 if (ret) {
3032 PERROR("Failed to get metadata consumed position");
3033 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
3034 goto end;
3035 }
3036
3037 ret = lttng_ustconsumer_get_produced_snapshot(stream, &produced_pos);
3038 if (ret) {
3039 PERROR("Failed to get metadata produced position");
3040 status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
3041 goto end;
3042 }
3043
3044 /* Last sub-buffer of the ring buffer ? */
3045 buffer_empty = (consumed_pos + stream->max_sb_size) == produced_pos;
3046
3047 /*
3048 * The sessiond registry lock ensures that coherent units of metadata
3049 * are pushed to the consumer daemon at once. Hence, if a sub-buffer is
3050 * acquired, the cache is empty, and it is the only available sub-buffer
3051 * available, it is safe to assume that it is "coherent".
3052 */
3053 coherent = got_subbuffer && cache_empty && buffer_empty;
3054
3055 LTTNG_OPTIONAL_SET(&subbuffer->info.metadata.coherent, coherent);
3056 status = GET_NEXT_SUBBUFFER_STATUS_OK;
3057 end:
3058 return status;
3059 }
3060
3061 static int put_next_subbuffer(struct lttng_consumer_stream *stream,
3062 struct stream_subbuffer *subbuffer)
3063 {
3064 const int ret = lttng_ust_ctl_put_next_subbuf(stream->ustream);
3065
3066 LTTNG_ASSERT(ret == 0);
3067 return ret;
3068 }
3069
3070 static int signal_metadata(struct lttng_consumer_stream *stream,
3071 struct lttng_consumer_local_data *ctx)
3072 {
3073 ASSERT_LOCKED(stream->metadata_rdv_lock);
3074 return pthread_cond_broadcast(&stream->metadata_rdv) ? -errno : 0;
3075 }
3076
3077 static int lttng_ustconsumer_set_stream_ops(
3078 struct lttng_consumer_stream *stream)
3079 {
3080 int ret = 0;
3081
3082 stream->read_subbuffer_ops.on_wake_up = consumer_stream_ust_on_wake_up;
3083 if (stream->metadata_flag) {
3084 stream->read_subbuffer_ops.get_next_subbuffer =
3085 get_next_subbuffer_metadata;
3086 stream->read_subbuffer_ops.extract_subbuffer_info =
3087 extract_metadata_subbuffer_info;
3088 stream->read_subbuffer_ops.reset_metadata =
3089 metadata_stream_reset_cache_consumed_position;
3090 if (stream->chan->is_live) {
3091 stream->read_subbuffer_ops.on_sleep = signal_metadata;
3092 ret = consumer_stream_enable_metadata_bucketization(
3093 stream);
3094 if (ret) {
3095 goto end;
3096 }
3097 }
3098 } else {
3099 stream->read_subbuffer_ops.get_next_subbuffer =
3100 get_next_subbuffer;
3101 stream->read_subbuffer_ops.extract_subbuffer_info =
3102 extract_data_subbuffer_info;
3103 stream->read_subbuffer_ops.on_sleep = notify_if_more_data;
3104 if (stream->chan->is_live) {
3105 stream->read_subbuffer_ops.send_live_beacon =
3106 consumer_flush_ust_index;
3107 }
3108 }
3109
3110 stream->read_subbuffer_ops.put_next_subbuffer = put_next_subbuffer;
3111 end:
3112 return ret;
3113 }
3114
3115 /*
3116 * Called when a stream is created.
3117 *
3118 * Return 0 on success or else a negative value.
3119 */
3120 int lttng_ustconsumer_on_recv_stream(struct lttng_consumer_stream *stream)
3121 {
3122 int ret;
3123
3124 LTTNG_ASSERT(stream);
3125
3126 /*
3127 * Don't create anything if this is set for streaming or if there is
3128 * no current trace chunk on the parent channel.
3129 */
3130 if (stream->net_seq_idx == (uint64_t) -1ULL && stream->chan->monitor &&
3131 stream->chan->trace_chunk) {
3132 ret = consumer_stream_create_output_files(stream, true);
3133 if (ret) {
3134 goto error;
3135 }
3136 }
3137
3138 lttng_ustconsumer_set_stream_ops(stream);
3139 ret = 0;
3140
3141 error:
3142 return ret;
3143 }
3144
3145 /*
3146 * Check if data is still being extracted from the buffers for a specific
3147 * stream. Consumer data lock MUST be acquired before calling this function
3148 * and the stream lock.
3149 *
3150 * Return 1 if the traced data are still getting read else 0 meaning that the
3151 * data is available for trace viewer reading.
3152 */
3153 int lttng_ustconsumer_data_pending(struct lttng_consumer_stream *stream)
3154 {
3155 int ret;
3156
3157 LTTNG_ASSERT(stream);
3158 LTTNG_ASSERT(stream->ustream);
3159 ASSERT_LOCKED(stream->lock);
3160
3161 DBG("UST consumer checking data pending");
3162
3163 if (stream->endpoint_status != CONSUMER_ENDPOINT_ACTIVE) {
3164 ret = 0;
3165 goto end;
3166 }
3167
3168 if (stream->chan->type == CONSUMER_CHANNEL_TYPE_METADATA) {
3169 uint64_t contiguous, pushed;
3170
3171 /* Ease our life a bit. */
3172 pthread_mutex_lock(&stream->chan->metadata_cache->lock);
3173 contiguous = stream->chan->metadata_cache->contents.size;
3174 pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
3175 pushed = stream->ust_metadata_pushed;
3176
3177 /*
3178 * We can simply check whether all contiguously available data
3179 * has been pushed to the ring buffer, since the push operation
3180 * is performed within get_next_subbuf(), and because both
3181 * get_next_subbuf() and put_next_subbuf() are issued atomically
3182 * thanks to the stream lock within
3183 * lttng_ustconsumer_read_subbuffer(). This basically means that
3184 * whetnever ust_metadata_pushed is incremented, the associated
3185 * metadata has been consumed from the metadata stream.
3186 */
3187 DBG("UST consumer metadata pending check: contiguous %" PRIu64 " vs pushed %" PRIu64,
3188 contiguous, pushed);
3189 LTTNG_ASSERT(((int64_t) (contiguous - pushed)) >= 0);
3190 if ((contiguous != pushed) ||
3191 (((int64_t) contiguous - pushed) > 0 || contiguous == 0)) {
3192 ret = 1; /* Data is pending */
3193 goto end;
3194 }
3195 } else {
3196 ret = lttng_ust_ctl_get_next_subbuf(stream->ustream);
3197 if (ret == 0) {
3198 /*
3199 * There is still data so let's put back this
3200 * subbuffer.
3201 */
3202 ret = lttng_ust_ctl_put_subbuf(stream->ustream);
3203 LTTNG_ASSERT(ret == 0);
3204 ret = 1; /* Data is pending */
3205 goto end;
3206 }
3207 }
3208
3209 /* Data is NOT pending so ready to be read. */
3210 ret = 0;
3211
3212 end:
3213 return ret;
3214 }
3215
3216 /*
3217 * Stop a given metadata channel timer if enabled and close the wait fd which
3218 * is the poll pipe of the metadata stream.
3219 *
3220 * This MUST be called with the metadata channel lock acquired.
3221 */
3222 void lttng_ustconsumer_close_metadata(struct lttng_consumer_channel *metadata)
3223 {
3224 int ret;
3225
3226 LTTNG_ASSERT(metadata);
3227 LTTNG_ASSERT(metadata->type == CONSUMER_CHANNEL_TYPE_METADATA);
3228
3229 DBG("Closing metadata channel key %" PRIu64, metadata->key);
3230
3231 if (metadata->switch_timer_enabled == 1) {
3232 consumer_timer_switch_stop(metadata);
3233 }
3234
3235 if (!metadata->metadata_stream) {
3236 goto end;
3237 }
3238
3239 /*
3240 * Closing write side so the thread monitoring the stream wakes up if any
3241 * and clean the metadata stream.
3242 */
3243 if (metadata->metadata_stream->ust_metadata_poll_pipe[1] >= 0) {
3244 ret = close(metadata->metadata_stream->ust_metadata_poll_pipe[1]);
3245 if (ret < 0) {
3246 PERROR("closing metadata pipe write side");
3247 }
3248 metadata->metadata_stream->ust_metadata_poll_pipe[1] = -1;
3249 }
3250
3251 end:
3252 return;
3253 }
3254
3255 /*
3256 * Close every metadata stream wait fd of the metadata hash table. This
3257 * function MUST be used very carefully so not to run into a race between the
3258 * metadata thread handling streams and this function closing their wait fd.
3259 *
3260 * For UST, this is used when the session daemon hangs up. Its the metadata
3261 * producer so calling this is safe because we are assured that no state change
3262 * can occur in the metadata thread for the streams in the hash table.
3263 */
3264 void lttng_ustconsumer_close_all_metadata(struct lttng_ht *metadata_ht)
3265 {
3266 struct lttng_ht_iter iter;
3267 struct lttng_consumer_stream *stream;
3268
3269 LTTNG_ASSERT(metadata_ht);
3270 LTTNG_ASSERT(metadata_ht->ht);
3271
3272 DBG("UST consumer closing all metadata streams");
3273
3274 rcu_read_lock();
3275 cds_lfht_for_each_entry(metadata_ht->ht, &iter.iter, stream,
3276 node.node) {
3277
3278 health_code_update();
3279
3280 pthread_mutex_lock(&stream->chan->lock);
3281 lttng_ustconsumer_close_metadata(stream->chan);
3282 pthread_mutex_unlock(&stream->chan->lock);
3283
3284 }
3285 rcu_read_unlock();
3286 }
3287
3288 void lttng_ustconsumer_close_stream_wakeup(struct lttng_consumer_stream *stream)
3289 {
3290 int ret;
3291
3292 ret = lttng_ust_ctl_stream_close_wakeup_fd(stream->ustream);
3293 if (ret < 0) {
3294 ERR("Unable to close wakeup fd");
3295 }
3296 }
3297
3298 /*
3299 * Please refer to consumer-timer.c before adding any lock within this
3300 * function or any of its callees. Timers have a very strict locking
3301 * semantic with respect to teardown. Failure to respect this semantic
3302 * introduces deadlocks.
3303 *
3304 * DON'T hold the metadata lock when calling this function, else this
3305 * can cause deadlock involving consumer awaiting for metadata to be
3306 * pushed out due to concurrent interaction with the session daemon.
3307 */
3308 int lttng_ustconsumer_request_metadata(struct lttng_consumer_local_data *ctx,
3309 struct lttng_consumer_channel *channel, int timer, int wait)
3310 {
3311 struct lttcomm_metadata_request_msg request;
3312 struct lttcomm_consumer_msg msg;
3313 enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS;
3314 uint64_t len, key, offset, version;
3315 int ret;
3316
3317 LTTNG_ASSERT(channel);
3318 LTTNG_ASSERT(channel->metadata_cache);
3319
3320 memset(&request, 0, sizeof(request));
3321
3322 /* send the metadata request to sessiond */
3323 switch (the_consumer_data.type) {
3324 case LTTNG_CONSUMER64_UST:
3325 request.bits_per_long = 64;
3326 break;
3327 case LTTNG_CONSUMER32_UST:
3328 request.bits_per_long = 32;
3329 break;
3330 default:
3331 request.bits_per_long = 0;
3332 break;
3333 }
3334
3335 request.session_id = channel->session_id;
3336 request.session_id_per_pid = channel->session_id_per_pid;
3337 /*
3338 * Request the application UID here so the metadata of that application can
3339 * be sent back. The channel UID corresponds to the user UID of the session
3340 * used for the rights on the stream file(s).
3341 */
3342 request.uid = channel->ust_app_uid;
3343 request.key = channel->key;
3344
3345 DBG("Sending metadata request to sessiond, session id %" PRIu64
3346 ", per-pid %" PRIu64 ", app UID %u and channel key %" PRIu64,
3347 request.session_id, request.session_id_per_pid, request.uid,
3348 request.key);
3349
3350 pthread_mutex_lock(&ctx->metadata_socket_lock);
3351
3352 health_code_update();
3353
3354 ret = lttcomm_send_unix_sock(ctx->consumer_metadata_socket, &request,
3355 sizeof(request));
3356 if (ret < 0) {
3357 ERR("Asking metadata to sessiond");
3358 goto end;
3359 }
3360
3361 health_code_update();
3362
3363 /* Receive the metadata from sessiond */
3364 ret = lttcomm_recv_unix_sock(ctx->consumer_metadata_socket, &msg,
3365 sizeof(msg));
3366 if (ret != sizeof(msg)) {
3367 DBG("Consumer received unexpected message size %d (expects %zu)",
3368 ret, sizeof(msg));
3369 lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_ERROR_RECV_CMD);
3370 /*
3371 * The ret value might 0 meaning an orderly shutdown but this is ok
3372 * since the caller handles this.
3373 */
3374 goto end;
3375 }
3376
3377 health_code_update();
3378
3379 if (msg.cmd_type == LTTNG_ERR_UND) {
3380 /* No registry found */
3381 (void) consumer_send_status_msg(ctx->consumer_metadata_socket,
3382 ret_code);
3383 ret = 0;
3384 goto end;
3385 } else if (msg.cmd_type != LTTNG_CONSUMER_PUSH_METADATA) {
3386 ERR("Unexpected cmd_type received %d", msg.cmd_type);
3387 ret = -1;
3388 goto end;
3389 }
3390
3391 len = msg.u.push_metadata.len;
3392 key = msg.u.push_metadata.key;
3393 offset = msg.u.push_metadata.target_offset;
3394 version = msg.u.push_metadata.version;
3395
3396 LTTNG_ASSERT(key == channel->key);
3397 if (len == 0) {
3398 DBG("No new metadata to receive for key %" PRIu64, key);
3399 }
3400
3401 health_code_update();
3402
3403 /* Tell session daemon we are ready to receive the metadata. */
3404 ret = consumer_send_status_msg(ctx->consumer_metadata_socket,
3405 LTTCOMM_CONSUMERD_SUCCESS);
3406 if (ret < 0 || len == 0) {
3407 /*
3408 * Somehow, the session daemon is not responding anymore or there is
3409 * nothing to receive.
3410 */
3411 goto end;
3412 }
3413
3414 health_code_update();
3415
3416 ret = lttng_ustconsumer_recv_metadata(ctx->consumer_metadata_socket,
3417 key, offset, len, version, channel, timer, wait);
3418 if (ret >= 0) {
3419 /*
3420 * Only send the status msg if the sessiond is alive meaning a positive
3421 * ret code.
3422 */
3423 (void) consumer_send_status_msg(ctx->consumer_metadata_socket, ret);
3424 }
3425 ret = 0;
3426
3427 end:
3428 health_code_update();
3429
3430 pthread_mutex_unlock(&ctx->metadata_socket_lock);
3431 return ret;
3432 }
3433
3434 /*
3435 * Return the ustctl call for the get stream id.
3436 */
3437 int lttng_ustconsumer_get_stream_id(struct lttng_consumer_stream *stream,
3438 uint64_t *stream_id)
3439 {
3440 LTTNG_ASSERT(stream);
3441 LTTNG_ASSERT(stream_id);
3442
3443 return lttng_ust_ctl_get_stream_id(stream->ustream, stream_id);
3444 }
3445
3446 void lttng_ustconsumer_sigbus_handle(void *addr)
3447 {
3448 lttng_ust_ctl_sigbus_handle(addr);
3449 }
This page took 0.143185 seconds and 4 git commands to generate.