b51b505f12994b0b8219b4efb846f32e2f5f5523
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.h
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>
23
24 #include <common/hashtable/hashtable.h>
25 #include <common/compat/uuid.h>
26
27 #include "ust-ctl.h"
28
29 #define CTF_SPEC_MAJOR 1
30 #define CTF_SPEC_MINOR 8
31
32 struct ust_app;
33
34 struct ust_registry_session {
35 /*
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.
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;
48 /* Universal unique identifier used by the tracer. */
49 unsigned char uuid[UUID_LEN];
50
51 /* session ABI description */
52
53 /* Size of long, in bits */
54 unsigned int bits_per_long;
55 /* Alignment, in bits */
56 unsigned int uint8_t_alignment,
57 uint16_t_alignment,
58 uint32_t_alignment,
59 uint64_t_alignment,
60 long_alignment;
61 /* endianness */
62 int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */
63
64 /* Generated metadata. */
65 char *metadata; /* NOT null-terminated ! Use memcpy. */
66 size_t metadata_len, metadata_alloc_len;
67 /* Length of bytes sent to the consumer. */
68 size_t metadata_len_sent;
69
70 char root_shm_path[PATH_MAX];
71 char shm_path[PATH_MAX];
72 char metadata_path[PATH_MAX];
73 int metadata_fd; /* file-backed metadata FD */
74
75 /*
76 * Hash table containing channels sent by the UST tracer. MUST
77 * be accessed with a RCU read side lock acquired.
78 */
79 struct lttng_ht *channels;
80 /*
81 * Unique key to identify the metadata on the consumer side.
82 */
83 uint64_t metadata_key;
84 /*
85 * Indicates if the metadata is closed on the consumer side. This is to
86 * avoid double close of metadata when an application unregisters AND
87 * deletes its sessions.
88 */
89 unsigned int metadata_closed;
90
91 /* User and group owning the session. */
92 uid_t uid;
93 gid_t gid;
94 };
95
96 struct ust_registry_channel {
97 uint64_t key;
98 /* Id set when replying to a register channel. */
99 uint32_t chan_id;
100 enum ustctl_channel_header header_type;
101
102 /*
103 * Flag for this channel if the metadata was dumped once during
104 * registration. 0 means no, 1 yes.
105 */
106 unsigned int metadata_dumped;
107 /* Indicates if this channel registry has already been registered. */
108 unsigned int register_done;
109
110 /*
111 * Hash table containing events sent by the UST tracer. MUST be accessed
112 * with a RCU read side lock acquired.
113 */
114 struct lttng_ht *ht;
115 /* Next event ID available for a newly registered event. */
116 uint32_t next_event_id;
117 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
118 uint32_t used_event_id;
119 /*
120 * Context fields of the registry. Context are per channel. Allocated by a
121 * register channel notification from the UST tracer.
122 */
123 size_t nr_ctx_fields;
124 struct ustctl_field *ctx_fields;
125 struct lttng_ht_node_u64 node;
126 /* For delayed reclaim */
127 struct rcu_head rcu_head;
128 };
129
130 /*
131 * Event registered from a UST tracer sent to the session daemon. This is
132 * indexed and matched by <event_name/signature>.
133 */
134 struct ust_registry_event {
135 int id;
136 /* Both objd are set by the tracer. */
137 int session_objd;
138 int channel_objd;
139 /* Name of the event returned by the tracer. */
140 char name[LTTNG_UST_SYM_NAME_LEN];
141 char *signature;
142 int loglevel_value;
143 size_t nr_fields;
144 struct ustctl_field *fields;
145 char *model_emf_uri;
146 /*
147 * Flag for this channel if the metadata was dumped once during
148 * registration. 0 means no, 1 yes.
149 */
150 unsigned int metadata_dumped;
151 /*
152 * Node in the ust-registry hash table. The event name is used to
153 * initialize the node and the event_name/signature for the match function.
154 */
155 struct lttng_ht_node_u64 node;
156 };
157
158 /*
159 * Validate that the id has reached the maximum allowed or not.
160 *
161 * Return 0 if NOT else 1.
162 */
163 static inline int ust_registry_is_max_id(uint32_t id)
164 {
165 return (id == UINT32_MAX) ? 1 : 0;
166 }
167
168 /*
169 * Return next available event id and increment the used counter. The
170 * ust_registry_is_max_id function MUST be called before in order to validate
171 * if the maximum number of IDs have been reached. If not, it is safe to call
172 * this function.
173 *
174 * Return a unique channel ID. If max is reached, the used_event_id counter is
175 * returned.
176 */
177 static inline uint32_t ust_registry_get_next_event_id(
178 struct ust_registry_channel *r)
179 {
180 if (ust_registry_is_max_id(r->used_event_id)) {
181 return r->used_event_id;
182 }
183
184 r->used_event_id++;
185 return r->next_event_id++;
186 }
187
188 /*
189 * Return next available channel id and increment the used counter. The
190 * ust_registry_is_max_id function MUST be called before in order to validate
191 * if the maximum number of IDs have been reached. If not, it is safe to call
192 * this function.
193 *
194 * Return a unique channel ID. If max is reached, the used_channel_id counter
195 * is returned.
196 */
197 static inline uint32_t ust_registry_get_next_chan_id(
198 struct ust_registry_session *r)
199 {
200 if (ust_registry_is_max_id(r->used_channel_id)) {
201 return r->used_channel_id;
202 }
203
204 r->used_channel_id++;
205 return r->next_channel_id++;
206 }
207
208 /*
209 * Return registry event count. This is read atomically.
210 */
211 static inline uint32_t ust_registry_get_event_count(
212 struct ust_registry_channel *r)
213 {
214 return (uint32_t) uatomic_read(&r->used_event_id);
215 }
216
217 #ifdef HAVE_LIBLTTNG_UST_CTL
218
219 void ust_registry_channel_destroy(struct ust_registry_session *session,
220 struct ust_registry_channel *chan);
221 struct ust_registry_channel *ust_registry_channel_find(
222 struct ust_registry_session *session, uint64_t key);
223 int ust_registry_channel_add(struct ust_registry_session *session,
224 uint64_t key);
225 void ust_registry_channel_del_free(struct ust_registry_session *session,
226 uint64_t key);
227
228 int ust_registry_session_init(struct ust_registry_session **sessionp,
229 struct ust_app *app,
230 uint32_t bits_per_long,
231 uint32_t uint8_t_alignment,
232 uint32_t uint16_t_alignment,
233 uint32_t uint32_t_alignment,
234 uint32_t uint64_t_alignment,
235 uint32_t long_alignment,
236 int byte_order,
237 uint32_t major,
238 uint32_t minor,
239 const char *root_shm_path,
240 const char *shm_path,
241 uid_t euid,
242 gid_t egid);
243 void ust_registry_session_destroy(struct ust_registry_session *session);
244
245 int ust_registry_create_event(struct ust_registry_session *session,
246 uint64_t chan_key, int session_objd, int channel_objd, char *name,
247 char *sig, size_t nr_fields, struct ustctl_field *fields,
248 int loglevel_value, char *model_emf_uri, int buffer_type,
249 uint32_t *event_id_p, struct ust_app *app);
250 struct ust_registry_event *ust_registry_find_event(
251 struct ust_registry_channel *chan, char *name, char *sig);
252 void ust_registry_destroy_event(struct ust_registry_channel *chan,
253 struct ust_registry_event *event);
254
255 /* app can be NULL for registry shared across applications. */
256 int ust_metadata_session_statedump(struct ust_registry_session *session,
257 struct ust_app *app, uint32_t major, uint32_t minor);
258 int ust_metadata_channel_statedump(struct ust_registry_session *session,
259 struct ust_registry_channel *chan);
260 int ust_metadata_event_statedump(struct ust_registry_session *session,
261 struct ust_registry_channel *chan,
262 struct ust_registry_event *event);
263
264 #else /* HAVE_LIBLTTNG_UST_CTL */
265
266 static inline
267 void ust_registry_channel_destroy(struct ust_registry_session *session,
268 struct ust_registry_channel *chan)
269 {}
270 static inline
271 struct ust_registry_channel *ust_registry_channel_find(
272 struct ust_registry_session *session, uint64_t key)
273 {
274 return NULL;
275 }
276 static inline
277 int ust_registry_channel_add(struct ust_registry_session *session,
278 uint64_t key)
279 {
280 return 0;
281 }
282 static inline
283 void ust_registry_channel_del_free(struct ust_registry_session *session,
284 uint64_t key)
285 {}
286 static inline
287 int ust_registry_session_init(struct ust_registry_session **sessionp,
288 struct ust_app *app,
289 uint32_t bits_per_long,
290 uint32_t uint8_t_alignment,
291 uint32_t uint16_t_alignment,
292 uint32_t uint32_t_alignment,
293 uint32_t uint64_t_alignment,
294 uint32_t long_alignment,
295 int byte_order)
296 {
297 return 0;
298 }
299 static inline
300 void ust_registry_session_destroy(struct ust_registry_session *session)
301 {}
302 static inline
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)
308 {
309 return 0;
310 }
311 static inline
312 struct ust_registry_event *ust_registry_find_event(
313 struct ust_registry_channel *chan, char *name, char *sig)
314 {
315 return NULL;
316 }
317 static inline
318 void ust_registry_destroy_event(struct ust_registry_channel *chan,
319 struct ust_registry_event *event)
320 {}
321
322 /* The app object can be NULL for registry shared across applications. */
323 static inline
324 int ust_metadata_session_statedump(struct ust_registry_session *session,
325 struct ust_app *app)
326 {
327 return 0;
328 }
329 static inline
330 int ust_metadata_channel_statedump(struct ust_registry_session *session,
331 struct ust_registry_channel *chan)
332 {
333 return 0;
334 }
335 static inline
336 int ust_metadata_event_statedump(struct ust_registry_session *session,
337 struct ust_registry_channel *chan,
338 struct ust_registry_event *event)
339 {
340 return 0;
341 }
342
343 #endif /* HAVE_LIBLTTNG_UST_CTL */
344
345 #endif /* LTTNG_UST_REGISTRY_H */
This page took 0.035553 seconds and 3 git commands to generate.