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