Add variant type support to ust registry and metadata
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.h
CommitLineData
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
32struct ust_app;
33
34struct 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;
d0b96690
DG
99};
100
101struct ust_registry_channel {
45893984 102 uint64_t key;
d0b96690
DG
103 /* Id set when replying to a register channel. */
104 uint32_t chan_id;
105 enum ustctl_channel_header header_type;
106
7972aab2
DG
107 /*
108 * Flag for this channel if the metadata was dumped once during
109 * registration. 0 means no, 1 yes.
110 */
111 unsigned int metadata_dumped;
112 /* Indicates if this channel registry has already been registered. */
113 unsigned int register_done;
114
d0b96690
DG
115 /*
116 * Hash table containing events sent by the UST tracer. MUST be accessed
117 * with a RCU read side lock acquired.
118 */
119 struct lttng_ht *ht;
120 /* Next event ID available for a newly registered event. */
121 uint32_t next_event_id;
122 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
123 uint32_t used_event_id;
124 /*
125 * Context fields of the registry. Context are per channel. Allocated by a
126 * register channel notification from the UST tracer.
127 */
128 size_t nr_ctx_fields;
129 struct ustctl_field *ctx_fields;
45893984 130 struct lttng_ht_node_u64 node;
36b588ed
MD
131 /* For delayed reclaim */
132 struct rcu_head rcu_head;
d0b96690
DG
133};
134
135/*
136 * Event registered from a UST tracer sent to the session daemon. This is
137 * indexed and matched by <event_name/signature>.
138 */
139struct ust_registry_event {
140 int id;
141 /* Both objd are set by the tracer. */
142 int session_objd;
143 int channel_objd;
144 /* Name of the event returned by the tracer. */
145 char name[LTTNG_UST_SYM_NAME_LEN];
146 char *signature;
2106efa0 147 int loglevel_value;
d0b96690
DG
148 size_t nr_fields;
149 struct ustctl_field *fields;
150 char *model_emf_uri;
7972aab2
DG
151 /*
152 * Flag for this channel if the metadata was dumped once during
153 * registration. 0 means no, 1 yes.
154 */
155 unsigned int metadata_dumped;
d0b96690
DG
156 /*
157 * Node in the ust-registry hash table. The event name is used to
158 * initialize the node and the event_name/signature for the match function.
159 */
7972aab2 160 struct lttng_ht_node_u64 node;
d0b96690
DG
161};
162
10b56aef
MD
163struct ust_registry_enum {
164 char name[LTTNG_UST_SYM_NAME_LEN];
165 struct ustctl_enum_entry *entries;
166 size_t nr_entries;
167 uint64_t id; /* enum id in session */
168 /* Enumeration node in session hash table. */
169 struct lttng_ht_node_str node;
170 /* For delayed reclaim. */
171 struct rcu_head rcu_head;
172};
173
d0b96690
DG
174/*
175 * Validate that the id has reached the maximum allowed or not.
176 *
177 * Return 0 if NOT else 1.
178 */
179static inline int ust_registry_is_max_id(uint32_t id)
180{
181 return (id == UINT32_MAX) ? 1 : 0;
182}
183
184/*
185 * Return next available event id and increment the used counter. The
186 * ust_registry_is_max_id function MUST be called before in order to validate
187 * if the maximum number of IDs have been reached. If not, it is safe to call
188 * this function.
189 *
190 * Return a unique channel ID. If max is reached, the used_event_id counter is
191 * returned.
192 */
193static inline uint32_t ust_registry_get_next_event_id(
194 struct ust_registry_channel *r)
195{
196 if (ust_registry_is_max_id(r->used_event_id)) {
197 return r->used_event_id;
198 }
199
200 r->used_event_id++;
201 return r->next_event_id++;
202}
203
204/*
205 * Return next available channel id and increment the used counter. The
206 * ust_registry_is_max_id function MUST be called before in order to validate
207 * if the maximum number of IDs have been reached. If not, it is safe to call
208 * this function.
209 *
210 * Return a unique channel ID. If max is reached, the used_channel_id counter
211 * is returned.
212 */
213static inline uint32_t ust_registry_get_next_chan_id(
214 struct ust_registry_session *r)
215{
216 if (ust_registry_is_max_id(r->used_channel_id)) {
217 return r->used_channel_id;
218 }
219
220 r->used_channel_id++;
221 return r->next_channel_id++;
222}
223
224/*
225 * Return registry event count. This is read atomically.
226 */
227static inline uint32_t ust_registry_get_event_count(
228 struct ust_registry_channel *r)
229{
230 return (uint32_t) uatomic_read(&r->used_event_id);
231}
232
7972aab2
DG
233#ifdef HAVE_LIBLTTNG_UST_CTL
234
d0b96690
DG
235void ust_registry_channel_destroy(struct ust_registry_session *session,
236 struct ust_registry_channel *chan);
45893984
DG
237struct ust_registry_channel *ust_registry_channel_find(
238 struct ust_registry_session *session, uint64_t key);
239int ust_registry_channel_add(struct ust_registry_session *session,
240 uint64_t key);
241void ust_registry_channel_del_free(struct ust_registry_session *session,
242 uint64_t key);
243
244int ust_registry_session_init(struct ust_registry_session **sessionp,
d0b96690
DG
245 struct ust_app *app,
246 uint32_t bits_per_long,
247 uint32_t uint8_t_alignment,
248 uint32_t uint16_t_alignment,
249 uint32_t uint32_t_alignment,
250 uint32_t uint64_t_alignment,
251 uint32_t long_alignment,
af6142cf
MD
252 int byte_order,
253 uint32_t major,
d7ba1388 254 uint32_t minor,
3d071855 255 const char *root_shm_path,
d7ba1388
MD
256 const char *shm_path,
257 uid_t euid,
258 gid_t egid);
d0b96690
DG
259void ust_registry_session_destroy(struct ust_registry_session *session);
260
261int ust_registry_create_event(struct ust_registry_session *session,
45893984 262 uint64_t chan_key, int session_objd, int channel_objd, char *name,
2106efa0
PP
263 char *sig, size_t nr_fields, struct ustctl_field *fields,
264 int loglevel_value, char *model_emf_uri, int buffer_type,
265 uint32_t *event_id_p, struct ust_app *app);
d0b96690
DG
266struct ust_registry_event *ust_registry_find_event(
267 struct ust_registry_channel *chan, char *name, char *sig);
268void ust_registry_destroy_event(struct ust_registry_channel *chan,
269 struct ust_registry_event *event);
270
271/* app can be NULL for registry shared across applications. */
272int ust_metadata_session_statedump(struct ust_registry_session *session,
af6142cf 273 struct ust_app *app, uint32_t major, uint32_t minor);
d0b96690
DG
274int ust_metadata_channel_statedump(struct ust_registry_session *session,
275 struct ust_registry_channel *chan);
276int ust_metadata_event_statedump(struct ust_registry_session *session,
277 struct ust_registry_channel *chan,
278 struct ust_registry_event *event);
10b56aef
MD
279int ust_registry_create_or_find_enum(struct ust_registry_session *session,
280 int session_objd, char *name,
281 struct ustctl_enum_entry *entries, size_t nr_entries,
282 uint64_t *enum_id);
283struct ust_registry_enum *
284 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
285 const char *name, uint64_t id);
d0b96690 286
7972aab2
DG
287#else /* HAVE_LIBLTTNG_UST_CTL */
288
289static inline
290void ust_registry_channel_destroy(struct ust_registry_session *session,
291 struct ust_registry_channel *chan)
292{}
293static inline
294struct ust_registry_channel *ust_registry_channel_find(
295 struct ust_registry_session *session, uint64_t key)
296{
297 return NULL;
298}
299static inline
300int ust_registry_channel_add(struct ust_registry_session *session,
301 uint64_t key)
302{
303 return 0;
304}
305static inline
306void ust_registry_channel_del_free(struct ust_registry_session *session,
307 uint64_t key)
308{}
309static inline
310int ust_registry_session_init(struct ust_registry_session **sessionp,
311 struct ust_app *app,
312 uint32_t bits_per_long,
313 uint32_t uint8_t_alignment,
314 uint32_t uint16_t_alignment,
315 uint32_t uint32_t_alignment,
316 uint32_t uint64_t_alignment,
317 uint32_t long_alignment,
318 int byte_order)
319{
320 return 0;
321}
322static inline
323void ust_registry_session_destroy(struct ust_registry_session *session)
324{}
325static inline
326int ust_registry_create_event(struct ust_registry_session *session,
327 uint64_t chan_key, int session_objd, int channel_objd, char *name,
2106efa0
PP
328 char *sig, size_t nr_fields, struct ustctl_field *fields,
329 int loglevel_value, char *model_emf_uri, int buffer_type,
330 uint32_t *event_id_p)
7972aab2
DG
331{
332 return 0;
333}
334static inline
335struct ust_registry_event *ust_registry_find_event(
336 struct ust_registry_channel *chan, char *name, char *sig)
337{
338 return NULL;
339}
340static inline
341void ust_registry_destroy_event(struct ust_registry_channel *chan,
342 struct ust_registry_event *event)
343{}
344
345/* The app object can be NULL for registry shared across applications. */
346static inline
347int ust_metadata_session_statedump(struct ust_registry_session *session,
348 struct ust_app *app)
349{
350 return 0;
351}
352static inline
353int ust_metadata_channel_statedump(struct ust_registry_session *session,
354 struct ust_registry_channel *chan)
355{
356 return 0;
357}
358static inline
359int ust_metadata_event_statedump(struct ust_registry_session *session,
360 struct ust_registry_channel *chan,
361 struct ust_registry_event *event)
362{
363 return 0;
364}
10b56aef
MD
365static inline
366int ust_registry_create_or_find_enum(struct ust_registry_session *session,
367 int session_objd, char *name,
368 struct ustctl_enum_entry *entries, size_t nr_entries,
369 uint64_t *enum_id)
370{
371 return 0;
372}
373static inline
374struct ust_registry_enum *
375 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
376 const char *name, uint64_t id)
377{
378 return NULL;
379}
7972aab2
DG
380
381#endif /* HAVE_LIBLTTNG_UST_CTL */
382
d0b96690 383#endif /* LTTNG_UST_REGISTRY_H */
This page took 0.074553 seconds and 4 git commands to generate.