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; | |
c1391746 JG |
161 | iterator& operator=(const iterator&) = delete; |
162 | iterator& operator=(iterator&&) noexcept = delete; | |
16d64977 JG |
163 | |
164 | iterator& operator++(); | |
165 | bool operator==(const iterator& other) const noexcept; | |
166 | bool operator!=(const iterator& other) const noexcept; | |
167 | key operator*() const; | |
168 | ||
169 | /* | |
170 | * Get the session registry of the channel currently | |
171 | * pointed by the iterator. Never returns nullptr. | |
172 | */ | |
173 | lttng::sessiond::ust::registry_session *get_registry_session(); | |
174 | ||
175 | private: | |
176 | struct _iterator_position { | |
177 | struct { | |
178 | lttng_ht_iter app_iterator = {}; | |
179 | nonstd::optional<ust_app_session::locked_weak_ref> | |
180 | current_app_session; | |
181 | lttng::sessiond::ust::registry_session *current_registry_session = | |
182 | nullptr; | |
183 | } _per_pid; | |
184 | struct { | |
185 | buffer_reg_uid *current_registry = nullptr; | |
186 | } _per_uid; | |
187 | ||
188 | lttng_ht_iter channel_iterator = {}; | |
189 | }; | |
190 | ||
191 | explicit iterator(const _iterator_creation_context& creation_context, | |
192 | bool is_end = false); | |
193 | ||
194 | void _init_per_pid() noexcept; | |
195 | void _skip_to_next_app_per_pid(bool try_current) noexcept; | |
196 | void _advance_one_per_pid(); | |
197 | key _get_current_value_per_pid() const noexcept; | |
198 | lttng::sessiond::ust::registry_session *_get_registry_session_per_pid(); | |
199 | ||
200 | void _init_per_uid() noexcept; | |
201 | void _advance_one_per_uid(); | |
202 | key _get_current_value_per_uid() const noexcept; | |
203 | lttng::sessiond::ust::registry_session *_get_registry_session_per_uid(); | |
204 | ||
205 | const _iterator_creation_context& _creation_context; | |
206 | _iterator_position _position; | |
207 | bool _is_end; | |
208 | }; | |
209 | ||
210 | private: | |
211 | user_space_consumer_channel_keys(const ltt_ust_session& ust_session, lttng_ht& apps) : | |
212 | _creation_context{ _iteration_mode::PER_PID, ust_session, { .apps = &apps } } | |
213 | { | |
214 | } | |
215 | ||
216 | user_space_consumer_channel_keys(const ltt_ust_session& ust_session, | |
217 | const cds_list_head& buffer_registry) : | |
218 | _creation_context{ _iteration_mode::PER_UID, | |
219 | ust_session, | |
220 | { .buffer_registry = &buffer_registry } } | |
221 | { | |
222 | } | |
223 | ||
224 | class _scoped_rcu_read_lock { | |
225 | public: | |
226 | _scoped_rcu_read_lock() | |
227 | { | |
228 | rcu_read_lock(); | |
229 | } | |
230 | ||
231 | ~_scoped_rcu_read_lock() | |
232 | { | |
233 | if (_armed) { | |
234 | rcu_read_unlock(); | |
235 | } | |
236 | } | |
237 | ||
c1391746 | 238 | _scoped_rcu_read_lock(_scoped_rcu_read_lock&& other) noexcept |
16d64977 JG |
239 | { |
240 | other._armed = false; | |
241 | } | |
242 | ||
c1391746 JG |
243 | _scoped_rcu_read_lock(_scoped_rcu_read_lock& other) = delete; |
244 | _scoped_rcu_read_lock& operator=(const _scoped_rcu_read_lock&) = delete; | |
245 | _scoped_rcu_read_lock& operator=(_scoped_rcu_read_lock&&) noexcept = delete; | |
246 | ||
16d64977 JG |
247 | private: |
248 | bool _armed = true; | |
249 | }; | |
250 | ||
251 | _scoped_rcu_read_lock _read_lock; | |
252 | _iterator_creation_context _creation_context; | |
253 | }; | |
254 | } /* namespace sessiond */ | |
255 | } /* namespace lttng */ | |
256 | ||
b5541356 DG |
257 | /* |
258 | * This data structure contains information needed to identify a tracing | |
259 | * session for both LTTng and UST. | |
5b74c7b1 DG |
260 | */ |
261 | struct ltt_session { | |
e99e3664 | 262 | using id_t = uint64_t; |
16d64977 | 263 | friend lttng::sessiond::user_space_consumer_channel_keys::iterator; |
d9a970b7 JG |
264 | |
265 | private: | |
266 | static void _locked_session_release(ltt_session *session); | |
267 | static void _locked_const_session_release(const ltt_session *session); | |
268 | static void _const_session_put(const ltt_session *session); | |
a0a4f314 | 269 | static void _const_session_unlock(const ltt_session& session); |
d9a970b7 JG |
270 | |
271 | public: | |
a0a4f314 JG |
272 | using locked_ref = lttng::non_copyable_reference< |
273 | ltt_session, | |
274 | lttng::memory::create_deleter_class<ltt_session, | |
275 | ltt_session::_locked_session_release>::deleter>; | |
276 | using ref = lttng::non_copyable_reference< | |
d9a970b7 JG |
277 | ltt_session, |
278 | lttng::memory::create_deleter_class<ltt_session, session_put>::deleter>; | |
a0a4f314 JG |
279 | using const_locked_ref = lttng::non_copyable_reference< |
280 | const ltt_session, | |
281 | lttng::memory::create_deleter_class< | |
282 | const ltt_session, | |
283 | ltt_session::_locked_const_session_release>::deleter>; | |
284 | using const_ref = lttng::non_copyable_reference< | |
d9a970b7 | 285 | const ltt_session, |
a0a4f314 JG |
286 | lttng::memory::create_deleter_class<const ltt_session, |
287 | ltt_session::_const_session_put>::deleter>; | |
d9a970b7 | 288 | |
16d64977 JG |
289 | static locked_ref make_locked_ref(ltt_session& session) |
290 | { | |
291 | return lttng::make_non_copyable_reference<locked_ref::referenced_type, | |
292 | locked_ref::deleter>(session); | |
293 | } | |
294 | ||
295 | static const_locked_ref make_locked_ref(const ltt_session& session) | |
296 | { | |
297 | return lttng::make_non_copyable_reference<const_locked_ref::referenced_type, | |
298 | const_locked_ref::deleter>(session); | |
299 | } | |
300 | ||
301 | static ref make_ref(ltt_session& session) | |
302 | { | |
303 | return lttng::make_non_copyable_reference<ref::referenced_type, ref::deleter>( | |
304 | session); | |
305 | } | |
306 | ||
307 | static const_ref make_ref(const ltt_session& session) | |
308 | { | |
309 | return lttng::make_non_copyable_reference<const_ref::referenced_type, | |
310 | const_ref::deleter>(session); | |
311 | } | |
312 | ||
d9a970b7 JG |
313 | void lock() const noexcept; |
314 | void unlock() const noexcept; | |
315 | ||
16d64977 JG |
316 | lttng::sessiond::user_space_consumer_channel_keys user_space_consumer_channel_keys() const; |
317 | ||
d9a970b7 JG |
318 | /* |
319 | * Session list lock must be acquired by the caller. | |
320 | * | |
321 | * The caller must not keep the ownership of the returned locked session | |
322 | * for longer than strictly necessary. If your intention is to acquire | |
323 | * a reference to an ltt_session, see `find_session()`. | |
324 | */ | |
325 | static locked_ref find_locked_session(ltt_session::id_t id); | |
326 | static locked_ref find_locked_session(lttng::c_string_view name); | |
327 | static const_locked_ref find_locked_const_session(ltt_session::id_t id); | |
328 | static const_locked_ref find_locked_const_session(lttng::c_string_view name); | |
329 | ||
330 | static ref find_session(ltt_session::id_t id); | |
331 | static ref find_session(lttng::c_string_view name); | |
332 | static const_ref find_const_session(ltt_session::id_t id); | |
333 | static const_ref find_const_session(lttng::c_string_view name); | |
e99e3664 | 334 | |
74babd95 | 335 | char name[NAME_MAX]; |
b178f53e | 336 | bool has_auto_generated_name; |
46ef2188 | 337 | bool name_contains_creation_time; |
32aef76c | 338 | char hostname[LTTNG_HOST_NAME_MAX]; /* Local hostname. */ |
ecd1a12f MD |
339 | /* Path of the last closed chunk. */ |
340 | char last_chunk_path[LTTNG_PATH_MAX]; | |
b178f53e | 341 | time_t creation_time; |
20fe2104 | 342 | struct ltt_kernel_session *kernel_session; |
f6a9efaa | 343 | struct ltt_ust_session *ust_session; |
d9a970b7 | 344 | mutable struct urcu_ref ref_count; |
b5541356 DG |
345 | /* |
346 | * Protect any read/write on this session data structure. This lock must be | |
347 | * acquired *before* using any public functions declared below. Use | |
54d01ffb | 348 | * session_lock() and session_unlock() for that. |
b5541356 | 349 | */ |
d9a970b7 | 350 | mutable pthread_mutex_t _lock; |
b5541356 | 351 | struct cds_list_head list; |
e99e3664 JG |
352 | /* session unique identifier */ |
353 | id_t id; | |
f4cc5e83 JG |
354 | /* Indicates if the session has been added to the session list and ht.*/ |
355 | bool published; | |
e32d7f27 JG |
356 | /* Indicates if a destroy command has been applied to this session. */ |
357 | bool destroyed; | |
6df2e2c9 MD |
358 | /* UID/GID of the user owning the session */ |
359 | uid_t uid; | |
360 | gid_t gid; | |
00e2e675 DG |
361 | /* |
362 | * Network session handle. A value of 0 means that there is no remote | |
363 | * session established. | |
364 | */ | |
365 | uint64_t net_handle; | |
366 | /* | |
367 | * This consumer is only set when the create_session_uri call is made. | |
368 | * This contains the temporary information for a consumer output. Upon | |
369 | * creation of the UST or kernel session, this consumer, if available, is | |
370 | * copied into those sessions. | |
371 | */ | |
372 | struct consumer_output *consumer; | |
b178f53e JG |
373 | /* |
374 | * Indicates whether or not the user has specified an output directory | |
375 | * or if it was configured using the default configuration. | |
376 | */ | |
377 | bool has_user_specified_directory; | |
8382cf6f | 378 | /* Did at least ONE start command has been triggered?. */ |
66cefebd JG |
379 | bool has_been_started; |
380 | /* Is the session active? */ | |
381 | bool active; | |
6dc3064a DG |
382 | |
383 | /* Snapshot representation in a session. */ | |
384 | struct snapshot snapshot; | |
385 | /* Indicate if the session has to output the traces or not. */ | |
386 | unsigned int output_traces; | |
27babd3a | 387 | /* |
92fe5ca1 JG |
388 | * This session is in snapshot mode. This means that channels enabled |
389 | * will be set in overwrite mode by default and must be in mmap | |
390 | * output mode. Note that snapshots can be taken on a session that | |
391 | * is not in "snapshot_mode". This parameter only affects channel | |
392 | * creation defaults. | |
27babd3a DG |
393 | */ |
394 | unsigned int snapshot_mode; | |
54213acc JG |
395 | /* |
396 | * A session that has channels that don't use 'mmap' output can't be | |
397 | * used to capture snapshots. This is set to true whenever a | |
398 | * 'splice' kernel channel is enabled. | |
399 | */ | |
400 | bool has_non_mmap_channel; | |
ecc48a90 JD |
401 | /* |
402 | * Timer set when the session is created for live reading. | |
403 | */ | |
d98ad589 | 404 | unsigned int live_timer; |
d7ba1388 MD |
405 | /* |
406 | * Path where to keep the shared memory files. | |
407 | */ | |
408 | char shm_path[PATH_MAX]; | |
23324029 JD |
409 | /* |
410 | * Node in ltt_sessions_ht_by_id. | |
411 | */ | |
412 | struct lttng_ht_node_u64 node; | |
e1bbf989 JR |
413 | /* |
414 | * Node in ltt_sessions_ht_by_name. | |
415 | */ | |
416 | struct lttng_ht_node_str node_by_name; | |
d88744a4 | 417 | /* |
92816cc3 JG |
418 | * Timer to check periodically if a relay and/or consumer has completed |
419 | * the last rotation. | |
d88744a4 | 420 | */ |
92816cc3 JG |
421 | bool rotation_pending_check_timer_enabled; |
422 | timer_t rotation_pending_check_timer; | |
259c2674 | 423 | /* Timer to periodically rotate a session. */ |
92816cc3 JG |
424 | bool rotation_schedule_timer_enabled; |
425 | timer_t rotation_schedule_timer; | |
66ea93b1 | 426 | /* Value for periodic rotations, 0 if disabled. */ |
259c2674 | 427 | uint64_t rotate_timer_period; |
66ea93b1 | 428 | /* Value for size-based rotations, 0 if disabled. */ |
259c2674 | 429 | uint64_t rotate_size; |
5c408ad8 JD |
430 | /* |
431 | * Keep a state if this session was rotated after the last stop command. | |
432 | * We only allow one rotation after a stop. At destroy, we also need to | |
a9577b76 | 433 | * know if a rotation occurred since the last stop to rename the current |
a2b988e2 MD |
434 | * chunk. After a stop followed by rotate, all subsequent clear |
435 | * (without prior start) will succeed, but will be effect-less. | |
5c408ad8 JD |
436 | */ |
437 | bool rotated_after_last_stop; | |
b02f5986 MD |
438 | /* |
439 | * Track whether the session was cleared after last stop. All subsequent | |
440 | * clear (without prior start) will succeed, but will be effect-less. A | |
441 | * subsequent rotate (without prior start) will return an error. | |
442 | */ | |
443 | bool cleared_after_last_stop; | |
a7ceb342 MD |
444 | /* |
445 | * True if the session has had an explicit non-quiet rotation. | |
446 | */ | |
447 | bool rotated; | |
90936dcf | 448 | /* |
c08136a3 | 449 | * Trigger for size-based rotations. |
90936dcf | 450 | */ |
90936dcf | 451 | struct lttng_trigger *rotate_trigger; |
d2956687 | 452 | LTTNG_OPTIONAL(uint64_t) most_recent_chunk_id; |
82b69413 | 453 | struct lttng_trace_chunk *current_trace_chunk; |
d2956687 JG |
454 | struct lttng_trace_chunk *chunk_being_archived; |
455 | /* Current state of a rotation. */ | |
456 | enum lttng_rotation_state rotation_state; | |
7fdbed1c | 457 | bool quiet_rotation; |
d2956687 JG |
458 | char *last_archived_chunk_name; |
459 | LTTNG_OPTIONAL(uint64_t) last_archived_chunk_id; | |
3e3665b8 | 460 | struct lttng_dynamic_array destroy_notifiers; |
ccbdaca4 | 461 | struct lttng_dynamic_array clear_notifiers; |
6fa5fe7c MD |
462 | /* Session base path override. Set non-null. */ |
463 | char *base_path; | |
d9a970b7 | 464 | }; |
e1bbf989 | 465 | |
a0a4f314 JG |
466 | /* |
467 | * Destruction notifiers are invoked in an exclusive context. There is no need for the session to be | |
468 | * locked nor for a reference to be acquired. | |
469 | */ | |
470 | using ltt_session_destroy_notifier = void (*)(const ltt_session::locked_ref&, void *); | |
471 | using ltt_session_clear_notifier = void (*)(const ltt_session::locked_ref&, void *); | |
472 | ||
e99e3664 JG |
473 | namespace lttng { |
474 | namespace sessiond { | |
475 | ||
d9a970b7 | 476 | std::unique_lock<std::mutex> lock_session_list(); |
e99e3664 | 477 | |
d9a970b7 JG |
478 | namespace exceptions { |
479 | /** | |
480 | * @class session_not_found_error | |
481 | * @brief Represents a session-not-found error and provides the parameters used to query the session | |
482 | * for use by error-reporting code. | |
483 | */ | |
484 | class session_not_found_error : public lttng::runtime_error { | |
485 | public: | |
486 | class query_parameter { | |
487 | public: | |
488 | enum class query_type : std::uint8_t { BY_NAME, BY_ID }; | |
489 | ||
490 | /* | |
491 | * Intentionally not explicit to allow construction from c-style strings, | |
492 | * std::string, and lttng::c_string_view. | |
493 | * | |
494 | * NOLINTBEGIN(google-explicit-constructor) | |
495 | */ | |
496 | query_parameter(const std::string& session_name) : | |
497 | type(query_type::BY_NAME), parameter(session_name) | |
498 | { | |
499 | } | |
500 | /* NOLINTEND(google-explicit-constructor) */ | |
501 | ||
a0a4f314 JG |
502 | explicit query_parameter(ltt_session::id_t id_) : |
503 | type(query_type::BY_ID), parameter(id_) | |
d9a970b7 JG |
504 | { |
505 | } | |
506 | ||
507 | query_parameter(const query_parameter& other) : type(other.type) | |
508 | { | |
509 | if (type == query_type::BY_NAME) { | |
510 | new (¶meter.name) std::string(other.parameter.name); | |
511 | } else { | |
512 | parameter.id = other.parameter.id; | |
513 | } | |
514 | } | |
515 | ||
516 | ~query_parameter() | |
517 | { | |
518 | if (type == query_type::BY_NAME) { | |
519 | parameter.name.~basic_string(); | |
520 | } | |
521 | } | |
522 | ||
c1391746 JG |
523 | query_parameter(query_parameter&& other) noexcept; |
524 | query_parameter& operator=(const query_parameter&) = delete; | |
525 | query_parameter& operator=(query_parameter&&) noexcept = delete; | |
526 | ||
d9a970b7 JG |
527 | query_type type; |
528 | union parameter { | |
529 | explicit parameter(std::string name_) : name(std::move(name_)) | |
530 | { | |
531 | } | |
532 | ||
533 | explicit parameter(ltt_session::id_t id_) : id(id_) | |
534 | { | |
535 | } | |
536 | ||
537 | /* | |
538 | * parameter doesn't have enough information to do this safely; it it | |
539 | * delegated to its parent which uses placement new. | |
540 | */ | |
541 | parameter() | |
542 | { | |
543 | } | |
544 | ||
545 | parameter(const parameter&) = delete; | |
546 | parameter(const parameter&&) = delete; | |
547 | parameter& operator=(parameter&) = delete; | |
548 | parameter& operator=(parameter&&) = delete; | |
549 | ||
550 | ~parameter() | |
551 | { | |
552 | } | |
553 | ||
554 | std::string name; | |
555 | ltt_session::id_t id; | |
556 | } parameter; | |
557 | }; | |
558 | ||
559 | session_not_found_error(const std::string& session_name, | |
560 | const lttng::source_location& source_location_) : | |
561 | lttng::runtime_error(fmt::format("Session not found: name=`{}`", session_name), | |
562 | source_location_), | |
563 | query_parameter(session_name) | |
564 | { | |
565 | } | |
566 | ||
567 | session_not_found_error(ltt_session::id_t session_id, | |
568 | const lttng::source_location& source_location_) : | |
569 | lttng::runtime_error("Session not found: id=" + std::to_string(session_id), | |
570 | source_location_), | |
571 | query_parameter(session_id) | |
572 | { | |
573 | } | |
574 | ||
575 | session_not_found_error(const session_not_found_error& other) = default; | |
576 | ~session_not_found_error() noexcept override = default; | |
34d5e96c KS |
577 | /* |
578 | * Setting an explicit `noexcept` causes compilation failure on gcc < 5.0 | |
579 | * @see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59526 | |
580 | */ | |
581 | session_not_found_error(session_not_found_error&& other) /* noexcept */ = default; | |
c1391746 JG |
582 | session_not_found_error& operator=(const session_not_found_error&) = delete; |
583 | session_not_found_error& operator=(session_not_found_error&&) noexcept = delete; | |
d9a970b7 JG |
584 | |
585 | query_parameter query_parameter; | |
586 | }; | |
587 | } // namespace exceptions | |
e99e3664 JG |
588 | } /* namespace sessiond */ |
589 | } /* namespace lttng */ | |
590 | ||
a0a4f314 JG |
591 | void session_destroy(struct ltt_session *session); |
592 | int session_add_destroy_notifier(const ltt_session::locked_ref& session, | |
593 | ltt_session_destroy_notifier notifier, | |
594 | void *user_data); | |
595 | ||
596 | int session_add_clear_notifier(const ltt_session::locked_ref& session, | |
597 | ltt_session_clear_notifier notifier, | |
598 | void *user_data); | |
599 | void session_notify_clear(const ltt_session::locked_ref& session); | |
600 | ||
601 | enum consumer_dst_type | |
602 | session_get_consumer_destination_type(const ltt_session::locked_ref& session); | |
603 | const char *session_get_net_consumer_hostname(const ltt_session::locked_ref& session); | |
604 | void session_get_net_consumer_ports(const ltt_session::locked_ref& session, | |
605 | uint16_t *control_port, | |
606 | uint16_t *data_port); | |
607 | struct lttng_trace_archive_location * | |
608 | session_get_trace_archive_location(const ltt_session::locked_ref& session); | |
609 | ||
610 | struct ltt_session_list *session_get_list(); | |
611 | void session_list_wait_empty(std::unique_lock<std::mutex> list_lock); | |
612 | ||
613 | bool session_access_ok(const ltt_session::locked_ref& session, uid_t uid); | |
614 | ||
615 | int session_reset_rotation_state(const ltt_session::locked_ref& session, | |
616 | enum lttng_rotation_state result); | |
617 | ||
618 | /* Create a new trace chunk object from the session's configuration. */ | |
619 | struct lttng_trace_chunk * | |
620 | session_create_new_trace_chunk(const ltt_session::locked_ref& session, | |
621 | const struct consumer_output *consumer_output_override, | |
622 | const char *session_base_path_override, | |
623 | const char *chunk_name_override); | |
624 | ||
625 | /* | |
626 | * Set `new_trace_chunk` as the session's current trace chunk. A reference | |
627 | * to `new_trace_chunk` is acquired by the session. The chunk is created | |
628 | * on remote peers (consumer and relay daemons). | |
629 | * | |
630 | * A reference to the session's current trace chunk is returned through | |
631 | * `current_session_trace_chunk` on success. | |
632 | */ | |
633 | int session_set_trace_chunk(const ltt_session::locked_ref& session, | |
634 | struct lttng_trace_chunk *new_trace_chunk, | |
635 | struct lttng_trace_chunk **current_session_trace_chunk); | |
636 | ||
637 | /* | |
638 | * Close a chunk on the remote peers of a session. Has no effect on the | |
639 | * ltt_session itself. | |
640 | */ | |
641 | int session_close_trace_chunk(const ltt_session::locked_ref& session, | |
642 | struct lttng_trace_chunk *trace_chunk, | |
643 | enum lttng_trace_chunk_command_type close_command, | |
644 | char *path); | |
645 | ||
646 | /* Open a packet in all channels of a given session. */ | |
647 | enum lttng_error_code session_open_packets(const ltt_session::locked_ref& session); | |
648 | ||
649 | bool session_output_supports_trace_chunks(const struct ltt_session *session); | |
650 | ||
651 | /* | |
652 | * Sample the id of a session looked up via its name. | |
653 | * Here the term "sampling" hint the caller that this return the id at a given | |
654 | * point in time with no guarantee that the session for which the id was | |
655 | * sampled still exist at that point. | |
656 | * | |
657 | * Return 0 when the session is not found, | |
658 | * Return 1 when the session is found and set `id`. | |
659 | */ | |
660 | bool sample_session_id_by_name(const char *name, uint64_t *id); | |
661 | ||
16d64977 JG |
662 | const char *session_get_base_path(const ltt_session::locked_ref& session); |
663 | ||
664 | #ifdef HAVE_LIBLTTNG_UST_CTL | |
665 | ||
666 | enum lttng_error_code ust_app_rotate_session(const ltt_session::locked_ref& session); | |
667 | enum lttng_error_code ust_app_clear_session(const ltt_session::locked_ref& session); | |
668 | enum lttng_error_code ust_app_open_packets(const ltt_session::locked_ref& session); | |
669 | ||
670 | #else /* HAVE_LIBLTTNG_UST_CTL */ | |
671 | ||
672 | static inline enum lttng_error_code ust_app_rotate_session(const ltt_session::locked_ref& session | |
673 | __attribute__((unused))) | |
674 | { | |
675 | return LTTNG_ERR_UNK; | |
676 | } | |
677 | ||
678 | static inline enum lttng_error_code ust_app_clear_session(const ltt_session::locked_ref& session | |
679 | __attribute__((unused))) | |
680 | { | |
681 | return LTTNG_ERR_UNK; | |
682 | } | |
683 | ||
684 | static inline enum lttng_error_code ust_app_open_packets(const ltt_session::locked_ref& session | |
685 | __attribute__((unused))) | |
686 | { | |
687 | return LTTNG_ERR_UNK; | |
688 | } | |
689 | ||
690 | #endif /* HAVE_LIBLTTNG_UST_CTL */ | |
691 | ||
5b74c7b1 | 692 | #endif /* _LTT_SESSION_H */ |