Move LTTng-UST buffer ownership from application to consumer
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.h
... / ...
CommitLineData
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
32struct lttng_filter_bytecode;
33struct lttng_ust_filter_bytecode;
34
35extern int ust_consumerd64_fd, ust_consumerd32_fd;
36
37struct 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 */
46struct 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 */
61struct 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 */
67struct lttng_ht *ust_app_ht_by_sock;
68
69/* Stream list containing ust_app_stream. */
70struct ust_app_stream_list {
71 unsigned int count;
72 struct cds_list_head head;
73};
74
75struct 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
82struct 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
92struct 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
103struct 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
122struct 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 */
144struct 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
175int ust_app_register(struct ust_register_msg *msg, int sock);
176static inline
177int ust_app_register_done(int sock)
178{
179 return ustctl_register_done(sock);
180}
181void ust_app_unregister(int sock);
182unsigned long ust_app_list_count(void);
183int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
184int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
185int ust_app_start_trace_all(struct ltt_ust_session *usess);
186int ust_app_stop_trace_all(struct ltt_ust_session *usess);
187int ust_app_destroy_trace_all(struct ltt_ust_session *usess);
188int ust_app_list_events(struct lttng_event **events);
189int ust_app_list_event_fields(struct lttng_event_field **fields);
190int ust_app_create_channel_glb(struct ltt_ust_session *usess,
191 struct ltt_ust_channel *uchan);
192int ust_app_create_event_glb(struct ltt_ust_session *usess,
193 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
194int 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);
197int 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);
200int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
201 struct ltt_ust_channel *uchan);
202int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
203 struct ltt_ust_channel *uchan);
204int ust_app_enable_event_glb(struct ltt_ust_session *usess,
205 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
206int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
207 struct ltt_ust_channel *uchan);
208int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
209 struct ltt_ust_channel *uchan);
210int ust_app_disable_event_glb(struct ltt_ust_session *usess,
211 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
212int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
213 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx);
214void ust_app_global_update(struct ltt_ust_session *usess, int sock);
215
216void ust_app_clean_list(void);
217void ust_app_ht_alloc(void);
218struct lttng_ht *ust_app_get_ht(void);
219struct ust_app *ust_app_find_by_pid(pid_t pid);
220int ust_app_validate_version(int sock);
221int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate);
222struct ust_app_stream *ust_app_alloc_stream(void);
223
224#else /* HAVE_LIBLTTNG_UST_CTL */
225
226static inline
227int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
228{
229 return 0;
230}
231static inline
232int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
233{
234 return 0;
235}
236static inline
237int ust_app_start_trace_all(struct ltt_ust_session *usess)
238{
239 return 0;
240}
241static inline
242int ust_app_stop_trace_all(struct ltt_ust_session *usess)
243{
244 return 0;
245}
246static inline
247int ust_app_list_events(struct lttng_event **events)
248{
249 return -ENOSYS;
250}
251static inline
252int ust_app_list_event_fields(struct lttng_event_field **fields)
253{
254 return -ENOSYS;
255}
256static inline
257int ust_app_register(struct ust_register_msg *msg, int sock)
258{
259 return -ENOSYS;
260}
261static inline
262int ust_app_register_done(int sock)
263{
264 return -ENOSYS;
265}
266static inline
267void ust_app_unregister(int sock)
268{
269}
270static inline
271unsigned int ust_app_list_count(void)
272{
273 return 0;
274}
275static inline
276void ust_app_lock_list(void)
277{
278}
279static inline
280void ust_app_unlock_list(void)
281{
282}
283static inline
284void ust_app_clean_list(void)
285{
286}
287static inline
288struct ust_app_list *ust_app_get_list(void)
289{
290 return NULL;
291}
292static inline
293struct ust_app *ust_app_get_by_pid(pid_t pid)
294{
295 return NULL;
296}
297static inline
298struct lttng_ht *ust_app_get_ht(void)
299{
300 return NULL;
301}
302static inline
303void ust_app_ht_alloc(void)
304{}
305static inline
306void ust_app_global_update(struct ltt_ust_session *usess, int sock)
307{}
308static inline
309int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
310 struct ltt_ust_channel *uchan)
311{
312 return 0;
313}
314static inline
315int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
316 struct ltt_ust_channel *uchan)
317{
318 return 0;
319}
320static inline
321int ust_app_create_channel_glb(struct ltt_ust_session *usess,
322 struct ltt_ust_channel *uchan)
323{
324 return 0;
325}
326static inline
327int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
328 struct ltt_ust_channel *uchan)
329{
330 return 0;
331}
332static inline
333int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
334 struct ltt_ust_channel *uchan)
335{
336 return 0;
337}
338static inline
339int 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}
344static inline
345int 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}
350static inline
351int 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}
356static inline
357int 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}
362static inline
363int 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}
369static inline
370int 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}
376static inline
377int ust_app_validate_version(int sock)
378{
379 return 0;
380}
381static inline
382int 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.025507 seconds and 5 git commands to generate.