5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License, version 2 only, as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <urcu/list.h>
29 #include <lttng/constant.h>
30 #include <common/hashtable/hashtable.h>
31 #include <common/uuid.h>
32 #include <common/trace-chunk.h>
33 #include <common/optional.h>
36 * Represents a session for the relay point of view
38 struct relay_session
{
40 * This session id is generated by the relay daemon to guarantee
41 * its uniqueness even when serving multiple session daemons.
42 * It is used to match a set of streams to their session.
46 * ID of the session in the session daemon's domain.
47 * This information is only provided by 2.11+ peers.
49 LTTNG_OPTIONAL(uint64_t) id_sessiond
;
51 * Only provided by 2.11+ peers. However, the UUID is set to 'nil' in
54 lttng_uuid sessiond_uuid
;
55 LTTNG_OPTIONAL(time_t) creation_time
;
56 /* Must _not_ be empty for 2.4+ peers. */
57 char session_name
[LTTNG_NAME_MAX
];
58 char hostname
[LTTNG_HOST_NAME_MAX
];
59 char base_path
[LTTNG_PATH_MAX
];
61 * Session output path relative to relayd's output path.
62 * Will be empty when interacting with peers < 2.11 since their
63 * streams' path are expressed relative to the relay daemon's
66 char output_path
[LTTNG_PATH_MAX
];
69 /* Session in snapshot mode. */
73 * Session has no back reference to its connection because it
74 * has a life-time that can be longer than the consumer connection's
75 * life-time; a reference can still be held by the viewer
76 * connection through the viewer streams.
83 /* major/minor version used for this session. */
88 /* Tell if the session connection has been closed on the streaming side. */
89 bool connection_closed
;
92 * Tell if the session is currently living in a exiting relayd and
93 * should be cleaned forcefully without waiting for pending data or
98 bool session_name_contains_creation_time
;
99 /* Whether session has performed an explicit rotation. */
102 /* Contains ctf_trace object of that session indexed by path name. */
103 struct lttng_ht
*ctf_traces_ht
;
106 * This contains streams that are received on that connection.
107 * It's used to store them until we get the streams sent
108 * command. When this is received, we remove those streams from
109 * the list and publish them.
111 * Updates are protected by the recv_list_lock.
112 * Traversals are protected by RCU.
113 * recv_list_lock also protects stream_count.
115 struct cds_list_head recv_list
; /* RCU list. */
116 uint32_t stream_count
;
117 pthread_mutex_t recv_list_lock
;
120 * Flag checked and exchanged with uatomic_cmpxchg to tell the
121 * viewer-side if new streams got added since the last check.
123 unsigned long new_streams
;
126 * Node in the global session hash table.
128 struct lttng_ht_node_u64 session_n
;
130 * Member of the session list in struct relay_viewer_session.
131 * Updates are protected by the relay_viewer_session
132 * session_list_lock. Traversals are protected by RCU.
134 struct cds_list_head viewer_session_node
;
135 struct lttng_trace_chunk
*current_trace_chunk
;
136 struct lttng_trace_chunk
*pending_closure_trace_chunk
;
137 struct rcu_head rcu_node
; /* For call_rcu teardown. */
140 struct relay_session
*session_create(const char *session_name
,
141 const char *hostname
, const char *base_path
,
144 const lttng_uuid sessiond_uuid
,
145 const uint64_t *id_sessiond
,
146 const uint64_t *current_chunk_id
,
147 const time_t *creation_time
,
150 bool session_name_contains_creation_timestamp
);
151 struct relay_session
*session_get_by_id(uint64_t id
);
152 bool session_get(struct relay_session
*session
);
153 void session_put(struct relay_session
*session
);
155 int session_close(struct relay_session
*session
);
156 int session_abort(struct relay_session
*session
);
158 struct lttng_directory_handle
*session_create_output_directory_handle(
159 struct relay_session
*session
);
161 void print_sessions(void);
163 #endif /* _SESSION_H */