return ret;
}
+/*
+ * Check if a connection is attached to a session.
+ * Return 1 if attached, 0 if not attached, a negative value on error.
+ */
+static
+int session_attached(struct relay_connection *conn, uint64_t session_id)
+{
+ struct relay_session *session;
+ int found = 0;
+
+ if (!conn->viewer_session) {
+ goto end;
+ }
+ cds_list_for_each_entry(session,
+ &conn->viewer_session->sessions_head,
+ viewer_session_list) {
+ if (session->id == session_id) {
+ found = 1;
+ goto end;
+ }
+ }
+
+end:
+ return found;
+}
+
/*
* Send the viewer the list of current sessions.
*/
struct lttng_viewer_new_streams_request request;
struct lttng_viewer_new_streams_response response;
struct relay_session *session;
+ uint64_t session_id;
assert(conn);
if (ret < 0) {
goto error;
}
+ session_id = be64toh(request.session_id);
health_code_update();
rcu_read_lock();
- session = session_find_by_id(conn->sessions_ht,
- be64toh(request.session_id));
+ session = session_find_by_id(conn->sessions_ht, session_id);
if (!session) {
- DBG("Relay session %" PRIu64 " not found",
- be64toh(request.session_id));
+ DBG("Relay session %" PRIu64 " not found", session_id);
response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR);
goto send_reply;
}
- if (conn->session_id == session->id) {
- /* We confirmed the viewer is asking for the same session. */
- send_streams = 1;
- response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_OK);
- } else {
+ if (!session_attached(conn, session_id)) {
send_streams = 0;
response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR);
goto send_reply;
}
+ send_streams = 1;
+ response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_OK);
+
if (!send_streams) {
goto send_reply;
}
if (nb_streams == 0 && session->close_flag) {
send_streams = 0;
response.status = htobe32(LTTNG_VIEWER_NEW_STREAMS_HUP);
+ /*
+ * Remove the session from the attached list of the connection
+ * and try to destroy it.
+ */
+ cds_list_del(&session->viewer_session_list);
+ session_viewer_try_destroy(conn->sessions_ht, session);
goto send_reply;
}
} else {
send_streams = 1;
response.status = htobe32(LTTNG_VIEWER_ATTACH_OK);
- conn->session_id = session->id;
- conn->session = session;
+ cds_list_add(&session->viewer_session_list,
+ &conn->viewer_session->sessions_head);
}
switch (be32toh(request.seek)) {
health_code_update();
rcu_read_lock();
- session = session_find_by_id(conn->sessions_ht, conn->session_id);
- if (!session) {
+ vstream = viewer_stream_find_by_id(be64toh(request_index.stream_id));
+ if (!vstream) {
ret = -1;
goto end_unlock;
}
- vstream = viewer_stream_find_by_id(be64toh(request_index.stream_id));
- if (!vstream) {
+ session = session_find_by_id(conn->sessions_ht, vstream->session_id);
+ if (!session) {
ret = -1;
goto end_unlock;
}
struct lttng_viewer_get_packet get_packet_info;
struct lttng_viewer_trace_packet reply;
struct relay_viewer_stream *stream;
+ struct relay_session *session;
struct ctf_trace *ctf_trace;
assert(conn);
goto error;
}
- ctf_trace = ctf_trace_find_by_path(conn->session->ctf_traces_ht,
+ session = session_find_by_id(conn->sessions_ht, stream->session_id);
+ if (!session) {
+ ret = -1;
+ goto error;
+ }
+
+ ctf_trace = ctf_trace_find_by_path(session->ctf_traces_ht,
stream->path_name);
assert(ctf_trace);
struct lttng_viewer_metadata_packet reply;
struct relay_viewer_stream *stream;
struct ctf_trace *ctf_trace;
+ struct relay_session *session;
assert(conn);
goto error;
}
- ctf_trace = ctf_trace_find_by_path(conn->session->ctf_traces_ht,
+ session = session_find_by_id(conn->sessions_ht, stream->session_id);
+ if (!session) {
+ ret = -1;
+ goto error;
+ }
+
+ ctf_trace = ctf_trace_find_by_path(session->ctf_traces_ht,
stream->path_name);
assert(ctf_trace);
assert(ctf_trace->metadata_sent <= ctf_trace->metadata_received);
static void destroy_connection(struct lttng_ht *relay_connections_ht,
struct relay_connection *conn)
{
- struct relay_session *session;
+ struct relay_session *session, *tmp_session;
assert(relay_connections_ht);
assert(conn);
- DBG("Cleaning connection of session ID %" PRIu64, conn->session_id);
-
connection_delete(relay_connections_ht, conn);
+ if (!conn->viewer_session) {
+ goto end;
+ }
+
rcu_read_lock();
- session = session_find_by_id(conn->sessions_ht, conn->session_id);
- if (session) {
+ cds_list_for_each_entry_safe(session, tmp_session,
+ &conn->viewer_session->sessions_head,
+ viewer_session_list) {
+ DBG("Cleaning connection of session ID %" PRIu64, session->id);
/*
* Very important that this is done before destroying the session so we
* can put back every viewer stream reference from the ctf_trace.
*/
destroy_viewer_streams_by_session(session);
try_destroy_streams(session);
+ cds_list_del(&session->viewer_session_list);
session_viewer_try_destroy(conn->sessions_ht, session);
}
rcu_read_unlock();
+end:
connection_destroy(conn);
}