From 59db0d42017ebea7422e31b3f8b137ba835e5e8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 5 May 2020 13:13:03 -0400 Subject: [PATCH] consumerd: pass channel instance to stream creation function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Both callsites of consumer_allocate_stream() set the stream's "chan" pointer after the creation. Pass the channel directly to the stream creation function so it can initialize the stream according to the channel's settings. Signed-off-by: Jérémie Galarneau Change-Id: Icea7088e7695e310585bf398e14e6443d67a30bb --- src/common/consumer/consumer.c | 6 ++++-- src/common/consumer/consumer.h | 4 +++- src/common/kernel-consumer/kernel-consumer.c | 11 +++++++++-- src/common/ust-consumer/ust-consumer.c | 6 +++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index f06ea9d4d..e1ee5f2fc 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -532,7 +532,9 @@ void consumer_del_stream_for_metadata(struct lttng_consumer_stream *stream) consumer_stream_destroy(stream, metadata_ht); } -struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key, +struct lttng_consumer_stream *consumer_allocate_stream( + struct lttng_consumer_channel *channel, + uint64_t channel_key, uint64_t stream_key, enum lttng_consumer_stream_state state, const char *channel_name, @@ -556,7 +558,7 @@ struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key, } rcu_read_lock(); - + stream->chan = channel; stream->key = stream_key; stream->out_fd = -1; stream->out_fd_offset = 0; diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index aebcf4bac..9ba1dacbc 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -645,7 +645,9 @@ void lttng_consumer_cleanup(void); */ int lttng_consumer_poll_socket(struct pollfd *kconsumer_sockpoll); -struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key, +struct lttng_consumer_stream *consumer_allocate_stream( + struct lttng_consumer_channel *channel, + uint64_t channel_key, uint64_t stream_key, enum lttng_consumer_stream_state state, const char *channel_name, diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 49b5070f7..29b75d68d 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -650,7 +650,10 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, health_code_update(); - new_stream = consumer_allocate_stream(channel->key, + pthread_mutex_lock(&channel->lock); + new_stream = consumer_allocate_stream( + channel, + channel->key, fd, LTTNG_CONSUMER_ACTIVE_STREAM, channel->name, @@ -670,10 +673,10 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR); break; } + pthread_mutex_unlock(&channel->lock); goto end_nosignal; } - new_stream->chan = channel; new_stream->wait_fd = fd; switch (channel->output) { case CONSUMER_CHANNEL_SPLICE: @@ -733,6 +736,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, "relayd id %" PRIu64, new_stream->name, new_stream->relayd_id); cds_list_add(&new_stream->send_node, &channel->streams.head); + pthread_mutex_unlock(&channel->lock); break; } @@ -741,6 +745,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, ret = consumer_send_relayd_stream(new_stream, new_stream->chan->pathname); if (ret < 0) { + pthread_mutex_unlock(&channel->lock); consumer_stream_free(new_stream); goto end_nosignal; } @@ -754,10 +759,12 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, ret = consumer_send_relayd_streams_sent( new_stream->relayd_id); if (ret < 0) { + pthread_mutex_unlock(&channel->lock); goto end_nosignal; } } } + pthread_mutex_unlock(&channel->lock); /* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 0318eecea..c37be8fb8 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -155,7 +155,9 @@ static struct lttng_consumer_stream *allocate_stream(int cpu, int key, assert(channel); assert(ctx); - stream = consumer_allocate_stream(channel->key, + stream = consumer_allocate_stream( + channel, + channel->key, key, LTTNG_CONSUMER_ACTIVE_STREAM, channel->name, @@ -185,8 +187,6 @@ static struct lttng_consumer_stream *allocate_stream(int cpu, int key, goto error; } - stream->chan = channel; - error: if (_alloc_ret) { *_alloc_ret = alloc_ret; -- 2.34.1