Commit | Line | Data |
---|---|---|
91d76f53 | 1 | /* |
21cf9b6b | 2 | * Copyright (C) 2011 EfficiOS Inc. |
5b74c7b1 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
5b74c7b1 | 5 | * |
5b74c7b1 DG |
6 | */ |
7 | ||
8 | #ifndef _LTT_SESSION_H | |
9 | #define _LTT_SESSION_H | |
10 | ||
28f23191 JG |
11 | #include "consumer.hpp" |
12 | #include "snapshot.hpp" | |
13 | #include "trace-kernel.hpp" | |
16d64977 JG |
14 | #include "trace-ust.hpp" |
15 | #include "ust-app.hpp" | |
d4a2a84a | 16 | |
c9e313bc | 17 | #include <common/dynamic-array.hpp> |
d9a970b7 | 18 | #include <common/exception.hpp> |
28f23191 | 19 | #include <common/hashtable/hashtable.hpp> |
e99e3664 | 20 | #include <common/make-unique-wrapper.hpp> |
d7bfb9b0 | 21 | #include <common/pthread-lock.hpp> |
a0a4f314 | 22 | #include <common/reference.hpp> |
16d64977 | 23 | #include <common/urcu.hpp> |
28f23191 | 24 | |
5d65beab | 25 | #include <lttng/location.h> |
82b69413 | 26 | #include <lttng/lttng-error.h> |
28f23191 | 27 | #include <lttng/rotation.h> |
6dc3064a | 28 | |
1a496780 | 29 | #include <condition_variable> |
28f23191 | 30 | #include <limits.h> |
1a496780 | 31 | #include <mutex> |
28f23191 JG |
32 | #include <stdbool.h> |
33 | #include <urcu/list.h> | |
7972aab2 | 34 | |
3130a40c JG |
35 | #define ASSERT_SESSION_LIST_LOCKED() LTTNG_ASSERT(session_trylock_list()) |
36 | ||
7972aab2 | 37 | struct ltt_ust_session; |
00187dd4 | 38 | |
d9a970b7 JG |
39 | struct ltt_session; |
40 | struct ltt_session_list; | |
16d64977 | 41 | struct buffer_reg_uid; |
d9a970b7 JG |
42 | |
43 | enum lttng_error_code | |
44 | session_create(const char *name, uid_t uid, gid_t gid, struct ltt_session **out_session); | |
16d64977 JG |
45 | void session_lock(const ltt_session *session); |
46 | void session_unlock(const ltt_session *session); | |
d9a970b7 JG |
47 | |
48 | bool session_get(struct ltt_session *session); | |
49 | void session_put(struct ltt_session *session); | |
50 | ||
51 | /* | |
52 | * The session list lock covers more ground than its name implies. While | |
53 | * it does protect against concurent mutations of the session list, it is | |
54 | * also used as a multi-session lock when synchronizing newly-registered | |
55 | * 'user space tracer' and 'agent' applications. | |
56 | * | |
57 | * In other words, it prevents tracer configurations from changing while they | |
58 | * are being transmitted to the various applications. | |
59 | */ | |
60 | int session_trylock_list() noexcept; | |
61 | ||
62 | #define LTTNG_THROW_SESSION_NOT_FOUND_BY_NAME_ERROR(session_name) \ | |
63 | throw lttng::sessiond::exceptions::session_not_found_error(session_name, \ | |
64 | LTTNG_SOURCE_LOCATION()) | |
65 | #define LTTNG_THROW_SESSION_NOT_FOUND_BY_ID_ERROR(id) \ | |
66 | throw lttng::sessiond::exceptions::session_not_found_error(id, LTTNG_SOURCE_LOCATION()) | |
67 | ||
b5541356 DG |
68 | /* |
69 | * Tracing session list | |
70 | * | |
71 | * Statically declared in session.c and can be accessed by using | |
54d01ffb | 72 | * session_get_list() function that returns the pointer to the list. |
b5541356 | 73 | */ |
5b74c7b1 | 74 | struct ltt_session_list { |
b5541356 | 75 | /* |
a24f7994 MD |
76 | * This lock protects any read/write access to the list and |
77 | * next_uuid. All public functions in session.c acquire this | |
78 | * lock and release it before returning. If none of those | |
79 | * functions are used, the lock MUST be acquired in order to | |
80 | * iterate or/and do any actions on that list. | |
b5541356 | 81 | */ |
1a496780 | 82 | std::mutex lock; |
99d688f2 JG |
83 | /* |
84 | * This condition variable is signaled on every removal from | |
85 | * the session list. | |
86 | */ | |
1a496780 | 87 | std::condition_variable removal_cond; |
6c9cc2ab | 88 | |
b5541356 | 89 | /* |
a24f7994 MD |
90 | * Session unique ID generator. The session list lock MUST be |
91 | * upon update and read of this counter. | |
b5541356 | 92 | */ |
1a496780 | 93 | uint64_t next_uuid = 0; |
6c9cc2ab DG |
94 | |
95 | /* Linked list head */ | |
1a496780 | 96 | struct cds_list_head head = CDS_LIST_HEAD_INIT(head); |
5b74c7b1 DG |
97 | }; |
98 | ||
16d64977 JG |
99 | namespace lttng { |
100 | namespace sessiond { | |
101 | class user_space_consumer_channel_keys { | |
102 | friend ltt_session; | |
103 | ||
104 | public: | |
105 | class iterator; | |
106 | ||
107 | enum class consumer_bitness : std::uint8_t { | |
108 | ABI_32 = 32, | |
109 | ABI_64 = 64, | |
110 | }; | |
111 | ||
112 | enum class channel_type : std::uint8_t { | |
113 | METADATA, | |
114 | DATA, | |
115 | }; | |
116 | ||
117 | iterator begin() const noexcept; | |
118 | iterator end() const noexcept; | |
119 | ||
120 | private: | |
121 | enum class _iteration_mode : std::uint8_t { | |
122 | PER_PID, | |
123 | PER_UID, | |
124 | ||
125 | }; | |
126 | ||
127 | struct _iterator_creation_context { | |
128 | const _iteration_mode _mode; | |
129 | const ltt_ust_session& _session; | |
130 | union { | |
131 | lttng_ht *apps; | |
132 | const cds_list_head *buffer_registry; | |
133 | } _container; | |
134 | }; | |
135 | ||
136 | public: | |
137 | class iterator : public std::iterator<std::input_iterator_tag, std::uint64_t> { | |
138 | friend user_space_consumer_channel_keys; | |
139 | ||
140 | public: | |
141 | struct key { | |
142 | /* Bitness is needed to query the appropriate consumer daemon. */ | |
143 | consumer_bitness bitness; | |
144 | std::uint64_t key_value; | |
145 | channel_type type; | |
146 | ||
147 | bool operator==(const key& other) | |
148 | { | |
149 | return bitness == other.bitness && key_value == other.key_value && | |
150 | type == other.type; | |
151 | } | |
152 | }; | |
153 | ||
154 | /* | |
155 | * Copy constructor disabled since it would require handling the copy of locked | |
156 | * references. | |
157 | */ | |
158 | iterator(const iterator& other) = delete; | |
159 | iterator(iterator&& other) = default; | |
160 | ~iterator() = default; | |
161 | ||
162 | iterator& operator++(); | |
163 | bool operator==(const iterator& other) const noexcept; | |
164 | bool operator!=(const iterator& other) const noexcept; | |
165 | key operator*() const; | |
166 | ||
167 | /* | |
168 | * Get the session registry of the channel currently | |
169 | * pointed by the iterator. Never returns nullptr. | |
170 | */ | |
171 | lttng::sessiond::ust::registry_session *get_registry_session(); | |
172 | ||
173 | private: | |
174 | struct _iterator_position { | |
175 | struct { | |
176 | lttng_ht_iter app_iterator = {}; | |
177 | nonstd::optional<ust_app_session::locked_weak_ref> | |
178 | current_app_session; | |
179 | lttng::sessiond::ust::registry_session *current_registry_session = | |
180 | nullptr; | |
181 | } _per_pid; | |
182 | struct { | |
183 | buffer_reg_uid *current_registry = nullptr; | |
184 | } _per_uid; | |
185 | ||
186 | lttng_ht_iter channel_iterator = {}; | |
187 | }; | |
188 | ||
189 | explicit iterator(const _iterator_creation_context& creation_context, | |
190 | bool is_end = false); | |
191 | ||
192 | void _init_per_pid() noexcept; | |
193 | void _skip_to_next_app_per_pid(bool try_current) noexcept; | |
194 | void _advance_one_per_pid(); | |
195 | key _get_current_value_per_pid() const noexcept; | |
196 | lttng::sessiond::ust::registry_session *_get_registry_session_per_pid(); | |
197 | ||
198 | void _init_per_uid() noexcept; | |
199 | void _advance_one_per_uid(); | |
200 | key _get_current_value_per_uid() const noexcept; | |
201 | lttng::sessiond::ust::registry_session *_get_registry_session_per_uid(); | |
202 | ||
203 | const _iterator_creation_context& _creation_context; | |
204 | _iterator_position _position; | |
205 | bool _is_end; | |
206 | }; | |
207 | ||
208 | private: | |
209 | user_space_consumer_channel_keys(const ltt_ust_session& ust_session, lttng_ht& apps) : | |
210 | _creation_context{ _iteration_mode::PER_PID, ust_session, { .apps = &apps } } | |
211 | { | |
212 | } | |
213 | ||
214 | user_space_consumer_channel_keys(const ltt_ust_session& ust_session, | |
215 | const cds_list_head& buffer_registry) : | |
216 | _creation_context{ _iteration_mode::PER_UID, | |
217 | ust_session, | |
218 | { .buffer_registry = &buffer_registry } } | |
219 | { | |
220 | } | |
221 | ||
222 | class _scoped_rcu_read_lock { | |
223 | public: | |
224 | _scoped_rcu_read_lock() | |
225 | { | |
226 | rcu_read_lock(); | |
227 | } | |
228 | ||
229 | ~_scoped_rcu_read_lock() | |
230 | { | |
231 | if (_armed) { | |
232 | rcu_read_unlock(); | |
233 | } | |
234 | } | |
235 | ||
236 | _scoped_rcu_read_lock(_scoped_rcu_read_lock&& other) | |
237 | { | |
238 | other._armed = false; | |
239 | } | |
240 | ||
241 | private: | |
242 | bool _armed = true; | |
243 | }; | |
244 | ||
245 | _scoped_rcu_read_lock _read_lock; | |
246 | _iterator_creation_context _creation_context; | |
247 | }; | |
248 | } /* namespace sessiond */ | |
249 | } /* namespace lttng */ | |
250 | ||
b5541356 DG |
251 | /* |
252 | * This data structure contains information needed to identify a tracing | |
253 | * session for both LTTng and UST. | |
5b74c7b1 DG |
254 | */ |
255 | struct ltt_session { | |
e99e3664 | 256 | using id_t = uint64_t; |
16d64977 | 257 | friend lttng::sessiond::user_space_consumer_channel_keys::iterator; |
d9a970b7 JG |
258 | |
259 | private: | |
260 | static void _locked_session_release(ltt_session *session); | |
261 | static void _locked_const_session_release(const ltt_session *session); | |
262 | static void _const_session_put(const ltt_session *session); | |
a0a4f314 | 263 | static void _const_session_unlock(const ltt_session& session); |
d9a970b7 JG |
264 | |
265 | public: | |
a0a4f314 JG |
266 | using locked_ref = lttng::non_copyable_reference< |
267 | ltt_session, | |
268 | lttng::memory::create_deleter_class<ltt_session, | |
269 | ltt_session::_locked_session_release>::deleter>; | |
270 | using ref = lttng::non_copyable_reference< | |
d9a970b7 JG |
271 | ltt_session, |
272 | lttng::memory::create_deleter_class<ltt_session, session_put>::deleter>; | |
a0a4f314 JG |
273 | using const_locked_ref = lttng::non_copyable_reference< |
274 | const ltt_session, | |
275 | lttng::memory::create_deleter_class< | |
276 | const ltt_session, | |
277 | ltt_session::_locked_const_session_release>::deleter>; | |
278 | using const_ref = lttng::non_copyable_reference< | |
d9a970b7 | 279 | const ltt_session, |
a0a4f314 JG |
280 | lttng::memory::create_deleter_class<const ltt_session, |
281 | ltt_session::_const_session_put>::deleter>; | |
d9a970b7 | 282 | |
16d64977 JG |
283 | static locked_ref make_locked_ref(ltt_session& session) |
284 | { | |
285 | return lttng::make_non_copyable_reference<locked_ref::referenced_type, | |
286 | locked_ref::deleter>(session); | |
287 | } | |
288 | ||
289 | static const_locked_ref make_locked_ref(const ltt_session& session) | |
290 | { | |
291 | return lttng::make_non_copyable_reference<const_locked_ref::referenced_type, | |
292 | const_locked_ref::deleter>(session); | |
293 | } | |
294 | ||
295 | static ref make_ref(ltt_session& session) | |
296 | { | |
297 | return lttng::make_non_copyable_reference<ref::referenced_type, ref::deleter>( | |
298 | session); | |
299 | } | |
300 | ||
301 | static const_ref make_ref(const ltt_session& session) | |
302 | { | |
303 | return lttng::make_non_copyable_reference<const_ref::referenced_type, | |
304 | const_ref::deleter>(session); | |
305 | } | |
306 | ||
d9a970b7 JG |
307 | void lock() const noexcept; |
308 | void unlock() const noexcept; | |
309 | ||
16d64977 JG |
310 | lttng::sessiond::user_space_consumer_channel_keys user_space_consumer_channel_keys() const; |
311 | ||
d9a970b7 JG |
312 | /* |
313 | * Session list lock must be acquired by the caller. | |
314 | * | |
315 | * The caller must not keep the ownership of the returned locked session | |
316 | * for longer than strictly necessary. If your intention is to acquire | |
317 | * a reference to an ltt_session, see `find_session()`. | |
318 | */ | |
319 | static locked_ref find_locked_session(ltt_session::id_t id); | |
320 | static locked_ref find_locked_session(lttng::c_string_view name); | |
321 | static const_locked_ref find_locked_const_session(ltt_session::id_t id); | |
322 | static const_locked_ref find_locked_const_session(lttng::c_string_view name); | |
323 | ||
324 | static ref find_session(ltt_session::id_t id); | |
325 | static ref find_session(lttng::c_string_view name); | |
326 | static const_ref find_const_session(ltt_session::id_t id); | |
327 | static const_ref find_const_session(lttng::c_string_view name); | |
e99e3664 | 328 | |
74babd95 | 329 | char name[NAME_MAX]; |
b178f53e | 330 | bool has_auto_generated_name; |
46ef2188 | 331 | bool name_contains_creation_time; |
32aef76c | 332 | char hostname[LTTNG_HOST_NAME_MAX]; /* Local hostname. */ |
ecd1a12f MD |
333 | /* Path of the last closed chunk. */ |
334 | char last_chunk_path[LTTNG_PATH_MAX]; | |
b178f53e | 335 | time_t creation_time; |
20fe2104 | 336 | struct ltt_kernel_session *kernel_session; |
f6a9efaa | 337 | struct ltt_ust_session *ust_session; |
d9a970b7 | 338 | mutable struct urcu_ref ref_count; |
b5541356 DG |
339 | /* |
340 | * Protect any read/write on this session data structure. This lock must be | |
341 | * acquired *before* using any public functions declared below. Use | |
54d01ffb | 342 | * session_lock() and session_unlock() for that. |
b5541356 | 343 | */ |
d9a970b7 | 344 | mutable pthread_mutex_t _lock; |
b5541356 | 345 | struct cds_list_head list; |
e99e3664 JG |
346 | /* session unique identifier */ |
347 | id_t id; | |
f4cc5e83 JG |
348 | /* Indicates if the session has been added to the session list and ht.*/ |
349 | bool published; | |
e32d7f27 JG |
350 | /* Indicates if a destroy command has been applied to this session. */ |
351 | bool destroyed; | |
6df2e2c9 MD |
352 | /* UID/GID of the user owning the session */ |
353 | uid_t uid; | |
354 | gid_t gid; | |
00e2e675 DG |
355 | /* |
356 | * Network session handle. A value of 0 means that there is no remote | |
357 | * session established. | |
358 | */ | |
359 | uint64_t net_handle; | |
360 | /* | |
361 | * This consumer is only set when the create_session_uri call is made. | |
362 | * This contains the temporary information for a consumer output. Upon | |
363 | * creation of the UST or kernel session, this consumer, if available, is | |
364 | * copied into those sessions. | |
365 | */ | |
366 | struct consumer_output *consumer; | |
b178f53e JG |
367 | /* |
368 | * Indicates whether or not the user has specified an output directory | |
369 | * or if it was configured using the default configuration. | |
370 | */ | |
371 | bool has_user_specified_directory; | |
8382cf6f | 372 | /* Did at least ONE start command has been triggered?. */ |
66cefebd JG |
373 | bool has_been_started; |
374 | /* Is the session active? */ | |
375 | bool active; | |
6dc3064a DG |
376 | |
377 | /* Snapshot representation in a session. */ | |
378 | struct snapshot snapshot; | |
379 | /* Indicate if the session has to output the traces or not. */ | |
380 | unsigned int output_traces; | |
27babd3a | 381 | /* |
92fe5ca1 JG |
382 | * This session is in snapshot mode. This means that channels enabled |
383 | * will be set in overwrite mode by default and must be in mmap | |
384 | * output mode. Note that snapshots can be taken on a session that | |
385 | * is not in "snapshot_mode". This parameter only affects channel | |
386 | * creation defaults. | |
27babd3a DG |
387 | */ |
388 | unsigned int snapshot_mode; | |
54213acc JG |
389 | /* |
390 | * A session that has channels that don't use 'mmap' output can't be | |
391 | * used to capture snapshots. This is set to true whenever a | |
392 | * 'splice' kernel channel is enabled. | |
393 | */ | |
394 | bool has_non_mmap_channel; | |
ecc48a90 JD |
395 | /* |
396 | * Timer set when the session is created for live reading. | |
397 | */ | |
d98ad589 | 398 | unsigned int live_timer; |
d7ba1388 MD |
399 | /* |
400 | * Path where to keep the shared memory files. | |
401 | */ | |
402 | char shm_path[PATH_MAX]; | |
23324029 JD |
403 | /* |
404 | * Node in ltt_sessions_ht_by_id. | |
405 | */ | |
406 | struct lttng_ht_node_u64 node; | |
e1bbf989 JR |
407 | /* |
408 | * Node in ltt_sessions_ht_by_name. | |
409 | */ | |
410 | struct lttng_ht_node_str node_by_name; | |
d88744a4 | 411 | /* |
92816cc3 JG |
412 | * Timer to check periodically if a relay and/or consumer has completed |
413 | * the last rotation. | |
d88744a4 | 414 | */ |
92816cc3 JG |
415 | bool rotation_pending_check_timer_enabled; |
416 | timer_t rotation_pending_check_timer; | |
259c2674 | 417 | /* Timer to periodically rotate a session. */ |
92816cc3 JG |
418 | bool rotation_schedule_timer_enabled; |
419 | timer_t rotation_schedule_timer; | |
66ea93b1 | 420 | /* Value for periodic rotations, 0 if disabled. */ |
259c2674 | 421 | uint64_t rotate_timer_period; |
66ea93b1 | 422 | /* Value for size-based rotations, 0 if disabled. */ |
259c2674 | 423 | uint64_t rotate_size; |
5c408ad8 JD |
424 | /* |
425 | * Keep a state if this session was rotated after the last stop command. | |
426 | * We only allow one rotation after a stop. At destroy, we also need to | |
a9577b76 | 427 | * know if a rotation occurred since the last stop to rename the current |
a2b988e2 MD |
428 | * chunk. After a stop followed by rotate, all subsequent clear |
429 | * (without prior start) will succeed, but will be effect-less. | |
5c408ad8 JD |
430 | */ |
431 | bool rotated_after_last_stop; | |
b02f5986 MD |
432 | /* |
433 | * Track whether the session was cleared after last stop. All subsequent | |
434 | * clear (without prior start) will succeed, but will be effect-less. A | |
435 | * subsequent rotate (without prior start) will return an error. | |
436 | */ | |
437 | bool cleared_after_last_stop; | |
a7ceb342 MD |
438 | /* |
439 | * True if the session has had an explicit non-quiet rotation. | |
440 | */ | |
441 | bool rotated; | |
90936dcf | 442 | /* |
c08136a3 | 443 | * Trigger for size-based rotations. |
90936dcf | 444 | */ |
90936dcf | 445 | struct lttng_trigger *rotate_trigger; |
d2956687 | 446 | LTTNG_OPTIONAL(uint64_t) most_recent_chunk_id; |
82b69413 | 447 | struct lttng_trace_chunk *current_trace_chunk; |
d2956687 JG |
448 | struct lttng_trace_chunk *chunk_being_archived; |
449 | /* Current state of a rotation. */ | |
450 | enum lttng_rotation_state rotation_state; | |
7fdbed1c | 451 | bool quiet_rotation; |
d2956687 JG |
452 | char *last_archived_chunk_name; |
453 | LTTNG_OPTIONAL(uint64_t) last_archived_chunk_id; | |
3e3665b8 | 454 | struct lttng_dynamic_array destroy_notifiers; |
ccbdaca4 | 455 | struct lttng_dynamic_array clear_notifiers; |
6fa5fe7c MD |
456 | /* Session base path override. Set non-null. */ |
457 | char *base_path; | |
d9a970b7 | 458 | }; |
e1bbf989 | 459 | |
a0a4f314 JG |
460 | /* |
461 | * Destruction notifiers are invoked in an exclusive context. There is no need for the session to be | |
462 | * locked nor for a reference to be acquired. | |
463 | */ | |
464 | using ltt_session_destroy_notifier = void (*)(const ltt_session::locked_ref&, void *); | |
465 | using ltt_session_clear_notifier = void (*)(const ltt_session::locked_ref&, void *); | |
466 | ||
e99e3664 JG |
467 | namespace lttng { |
468 | namespace sessiond { | |
469 | ||
d9a970b7 | 470 | std::unique_lock<std::mutex> lock_session_list(); |
e99e3664 | 471 | |
d9a970b7 JG |
472 | namespace exceptions { |
473 | /** | |
474 | * @class session_not_found_error | |
475 | * @brief Represents a session-not-found error and provides the parameters used to query the session | |
476 | * for use by error-reporting code. | |
477 | */ | |
478 | class session_not_found_error : public lttng::runtime_error { | |
479 | public: | |
480 | class query_parameter { | |
481 | public: | |
482 | enum class query_type : std::uint8_t { BY_NAME, BY_ID }; | |
483 | ||
484 | /* | |
485 | * Intentionally not explicit to allow construction from c-style strings, | |
486 | * std::string, and lttng::c_string_view. | |
487 | * | |
488 | * NOLINTBEGIN(google-explicit-constructor) | |
489 | */ | |
490 | query_parameter(const std::string& session_name) : | |
491 | type(query_type::BY_NAME), parameter(session_name) | |
492 | { | |
493 | } | |
494 | /* NOLINTEND(google-explicit-constructor) */ | |
495 | ||
a0a4f314 JG |
496 | explicit query_parameter(ltt_session::id_t id_) : |
497 | type(query_type::BY_ID), parameter(id_) | |
d9a970b7 JG |
498 | { |
499 | } | |
500 | ||
501 | query_parameter(const query_parameter& other) : type(other.type) | |
502 | { | |
503 | if (type == query_type::BY_NAME) { | |
504 | new (¶meter.name) std::string(other.parameter.name); | |
505 | } else { | |
506 | parameter.id = other.parameter.id; | |
507 | } | |
508 | } | |
509 | ||
510 | ~query_parameter() | |
511 | { | |
512 | if (type == query_type::BY_NAME) { | |
513 | parameter.name.~basic_string(); | |
514 | } | |
515 | } | |
516 | ||
517 | query_type type; | |
518 | union parameter { | |
519 | explicit parameter(std::string name_) : name(std::move(name_)) | |
520 | { | |
521 | } | |
522 | ||
523 | explicit parameter(ltt_session::id_t id_) : id(id_) | |
524 | { | |
525 | } | |
526 | ||
527 | /* | |
528 | * parameter doesn't have enough information to do this safely; it it | |
529 | * delegated to its parent which uses placement new. | |
530 | */ | |
531 | parameter() | |
532 | { | |
533 | } | |
534 | ||
535 | parameter(const parameter&) = delete; | |
536 | parameter(const parameter&&) = delete; | |
537 | parameter& operator=(parameter&) = delete; | |
538 | parameter& operator=(parameter&&) = delete; | |
539 | ||
540 | ~parameter() | |
541 | { | |
542 | } | |
543 | ||
544 | std::string name; | |
545 | ltt_session::id_t id; | |
546 | } parameter; | |
547 | }; | |
548 | ||
549 | session_not_found_error(const std::string& session_name, | |
550 | const lttng::source_location& source_location_) : | |
551 | lttng::runtime_error(fmt::format("Session not found: name=`{}`", session_name), | |
552 | source_location_), | |
553 | query_parameter(session_name) | |
554 | { | |
555 | } | |
556 | ||
557 | session_not_found_error(ltt_session::id_t session_id, | |
558 | const lttng::source_location& source_location_) : | |
559 | lttng::runtime_error("Session not found: id=" + std::to_string(session_id), | |
560 | source_location_), | |
561 | query_parameter(session_id) | |
562 | { | |
563 | } | |
564 | ||
565 | session_not_found_error(const session_not_found_error& other) = default; | |
566 | ~session_not_found_error() noexcept override = default; | |
567 | ||
568 | query_parameter query_parameter; | |
569 | }; | |
570 | } // namespace exceptions | |
e99e3664 JG |
571 | } /* namespace sessiond */ |
572 | } /* namespace lttng */ | |
573 | ||
a0a4f314 JG |
574 | void session_destroy(struct ltt_session *session); |
575 | int session_add_destroy_notifier(const ltt_session::locked_ref& session, | |
576 | ltt_session_destroy_notifier notifier, | |
577 | void *user_data); | |
578 | ||
579 | int session_add_clear_notifier(const ltt_session::locked_ref& session, | |
580 | ltt_session_clear_notifier notifier, | |
581 | void *user_data); | |
582 | void session_notify_clear(const ltt_session::locked_ref& session); | |
583 | ||
584 | enum consumer_dst_type | |
585 | session_get_consumer_destination_type(const ltt_session::locked_ref& session); | |
586 | const char *session_get_net_consumer_hostname(const ltt_session::locked_ref& session); | |
587 | void session_get_net_consumer_ports(const ltt_session::locked_ref& session, | |
588 | uint16_t *control_port, | |
589 | uint16_t *data_port); | |
590 | struct lttng_trace_archive_location * | |
591 | session_get_trace_archive_location(const ltt_session::locked_ref& session); | |
592 | ||
593 | struct ltt_session_list *session_get_list(); | |
594 | void session_list_wait_empty(std::unique_lock<std::mutex> list_lock); | |
595 | ||
596 | bool session_access_ok(const ltt_session::locked_ref& session, uid_t uid); | |
597 | ||
598 | int session_reset_rotation_state(const ltt_session::locked_ref& session, | |
599 | enum lttng_rotation_state result); | |
600 | ||
601 | /* Create a new trace chunk object from the session's configuration. */ | |
602 | struct lttng_trace_chunk * | |
603 | session_create_new_trace_chunk(const ltt_session::locked_ref& session, | |
604 | const struct consumer_output *consumer_output_override, | |
605 | const char *session_base_path_override, | |
606 | const char *chunk_name_override); | |
607 | ||
608 | /* | |
609 | * Set `new_trace_chunk` as the session's current trace chunk. A reference | |
610 | * to `new_trace_chunk` is acquired by the session. The chunk is created | |
611 | * on remote peers (consumer and relay daemons). | |
612 | * | |
613 | * A reference to the session's current trace chunk is returned through | |
614 | * `current_session_trace_chunk` on success. | |
615 | */ | |
616 | int session_set_trace_chunk(const ltt_session::locked_ref& session, | |
617 | struct lttng_trace_chunk *new_trace_chunk, | |
618 | struct lttng_trace_chunk **current_session_trace_chunk); | |
619 | ||
620 | /* | |
621 | * Close a chunk on the remote peers of a session. Has no effect on the | |
622 | * ltt_session itself. | |
623 | */ | |
624 | int session_close_trace_chunk(const ltt_session::locked_ref& session, | |
625 | struct lttng_trace_chunk *trace_chunk, | |
626 | enum lttng_trace_chunk_command_type close_command, | |
627 | char *path); | |
628 | ||
629 | /* Open a packet in all channels of a given session. */ | |
630 | enum lttng_error_code session_open_packets(const ltt_session::locked_ref& session); | |
631 | ||
632 | bool session_output_supports_trace_chunks(const struct ltt_session *session); | |
633 | ||
634 | /* | |
635 | * Sample the id of a session looked up via its name. | |
636 | * Here the term "sampling" hint the caller that this return the id at a given | |
637 | * point in time with no guarantee that the session for which the id was | |
638 | * sampled still exist at that point. | |
639 | * | |
640 | * Return 0 when the session is not found, | |
641 | * Return 1 when the session is found and set `id`. | |
642 | */ | |
643 | bool sample_session_id_by_name(const char *name, uint64_t *id); | |
644 | ||
16d64977 JG |
645 | const char *session_get_base_path(const ltt_session::locked_ref& session); |
646 | ||
647 | #ifdef HAVE_LIBLTTNG_UST_CTL | |
648 | ||
649 | enum lttng_error_code ust_app_rotate_session(const ltt_session::locked_ref& session); | |
650 | enum lttng_error_code ust_app_clear_session(const ltt_session::locked_ref& session); | |
651 | enum lttng_error_code ust_app_open_packets(const ltt_session::locked_ref& session); | |
652 | ||
653 | #else /* HAVE_LIBLTTNG_UST_CTL */ | |
654 | ||
655 | static inline enum lttng_error_code ust_app_rotate_session(const ltt_session::locked_ref& session | |
656 | __attribute__((unused))) | |
657 | { | |
658 | return LTTNG_ERR_UNK; | |
659 | } | |
660 | ||
661 | static inline enum lttng_error_code ust_app_clear_session(const ltt_session::locked_ref& session | |
662 | __attribute__((unused))) | |
663 | { | |
664 | return LTTNG_ERR_UNK; | |
665 | } | |
666 | ||
667 | static inline enum lttng_error_code ust_app_open_packets(const ltt_session::locked_ref& session | |
668 | __attribute__((unused))) | |
669 | { | |
670 | return LTTNG_ERR_UNK; | |
671 | } | |
672 | ||
673 | #endif /* HAVE_LIBLTTNG_UST_CTL */ | |
674 | ||
5b74c7b1 | 675 | #endif /* _LTT_SESSION_H */ |