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