lttng-sessiond: rename ust_registry_channel::ht to events
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.hpp
1 /*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef LTTNG_UST_REGISTRY_H
9 #define LTTNG_UST_REGISTRY_H
10
11 #include <pthread.h>
12 #include <stdint.h>
13
14 #include <common/hashtable/hashtable.hpp>
15 #include <common/uuid.hpp>
16
17 #include "lttng-ust-ctl.hpp"
18
19 #define CTF_SPEC_MAJOR 1
20 #define CTF_SPEC_MINOR 8
21
22 struct ust_app;
23
24 struct ust_registry_session {
25 /*
26 * With multiple writers and readers, use this lock to access
27 * the registry. Can nest within the ust app session lock.
28 * Also acts as a registry serialization lock. Used by registry
29 * readers to serialize the registry information sent from the
30 * sessiond to the consumerd.
31 * The consumer socket lock nests within this lock.
32 */
33 pthread_mutex_t lock;
34 /* Next channel ID available for a newly registered channel. */
35 uint32_t next_channel_id;
36 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
37 uint32_t used_channel_id;
38 /* Next enumeration ID available. */
39 uint64_t next_enum_id;
40 /* Universal unique identifier used by the tracer. */
41 unsigned char uuid[LTTNG_UUID_LEN];
42
43 /* session ABI description */
44
45 /* Size of long, in bits */
46 unsigned int bits_per_long;
47 /* Alignment, in bits */
48 unsigned int uint8_t_alignment,
49 uint16_t_alignment,
50 uint32_t_alignment,
51 uint64_t_alignment,
52 long_alignment;
53 /* endianness */
54 int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */
55
56 /* Generated metadata. */
57 char *metadata; /* NOT null-terminated ! Use memcpy. */
58 size_t metadata_len, metadata_alloc_len;
59 /* Length of bytes sent to the consumer. */
60 size_t metadata_len_sent;
61 /* Current version of the metadata. */
62 uint64_t metadata_version;
63
64 /*
65 * Those fields are only used when a session is created with
66 * the --shm-path option. In this case, the metadata is output
67 * twice: once to the consumer, as ususal, but a second time
68 * also in the shm path directly. This is done so that a copy
69 * of the metadata that is as fresh as possible is available
70 * on the event of a crash.
71 *
72 * root_shm_path contains the shm-path provided by the user, along with
73 * the session's name and timestamp:
74 * e.g. /tmp/my_shm/my_session-20180612-135822
75 *
76 * shm_path contains the full path of the memory buffers:
77 * e.g. /tmp/my_shm/my_session-20180612-135822/ust/uid/1000/64-bit
78 *
79 * metadata_path contains the full path to the metadata file that
80 * is kept for the "crash buffer" extraction:
81 * e.g. /tmp/my_shm/my_session-20180612-135822/ust/uid/1000/64-bit/metadata
82 *
83 * Note that this is not the trace's final metadata file. It is
84 * only meant to be used to read the contents of the ring buffers
85 * in the event of a crash.
86 *
87 * metadata_fd is a file descriptor that points to the file at
88 * 'metadata_path'.
89 */
90 char root_shm_path[PATH_MAX];
91 char shm_path[PATH_MAX];
92 char metadata_path[PATH_MAX];
93 int metadata_fd; /* file-backed metadata FD */
94
95 /*
96 * Hash table containing channels sent by the UST tracer. MUST
97 * be accessed with a RCU read side lock acquired.
98 */
99 struct lttng_ht *channels;
100 /*
101 * Unique key to identify the metadata on the consumer side.
102 */
103 uint64_t metadata_key;
104 /*
105 * Indicates if the metadata is closed on the consumer side. This is to
106 * avoid double close of metadata when an application unregisters AND
107 * deletes its sessions.
108 */
109 unsigned int metadata_closed;
110
111 /* User and group owning the session. */
112 uid_t uid;
113 gid_t gid;
114
115 /* Enumerations table. */
116 struct lttng_ht *enums;
117
118 /*
119 * Copy of the tracer version when the first app is registered.
120 * It is used if we need to regenerate the metadata.
121 */
122 uint32_t major;
123 uint32_t minor;
124
125 /* The id of the parent session */
126 uint64_t tracing_id;
127 uid_t tracing_uid;
128 };
129
130 struct ust_registry_channel {
131 uint64_t key;
132 uint64_t consumer_key;
133 /* Id set when replying to a register channel. */
134 uint32_t chan_id;
135 enum lttng_ust_ctl_channel_header header_type;
136
137 /*
138 * Flag for this channel if the metadata was dumped once during
139 * registration. 0 means no, 1 yes.
140 */
141 unsigned int metadata_dumped;
142 /* Indicates if this channel registry has already been registered. */
143 unsigned int register_done;
144
145 /*
146 * Hash table containing events sent by the UST tracer. MUST be accessed
147 * with a RCU read side lock acquired.
148 */
149 struct lttng_ht *events;
150 /* Next event ID available for a newly registered event. */
151 uint32_t next_event_id;
152 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
153 uint32_t used_event_id;
154 /*
155 * Context fields of the registry. Context are per channel. Allocated by a
156 * register channel notification from the UST tracer.
157 */
158 size_t nr_ctx_fields;
159 struct lttng_ust_ctl_field *ctx_fields;
160 struct lttng_ht_node_u64 node;
161 /* For delayed reclaim */
162 struct rcu_head rcu_head;
163 };
164
165 /*
166 * Event registered from a UST tracer sent to the session daemon. This is
167 * indexed and matched by <event_name/signature>.
168 */
169 struct ust_registry_event {
170 int id;
171 /* Both objd are set by the tracer. */
172 int session_objd;
173 int channel_objd;
174 /* Name of the event returned by the tracer. */
175 char name[LTTNG_UST_ABI_SYM_NAME_LEN];
176 char *signature;
177 int loglevel_value;
178 size_t nr_fields;
179 struct lttng_ust_ctl_field *fields;
180 char *model_emf_uri;
181 /*
182 * Flag for this channel if the metadata was dumped once during
183 * registration. 0 means no, 1 yes.
184 */
185 unsigned int metadata_dumped;
186 /*
187 * Node in the ust-registry hash table. The event name is used to
188 * initialize the node and the event_name/signature for the match function.
189 */
190 struct lttng_ht_node_u64 node;
191 };
192
193 struct ust_registry_enum {
194 char name[LTTNG_UST_ABI_SYM_NAME_LEN];
195 struct lttng_ust_ctl_enum_entry *entries;
196 size_t nr_entries;
197 uint64_t id; /* enum id in session */
198 /* Enumeration node in session hash table. */
199 struct lttng_ht_node_str node;
200 /* For delayed reclaim. */
201 struct rcu_head rcu_head;
202 };
203
204 /*
205 * Validate that the id has reached the maximum allowed or not.
206 *
207 * Return 0 if NOT else 1.
208 */
209 static inline int ust_registry_is_max_id(uint32_t id)
210 {
211 return (id == UINT32_MAX) ? 1 : 0;
212 }
213
214 /*
215 * Return next available event id and increment the used counter. The
216 * ust_registry_is_max_id function MUST be called before in order to validate
217 * if the maximum number of IDs have been reached. If not, it is safe to call
218 * this function.
219 *
220 * Return a unique channel ID. If max is reached, the used_event_id counter is
221 * returned.
222 */
223 static inline uint32_t ust_registry_get_next_event_id(
224 struct ust_registry_channel *r)
225 {
226 if (ust_registry_is_max_id(r->used_event_id)) {
227 return r->used_event_id;
228 }
229
230 r->used_event_id++;
231 return r->next_event_id++;
232 }
233
234 /*
235 * Return next available channel id and increment the used counter. The
236 * ust_registry_is_max_id function MUST be called before in order to validate
237 * if the maximum number of IDs have been reached. If not, it is safe to call
238 * this function.
239 *
240 * Return a unique channel ID. If max is reached, the used_channel_id counter
241 * is returned.
242 */
243 static inline uint32_t ust_registry_get_next_chan_id(
244 struct ust_registry_session *r)
245 {
246 if (ust_registry_is_max_id(r->used_channel_id)) {
247 return r->used_channel_id;
248 }
249
250 r->used_channel_id++;
251 return r->next_channel_id++;
252 }
253
254 /*
255 * Return registry event count. This is read atomically.
256 */
257 static inline uint32_t ust_registry_get_event_count(
258 struct ust_registry_channel *r)
259 {
260 return (uint32_t) uatomic_read(&r->used_event_id);
261 }
262
263 #ifdef HAVE_LIBLTTNG_UST_CTL
264
265 void ust_registry_channel_destroy(struct ust_registry_session *session,
266 struct ust_registry_channel *chan);
267 struct ust_registry_channel *ust_registry_channel_find(
268 struct ust_registry_session *session, uint64_t key);
269 int ust_registry_channel_add(struct ust_registry_session *session,
270 uint64_t key);
271 void ust_registry_channel_del_free(struct ust_registry_session *session,
272 uint64_t key, bool notif);
273
274 int ust_registry_session_init(struct ust_registry_session **sessionp,
275 struct ust_app *app,
276 uint32_t bits_per_long,
277 uint32_t uint8_t_alignment,
278 uint32_t uint16_t_alignment,
279 uint32_t uint32_t_alignment,
280 uint32_t uint64_t_alignment,
281 uint32_t long_alignment,
282 int byte_order,
283 uint32_t major,
284 uint32_t minor,
285 const char *root_shm_path,
286 const char *shm_path,
287 uid_t euid,
288 gid_t egid,
289 uint64_t tracing_id,
290 uid_t tracing_uid);
291 void ust_registry_session_destroy(struct ust_registry_session *session);
292
293 int ust_registry_create_event(struct ust_registry_session *session,
294 uint64_t chan_key, int session_objd, int channel_objd, char *name,
295 char *sig, size_t nr_fields, struct lttng_ust_ctl_field *fields,
296 int loglevel_value, char *model_emf_uri, int buffer_type,
297 uint32_t *event_id_p, struct ust_app *app);
298 struct ust_registry_event *ust_registry_find_event(
299 struct ust_registry_channel *chan, char *name, char *sig);
300 void ust_registry_destroy_event(struct ust_registry_channel *chan,
301 struct ust_registry_event *event);
302
303 /* app can be NULL for registry shared across applications. */
304 int ust_metadata_session_statedump(struct ust_registry_session *session,
305 struct ust_app *app, uint32_t major, uint32_t minor);
306 int ust_metadata_channel_statedump(struct ust_registry_session *session,
307 struct ust_registry_channel *chan);
308 int ust_metadata_event_statedump(struct ust_registry_session *session,
309 struct ust_registry_channel *chan,
310 struct ust_registry_event *event);
311 int ust_registry_create_or_find_enum(struct ust_registry_session *session,
312 int session_objd, char *name,
313 struct lttng_ust_ctl_enum_entry *entries, size_t nr_entries,
314 uint64_t *enum_id);
315 struct ust_registry_enum *
316 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
317 const char *name, uint64_t id);
318
319 #else /* HAVE_LIBLTTNG_UST_CTL */
320
321 static inline
322 void ust_registry_channel_destroy(
323 struct ust_registry_session *session __attribute__((unused)),
324 struct ust_registry_channel *chan __attribute__((unused)))
325 {}
326
327 static inline
328 struct ust_registry_channel *ust_registry_channel_find(
329 struct ust_registry_session *session __attribute__((unused)),
330 uint64_t key __attribute__((unused)))
331 {
332 return NULL;
333 }
334
335 static inline
336 int ust_registry_channel_add(
337 struct ust_registry_session *session __attribute__((unused)),
338 uint64_t key __attribute__((unused)))
339 {
340 return 0;
341 }
342
343 static inline
344 void ust_registry_channel_del_free(
345 struct ust_registry_session *session __attribute__((unused)),
346 uint64_t key __attribute__((unused)),
347 bool notif __attribute__((unused)))
348 {}
349
350 static inline
351 int ust_registry_session_init(
352 struct ust_registry_session **sessionp __attribute__((unused)),
353 struct ust_app *app __attribute__((unused)),
354 uint32_t bits_per_long __attribute__((unused)),
355 uint32_t uint8_t_alignment __attribute__((unused)),
356 uint32_t uint16_t_alignment __attribute__((unused)),
357 uint32_t uint32_t_alignment __attribute__((unused)),
358 uint32_t uint64_t_alignment __attribute__((unused)),
359 uint32_t long_alignment __attribute__((unused)),
360 int byte_order __attribute__((unused)),
361 uint32_t major __attribute__((unused)),
362 uint32_t minor __attribute__((unused)),
363 const char *root_shm_path __attribute__((unused)),
364 const char *shm_path __attribute__((unused)),
365 uid_t euid __attribute__((unused)),
366 gid_t egid __attribute__((unused)),
367 uint64_t tracing_id __attribute__((unused)),
368 uid_t tracing_uid __attribute__((unused)))
369 {
370 return 0;
371 }
372
373 static inline
374 void ust_registry_session_destroy(
375 struct ust_registry_session *session __attribute__((unused)))
376 {}
377
378 static inline
379 int ust_registry_create_event(
380 struct ust_registry_session *session __attribute__((unused)),
381 uint64_t chan_key __attribute__((unused)),
382 int session_objd __attribute__((unused)),
383 int channel_objd __attribute__((unused)),
384 char *name __attribute__((unused)),
385 char *sig __attribute__((unused)),
386 size_t nr_fields __attribute__((unused)),
387 struct lttng_ust_ctl_field *fields __attribute__((unused)),
388 int loglevel_value __attribute__((unused)),
389 char *model_emf_uri __attribute__((unused)),
390 int buffer_type __attribute__((unused)),
391 uint32_t *event_id_p __attribute__((unused)))
392 {
393 return 0;
394 }
395 static inline
396 struct ust_registry_event *ust_registry_find_event(
397 struct ust_registry_channel *chan __attribute__((unused)),
398 char *name __attribute__((unused)),
399 char *sig __attribute__((unused)))
400 {
401 return NULL;
402 }
403
404 static inline
405 void ust_registry_destroy_event(
406 struct ust_registry_channel *chan __attribute__((unused)),
407 struct ust_registry_event *event __attribute__((unused)))
408 {}
409
410 /* The app object can be NULL for registry shared across applications. */
411 static inline
412 int ust_metadata_session_statedump(
413 struct ust_registry_session *session __attribute__((unused)),
414 struct ust_app *app __attribute__((unused)),
415 uint32_t major __attribute__((unused)),
416 uint32_t minor __attribute__((unused)))
417 {
418 return 0;
419 }
420
421 static inline
422 int ust_metadata_channel_statedump(
423 struct ust_registry_session *session __attribute__((unused)),
424 struct ust_registry_channel *chan __attribute__((unused)))
425 {
426 return 0;
427 }
428
429 static inline
430 int ust_metadata_event_statedump(
431 struct ust_registry_session *session __attribute__((unused)),
432 struct ust_registry_channel *chan __attribute__((unused)),
433 struct ust_registry_event *event __attribute__((unused)))
434 {
435 return 0;
436 }
437
438 static inline
439 int ust_registry_create_or_find_enum(
440 struct ust_registry_session *session __attribute__((unused)),
441 int session_objd __attribute__((unused)),
442 char *name __attribute__((unused)),
443 struct lttng_ust_ctl_enum_entry *entries __attribute__((unused)),
444 size_t nr_entries __attribute__((unused)),
445 uint64_t *enum_id __attribute__((unused)))
446 {
447 return 0;
448 }
449
450 static inline
451 struct ust_registry_enum *
452 ust_registry_lookup_enum_by_id(
453 struct ust_registry_session *session __attribute__((unused)),
454 const char *name __attribute__((unused)),
455 uint64_t id __attribute__((unused)))
456 {
457 return NULL;
458 }
459
460 #endif /* HAVE_LIBLTTNG_UST_CTL */
461
462 #endif /* LTTNG_UST_REGISTRY_H */
This page took 0.039311 seconds and 4 git commands to generate.