X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fviewer-stream.c;h=67c452eec7d4264139f1134b1fcdd4bc2aa2d49c;hp=9d852b661ab420332308fb5d16a75fe093326dd0;hb=80516611b6f19201b1e173fb448935aca7a9e668;hpb=8bb66c3cd60938352927ee865759433387324250 diff --git a/src/bin/lttng-relayd/viewer-stream.c b/src/bin/lttng-relayd/viewer-stream.c index 9d852b661..67c452eec 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 @@ -31,6 +21,7 @@ static void viewer_stream_destroy(struct relay_viewer_stream *vstream) { + lttng_trace_chunk_put(vstream->stream_file.trace_chunk); free(vstream->path_name); free(vstream->channel_name); free(vstream); @@ -44,17 +35,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 +50,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 +76,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 +113,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 +141,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 +160,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 +168,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 +178,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 +195,10 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, return vstream; -error_unlock: - pthread_mutex_unlock(&stream->lock); error: if (vstream) { viewer_stream_destroy(vstream); } - if (viewer_trace_chunk && acquired_reference) { - lttng_trace_chunk_put(viewer_trace_chunk); - } return NULL; }