X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fust-consumer%2Fust-consumer.c;h=7ce03ad87dde9b442015f3dc5af9b05697e2d8a5;hp=1cd39ef34b7e957bf9cfa95ac93e7fb40374fb9c;hb=f64161251bd649abe5b6a473531adfa3af9bd6b6;hpb=6f94560a050962daad560dac2823bd97b0b1bf98 diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 1cd39ef34..7ce03ad87 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -56,10 +56,15 @@ ssize_t lttng_ustconsumer_on_read_subbuffer_mmap( uint64_t metadata_id; struct consumer_relayd_sock_pair *relayd = NULL; + /* RCU lock for the relayd pointer */ + rcu_read_lock(); + /* Flag that the current stream if set for network streaming. */ if (stream->net_seq_idx != -1) { relayd = consumer_find_relayd(stream->net_seq_idx); if (relayd == NULL) { + ERR("UST consumer mmap(), unable to find relay for index %d", + stream->net_seq_idx); goto end; } } @@ -76,12 +81,15 @@ ssize_t lttng_ustconsumer_on_read_subbuffer_mmap( /* Handle stream on the relayd if the output is on the network */ if (relayd) { + unsigned long netlen = len; + if (stream->metadata_flag) { /* Only lock if metadata since we use the control socket. */ pthread_mutex_lock(&relayd->ctrl_sock_mutex); + netlen += sizeof(stream->relayd_stream_id); } - ret = consumer_handle_stream_before_relayd(stream, len); + ret = consumer_handle_stream_before_relayd(stream, netlen); if (ret >= 0) { outfd = ret; @@ -139,6 +147,7 @@ end: if (relayd && stream->metadata_flag) { pthread_mutex_unlock(&relayd->ctrl_sock_mutex); } + rcu_read_unlock(); return written; } @@ -210,6 +219,9 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, return -ENOENT; } + /* relayd need RCU read-side lock */ + rcu_read_lock(); + switch (msg.cmd_type) { case LTTNG_CONSUMER_ADD_RELAYD_SOCKET: { @@ -433,6 +445,7 @@ end: ret = write(ctx->consumer_poll_pipe[1], "", 1); } while (ret < 0 && errno == EINTR); end_nosignal: + rcu_read_unlock(); return 0; }