Move LTTng-UST buffer ownership from application to consumer
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.h
CommitLineData
91d76f53
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
d14d33bf
AM
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.
91d76f53
DG
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 *
d14d33bf
AM
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.
91d76f53
DG
16 */
17
f6a9efaa
DG
18#ifndef _LTT_UST_APP_H
19#define _LTT_UST_APP_H
91d76f53 20
099e26bd 21#include <stdint.h>
1e307fab 22
ffe60014 23#include <common/compat/uuid.h>
44d3bd01
DG
24#include "trace-ust.h"
25
e0c7ec2b 26/* lttng-ust supported version. */
3f2c5fcc 27#define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
68264071 28#define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
e0c7ec2b 29
b551a063
DG
30#define UST_APP_EVENT_LIST_SIZE 32
31
53a80697
MD
32struct lttng_filter_bytecode;
33struct lttng_ust_filter_bytecode;
34
7753dea8 35extern int ust_consumerd64_fd, ust_consumerd32_fd;
ba5d816e 36
18eace3b
DG
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
099e26bd
DG
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;
0df502fd 53 uint32_t bits_per_long;
099e26bd
DG
54 char name[16];
55};
56
48842b30 57/*
852d0037
DG
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.
48842b30 60 */
bec39940 61struct lttng_ht *ust_app_ht;
f6a9efaa 62
852d0037
DG
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;
91d76f53 68
030a66fa
DG
69/* Stream list containing ust_app_stream. */
70struct ust_app_stream_list {
71 unsigned int count;
72 struct cds_list_head head;
73};
74
55cc08a6
DG
75struct ust_app_ctx {
76 int handle;
77 struct lttng_ust_context ctx;
78 struct lttng_ust_object_data *obj;
bec39940 79 struct lttng_ht_node_ulong node;
55cc08a6
DG
80};
81
48842b30
DG
82struct ust_app_event {
83 int enabled;
84 int handle;
13161846 85 struct lttng_ust_object_data *obj;
284d8f55 86 struct lttng_ust_event attr;
48842b30 87 char name[LTTNG_UST_SYM_NAME_LEN];
bec39940 88 struct lttng_ht_node_str node;
53a80697 89 struct lttng_ust_filter_bytecode *filter;
48842b30
DG
90};
91
030a66fa
DG
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;
ffe60014 100 struct ustctl_consumer_stream *ustream;
030a66fa
DG
101};
102
48842b30
DG
103struct ust_app_channel {
104 int enabled;
105 int handle;
ffe60014
DG
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;
48842b30 112 char name[LTTNG_UST_SYM_NAME_LEN];
13161846 113 struct lttng_ust_object_data *obj;
ffe60014
DG
114 struct ustctl_consumer_channel_attr attr;
115 struct ustctl_consumer_channel *channel;
030a66fa 116 struct ust_app_stream_list streams;
bec39940
DG
117 struct lttng_ht *ctx;
118 struct lttng_ht *events;
119 struct lttng_ht_node_str node;
48842b30
DG
120};
121
122struct ust_app_session {
123 int enabled;
8be98f9a
MD
124 /* started: has the session been in started state at any time ? */
125 int started; /* allows detection of start vs restart. */
a991f516
MD
126 int handle; /* used has unique identifier for app session */
127 int id; /* session unique identifier */
ffe60014 128 struct ust_app_channel *metadata;
bec39940
DG
129 struct lttng_ht *channels; /* Registered channels */
130 struct lttng_ht_node_ulong node;
131 char path[PATH_MAX];
6df2e2c9
MD
132 /* UID/GID of the user owning the session */
133 uid_t uid;
134 gid_t gid;
d42f20df 135 struct cds_list_head teardown_node;
ffe60014
DG
136 /* Universal unique identifier used by the tracer. */
137 unsigned char uuid[UUID_STR_LEN];
48842b30
DG
138};
139
f6a9efaa
DG
140/*
141 * Registered traceable applications. Libust registers to the session daemon
050349bb 142 * and a linked list is kept of all running traceable app.
91d76f53 143 */
56fff090 144struct ust_app {
852d0037
DG
145 int sock;
146 pid_t pid;
099e26bd
DG
147 pid_t ppid;
148 uid_t uid; /* User ID that owns the apps */
aea829b3 149 gid_t gid; /* Group ID that owns the apps */
7753dea8 150 int bits_per_long;
e0c7ec2b
DG
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;
099e26bd
DG
155 uint32_t v_major; /* Verion major number */
156 uint32_t v_minor; /* Verion minor number */
157 char name[17]; /* Process name (short) */
bec39940 158 struct lttng_ht *sessions;
852d0037
DG
159 struct lttng_ht_node_ulong pid_n;
160 struct lttng_ht_node_ulong sock_n;
d42f20df
DG
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;
91d76f53
DG
171};
172
74d0b642 173#ifdef HAVE_LIBLTTNG_UST_CTL
3bd1e081 174
56fff090 175int ust_app_register(struct ust_register_msg *msg, int sock);
f2ca2e25
GF
176static inline
177int ust_app_register_done(int sock)
178{
179 return ustctl_register_done(sock);
180}
56fff090 181void ust_app_unregister(int sock);
f6a9efaa 182unsigned long ust_app_list_count(void);
421cb601 183int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
8be98f9a 184int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
421cb601 185int ust_app_start_trace_all(struct ltt_ust_session *usess);
8be98f9a 186int ust_app_stop_trace_all(struct ltt_ust_session *usess);
84cd17c6 187int ust_app_destroy_trace_all(struct ltt_ust_session *usess);
b551a063 188int ust_app_list_events(struct lttng_event **events);
f37d259d 189int ust_app_list_event_fields(struct lttng_event_field **fields);
35a9059d
DG
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);
7f79d3a1
DG
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);
76d45b40
DG
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);
35a9059d 200int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
78f0bacd 201 struct ltt_ust_channel *uchan);
35a9059d 202int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
78f0bacd 203 struct ltt_ust_channel *uchan);
35a9059d 204int ust_app_enable_event_glb(struct ltt_ust_session *usess,
edb67388 205 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
35a9059d
DG
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,
9730260e 209 struct ltt_ust_channel *uchan);
35a9059d
DG
210int ust_app_disable_event_glb(struct ltt_ust_session *usess,
211 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
55cc08a6
DG
212int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
213 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx);
487cf67c 214void ust_app_global_update(struct ltt_ust_session *usess, int sock);
91d76f53 215
56fff090 216void ust_app_clean_list(void);
f6a9efaa 217void ust_app_ht_alloc(void);
bec39940 218struct lttng_ht *ust_app_get_ht(void);
f6a9efaa 219struct ust_app *ust_app_find_by_pid(pid_t pid);
e0c7ec2b 220int ust_app_validate_version(int sock);
4466912f 221int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate);
ffe60014 222struct ust_app_stream *ust_app_alloc_stream(void);
44d3bd01 223
74d0b642 224#else /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 225
cc920def
DG
226static inline
227int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
228{
229 return 0;
230}
d974f197 231static inline
421cb601
DG
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)
d974f197 238{
5cf5d0e7 239 return 0;
d974f197 240}
3bd1e081 241static inline
cc920def
DG
242int ust_app_stop_trace_all(struct ltt_ust_session *usess)
243{
244 return 0;
245}
246static inline
b551a063
DG
247int ust_app_list_events(struct lttng_event **events)
248{
db7c0497 249 return -ENOSYS;
b551a063
DG
250}
251static inline
da0bdb87
MD
252int ust_app_list_event_fields(struct lttng_event_field **fields)
253{
254 return -ENOSYS;
255}
256static inline
3bd1e081
MD
257int ust_app_register(struct ust_register_msg *msg, int sock)
258{
259 return -ENOSYS;
260}
261static inline
f2ca2e25
GF
262int ust_app_register_done(int sock)
263{
264 return -ENOSYS;
265}
266static inline
3bd1e081
MD
267void ust_app_unregister(int sock)
268{
269}
270static inline
271unsigned int ust_app_list_count(void)
272{
273 return 0;
274}
3bd1e081
MD
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}
48842b30 297static inline
bec39940 298struct lttng_ht *ust_app_get_ht(void)
d974f197
DG
299{
300 return NULL;
301}
302static inline
303void ust_app_ht_alloc(void)
cc920def
DG
304{}
305static inline
306void ust_app_global_update(struct ltt_ust_session *usess, int sock)
307{}
308static inline
35a9059d 309int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
cc920def 310 struct ltt_ust_channel *uchan)
d974f197 311{
cc920def 312 return 0;
d974f197 313}
487cf67c 314static inline
35a9059d 315int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
cc920def 316 struct ltt_ust_channel *uchan)
487cf67c 317{
cc920def
DG
318 return 0;
319}
320static inline
35a9059d 321int ust_app_create_channel_glb(struct ltt_ust_session *usess,
cc920def
DG
322 struct ltt_ust_channel *uchan)
323{
324 return 0;
325}
326static inline
35a9059d
DG
327int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
328 struct ltt_ust_channel *uchan)
cc920def
DG
329{
330 return 0;
331}
332static inline
35a9059d 333int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
cc920def
DG
334 struct ltt_ust_channel *uchan)
335{
336 return 0;
337}
338static inline
35a9059d
DG
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,
cc920def
DG
346 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
347{
348 return 0;
487cf67c 349}
edb67388 350static inline
35a9059d 351int ust_app_enable_event_glb(struct ltt_ust_session *usess,
edb67388
DG
352 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
353{
354 return 0;
355}
55cc08a6 356static inline
55cc08a6
DG
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}
76d45b40
DG
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}
7f79d3a1
DG
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}
e0c7ec2b
DG
376static inline
377int ust_app_validate_version(int sock)
378{
379 return 0;
380}
4466912f
DG
381static inline
382int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
383{
384 return 0;
385}
48842b30 386
74d0b642 387#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 388
f6a9efaa 389#endif /* _LTT_UST_APP_H */
This page took 0.050369 seconds and 4 git commands to generate.