Commit | Line | Data |
---|---|---|
d0b96690 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
aeeb48c6 | 3 | * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
d0b96690 | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: GPL-2.0-only |
d0b96690 | 6 | * |
d0b96690 DG |
7 | */ |
8 | ||
9 | #ifndef LTTNG_UST_REGISTRY_H | |
10 | #define LTTNG_UST_REGISTRY_H | |
11 | ||
d7bfb9b0 JG |
12 | #include "event-class.hpp" |
13 | #include "field.hpp" | |
14 | #include "lttng-ust-ctl.hpp" | |
15 | #include "session.hpp" | |
16 | #include "stream-class.hpp" | |
17 | #include "trace-class.hpp" | |
18 | #include "ust-clock-class.hpp" | |
19 | #include "ust-registry-channel.hpp" | |
20 | #include "ust-registry-event.hpp" | |
21 | ||
22 | #include <common/format.hpp> | |
c9e313bc | 23 | #include <common/hashtable/hashtable.hpp> |
d7bfb9b0 JG |
24 | #include <common/locked-reference.hpp> |
25 | #include <common/urcu.hpp> | |
c9e313bc | 26 | #include <common/uuid.hpp> |
d0b96690 | 27 | |
aeeb48c6 JG |
28 | #include <lttng/domain.h> |
29 | ||
d7bfb9b0 JG |
30 | #include <ctime> |
31 | #include <memory> | |
32 | #include <pthread.h> | |
33 | #include <stdint.h> | |
34 | #include <string> | |
35 | #include <type_traits> | |
7972aab2 | 36 | |
28f23191 JG |
37 | #define CTF_SPEC_MAJOR 1 |
38 | #define CTF_SPEC_MINOR 8 | |
d0b96690 DG |
39 | |
40 | struct ust_app; | |
d0b96690 | 41 | |
d7bfb9b0 JG |
42 | namespace lttng { |
43 | namespace sessiond { | |
44 | namespace ust { | |
97f630d4 JG |
45 | |
46 | class registry_session; | |
47 | ||
d7bfb9b0 | 48 | namespace details { |
b0f2e8db | 49 | |
d7bfb9b0 | 50 | template <class MappingIntegerType> |
28f23191 JG |
51 | typename trace::typed_enumeration_type<MappingIntegerType>::mappings |
52 | mappings_from_ust_ctl_entries(const lttng_ust_ctl_enum_entry *in_entries, size_t in_entry_count) | |
d0b96690 | 53 | { |
d7bfb9b0 JG |
54 | typename trace::typed_enumeration_type<MappingIntegerType>::mappings mappings; |
55 | ||
da9dd521 | 56 | MappingIntegerType next_range_begin = 0; |
d7bfb9b0 JG |
57 | for (size_t entry_idx = 0; entry_idx < in_entry_count; entry_idx++) { |
58 | const auto& entry = in_entries[entry_idx]; | |
da9dd521 JG |
59 | MappingIntegerType range_begin, range_end; |
60 | ||
61 | if (entry.u.extra.options & LTTNG_UST_CTL_UST_ENUM_ENTRY_OPTION_IS_AUTO) { | |
62 | range_begin = range_end = next_range_begin; | |
63 | } else { | |
64 | range_begin = (MappingIntegerType) entry.start.value; | |
65 | range_end = (MappingIntegerType) entry.end.value; | |
66 | } | |
67 | ||
68 | next_range_begin = range_end + 1; | |
28f23191 JG |
69 | mappings.emplace_back( |
70 | entry.string, | |
71 | typename trace::typed_enumeration_type<MappingIntegerType>::mapping::range_t{ | |
72 | range_begin, range_end }); | |
d0b96690 DG |
73 | } |
74 | ||
d7bfb9b0 | 75 | return mappings; |
d0b96690 | 76 | } |
d7bfb9b0 | 77 | } /* namespace details */ |
d0b96690 | 78 | |
b0f2e8db JG |
79 | class registry_enum { |
80 | public: | |
28f23191 JG |
81 | using const_rcu_protected_reference = |
82 | lttng::locked_reference<const registry_enum, lttng::urcu::unique_read_lock>; | |
b0f2e8db | 83 | |
28f23191 JG |
84 | registry_enum(std::string name, |
85 | enum lttng::sessiond::trace::integer_type::signedness signedness); | |
b0f2e8db | 86 | virtual ~registry_enum() = default; |
9d89db29 JG |
87 | registry_enum(const registry_enum&) = delete; |
88 | registry_enum(registry_enum&&) = delete; | |
89 | registry_enum& operator=(registry_enum&&) = delete; | |
90 | registry_enum& operator=(const registry_enum&) = delete; | |
b0f2e8db JG |
91 | |
92 | std::string name; | |
93 | enum lttng::sessiond::trace::integer_type::signedness signedness; | |
94 | /* enum id in session */ | |
95 | uint64_t id = -1ULL; | |
96 | /* Enumeration node in session hash table. */ | |
97 | struct lttng_ht_node_str node; | |
98 | /* For delayed reclaim. */ | |
99 | struct rcu_head rcu_head; | |
100 | ||
101 | friend bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept; | |
28f23191 | 102 | |
b0f2e8db JG |
103 | protected: |
104 | virtual bool _is_equal(const registry_enum& other) const noexcept = 0; | |
105 | }; | |
106 | ||
107 | bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept; | |
108 | ||
d7bfb9b0 JG |
109 | template <class MappingIntegerType> |
110 | class registry_typed_enum : public registry_enum { | |
111 | public: | |
112 | registry_typed_enum(const char *in_name, | |
28f23191 JG |
113 | const lttng_ust_ctl_enum_entry *entries, |
114 | size_t entry_count) : | |
d7bfb9b0 | 115 | registry_enum(in_name, |
28f23191 JG |
116 | std::is_signed<MappingIntegerType>::value ? |
117 | lttng::sessiond::trace::integer_type::signedness::SIGNED : | |
118 | lttng::sessiond::trace::integer_type::signedness::UNSIGNED), | |
119 | _mappings{ std::make_shared< | |
120 | typename trace::typed_enumeration_type<MappingIntegerType>::mappings>( | |
121 | details::mappings_from_ust_ctl_entries<MappingIntegerType>(entries, | |
122 | entry_count)) } | |
d7bfb9b0 | 123 | { |
d0b96690 DG |
124 | } |
125 | ||
d7bfb9b0 | 126 | const typename std::shared_ptr<const typename lttng::sessiond::trace::typed_enumeration_type< |
28f23191 JG |
127 | MappingIntegerType>::mappings> |
128 | _mappings; | |
d0b96690 | 129 | |
d7bfb9b0 | 130 | protected: |
cd9adb8b | 131 | bool _is_equal(const registry_enum& base_other) const noexcept override |
d7bfb9b0 | 132 | { |
28f23191 | 133 | const auto& other = static_cast<decltype(*this)&>(base_other); |
d0b96690 | 134 | |
d7bfb9b0 JG |
135 | /* Don't compare IDs as some comparisons are performed before an id is assigned. */ |
136 | return this->name == other.name && *this->_mappings == *other._mappings; | |
137 | } | |
138 | }; | |
7972aab2 | 139 | |
d7bfb9b0 JG |
140 | using registry_signed_enum = registry_typed_enum<int64_t>; |
141 | using registry_unsigned_enum = registry_typed_enum<uint64_t>; | |
142 | ||
143 | } /* namespace ust */ | |
144 | } /* namespace sessiond */ | |
145 | } /* namespace lttng */ | |
146 | ||
147 | #ifdef HAVE_LIBLTTNG_UST_CTL | |
45893984 | 148 | |
aeeb48c6 JG |
149 | /* |
150 | * Create per-uid registry with default values. | |
151 | * | |
152 | * Return new instance on success, nullptr on error. | |
153 | */ | |
28f23191 JG |
154 | lttng::sessiond::ust::registry_session * |
155 | ust_registry_session_per_uid_create(const lttng::sessiond::trace::abi& abi, | |
156 | uint32_t major, | |
157 | uint32_t minor, | |
158 | const char *root_shm_path, | |
159 | const char *shm_path, | |
160 | uid_t euid, | |
161 | gid_t egid, | |
162 | uint64_t tracing_id, | |
163 | uid_t tracing_uid); | |
d0b96690 | 164 | |
aeeb48c6 JG |
165 | /* |
166 | * Create per-pid registry with default values. | |
167 | * | |
168 | * Return new instance on success, nullptr on error. | |
169 | */ | |
28f23191 JG |
170 | lttng::sessiond::ust::registry_session * |
171 | ust_registry_session_per_pid_create(struct ust_app *app, | |
172 | const lttng::sessiond::trace::abi& abi, | |
173 | uint32_t major, | |
174 | uint32_t minor, | |
175 | const char *root_shm_path, | |
176 | const char *shm_path, | |
177 | uid_t euid, | |
178 | gid_t egid, | |
179 | uint64_t tracing_id); | |
b0f2e8db | 180 | void ust_registry_session_destroy(lttng::sessiond::ust::registry_session *session); |
aeeb48c6 | 181 | |
d7bfb9b0 | 182 | void ust_registry_channel_destroy_event(lttng::sessiond::ust::registry_channel *chan, |
28f23191 | 183 | lttng::sessiond::ust::registry_event *event); |
d7bfb9b0 | 184 | |
7972aab2 DG |
185 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
186 | ||
28f23191 JG |
187 | static inline lttng::sessiond::ust::registry_session * |
188 | ust_registry_session_per_uid_create(uint32_t bits_per_long __attribute__((unused)), | |
189 | uint32_t uint8_t_alignment __attribute__((unused)), | |
190 | uint32_t uint16_t_alignment __attribute__((unused)), | |
191 | uint32_t uint32_t_alignment __attribute__((unused)), | |
192 | uint32_t uint64_t_alignment __attribute__((unused)), | |
193 | uint32_t long_alignment __attribute__((unused)), | |
194 | int byte_order __attribute__((unused)), | |
195 | uint32_t major __attribute__((unused)), | |
196 | uint32_t minor __attribute__((unused)), | |
197 | const char *root_shm_path __attribute__((unused)), | |
198 | const char *shm_path __attribute__((unused)), | |
199 | uid_t euid __attribute__((unused)), | |
200 | gid_t egid __attribute__((unused)), | |
201 | uint64_t tracing_id __attribute__((unused)), | |
202 | uid_t tracing_uid __attribute__((unused))) | |
7972aab2 | 203 | { |
aeeb48c6 JG |
204 | return nullptr; |
205 | } | |
206 | ||
28f23191 JG |
207 | static inline lttng::sessiond::ust::registry_session * |
208 | ust_registry_session_per_pid_create(struct ust_app *app __attribute__((unused)), | |
209 | uint32_t bits_per_long __attribute__((unused)), | |
210 | uint32_t uint8_t_alignment __attribute__((unused)), | |
211 | uint32_t uint16_t_alignment __attribute__((unused)), | |
212 | uint32_t uint32_t_alignment __attribute__((unused)), | |
213 | uint32_t uint64_t_alignment __attribute__((unused)), | |
214 | uint32_t long_alignment __attribute__((unused)), | |
215 | int byte_order __attribute__((unused)), | |
216 | uint32_t major __attribute__((unused)), | |
217 | uint32_t minor __attribute__((unused)), | |
218 | const char *root_shm_path __attribute__((unused)), | |
219 | const char *shm_path __attribute__((unused)), | |
220 | uid_t euid __attribute__((unused)), | |
221 | gid_t egid __attribute__((unused)), | |
222 | uint64_t tracing_id __attribute__((unused))) | |
aeeb48c6 JG |
223 | { |
224 | return nullptr; | |
7972aab2 | 225 | } |
f46376a1 | 226 | |
28f23191 JG |
227 | static inline void ust_registry_session_destroy(lttng::sessiond::ust::registry_session *session |
228 | __attribute__((unused))) | |
229 | { | |
230 | } | |
f46376a1 | 231 | |
28f23191 JG |
232 | static inline void ust_registry_destroy_event(lttng::sessiond::ust::registry_channel *chan |
233 | __attribute__((unused)), | |
234 | lttng::sessiond::ust::registry_event *event | |
235 | __attribute__((unused))) | |
236 | { | |
237 | } | |
7972aab2 DG |
238 | |
239 | /* The app object can be NULL for registry shared across applications. */ | |
28f23191 JG |
240 | static inline int ust_metadata_session_statedump(lttng::sessiond::ust::registry_session *session |
241 | __attribute__((unused))) | |
7972aab2 DG |
242 | { |
243 | return 0; | |
244 | } | |
f46376a1 | 245 | |
28f23191 JG |
246 | static inline int ust_metadata_channel_statedump(lttng::sessiond::ust::registry_session *session |
247 | __attribute__((unused)), | |
248 | lttng::sessiond::ust::registry_channel *chan | |
249 | __attribute__((unused))) | |
7972aab2 DG |
250 | { |
251 | return 0; | |
252 | } | |
f46376a1 | 253 | |
28f23191 JG |
254 | static inline int ust_metadata_event_statedump(lttng::sessiond::ust::registry_session *session |
255 | __attribute__((unused)), | |
256 | lttng::sessiond::ust::registry_channel *chan | |
257 | __attribute__((unused)), | |
258 | lttng::sessiond::ust::registry_event *event | |
259 | __attribute__((unused))) | |
7972aab2 DG |
260 | { |
261 | return 0; | |
262 | } | |
f46376a1 | 263 | |
7972aab2 DG |
264 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
265 | ||
d0b96690 | 266 | #endif /* LTTNG_UST_REGISTRY_H */ |