X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fkernel-consumer%2Fkernel-consumer.cpp;h=d22aea1831978225da90eaf5b5d9507bd248ca4a;hb=a4beac76c09632fda439fac25fdb0f7191234191;hp=52266f9eb2a5f18971acbd0b531f8ff4b0c0851e;hpb=4222116f0098672bbbc0fea2b994e50007929d58;p=lttng-tools.git diff --git a/src/common/kernel-consumer/kernel-consumer.cpp b/src/common/kernel-consumer/kernel-consumer.cpp index 52266f9eb..d22aea183 100644 --- a/src/common/kernel-consumer/kernel-consumer.cpp +++ b/src/common/kernel-consumer/kernel-consumer.cpp @@ -20,25 +20,25 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kernel-consumer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kernel-consumer.hpp" extern struct lttng_consumer_global_data the_consumer_data; extern int consumer_poll_timeout; @@ -135,6 +135,30 @@ error: return ret; } +static void finalize_snapshot_stream( + struct lttng_consumer_stream *stream, uint64_t relayd_id) +{ + ASSERT_LOCKED(stream->lock); + + if (relayd_id == (uint64_t) -1ULL) { + if (stream->out_fd >= 0) { + const int ret = close(stream->out_fd); + + if (ret < 0) { + PERROR("Failed to close stream snapshot output file descriptor"); + } + + stream->out_fd = -1; + } + } else { + close_relayd_stream(stream); + stream->net_seq_idx = (uint64_t) -1ULL; + } + + lttng_trace_chunk_put(stream->trace_chunk); + stream->trace_chunk = NULL; +} + /* * Take a snapshot of all the stream of a channel * RCU read-side lock must be held across this function to ensure existence of @@ -145,8 +169,7 @@ error: static int lttng_kconsumer_snapshot_channel( struct lttng_consumer_channel *channel, uint64_t key, char *path, uint64_t relayd_id, - uint64_t nb_packets_per_stream, - struct lttng_consumer_local_data *ctx) + uint64_t nb_packets_per_stream) { int ret; struct lttng_consumer_stream *stream; @@ -199,13 +222,13 @@ static int lttng_kconsumer_snapshot_channel( ret = consumer_send_relayd_stream(stream, path); if (ret < 0) { ERR("sending stream to relayd"); - goto end_unlock; + goto error_finalize_stream; } } else { ret = consumer_stream_create_output_files(stream, false); if (ret < 0) { - goto end_unlock; + goto error_finalize_stream; } DBG("Kernel consumer snapshot stream (%" PRIu64 ")", stream->key); @@ -223,7 +246,7 @@ static int lttng_kconsumer_snapshot_channel( ret = kernctl_buffer_flush(stream->wait_fd); if (ret < 0) { ERR("Failed to flush kernel stream"); - goto end_unlock; + goto error_finalize_stream; } goto end_unlock; } @@ -231,19 +254,19 @@ static int lttng_kconsumer_snapshot_channel( ret = lttng_kconsumer_take_snapshot(stream); if (ret < 0) { ERR("Taking kernel snapshot"); - goto end_unlock; + goto error_finalize_stream; } ret = lttng_kconsumer_get_produced_snapshot(stream, &produced_pos); if (ret < 0) { ERR("Produced kernel snapshot position"); - goto end_unlock; + goto error_finalize_stream; } ret = lttng_kconsumer_get_consumed_snapshot(stream, &consumed_pos); if (ret < 0) { ERR("Consumerd kernel snapshot position"); - goto end_unlock; + goto error_finalize_stream; } consumed_pos = consumer_get_consume_start_pos(consumed_pos, @@ -263,7 +286,7 @@ static int lttng_kconsumer_snapshot_channel( if (ret < 0) { if (ret != -EAGAIN) { PERROR("kernctl_get_subbuf snapshot"); - goto end_unlock; + goto error_finalize_stream; } DBG("Kernel consumer get subbuf failed. Skipping it."); consumed_pos += stream->max_sb_size; @@ -313,26 +336,12 @@ static int lttng_kconsumer_snapshot_channel( ret = kernctl_put_subbuf(stream->wait_fd); if (ret < 0) { ERR("Snapshot kernctl_put_subbuf"); - goto end_unlock; + goto error_finalize_stream; } consumed_pos += stream->max_sb_size; } - if (relayd_id == (uint64_t) -1ULL) { - if (stream->out_fd >= 0) { - ret = close(stream->out_fd); - if (ret < 0) { - PERROR("Kernel consumer snapshot close out_fd"); - goto end_unlock; - } - stream->out_fd = -1; - } - } else { - close_relayd_stream(stream); - stream->net_seq_idx = (uint64_t) -1ULL; - } - lttng_trace_chunk_put(stream->trace_chunk); - stream->trace_chunk = NULL; + finalize_snapshot_stream(stream, relayd_id); pthread_mutex_unlock(&stream->lock); } @@ -345,6 +354,8 @@ error_put_subbuf: if (ret < 0) { ERR("Snapshot kernctl_put_subbuf error path"); } +error_finalize_stream: + finalize_snapshot_stream(stream, relayd_id); end_unlock: pthread_mutex_unlock(&stream->lock); end: @@ -435,7 +446,6 @@ static int lttng_kconsumer_snapshot_metadata( ret = 0; error_snapshot: metadata_stream->read_subbuffer_ops.unlock(metadata_stream); - cds_list_del(&metadata_stream->send_node); consumer_stream_destroy(metadata_stream, NULL); metadata_channel->metadata_stream = NULL; rcu_read_unlock(); @@ -990,8 +1000,7 @@ error_streams_sent_nosignal: msg.u.snapshot_channel.pathname, msg.u.snapshot_channel.relayd_id, msg.u.snapshot_channel - .nb_packets_per_stream, - ctx); + .nb_packets_per_stream); if (ret_snapshot < 0) { ERR("Snapshot channel failed"); ret_code = LTTCOMM_CONSUMERD_SNAPSHOT_FAILED; @@ -1185,8 +1194,7 @@ end_destroy_channel: ret_rotate_channel = lttng_consumer_rotate_channel( channel, key, - msg.u.rotate_channel.relayd_id, - msg.u.rotate_channel.metadata, ctx); + msg.u.rotate_channel.relayd_id); if (ret_rotate_channel < 0) { ERR("Rotate channel failed"); ret_code = LTTCOMM_CONSUMERD_ROTATION_FAIL; @@ -1205,7 +1213,7 @@ end_destroy_channel: int ret_rotate; ret_rotate = lttng_consumer_rotate_ready_streams( - channel, key, ctx); + channel, key); if (ret_rotate < 0) { ERR("Rotate ready streams failed"); } @@ -1248,9 +1256,13 @@ error_rotate_channel: case LTTNG_CONSUMER_INIT: { int ret_send_status; + lttng_uuid sessiond_uuid; + + std::copy(std::begin(msg.u.init.sessiond_uuid), std::end(msg.u.init.sessiond_uuid), + sessiond_uuid.begin()); ret_code = lttng_consumer_init_command(ctx, - msg.u.init.sessiond_uuid); + sessiond_uuid); health_code_update(); ret_send_status = consumer_send_status_msg(sock, ret_code); if (ret_send_status < 0) { @@ -1735,7 +1747,7 @@ end: static int put_next_subbuffer(struct lttng_consumer_stream *stream, - struct stream_subbuffer *subbuffer) + struct stream_subbuffer *subbuffer __attribute__((unused))) { const int ret = kernctl_put_next_subbuf(stream->wait_fd); @@ -1767,7 +1779,7 @@ bool is_get_next_check_metadata_available(int tracer_fd) static int signal_metadata(struct lttng_consumer_stream *stream, - struct lttng_consumer_local_data *ctx) + struct lttng_consumer_local_data *ctx __attribute__((unused))) { ASSERT_LOCKED(stream->metadata_rdv_lock); return pthread_cond_broadcast(&stream->metadata_rdv) ? -errno : 0;