2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
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.
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
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.
18 #ifndef LTTNG_UST_REGISTRY_H
19 #define LTTNG_UST_REGISTRY_H
24 #include <common/hashtable/hashtable.h>
25 #include <common/uuid.h>
27 #include "lttng-ust-ctl.h"
29 #define CTF_SPEC_MAJOR 1
30 #define CTF_SPEC_MINOR 8
34 struct ust_registry_session
{
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.
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
;
48 /* Next enumeration ID available. */
49 uint64_t next_enum_id
;
50 /* Universal unique identifier used by the tracer. */
51 unsigned char uuid
[LTTNG_UUID_LEN
];
53 /* session ABI description */
55 /* Size of long, in bits */
56 unsigned int bits_per_long
;
57 /* Alignment, in bits */
58 unsigned int uint8_t_alignment
,
64 int byte_order
; /* BIG_ENDIAN or LITTLE_ENDIAN */
66 /* Generated metadata. */
67 char *metadata
; /* NOT null-terminated ! Use memcpy. */
68 size_t metadata_len
, metadata_alloc_len
;
69 /* Length of bytes sent to the consumer. */
70 size_t metadata_len_sent
;
71 /* Current version of the metadata. */
72 uint64_t metadata_version
;
75 * Those fields are only used when a session is created with
76 * the --shm-path option. In this case, the metadata is output
77 * twice: once to the consumer, as ususal, but a second time
78 * also in the shm path directly. This is done so that a copy
79 * of the metadata that is as fresh as possible is available
80 * on the event of a crash.
82 * root_shm_path contains the shm-path provided by the user, along with
83 * the session's name and timestamp:
84 * e.g. /tmp/my_shm/my_session-20180612-135822
86 * shm_path contains the full path of the memory buffers:
87 * e.g. /tmp/my_shm/my_session-20180612-135822/ust/uid/1000/64-bit
89 * metadata_path contains the full path to the metadata file that
90 * is kept for the "crash buffer" extraction:
91 * e.g. /tmp/my_shm/my_session-20180612-135822/ust/uid/1000/64-bit/metadata
93 * Note that this is not the trace's final metadata file. It is
94 * only meant to be used to read the contents of the ring buffers
95 * in the event of a crash.
97 * metadata_fd is a file descriptor that points to the file at
100 char root_shm_path
[PATH_MAX
];
101 char shm_path
[PATH_MAX
];
102 char metadata_path
[PATH_MAX
];
103 int metadata_fd
; /* file-backed metadata FD */
106 * Hash table containing channels sent by the UST tracer. MUST
107 * be accessed with a RCU read side lock acquired.
109 struct lttng_ht
*channels
;
111 * Unique key to identify the metadata on the consumer side.
113 uint64_t metadata_key
;
115 * Indicates if the metadata is closed on the consumer side. This is to
116 * avoid double close of metadata when an application unregisters AND
117 * deletes its sessions.
119 unsigned int metadata_closed
;
121 /* User and group owning the session. */
125 /* Enumerations table. */
126 struct lttng_ht
*enums
;
129 * Copy of the tracer version when the first app is registered.
130 * It is used if we need to regenerate the metadata.
135 /* The id of the parent session */
140 struct ust_registry_channel
{
142 uint64_t consumer_key
;
143 /* Id set when replying to a register channel. */
145 enum ustctl_channel_header header_type
;
148 * Flag for this channel if the metadata was dumped once during
149 * registration. 0 means no, 1 yes.
151 unsigned int metadata_dumped
;
152 /* Indicates if this channel registry has already been registered. */
153 unsigned int register_done
;
156 * Hash table containing events sent by the UST tracer. MUST be accessed
157 * with a RCU read side lock acquired.
160 /* Next event ID available for a newly registered event. */
161 uint32_t next_event_id
;
162 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
163 uint32_t used_event_id
;
165 * Context fields of the registry. Context are per channel. Allocated by a
166 * register channel notification from the UST tracer.
168 size_t nr_ctx_fields
;
169 struct ustctl_field
*ctx_fields
;
170 struct lttng_ht_node_u64 node
;
171 /* For delayed reclaim */
172 struct rcu_head rcu_head
;
176 * Event registered from a UST tracer sent to the session daemon. This is
177 * indexed and matched by <event_name/signature>.
179 struct ust_registry_event
{
181 /* Both objd are set by the tracer. */
184 /* Name of the event returned by the tracer. */
185 char name
[LTTNG_UST_SYM_NAME_LEN
];
189 struct ustctl_field
*fields
;
192 * Flag for this channel if the metadata was dumped once during
193 * registration. 0 means no, 1 yes.
195 unsigned int metadata_dumped
;
197 * Node in the ust-registry hash table. The event name is used to
198 * initialize the node and the event_name/signature for the match function.
200 struct lttng_ht_node_u64 node
;
203 struct ust_registry_enum
{
204 char name
[LTTNG_UST_SYM_NAME_LEN
];
205 struct ustctl_enum_entry
*entries
;
207 uint64_t id
; /* enum id in session */
208 /* Enumeration node in session hash table. */
209 struct lttng_ht_node_str node
;
210 /* For delayed reclaim. */
211 struct rcu_head rcu_head
;
215 * Validate that the id has reached the maximum allowed or not.
217 * Return 0 if NOT else 1.
219 static inline int ust_registry_is_max_id(uint32_t id
)
221 return (id
== UINT32_MAX
) ? 1 : 0;
225 * Return next available event id and increment the used counter. The
226 * ust_registry_is_max_id function MUST be called before in order to validate
227 * if the maximum number of IDs have been reached. If not, it is safe to call
230 * Return a unique channel ID. If max is reached, the used_event_id counter is
233 static inline uint32_t ust_registry_get_next_event_id(
234 struct ust_registry_channel
*r
)
236 if (ust_registry_is_max_id(r
->used_event_id
)) {
237 return r
->used_event_id
;
241 return r
->next_event_id
++;
245 * Return next available channel id and increment the used counter. The
246 * ust_registry_is_max_id function MUST be called before in order to validate
247 * if the maximum number of IDs have been reached. If not, it is safe to call
250 * Return a unique channel ID. If max is reached, the used_channel_id counter
253 static inline uint32_t ust_registry_get_next_chan_id(
254 struct ust_registry_session
*r
)
256 if (ust_registry_is_max_id(r
->used_channel_id
)) {
257 return r
->used_channel_id
;
260 r
->used_channel_id
++;
261 return r
->next_channel_id
++;
265 * Return registry event count. This is read atomically.
267 static inline uint32_t ust_registry_get_event_count(
268 struct ust_registry_channel
*r
)
270 return (uint32_t) uatomic_read(&r
->used_event_id
);
273 #ifdef HAVE_LIBLTTNG_UST_CTL
275 void ust_registry_channel_destroy(struct ust_registry_session
*session
,
276 struct ust_registry_channel
*chan
);
277 struct ust_registry_channel
*ust_registry_channel_find(
278 struct ust_registry_session
*session
, uint64_t key
);
279 int ust_registry_channel_add(struct ust_registry_session
*session
,
281 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
282 uint64_t key
, bool notif
);
284 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
286 uint32_t bits_per_long
,
287 uint32_t uint8_t_alignment
,
288 uint32_t uint16_t_alignment
,
289 uint32_t uint32_t_alignment
,
290 uint32_t uint64_t_alignment
,
291 uint32_t long_alignment
,
295 const char *root_shm_path
,
296 const char *shm_path
,
301 void ust_registry_session_destroy(struct ust_registry_session
*session
);
303 int ust_registry_create_event(struct ust_registry_session
*session
,
304 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
305 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
,
306 int loglevel_value
, char *model_emf_uri
, int buffer_type
,
307 uint32_t *event_id_p
, struct ust_app
*app
);
308 struct ust_registry_event
*ust_registry_find_event(
309 struct ust_registry_channel
*chan
, char *name
, char *sig
);
310 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
311 struct ust_registry_event
*event
);
313 /* app can be NULL for registry shared across applications. */
314 int ust_metadata_session_statedump(struct ust_registry_session
*session
,
315 struct ust_app
*app
, uint32_t major
, uint32_t minor
);
316 int ust_metadata_channel_statedump(struct ust_registry_session
*session
,
317 struct ust_registry_channel
*chan
);
318 int ust_metadata_event_statedump(struct ust_registry_session
*session
,
319 struct ust_registry_channel
*chan
,
320 struct ust_registry_event
*event
);
321 int ust_registry_create_or_find_enum(struct ust_registry_session
*session
,
322 int session_objd
, char *name
,
323 struct ustctl_enum_entry
*entries
, size_t nr_entries
,
325 struct ust_registry_enum
*
326 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
327 const char *name
, uint64_t id
);
329 #else /* HAVE_LIBLTTNG_UST_CTL */
332 void ust_registry_channel_destroy(struct ust_registry_session
*session
,
333 struct ust_registry_channel
*chan
)
336 struct ust_registry_channel
*ust_registry_channel_find(
337 struct ust_registry_session
*session
, uint64_t key
)
342 int ust_registry_channel_add(struct ust_registry_session
*session
,
348 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
349 uint64_t key
, bool notif
)
352 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
354 uint32_t bits_per_long
,
355 uint32_t uint8_t_alignment
,
356 uint32_t uint16_t_alignment
,
357 uint32_t uint32_t_alignment
,
358 uint32_t uint64_t_alignment
,
359 uint32_t long_alignment
,
363 const char *root_shm_path
,
364 const char *shm_path
,
373 void ust_registry_session_destroy(struct ust_registry_session
*session
)
376 int ust_registry_create_event(struct ust_registry_session
*session
,
377 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
378 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
,
379 int loglevel_value
, char *model_emf_uri
, int buffer_type
,
380 uint32_t *event_id_p
)
385 struct ust_registry_event
*ust_registry_find_event(
386 struct ust_registry_channel
*chan
, char *name
, char *sig
)
391 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
392 struct ust_registry_event
*event
)
395 /* The app object can be NULL for registry shared across applications. */
397 int ust_metadata_session_statedump(struct ust_registry_session
*session
,
398 struct ust_app
*app
, uint32_t major
, uint32_t minor
)
403 int ust_metadata_channel_statedump(struct ust_registry_session
*session
,
404 struct ust_registry_channel
*chan
)
409 int ust_metadata_event_statedump(struct ust_registry_session
*session
,
410 struct ust_registry_channel
*chan
,
411 struct ust_registry_event
*event
)
416 int ust_registry_create_or_find_enum(struct ust_registry_session
*session
,
417 int session_objd
, char *name
,
418 struct ustctl_enum_entry
*entries
, size_t nr_entries
,
424 struct ust_registry_enum
*
425 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
426 const char *name
, uint64_t id
)
431 #endif /* HAVE_LIBLTTNG_UST_CTL */
433 #endif /* LTTNG_UST_REGISTRY_H */