+ /* Depending on the buffer type, a different channel key is used. */
+ if (ua_sess->buffer_type == LTTNG_BUFFER_PER_UID) {
+ chan_reg_key = ua_chan->tracing_channel_id;
+ } else {
+ chan_reg_key = ua_chan->key;
+ }
+
+ if (ua_chan->attr.type == LTTNG_UST_CHAN_METADATA) {
+ chan_id = -1U;
+ /*
+ * Metadata channels shm_path (buffers) are handled within
+ * session daemon. Consumer daemon should not try to create
+ * those buffer files.
+ */
+ } else {
+ chan_reg = ust_registry_channel_find(registry, chan_reg_key);
+ assert(chan_reg);
+ chan_id = chan_reg->chan_id;
+ if (ua_sess->shm_path[0]) {
+ strncpy(shm_path, ua_sess->shm_path, sizeof(shm_path));
+ shm_path[sizeof(shm_path) - 1] = '\0';
+ strncat(shm_path, "/",
+ sizeof(shm_path) - strlen(shm_path) - 1);
+ strncat(shm_path, ua_chan->name,
+ sizeof(shm_path) - strlen(shm_path) - 1);
+ strncat(shm_path, "_",
+ sizeof(shm_path) - strlen(shm_path) - 1);
+ }
+ strncpy(root_shm_path, ua_sess->root_shm_path, sizeof(root_shm_path));
+ root_shm_path[sizeof(root_shm_path) - 1] = '\0';
+ }
+
+ switch (ua_chan->attr.output) {
+ case LTTNG_UST_MMAP:
+ default:
+ output = LTTNG_EVENT_MMAP;
+ break;
+ }
+
+ consumer_init_ask_channel_comm_msg(&msg,
+ ua_chan->attr.subbuf_size,
+ ua_chan->attr.num_subbuf,
+ ua_chan->attr.overwrite,
+ ua_chan->attr.switch_timer_interval,
+ ua_chan->attr.read_timer_interval,
+ ua_sess->live_timer_interval,
+ ua_chan->monitor_timer_interval,
+ output,
+ (int) ua_chan->attr.type,
+ ua_sess->tracing_id,
+ pathname,
+ ua_chan->name,
+ ua_sess->euid,
+ ua_sess->egid,
+ consumer->net_seq_index,
+ ua_chan->key,
+ registry->uuid,
+ chan_id,
+ ua_chan->tracefile_size,
+ ua_chan->tracefile_count,
+ ua_sess->id,
+ ua_sess->output_traces,
+ ua_sess->uid,
+ ua_chan->attr.blocking_timeout,
+ root_shm_path, shm_path);
+
+ health_code_update();
+
+ ret = consumer_socket_send(socket, &msg, sizeof(msg));
+ if (ret < 0) {
+ goto error;
+ }
+
+ ret = consumer_recv_status_channel(socket, &key,
+ &ua_chan->expected_stream_count);
+ if (ret < 0) {
+ goto error;
+ }
+ /* Communication protocol error. */
+ assert(key == ua_chan->key);
+ /* We need at least one where 1 stream for 1 cpu. */
+ if (ua_sess->output_traces) {
+ assert(ua_chan->expected_stream_count > 0);
+ }
+
+ DBG2("UST ask channel %" PRIu64 " successfully done with %u stream(s)", key,
+ ua_chan->expected_stream_count);
+
+error:
+ free(pathname);
+ health_code_update();
+ return ret;
+}
+
+/*
+ * Ask consumer to create a channel for a given session.
+ *
+ * Session list and rcu read side locks must be held by the caller.
+ *
+ * Returns 0 on success else a negative value.
+ */
+int ust_consumer_ask_channel(struct ust_app_session *ua_sess,
+ struct ust_app_channel *ua_chan, struct consumer_output *consumer,
+ struct consumer_socket *socket, struct ust_registry_session *registry)
+{
+ int ret;
+ struct ltt_session *session;
+
+ assert(ua_sess);
+ assert(ua_chan);
+ assert(consumer);
+ assert(socket);
+ assert(registry);
+
+ if (!consumer->enabled) {
+ ret = -LTTNG_ERR_NO_CONSUMER;
+ DBG3("Consumer is disabled");
+ goto error;
+ }
+
+ session = session_find_by_id(ua_sess->tracing_id);
+ assert(session);