Move LTTng-UST buffer ownership from application to consumer
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.h
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifndef _LTT_UST_APP_H
19 #define _LTT_UST_APP_H
20
21 #include <stdint.h>
22
23 #include <common/compat/uuid.h>
24 #include "trace-ust.h"
25
26 /* lttng-ust supported version. */
27 #define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
28 #define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
29
30 #define UST_APP_EVENT_LIST_SIZE 32
31
32 struct lttng_filter_bytecode;
33 struct lttng_ust_filter_bytecode;
34
35 extern int ust_consumerd64_fd, ust_consumerd32_fd;
36
37 struct ust_app_ht_key {
38 const char *name;
39 const struct lttng_ust_filter_bytecode *filter;
40 enum lttng_ust_loglevel_type loglevel;
41 };
42
43 /*
44 * Application registration data structure.
45 */
46 struct ust_register_msg {
47 uint32_t major;
48 uint32_t minor;
49 pid_t pid;
50 pid_t ppid;
51 uid_t uid;
52 gid_t gid;
53 uint32_t bits_per_long;
54 char name[16];
55 };
56
57 /*
58 * Global applications HT used by the session daemon. This table is indexed by
59 * PID using the pid_n node and pid value of an ust_app.
60 */
61 struct lttng_ht *ust_app_ht;
62
63 /*
64 * Global applications HT used by the session daemon. This table is indexed by
65 * socket using the sock_n node and sock value of an ust_app.
66 */
67 struct lttng_ht *ust_app_ht_by_sock;
68
69 /* Stream list containing ust_app_stream. */
70 struct ust_app_stream_list {
71 unsigned int count;
72 struct cds_list_head head;
73 };
74
75 struct ust_app_ctx {
76 int handle;
77 struct lttng_ust_context ctx;
78 struct lttng_ust_object_data *obj;
79 struct lttng_ht_node_ulong node;
80 };
81
82 struct ust_app_event {
83 int enabled;
84 int handle;
85 struct lttng_ust_object_data *obj;
86 struct lttng_ust_event attr;
87 char name[LTTNG_UST_SYM_NAME_LEN];
88 struct lttng_ht_node_str node;
89 struct lttng_ust_filter_bytecode *filter;
90 };
91
92 struct ust_app_stream {
93 int handle;
94 char pathname[PATH_MAX];
95 /* Format is %s_%d respectively channel name and CPU number. */
96 char name[DEFAULT_STREAM_NAME_LEN];
97 struct lttng_ust_object_data *obj;
98 /* Using a list of streams to keep order. */
99 struct cds_list_head list;
100 struct ustctl_consumer_stream *ustream;
101 };
102
103 struct ust_app_channel {
104 int enabled;
105 int handle;
106 /* Channel and streams were sent to the UST tracer. */
107 int is_sent;
108 /* Unique key used to identify the channel on the consumer side. */
109 unsigned long key;
110 /* Number of stream that this channel is expected to receive. */
111 unsigned int expected_stream_count;
112 char name[LTTNG_UST_SYM_NAME_LEN];
113 struct lttng_ust_object_data *obj;
114 struct ustctl_consumer_channel_attr attr;
115 struct ustctl_consumer_channel *channel;
116 struct ust_app_stream_list streams;
117 struct lttng_ht *ctx;
118 struct lttng_ht *events;
119 struct lttng_ht_node_str node;
120 };
121
122 struct ust_app_session {
123 int enabled;
124 /* started: has the session been in started state at any time ? */
125 int started; /* allows detection of start vs restart. */
126 int handle; /* used has unique identifier for app session */
127 int id; /* session unique identifier */
128 struct ust_app_channel *metadata;
129 struct lttng_ht *channels; /* Registered channels */
130 struct lttng_ht_node_ulong node;
131 char path[PATH_MAX];
132 /* UID/GID of the user owning the session */
133 uid_t uid;
134 gid_t gid;
135 struct cds_list_head teardown_node;
136 /* Universal unique identifier used by the tracer. */
137 unsigned char uuid[UUID_STR_LEN];
138 };
139
140 /*
141 * Registered traceable applications. Libust registers to the session daemon
142 * and a linked list is kept of all running traceable app.
143 */
144 struct ust_app {
145 int sock;
146 pid_t pid;
147 pid_t ppid;
148 uid_t uid; /* User ID that owns the apps */
149 gid_t gid; /* Group ID that owns the apps */
150 int bits_per_long;
151 int compatible; /* If the lttng-ust tracer version does not match the
152 supported version of the session daemon, this flag is
153 set to 0 (NOT compatible) else 1. */
154 struct lttng_ust_tracer_version version;
155 uint32_t v_major; /* Verion major number */
156 uint32_t v_minor; /* Verion minor number */
157 char name[17]; /* Process name (short) */
158 struct lttng_ht *sessions;
159 struct lttng_ht_node_ulong pid_n;
160 struct lttng_ht_node_ulong sock_n;
161 /*
162 * This is a list of ust app session that, once the app is going into
163 * teardown mode, in the RCU call, each node in this list is removed and
164 * deleted.
165 *
166 * Element of the list are added when an application unregisters after each
167 * ht_del of ust_app_session associated to this app. This list is NOT used
168 * when a session is destroyed.
169 */
170 struct cds_list_head teardown_head;
171 };
172
173 #ifdef HAVE_LIBLTTNG_UST_CTL
174
175 int ust_app_register(struct ust_register_msg *msg, int sock);
176 static inline
177 int ust_app_register_done(int sock)
178 {
179 return ustctl_register_done(sock);
180 }
181 void ust_app_unregister(int sock);
182 unsigned long ust_app_list_count(void);
183 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
184 int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
185 int ust_app_start_trace_all(struct ltt_ust_session *usess);
186 int ust_app_stop_trace_all(struct ltt_ust_session *usess);
187 int ust_app_destroy_trace_all(struct ltt_ust_session *usess);
188 int ust_app_list_events(struct lttng_event **events);
189 int ust_app_list_event_fields(struct lttng_event_field **fields);
190 int ust_app_create_channel_glb(struct ltt_ust_session *usess,
191 struct ltt_ust_channel *uchan);
192 int ust_app_create_event_glb(struct ltt_ust_session *usess,
193 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
194 int ust_app_disable_event_pid(struct ltt_ust_session *usess,
195 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
196 pid_t pid);
197 int ust_app_enable_event_pid(struct ltt_ust_session *usess,
198 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
199 pid_t pid);
200 int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
201 struct ltt_ust_channel *uchan);
202 int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
203 struct ltt_ust_channel *uchan);
204 int ust_app_enable_event_glb(struct ltt_ust_session *usess,
205 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
206 int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
207 struct ltt_ust_channel *uchan);
208 int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
209 struct ltt_ust_channel *uchan);
210 int ust_app_disable_event_glb(struct ltt_ust_session *usess,
211 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
212 int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
213 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx);
214 void ust_app_global_update(struct ltt_ust_session *usess, int sock);
215
216 void ust_app_clean_list(void);
217 void ust_app_ht_alloc(void);
218 struct lttng_ht *ust_app_get_ht(void);
219 struct ust_app *ust_app_find_by_pid(pid_t pid);
220 int ust_app_validate_version(int sock);
221 int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate);
222 struct ust_app_stream *ust_app_alloc_stream(void);
223
224 #else /* HAVE_LIBLTTNG_UST_CTL */
225
226 static inline
227 int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
228 {
229 return 0;
230 }
231 static inline
232 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
233 {
234 return 0;
235 }
236 static inline
237 int ust_app_start_trace_all(struct ltt_ust_session *usess)
238 {
239 return 0;
240 }
241 static inline
242 int ust_app_stop_trace_all(struct ltt_ust_session *usess)
243 {
244 return 0;
245 }
246 static inline
247 int ust_app_list_events(struct lttng_event **events)
248 {
249 return -ENOSYS;
250 }
251 static inline
252 int ust_app_list_event_fields(struct lttng_event_field **fields)
253 {
254 return -ENOSYS;
255 }
256 static inline
257 int ust_app_register(struct ust_register_msg *msg, int sock)
258 {
259 return -ENOSYS;
260 }
261 static inline
262 int ust_app_register_done(int sock)
263 {
264 return -ENOSYS;
265 }
266 static inline
267 void ust_app_unregister(int sock)
268 {
269 }
270 static inline
271 unsigned int ust_app_list_count(void)
272 {
273 return 0;
274 }
275 static inline
276 void ust_app_lock_list(void)
277 {
278 }
279 static inline
280 void ust_app_unlock_list(void)
281 {
282 }
283 static inline
284 void ust_app_clean_list(void)
285 {
286 }
287 static inline
288 struct ust_app_list *ust_app_get_list(void)
289 {
290 return NULL;
291 }
292 static inline
293 struct ust_app *ust_app_get_by_pid(pid_t pid)
294 {
295 return NULL;
296 }
297 static inline
298 struct lttng_ht *ust_app_get_ht(void)
299 {
300 return NULL;
301 }
302 static inline
303 void ust_app_ht_alloc(void)
304 {}
305 static inline
306 void ust_app_global_update(struct ltt_ust_session *usess, int sock)
307 {}
308 static inline
309 int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
310 struct ltt_ust_channel *uchan)
311 {
312 return 0;
313 }
314 static inline
315 int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
316 struct ltt_ust_channel *uchan)
317 {
318 return 0;
319 }
320 static inline
321 int ust_app_create_channel_glb(struct ltt_ust_session *usess,
322 struct ltt_ust_channel *uchan)
323 {
324 return 0;
325 }
326 static inline
327 int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
328 struct ltt_ust_channel *uchan)
329 {
330 return 0;
331 }
332 static inline
333 int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
334 struct ltt_ust_channel *uchan)
335 {
336 return 0;
337 }
338 static inline
339 int ust_app_create_event_glb(struct ltt_ust_session *usess,
340 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
341 {
342 return 0;
343 }
344 static inline
345 int ust_app_disable_event_glb(struct ltt_ust_session *usess,
346 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
347 {
348 return 0;
349 }
350 static inline
351 int ust_app_enable_event_glb(struct ltt_ust_session *usess,
352 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
353 {
354 return 0;
355 }
356 static inline
357 int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
358 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx)
359 {
360 return 0;
361 }
362 static inline
363 int ust_app_enable_event_pid(struct ltt_ust_session *usess,
364 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
365 pid_t pid)
366 {
367 return 0;
368 }
369 static inline
370 int ust_app_disable_event_pid(struct ltt_ust_session *usess,
371 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
372 pid_t pid)
373 {
374 return 0;
375 }
376 static inline
377 int ust_app_validate_version(int sock)
378 {
379 return 0;
380 }
381 static inline
382 int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
383 {
384 return 0;
385 }
386
387 #endif /* HAVE_LIBLTTNG_UST_CTL */
388
389 #endif /* _LTT_UST_APP_H */
This page took 0.03699 seconds and 4 git commands to generate.