+int kernel_consumer_add_metadata(struct consumer_socket *sock,
+ struct ltt_kernel_session *ksession, unsigned int monitor)
+{
+ int ret;
+ struct lttcomm_consumer_msg lkm;
+ struct consumer_output *consumer;
+
+ rcu_read_lock();
+
+ /* Safety net */
+ assert(ksession);
+ assert(ksession->consumer);
+ assert(sock);
+
+ DBG("Sending metadata %d to kernel consumer",
+ ksession->metadata_stream_fd);
+
+ /* Get consumer output pointer */
+ consumer = ksession->consumer;
+
+ /* Prep channel message structure */
+ consumer_init_add_channel_comm_msg(&lkm, ksession->metadata->key,
+ ksession->id, "", ksession->uid, ksession->gid,
+ consumer->net_seq_index, DEFAULT_METADATA_NAME, 1,
+ DEFAULT_KERNEL_CHANNEL_OUTPUT,
+ CONSUMER_CHANNEL_TYPE_METADATA, 0, 0, monitor, 0,
+ ksession->is_live_session, 0,
+ ksession->current_trace_chunk);
+
+ health_code_update();
+
+ ret = consumer_send_channel(sock, &lkm);
+ if (ret < 0) {
+ goto error;
+ }
+
+ health_code_update();
+
+ /* Prep stream message structure */
+ consumer_init_add_stream_comm_msg(&lkm,
+ ksession->metadata->key,
+ ksession->metadata_stream_fd,
+ 0 /* CPU: 0 for metadata. */);
+
+ health_code_update();
+
+ /* Send stream and file descriptor */
+ ret = consumer_send_stream(sock, consumer, &lkm,
+ &ksession->metadata_stream_fd, 1);
+ if (ret < 0) {
+ goto error;
+ }
+
+ health_code_update();
+
+error:
+ rcu_read_unlock();
+ return ret;
+}
+
+/*
+ * Sending a single stream to the consumer with command ADD_STREAM.
+ */
+static
+int kernel_consumer_add_stream(struct consumer_socket *sock,
+ struct ltt_kernel_channel *channel,
+ struct ltt_kernel_stream *stream,
+ struct ltt_kernel_session *session, unsigned int monitor)
+{
+ int ret;
+ struct lttcomm_consumer_msg lkm;
+ struct consumer_output *consumer;
+
+ assert(channel);
+ assert(stream);
+ assert(session);
+ assert(session->consumer);
+ assert(sock);
+
+ DBG("Sending stream %d of channel %s to kernel consumer",
+ stream->fd, channel->channel->name);
+
+ /* Get consumer output pointer */
+ consumer = session->consumer;
+
+ /* Prep stream consumer message */
+ consumer_init_add_stream_comm_msg(&lkm,
+ channel->key,
+ stream->fd,
+ stream->cpu);
+
+ health_code_update();
+
+ /* Send stream and file descriptor */
+ ret = consumer_send_stream(sock, consumer, &lkm, &stream->fd, 1);
+ if (ret < 0) {
+ goto error;
+ }
+
+ health_code_update();
+
+error:
+ return ret;
+}
+
+/*
+ * Sending the notification that all streams were sent with STREAMS_SENT.
+ */
+int kernel_consumer_streams_sent(struct consumer_socket *sock,
+ struct ltt_kernel_session *session, uint64_t channel_key)