X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fviewer-stream.cpp;h=f37d8e33040d991d7ea3ecd818508d1d9ac1f3f2;hb=52e345b9ac912d033c2a2c25a170a01cf209839d;hp=7a66fde5bd6b8bf54d540a8aa0762e47ee9017bd;hpb=ac497a37018f3c253d2e50397294f58d33f7f24f;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/viewer-stream.cpp b/src/bin/lttng-relayd/viewer-stream.cpp index 7a66fde5b..f37d8e330 100644 --- a/src/bin/lttng-relayd/viewer-stream.cpp +++ b/src/bin/lttng-relayd/viewer-stream.cpp @@ -8,20 +8,38 @@ */ #define _LGPL_SOURCE -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include +#include -#include "lttng-relayd.h" -#include "viewer-stream.h" +#include "lttng-relayd.hpp" +#include "viewer-stream.hpp" -static void viewer_stream_destroy(struct relay_viewer_stream *vstream) +static void viewer_stream_release_composite_objects(struct relay_viewer_stream *vstream) { + if (vstream->stream_file.handle) { + fs_handle_close(vstream->stream_file.handle); + vstream->stream_file.handle = NULL; + } + if (vstream->index_file) { + lttng_index_file_put(vstream->index_file); + vstream->index_file = NULL; + } + if (vstream->stream) { + stream_put(vstream->stream); + vstream->stream = NULL; + } lttng_trace_chunk_put(vstream->stream_file.trace_chunk); + vstream->stream_file.trace_chunk = NULL; +} + +static void viewer_stream_destroy(struct relay_viewer_stream *vstream) +{ free(vstream->path_name); free(vstream->channel_name); free(vstream); @@ -30,7 +48,7 @@ static void viewer_stream_destroy(struct relay_viewer_stream *vstream) static void viewer_stream_destroy_rcu(struct rcu_head *head) { struct relay_viewer_stream *vstream = - caa_container_of(head, struct relay_viewer_stream, rcu_node); + lttng::utils::container_of(head, &relay_viewer_stream::rcu_node); viewer_stream_destroy(vstream); } @@ -44,7 +62,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, ASSERT_LOCKED(stream->lock); - vstream = (relay_viewer_stream *) zmalloc(sizeof(*vstream)); + vstream = zmalloc(); if (!vstream) { PERROR("relay viewer stream zmalloc"); goto error; @@ -197,6 +215,8 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, error: if (vstream) { + /* Not using `put` since vstream is assumed to be published. */ + viewer_stream_release_composite_objects(vstream); viewer_stream_destroy(vstream); } return NULL; @@ -220,23 +240,8 @@ static void viewer_stream_release(struct urcu_ref *ref) if (vstream->stream->is_metadata) { rcu_assign_pointer(vstream->stream->trace->viewer_metadata_stream, NULL); } - viewer_stream_unpublish(vstream); - - if (vstream->stream_file.handle) { - fs_handle_close(vstream->stream_file.handle); - vstream->stream_file.handle = NULL; - } - if (vstream->index_file) { - lttng_index_file_put(vstream->index_file); - vstream->index_file = NULL; - } - if (vstream->stream) { - stream_put(vstream->stream); - vstream->stream = NULL; - } - lttng_trace_chunk_put(vstream->stream_file.trace_chunk); - vstream->stream_file.trace_chunk = NULL; + viewer_stream_release_composite_objects(vstream); call_rcu(&vstream->rcu_node, viewer_stream_destroy_rcu); } @@ -264,7 +269,7 @@ struct relay_viewer_stream *viewer_stream_get_by_id(uint64_t id) DBG("Relay viewer stream %" PRIu64 " not found", id); goto end; } - vstream = caa_container_of(node, struct relay_viewer_stream, stream_n); + vstream = lttng::utils::container_of(node, &relay_viewer_stream::stream_n); if (!viewer_stream_get(vstream)) { vstream = NULL; } @@ -302,7 +307,15 @@ void viewer_stream_sync_tracefile_array_tail(struct relay_viewer_stream *vstream if (seq_tail == -1ULL) { seq_tail = 0; } - vstream->index_sent_seqcount = seq_tail; + + /* + * Move the index sent seqcount forward if it was lagging behind + * the new tail of the tracefile array. If the current + * index_sent_seqcount is already further than the tracefile + * array tail position, keep its current position. + */ + vstream->index_sent_seqcount = + std::max(seq_tail, vstream->index_sent_seqcount); } /*