Commit | Line | Data |
---|---|---|
d0b96690 DG |
1 | /* |
2 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License, version 2 only, as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
16 | */ | |
17 | ||
18 | #ifndef LTTNG_UST_REGISTRY_H | |
19 | #define LTTNG_UST_REGISTRY_H | |
20 | ||
21 | #include <pthread.h> | |
22 | #include <stdint.h> | |
d0b96690 DG |
23 | |
24 | #include <common/hashtable/hashtable.h> | |
25 | #include <common/compat/uuid.h> | |
26 | ||
7972aab2 DG |
27 | #include "ust-ctl.h" |
28 | ||
d0b96690 DG |
29 | #define CTF_SPEC_MAJOR 1 |
30 | #define CTF_SPEC_MINOR 8 | |
31 | ||
32 | struct ust_app; | |
33 | ||
34 | struct ust_registry_session { | |
35 | /* | |
dc2bbdae MD |
36 | * With multiple writers and readers, use this lock to access |
37 | * the registry. Can nest within the ust app session lock. | |
38 | * Also acts as a registry serialization lock. Used by registry | |
39 | * readers to serialize the registry information sent from the | |
40 | * sessiond to the consumerd. | |
41 | * The consumer socket lock nests within this lock. | |
d0b96690 DG |
42 | */ |
43 | pthread_mutex_t lock; | |
44 | /* Next channel ID available for a newly registered channel. */ | |
45 | uint32_t next_channel_id; | |
46 | /* Once this value reaches UINT32_MAX, no more id can be allocated. */ | |
47 | uint32_t used_channel_id; | |
10b56aef MD |
48 | /* Next enumeration ID available. */ |
49 | uint64_t next_enum_id; | |
d0b96690 DG |
50 | /* Universal unique identifier used by the tracer. */ |
51 | unsigned char uuid[UUID_LEN]; | |
52 | ||
53 | /* session ABI description */ | |
54 | ||
55 | /* Size of long, in bits */ | |
56 | unsigned int bits_per_long; | |
57 | /* Alignment, in bits */ | |
58 | unsigned int uint8_t_alignment, | |
59 | uint16_t_alignment, | |
60 | uint32_t_alignment, | |
61 | uint64_t_alignment, | |
62 | long_alignment; | |
63 | /* endianness */ | |
64 | int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */ | |
65 | ||
66 | /* Generated metadata. */ | |
67 | char *metadata; /* NOT null-terminated ! Use memcpy. */ | |
68 | size_t metadata_len, metadata_alloc_len; | |
d88aee68 DG |
69 | /* Length of bytes sent to the consumer. */ |
70 | size_t metadata_len_sent; | |
d7ba1388 | 71 | |
3d071855 | 72 | char root_shm_path[PATH_MAX]; |
d7ba1388 MD |
73 | char shm_path[PATH_MAX]; |
74 | char metadata_path[PATH_MAX]; | |
75 | int metadata_fd; /* file-backed metadata FD */ | |
76 | ||
45893984 | 77 | /* |
dc2bbdae MD |
78 | * Hash table containing channels sent by the UST tracer. MUST |
79 | * be accessed with a RCU read side lock acquired. | |
45893984 DG |
80 | */ |
81 | struct lttng_ht *channels; | |
dc2bbdae MD |
82 | /* |
83 | * Unique key to identify the metadata on the consumer side. | |
84 | */ | |
7972aab2 DG |
85 | uint64_t metadata_key; |
86 | /* | |
87 | * Indicates if the metadata is closed on the consumer side. This is to | |
88 | * avoid double close of metadata when an application unregisters AND | |
89 | * deletes its sessions. | |
90 | */ | |
91 | unsigned int metadata_closed; | |
4628484a MD |
92 | |
93 | /* User and group owning the session. */ | |
94 | uid_t uid; | |
95 | gid_t gid; | |
10b56aef MD |
96 | |
97 | /* Enumerations table. */ | |
98 | struct lttng_ht *enums; | |
7062f070 JD |
99 | |
100 | /* | |
101 | * Copy of the tracer version when the first app is registered. | |
102 | * It is used if we need to regenerate the metadata. | |
103 | */ | |
104 | uint32_t major; | |
105 | uint32_t minor; | |
d0b96690 DG |
106 | }; |
107 | ||
108 | struct ust_registry_channel { | |
45893984 | 109 | uint64_t key; |
d0b96690 DG |
110 | /* Id set when replying to a register channel. */ |
111 | uint32_t chan_id; | |
112 | enum ustctl_channel_header header_type; | |
113 | ||
7972aab2 DG |
114 | /* |
115 | * Flag for this channel if the metadata was dumped once during | |
116 | * registration. 0 means no, 1 yes. | |
117 | */ | |
118 | unsigned int metadata_dumped; | |
119 | /* Indicates if this channel registry has already been registered. */ | |
120 | unsigned int register_done; | |
121 | ||
d0b96690 DG |
122 | /* |
123 | * Hash table containing events sent by the UST tracer. MUST be accessed | |
124 | * with a RCU read side lock acquired. | |
125 | */ | |
126 | struct lttng_ht *ht; | |
127 | /* Next event ID available for a newly registered event. */ | |
128 | uint32_t next_event_id; | |
129 | /* Once this value reaches UINT32_MAX, no more id can be allocated. */ | |
130 | uint32_t used_event_id; | |
131 | /* | |
132 | * Context fields of the registry. Context are per channel. Allocated by a | |
133 | * register channel notification from the UST tracer. | |
134 | */ | |
135 | size_t nr_ctx_fields; | |
136 | struct ustctl_field *ctx_fields; | |
45893984 | 137 | struct lttng_ht_node_u64 node; |
36b588ed MD |
138 | /* For delayed reclaim */ |
139 | struct rcu_head rcu_head; | |
d0b96690 DG |
140 | }; |
141 | ||
142 | /* | |
143 | * Event registered from a UST tracer sent to the session daemon. This is | |
144 | * indexed and matched by <event_name/signature>. | |
145 | */ | |
146 | struct ust_registry_event { | |
147 | int id; | |
148 | /* Both objd are set by the tracer. */ | |
149 | int session_objd; | |
150 | int channel_objd; | |
151 | /* Name of the event returned by the tracer. */ | |
152 | char name[LTTNG_UST_SYM_NAME_LEN]; | |
153 | char *signature; | |
2106efa0 | 154 | int loglevel_value; |
d0b96690 DG |
155 | size_t nr_fields; |
156 | struct ustctl_field *fields; | |
157 | char *model_emf_uri; | |
7972aab2 DG |
158 | /* |
159 | * Flag for this channel if the metadata was dumped once during | |
160 | * registration. 0 means no, 1 yes. | |
161 | */ | |
162 | unsigned int metadata_dumped; | |
d0b96690 DG |
163 | /* |
164 | * Node in the ust-registry hash table. The event name is used to | |
165 | * initialize the node and the event_name/signature for the match function. | |
166 | */ | |
7972aab2 | 167 | struct lttng_ht_node_u64 node; |
d0b96690 DG |
168 | }; |
169 | ||
10b56aef MD |
170 | struct ust_registry_enum { |
171 | char name[LTTNG_UST_SYM_NAME_LEN]; | |
172 | struct ustctl_enum_entry *entries; | |
173 | size_t nr_entries; | |
174 | uint64_t id; /* enum id in session */ | |
175 | /* Enumeration node in session hash table. */ | |
176 | struct lttng_ht_node_str node; | |
177 | /* For delayed reclaim. */ | |
178 | struct rcu_head rcu_head; | |
179 | }; | |
180 | ||
d0b96690 DG |
181 | /* |
182 | * Validate that the id has reached the maximum allowed or not. | |
183 | * | |
184 | * Return 0 if NOT else 1. | |
185 | */ | |
186 | static inline int ust_registry_is_max_id(uint32_t id) | |
187 | { | |
188 | return (id == UINT32_MAX) ? 1 : 0; | |
189 | } | |
190 | ||
191 | /* | |
192 | * Return next available event id and increment the used counter. The | |
193 | * ust_registry_is_max_id function MUST be called before in order to validate | |
194 | * if the maximum number of IDs have been reached. If not, it is safe to call | |
195 | * this function. | |
196 | * | |
197 | * Return a unique channel ID. If max is reached, the used_event_id counter is | |
198 | * returned. | |
199 | */ | |
200 | static inline uint32_t ust_registry_get_next_event_id( | |
201 | struct ust_registry_channel *r) | |
202 | { | |
203 | if (ust_registry_is_max_id(r->used_event_id)) { | |
204 | return r->used_event_id; | |
205 | } | |
206 | ||
207 | r->used_event_id++; | |
208 | return r->next_event_id++; | |
209 | } | |
210 | ||
211 | /* | |
212 | * Return next available channel id and increment the used counter. The | |
213 | * ust_registry_is_max_id function MUST be called before in order to validate | |
214 | * if the maximum number of IDs have been reached. If not, it is safe to call | |
215 | * this function. | |
216 | * | |
217 | * Return a unique channel ID. If max is reached, the used_channel_id counter | |
218 | * is returned. | |
219 | */ | |
220 | static inline uint32_t ust_registry_get_next_chan_id( | |
221 | struct ust_registry_session *r) | |
222 | { | |
223 | if (ust_registry_is_max_id(r->used_channel_id)) { | |
224 | return r->used_channel_id; | |
225 | } | |
226 | ||
227 | r->used_channel_id++; | |
228 | return r->next_channel_id++; | |
229 | } | |
230 | ||
231 | /* | |
232 | * Return registry event count. This is read atomically. | |
233 | */ | |
234 | static inline uint32_t ust_registry_get_event_count( | |
235 | struct ust_registry_channel *r) | |
236 | { | |
237 | return (uint32_t) uatomic_read(&r->used_event_id); | |
238 | } | |
239 | ||
7972aab2 DG |
240 | #ifdef HAVE_LIBLTTNG_UST_CTL |
241 | ||
d0b96690 DG |
242 | void ust_registry_channel_destroy(struct ust_registry_session *session, |
243 | struct ust_registry_channel *chan); | |
45893984 DG |
244 | struct ust_registry_channel *ust_registry_channel_find( |
245 | struct ust_registry_session *session, uint64_t key); | |
246 | int ust_registry_channel_add(struct ust_registry_session *session, | |
247 | uint64_t key); | |
248 | void ust_registry_channel_del_free(struct ust_registry_session *session, | |
249 | uint64_t key); | |
250 | ||
251 | int ust_registry_session_init(struct ust_registry_session **sessionp, | |
d0b96690 DG |
252 | struct ust_app *app, |
253 | uint32_t bits_per_long, | |
254 | uint32_t uint8_t_alignment, | |
255 | uint32_t uint16_t_alignment, | |
256 | uint32_t uint32_t_alignment, | |
257 | uint32_t uint64_t_alignment, | |
258 | uint32_t long_alignment, | |
af6142cf MD |
259 | int byte_order, |
260 | uint32_t major, | |
d7ba1388 | 261 | uint32_t minor, |
3d071855 | 262 | const char *root_shm_path, |
d7ba1388 MD |
263 | const char *shm_path, |
264 | uid_t euid, | |
265 | gid_t egid); | |
d0b96690 DG |
266 | void ust_registry_session_destroy(struct ust_registry_session *session); |
267 | ||
268 | int ust_registry_create_event(struct ust_registry_session *session, | |
45893984 | 269 | uint64_t chan_key, int session_objd, int channel_objd, char *name, |
2106efa0 PP |
270 | char *sig, size_t nr_fields, struct ustctl_field *fields, |
271 | int loglevel_value, char *model_emf_uri, int buffer_type, | |
272 | uint32_t *event_id_p, struct ust_app *app); | |
d0b96690 DG |
273 | struct ust_registry_event *ust_registry_find_event( |
274 | struct ust_registry_channel *chan, char *name, char *sig); | |
275 | void ust_registry_destroy_event(struct ust_registry_channel *chan, | |
276 | struct ust_registry_event *event); | |
277 | ||
278 | /* app can be NULL for registry shared across applications. */ | |
279 | int ust_metadata_session_statedump(struct ust_registry_session *session, | |
af6142cf | 280 | struct ust_app *app, uint32_t major, uint32_t minor); |
d0b96690 DG |
281 | int ust_metadata_channel_statedump(struct ust_registry_session *session, |
282 | struct ust_registry_channel *chan); | |
283 | int ust_metadata_event_statedump(struct ust_registry_session *session, | |
284 | struct ust_registry_channel *chan, | |
285 | struct ust_registry_event *event); | |
10b56aef MD |
286 | int ust_registry_create_or_find_enum(struct ust_registry_session *session, |
287 | int session_objd, char *name, | |
288 | struct ustctl_enum_entry *entries, size_t nr_entries, | |
289 | uint64_t *enum_id); | |
290 | struct ust_registry_enum * | |
291 | ust_registry_lookup_enum_by_id(struct ust_registry_session *session, | |
292 | const char *name, uint64_t id); | |
d0b96690 | 293 | |
7972aab2 DG |
294 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
295 | ||
296 | static inline | |
297 | void ust_registry_channel_destroy(struct ust_registry_session *session, | |
298 | struct ust_registry_channel *chan) | |
299 | {} | |
300 | static inline | |
301 | struct ust_registry_channel *ust_registry_channel_find( | |
302 | struct ust_registry_session *session, uint64_t key) | |
303 | { | |
304 | return NULL; | |
305 | } | |
306 | static inline | |
307 | int ust_registry_channel_add(struct ust_registry_session *session, | |
308 | uint64_t key) | |
309 | { | |
310 | return 0; | |
311 | } | |
312 | static inline | |
313 | void ust_registry_channel_del_free(struct ust_registry_session *session, | |
314 | uint64_t key) | |
315 | {} | |
316 | static inline | |
317 | int ust_registry_session_init(struct ust_registry_session **sessionp, | |
318 | struct ust_app *app, | |
319 | uint32_t bits_per_long, | |
320 | uint32_t uint8_t_alignment, | |
321 | uint32_t uint16_t_alignment, | |
322 | uint32_t uint32_t_alignment, | |
323 | uint32_t uint64_t_alignment, | |
324 | uint32_t long_alignment, | |
325 | int byte_order) | |
326 | { | |
327 | return 0; | |
328 | } | |
329 | static inline | |
330 | void ust_registry_session_destroy(struct ust_registry_session *session) | |
331 | {} | |
332 | static inline | |
333 | int ust_registry_create_event(struct ust_registry_session *session, | |
334 | uint64_t chan_key, int session_objd, int channel_objd, char *name, | |
2106efa0 PP |
335 | char *sig, size_t nr_fields, struct ustctl_field *fields, |
336 | int loglevel_value, char *model_emf_uri, int buffer_type, | |
337 | uint32_t *event_id_p) | |
7972aab2 DG |
338 | { |
339 | return 0; | |
340 | } | |
341 | static inline | |
342 | struct ust_registry_event *ust_registry_find_event( | |
343 | struct ust_registry_channel *chan, char *name, char *sig) | |
344 | { | |
345 | return NULL; | |
346 | } | |
347 | static inline | |
348 | void ust_registry_destroy_event(struct ust_registry_channel *chan, | |
349 | struct ust_registry_event *event) | |
350 | {} | |
351 | ||
352 | /* The app object can be NULL for registry shared across applications. */ | |
353 | static inline | |
354 | int ust_metadata_session_statedump(struct ust_registry_session *session, | |
355 | struct ust_app *app) | |
356 | { | |
357 | return 0; | |
358 | } | |
359 | static inline | |
360 | int ust_metadata_channel_statedump(struct ust_registry_session *session, | |
361 | struct ust_registry_channel *chan) | |
362 | { | |
363 | return 0; | |
364 | } | |
365 | static inline | |
366 | int ust_metadata_event_statedump(struct ust_registry_session *session, | |
367 | struct ust_registry_channel *chan, | |
368 | struct ust_registry_event *event) | |
369 | { | |
370 | return 0; | |
371 | } | |
10b56aef MD |
372 | static inline |
373 | int ust_registry_create_or_find_enum(struct ust_registry_session *session, | |
374 | int session_objd, char *name, | |
375 | struct ustctl_enum_entry *entries, size_t nr_entries, | |
376 | uint64_t *enum_id) | |
377 | { | |
378 | return 0; | |
379 | } | |
380 | static inline | |
381 | struct ust_registry_enum * | |
382 | ust_registry_lookup_enum_by_id(struct ust_registry_session *session, | |
383 | const char *name, uint64_t id) | |
384 | { | |
385 | return NULL; | |
386 | } | |
7972aab2 DG |
387 | |
388 | #endif /* HAVE_LIBLTTNG_UST_CTL */ | |
389 | ||
d0b96690 | 390 | #endif /* LTTNG_UST_REGISTRY_H */ |