X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fviewer-stream.c;h=a88a145e0d2136aed762c10dba59201427d4285d;hb=4e15f915216d4956a31011eb10c26398f81adafa;hp=9d852b661ab420332308fb5d16a75fe093326dd0;hpb=8bb66c3cd60938352927ee865759433387324250;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/viewer-stream.c b/src/bin/lttng-relayd/viewer-stream.c index 9d852b661..a88a145e0 100644 --- a/src/bin/lttng-relayd/viewer-stream.c +++ b/src/bin/lttng-relayd/viewer-stream.c @@ -1,20 +1,10 @@ /* - * Copyright (C) 2013 - Julien Desfossez - * David Goulet - * 2015 - Mathieu Desnoyers + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _LGPL_SOURCE @@ -29,6 +19,24 @@ #include "lttng-relayd.h" #include "viewer-stream.h" +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); @@ -44,17 +52,14 @@ static void viewer_stream_destroy_rcu(struct rcu_head *head) viewer_stream_destroy(vstream); } +/* Relay stream's lock must be held by the caller. */ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, - struct lttng_trace_chunk *viewer_trace_chunk, + struct lttng_trace_chunk *trace_chunk, enum lttng_viewer_seek seek_t) { struct relay_viewer_stream *vstream = NULL; - const bool acquired_reference = lttng_trace_chunk_get( - viewer_trace_chunk); - if (!acquired_reference) { - goto error; - } + ASSERT_LOCKED(stream->lock); vstream = zmalloc(sizeof(*vstream)); if (!vstream) { @@ -62,8 +67,14 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, goto error; } - vstream->stream_file.trace_chunk = viewer_trace_chunk; - viewer_trace_chunk = NULL; + if (trace_chunk) { + const bool acquired_reference = lttng_trace_chunk_get( + trace_chunk); + + assert(acquired_reference); + } + + vstream->stream_file.trace_chunk = trace_chunk; vstream->path_name = lttng_strndup(stream->path_name, LTTNG_VIEWER_PATH_MAX); if (vstream->path_name == NULL) { PERROR("relay viewer path_name alloc"); @@ -82,11 +93,9 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, } vstream->stream = stream; - pthread_mutex_lock(&stream->lock); - if (stream->is_metadata && stream->trace->viewer_metadata_stream) { ERR("Cannot attach viewer metadata stream to trace (busy)."); - goto error_unlock; + goto error; } switch (seek_t) { @@ -121,7 +130,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, tracefile_array_get_seq_head(stream->tfa) + 1; break; default: - goto error_unlock; + goto error; } /* @@ -149,7 +158,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, if (chunk_status == LTTNG_TRACE_CHUNK_STATUS_NO_FILE) { vstream->index_file = NULL; } else { - goto error_unlock; + goto error; } } } @@ -168,7 +177,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, vstream->current_tracefile_id, NULL, file_path, sizeof(file_path)); if (ret < 0) { - goto error_unlock; + goto error; } status = lttng_trace_chunk_open_fs_handle( @@ -176,7 +185,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, O_RDONLY, 0, &vstream->stream_file.handle, true); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { - goto error_unlock; + goto error; } } @@ -186,14 +195,15 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, lseek_ret = fs_handle_seek( vstream->index_file->file, 0, SEEK_END); if (lseek_ret < 0) { - goto error_unlock; + goto error; } } if (stream->is_metadata) { rcu_assign_pointer(stream->trace->viewer_metadata_stream, vstream); } - pthread_mutex_unlock(&stream->lock); + + vstream->last_seen_rotation_count = stream->completed_rotation_count; /* Globally visible after the add unique. */ lttng_ht_node_init_u64(&vstream->stream_n, stream->stream_handle); @@ -202,15 +212,12 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, return vstream; -error_unlock: - pthread_mutex_unlock(&stream->lock); error: if (vstream) { + /* Not using `put` since vstream is assumed to be published. */ + viewer_stream_release_composite_objects(vstream); viewer_stream_destroy(vstream); } - if (viewer_trace_chunk && acquired_reference) { - lttng_trace_chunk_put(viewer_trace_chunk); - } return NULL; } @@ -232,23 +239,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); } @@ -314,7 +306,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 = seq_tail > vstream->index_sent_seqcount ? + seq_tail : vstream->index_sent_seqcount; } /*