*
* Return 0 on success or else a negative value.
*/
-static
-int make_viewer_streams(struct relay_session *session,
- enum lttng_viewer_seek seek_t, uint32_t *nb_total, uint32_t *nb_unsent,
- uint32_t *nb_created, bool *closed)
+static int make_viewer_streams(struct relay_session *session,
+ struct lttng_trace_chunk *viewer_trace_chunk,
+ enum lttng_viewer_seek seek_t,
+ uint32_t *nb_total,
+ uint32_t *nb_unsent,
+ uint32_t *nb_created,
+ bool *closed)
{
int ret;
struct lttng_ht_iter iter;
}
vstream = viewer_stream_get_by_id(stream->stream_handle);
if (!vstream) {
- vstream = viewer_stream_create(stream, seek_t);
+ vstream = viewer_stream_create(stream,
+ viewer_trace_chunk, seek_t);
if (!vstream) {
ret = -1;
ctf_trace_put(ctf_trace);
uint32_t nb_created = 0, nb_unsent = 0, nb_streams = 0, nb_total = 0;
struct lttng_viewer_new_streams_request request;
struct lttng_viewer_new_streams_response response;
- struct relay_session *session;
+ struct relay_session *session = NULL;
uint64_t session_id;
bool closed = false;
response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_OK);
pthread_mutex_lock(&session->lock);
- ret = make_viewer_streams(session, LTTNG_VIEWER_SEEK_LAST, &nb_total, &nb_unsent,
+ if (!conn->viewer_session->current_trace_chunk &&
+ session->current_trace_chunk) {
+ ret = viewer_session_set_trace_chunk(conn->viewer_session,
+ session->current_trace_chunk);
+ if (ret) {
+ goto error_unlock_session;
+ }
+ }
+ ret = make_viewer_streams(session,
+ conn->viewer_session->current_trace_chunk,
+ LTTNG_VIEWER_SEEK_LAST, &nb_total, &nb_unsent,
&nb_created, &closed);
- pthread_mutex_unlock(&session->lock);
if (ret < 0) {
- goto end_put_session;
+ goto error_unlock_session;
}
+ pthread_mutex_unlock(&session->lock);
+
/* Only send back the newly created streams with the unsent ones. */
nb_streams = nb_created + nb_unsent;
response.streams_count = htobe32(nb_streams);
}
error:
return ret;
+error_unlock_session:
+ pthread_mutex_unlock(&session->lock);
+ session_put(session);
+ return ret;
}
/*
goto send_reply;
}
- ret = make_viewer_streams(session, seek_type, &nb_streams, NULL,
- NULL, &closed);
+ if (!conn->viewer_session->current_trace_chunk &&
+ session->current_trace_chunk) {
+ ret = viewer_session_set_trace_chunk(conn->viewer_session,
+ session->current_trace_chunk);
+ if (ret) {
+ goto end_put_session;
+ }
+ }
+ ret = make_viewer_streams(session,
+ conn->viewer_session->current_trace_chunk, seek_type,
+ &nb_streams, NULL, NULL, &closed);
if (ret < 0) {
goto end_put_session;
}
-
pthread_mutex_unlock(&session->lock);
session_put(session);
session = NULL;
goto end;
}
vstream->index_file = lttng_index_file_create_from_trace_chunk_read_only(
- rstream->trace_chunk, rstream->path_name,
+ vstream->stream_file.trace_chunk, rstream->path_name,
rstream->channel_name, rstream->tracefile_size,
vstream->current_tracefile_id,
lttng_to_index_major(connection_major, connection_minor),
#include <urcu/ref.h>
#include <common/hashtable/hashtable.h>
+#include <common/trace-chunk.h>
#include "session.h"
*/
struct cds_list_head session_list; /* RCU list. */
pthread_mutex_t session_list_lock; /* Protects list updates. */
+ /* Once set, the current trace chunk of a viewer must not change. */
+ struct lttng_trace_chunk *current_trace_chunk;
};
struct relay_viewer_session *viewer_session_create(void);
struct relay_session *session);
void viewer_session_close_one_session(struct relay_viewer_session *vsession,
struct relay_session *session);
+int viewer_session_set_trace_chunk(struct relay_viewer_session *vsession,
+ struct lttng_trace_chunk *relay_session_trace_chunk);
#endif /* _VIEWER_SESSION_H */
}
struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream,
+ struct lttng_trace_chunk *viewer_trace_chunk,
enum lttng_viewer_seek seek_t)
{
struct relay_viewer_stream *vstream = NULL;
const bool acquired_reference = lttng_trace_chunk_get(
- stream->trace_chunk);
+ viewer_trace_chunk);
if (!acquired_reference) {
goto error;
goto error;
}
- vstream->stream_file.trace_chunk = stream->trace_chunk;
+ vstream->stream_file.trace_chunk = viewer_trace_chunk;
+ viewer_trace_chunk = NULL;
vstream->path_name = lttng_strndup(stream->path_name, LTTNG_VIEWER_PATH_MAX);
if (vstream->path_name == NULL) {
PERROR("relay viewer path_name alloc");
const uint32_t connection_minor = stream->trace->session->minor;
vstream->index_file = lttng_index_file_create_from_trace_chunk_read_only(
- stream->trace_chunk, stream->path_name,
+ vstream->stream_file.trace_chunk,
+ stream->path_name,
stream->channel_name, stream->tracefile_size,
vstream->current_tracefile_id,
lttng_to_index_major(connection_major,
if (vstream) {
viewer_stream_destroy(vstream);
}
+ if (viewer_trace_chunk) {
+ lttng_trace_chunk_put(viewer_trace_chunk);
+ }
return NULL;
}
}
vstream->index_file =
lttng_index_file_create_from_trace_chunk_read_only(
- stream->trace_chunk, stream->path_name,
+ vstream->stream_file.trace_chunk,
+ stream->path_name,
stream->channel_name,
stream->tracefile_size,
vstream->current_tracefile_id,