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