2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef LTTNG_UST_REGISTRY_H
9 #define LTTNG_UST_REGISTRY_H
14 #include <common/hashtable/hashtable.h>
15 #include <common/uuid.h>
17 #include "lttng-ust-ctl.h"
19 #define CTF_SPEC_MAJOR 1
20 #define CTF_SPEC_MINOR 8
24 struct ust_registry_session
{
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.
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
];
43 /* session ABI description */
45 /* Size of long, in bits */
46 unsigned int bits_per_long
;
47 /* Alignment, in bits */
48 unsigned int uint8_t_alignment
,
54 int byte_order
; /* BIG_ENDIAN or LITTLE_ENDIAN */
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
;
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.
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
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
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
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.
87 * metadata_fd is a file descriptor that points to the file at
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 */
96 * Hash table containing channels sent by the UST tracer. MUST
97 * be accessed with a RCU read side lock acquired.
99 struct lttng_ht
*channels
;
101 * Unique key to identify the metadata on the consumer side.
103 uint64_t metadata_key
;
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.
109 unsigned int metadata_closed
;
111 /* User and group owning the session. */
115 /* Enumerations table. */
116 struct lttng_ht
*enums
;
119 * Copy of the tracer version when the first app is registered.
120 * It is used if we need to regenerate the metadata.
125 /* The id of the parent session */
130 struct ust_registry_channel
{
132 uint64_t consumer_key
;
133 /* Id set when replying to a register channel. */
135 enum ustctl_channel_header header_type
;
138 * Flag for this channel if the metadata was dumped once during
139 * registration. 0 means no, 1 yes.
141 unsigned int metadata_dumped
;
142 /* Indicates if this channel registry has already been registered. */
143 unsigned int register_done
;
146 * Hash table containing events sent by the UST tracer. MUST be accessed
147 * with a RCU read side lock acquired.
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
;
155 * Context fields of the registry. Context are per channel. Allocated by a
156 * register channel notification from the UST tracer.
158 size_t nr_ctx_fields
;
159 struct ustctl_field
*ctx_fields
;
160 struct lttng_ht_node_u64 node
;
161 /* For delayed reclaim */
162 struct rcu_head rcu_head
;
166 * Event registered from a UST tracer sent to the session daemon. This is
167 * indexed and matched by <event_name/signature>.
169 struct ust_registry_event
{
171 /* Both objd are set by the tracer. */
174 /* Name of the event returned by the tracer. */
175 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
179 struct ustctl_field
*fields
;
182 * Flag for this channel if the metadata was dumped once during
183 * registration. 0 means no, 1 yes.
185 unsigned int metadata_dumped
;
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.
190 struct lttng_ht_node_u64 node
;
193 struct ust_registry_enum
{
194 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
195 struct ustctl_enum_entry
*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
;
205 * Validate that the id has reached the maximum allowed or not.
207 * Return 0 if NOT else 1.
209 static inline int ust_registry_is_max_id(uint32_t id
)
211 return (id
== UINT32_MAX
) ? 1 : 0;
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
220 * Return a unique channel ID. If max is reached, the used_event_id counter is
223 static inline uint32_t ust_registry_get_next_event_id(
224 struct ust_registry_channel
*r
)
226 if (ust_registry_is_max_id(r
->used_event_id
)) {
227 return r
->used_event_id
;
231 return r
->next_event_id
++;
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
240 * Return a unique channel ID. If max is reached, the used_channel_id counter
243 static inline uint32_t ust_registry_get_next_chan_id(
244 struct ust_registry_session
*r
)
246 if (ust_registry_is_max_id(r
->used_channel_id
)) {
247 return r
->used_channel_id
;
250 r
->used_channel_id
++;
251 return r
->next_channel_id
++;
255 * Return registry event count. This is read atomically.
257 static inline uint32_t ust_registry_get_event_count(
258 struct ust_registry_channel
*r
)
260 return (uint32_t) uatomic_read(&r
->used_event_id
);
263 #ifdef HAVE_LIBLTTNG_UST_CTL
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
,
271 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
272 uint64_t key
, bool notif
);
274 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
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
,
285 const char *root_shm_path
,
286 const char *shm_path
,
291 void ust_registry_session_destroy(struct ust_registry_session
*session
);
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 ustctl_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
);
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 ustctl_enum_entry
*entries
, size_t nr_entries
,
315 struct ust_registry_enum
*
316 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
317 const char *name
, uint64_t id
);
319 #else /* HAVE_LIBLTTNG_UST_CTL */
322 void ust_registry_channel_destroy(struct ust_registry_session
*session
,
323 struct ust_registry_channel
*chan
)
326 struct ust_registry_channel
*ust_registry_channel_find(
327 struct ust_registry_session
*session
, uint64_t key
)
332 int ust_registry_channel_add(struct ust_registry_session
*session
,
338 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
339 uint64_t key
, bool notif
)
342 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
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
,
353 const char *root_shm_path
,
354 const char *shm_path
,
363 void ust_registry_session_destroy(struct ust_registry_session
*session
)
366 int ust_registry_create_event(struct ust_registry_session
*session
,
367 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
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
)
375 struct ust_registry_event
*ust_registry_find_event(
376 struct ust_registry_channel
*chan
, char *name
, char *sig
)
381 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
382 struct ust_registry_event
*event
)
385 /* The app object can be NULL for registry shared across applications. */
387 int ust_metadata_session_statedump(struct ust_registry_session
*session
,
388 struct ust_app
*app
, uint32_t major
, uint32_t minor
)
393 int ust_metadata_channel_statedump(struct ust_registry_session
*session
,
394 struct ust_registry_channel
*chan
)
399 int ust_metadata_event_statedump(struct ust_registry_session
*session
,
400 struct ust_registry_channel
*chan
,
401 struct ust_registry_event
*event
)
406 int 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
,
414 struct ust_registry_enum
*
415 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
416 const char *name
, uint64_t id
)
421 #endif /* HAVE_LIBLTTNG_UST_CTL */
423 #endif /* LTTNG_UST_REGISTRY_H */