Clean-up: sort noinst_PROGRAMS in test/unit/Makefile.am
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.h
CommitLineData
d0b96690 1/*
ab5be9fa 2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
d0b96690 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
d0b96690 5 *
d0b96690
DG
6 */
7
8#ifndef LTTNG_UST_REGISTRY_H
9#define LTTNG_UST_REGISTRY_H
10
11#include <pthread.h>
12#include <stdint.h>
d0b96690
DG
13
14#include <common/hashtable/hashtable.h>
c70636a7 15#include <common/uuid.h>
d0b96690 16
75018ab6 17#include "lttng-ust-ctl.h"
7972aab2 18
d0b96690
DG
19#define CTF_SPEC_MAJOR 1
20#define CTF_SPEC_MINOR 8
21
22struct ust_app;
23
24struct ust_registry_session {
25 /*
dc2bbdae
MD
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.
d0b96690
DG
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;
10b56aef
MD
38 /* Next enumeration ID available. */
39 uint64_t next_enum_id;
d0b96690 40 /* Universal unique identifier used by the tracer. */
c70636a7 41 unsigned char uuid[LTTNG_UUID_LEN];
d0b96690
DG
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;
d88aee68
DG
59 /* Length of bytes sent to the consumer. */
60 size_t metadata_len_sent;
93ec662e
JD
61 /* Current version of the metadata. */
62 uint64_t metadata_version;
d7ba1388 63
9aed4377
JG
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 */
3d071855 90 char root_shm_path[PATH_MAX];
d7ba1388
MD
91 char shm_path[PATH_MAX];
92 char metadata_path[PATH_MAX];
93 int metadata_fd; /* file-backed metadata FD */
94
45893984 95 /*
dc2bbdae
MD
96 * Hash table containing channels sent by the UST tracer. MUST
97 * be accessed with a RCU read side lock acquired.
45893984
DG
98 */
99 struct lttng_ht *channels;
dc2bbdae
MD
100 /*
101 * Unique key to identify the metadata on the consumer side.
102 */
7972aab2
DG
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;
4628484a
MD
110
111 /* User and group owning the session. */
112 uid_t uid;
113 gid_t gid;
10b56aef
MD
114
115 /* Enumerations table. */
116 struct lttng_ht *enums;
7062f070
JD
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;
8de88061
JR
124
125 /* The id of the parent session */
126 uint64_t tracing_id;
127 uid_t tracing_uid;
d0b96690
DG
128};
129
130struct ust_registry_channel {
45893984 131 uint64_t key;
e9404c27 132 uint64_t consumer_key;
d0b96690
DG
133 /* Id set when replying to a register channel. */
134 uint32_t chan_id;
135 enum ustctl_channel_header header_type;
136
7972aab2
DG
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
d0b96690
DG
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 *ht;
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 ustctl_field *ctx_fields;
45893984 160 struct lttng_ht_node_u64 node;
36b588ed
MD
161 /* For delayed reclaim */
162 struct rcu_head rcu_head;
d0b96690
DG
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 */
169struct 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. */
fc4b93fa 175 char name[LTTNG_UST_ABI_SYM_NAME_LEN];
d0b96690 176 char *signature;
2106efa0 177 int loglevel_value;
d0b96690
DG
178 size_t nr_fields;
179 struct ustctl_field *fields;
180 char *model_emf_uri;
7972aab2
DG
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;
d0b96690
DG
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 */
7972aab2 190 struct lttng_ht_node_u64 node;
d0b96690
DG
191};
192
10b56aef 193struct ust_registry_enum {
fc4b93fa 194 char name[LTTNG_UST_ABI_SYM_NAME_LEN];
10b56aef
MD
195 struct ustctl_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
d0b96690
DG
204/*
205 * Validate that the id has reached the maximum allowed or not.
206 *
207 * Return 0 if NOT else 1.
208 */
209static 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 */
223static 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 */
243static 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 */
257static 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
7972aab2
DG
263#ifdef HAVE_LIBLTTNG_UST_CTL
264
d0b96690
DG
265void ust_registry_channel_destroy(struct ust_registry_session *session,
266 struct ust_registry_channel *chan);
45893984
DG
267struct ust_registry_channel *ust_registry_channel_find(
268 struct ust_registry_session *session, uint64_t key);
269int ust_registry_channel_add(struct ust_registry_session *session,
270 uint64_t key);
271void ust_registry_channel_del_free(struct ust_registry_session *session,
e9404c27 272 uint64_t key, bool notif);
45893984
DG
273
274int ust_registry_session_init(struct ust_registry_session **sessionp,
d0b96690
DG
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,
af6142cf
MD
282 int byte_order,
283 uint32_t major,
d7ba1388 284 uint32_t minor,
3d071855 285 const char *root_shm_path,
d7ba1388
MD
286 const char *shm_path,
287 uid_t euid,
8de88061
JR
288 gid_t egid,
289 uint64_t tracing_id,
290 uid_t tracing_uid);
d0b96690
DG
291void ust_registry_session_destroy(struct ust_registry_session *session);
292
293int ust_registry_create_event(struct ust_registry_session *session,
45893984 294 uint64_t chan_key, int session_objd, int channel_objd, char *name,
2106efa0
PP
295 char *sig, size_t nr_fields, struct ustctl_field *fields,
296 int loglevel_value, char *model_emf_uri, int buffer_type,
297 uint32_t *event_id_p, struct ust_app *app);
d0b96690
DG
298struct ust_registry_event *ust_registry_find_event(
299 struct ust_registry_channel *chan, char *name, char *sig);
300void 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. */
304int ust_metadata_session_statedump(struct ust_registry_session *session,
af6142cf 305 struct ust_app *app, uint32_t major, uint32_t minor);
d0b96690
DG
306int ust_metadata_channel_statedump(struct ust_registry_session *session,
307 struct ust_registry_channel *chan);
308int ust_metadata_event_statedump(struct ust_registry_session *session,
309 struct ust_registry_channel *chan,
310 struct ust_registry_event *event);
10b56aef
MD
311int ust_registry_create_or_find_enum(struct ust_registry_session *session,
312 int session_objd, char *name,
313 struct ustctl_enum_entry *entries, size_t nr_entries,
314 uint64_t *enum_id);
315struct ust_registry_enum *
316 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
317 const char *name, uint64_t id);
d0b96690 318
7972aab2
DG
319#else /* HAVE_LIBLTTNG_UST_CTL */
320
321static inline
322void ust_registry_channel_destroy(struct ust_registry_session *session,
323 struct ust_registry_channel *chan)
324{}
325static inline
326struct ust_registry_channel *ust_registry_channel_find(
327 struct ust_registry_session *session, uint64_t key)
328{
329 return NULL;
330}
331static inline
332int ust_registry_channel_add(struct ust_registry_session *session,
333 uint64_t key)
334{
335 return 0;
336}
337static inline
338void ust_registry_channel_del_free(struct ust_registry_session *session,
e9404c27 339 uint64_t key, bool notif)
7972aab2
DG
340{}
341static inline
342int ust_registry_session_init(struct ust_registry_session **sessionp,
343 struct ust_app *app,
344 uint32_t bits_per_long,
345 uint32_t uint8_t_alignment,
346 uint32_t uint16_t_alignment,
347 uint32_t uint32_t_alignment,
348 uint32_t uint64_t_alignment,
349 uint32_t long_alignment,
8de88061
JR
350 int byte_order,
351 uint32_t major,
352 uint32_t minor,
353 const char *root_shm_path,
354 const char *shm_path,
355 uid_t euid,
356 gid_t egid,
357 uint64_t tracing_id,
16ea9370 358 uid_t tracing_uid)
7972aab2
DG
359{
360 return 0;
361}
362static inline
363void ust_registry_session_destroy(struct ust_registry_session *session)
364{}
365static inline
366int ust_registry_create_event(struct ust_registry_session *session,
367 uint64_t chan_key, int session_objd, int channel_objd, char *name,
2106efa0
PP
368 char *sig, size_t nr_fields, struct ustctl_field *fields,
369 int loglevel_value, char *model_emf_uri, int buffer_type,
370 uint32_t *event_id_p)
7972aab2
DG
371{
372 return 0;
373}
374static inline
375struct ust_registry_event *ust_registry_find_event(
376 struct ust_registry_channel *chan, char *name, char *sig)
377{
378 return NULL;
379}
380static inline
381void ust_registry_destroy_event(struct ust_registry_channel *chan,
382 struct ust_registry_event *event)
383{}
384
385/* The app object can be NULL for registry shared across applications. */
386static inline
387int ust_metadata_session_statedump(struct ust_registry_session *session,
9804676e 388 struct ust_app *app, uint32_t major, uint32_t minor)
7972aab2
DG
389{
390 return 0;
391}
392static inline
393int ust_metadata_channel_statedump(struct ust_registry_session *session,
394 struct ust_registry_channel *chan)
395{
396 return 0;
397}
398static inline
399int ust_metadata_event_statedump(struct ust_registry_session *session,
400 struct ust_registry_channel *chan,
401 struct ust_registry_event *event)
402{
403 return 0;
404}
10b56aef
MD
405static inline
406int ust_registry_create_or_find_enum(struct ust_registry_session *session,
407 int session_objd, char *name,
408 struct ustctl_enum_entry *entries, size_t nr_entries,
409 uint64_t *enum_id)
410{
411 return 0;
412}
413static inline
414struct ust_registry_enum *
415 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
416 const char *name, uint64_t id)
417{
418 return NULL;
419}
7972aab2
DG
420
421#endif /* HAVE_LIBLTTNG_UST_CTL */
422
d0b96690 423#endif /* LTTNG_UST_REGISTRY_H */
This page took 0.073348 seconds and 4 git commands to generate.