Move UST registry into sessiond and implement notifiers
[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 24#include "trace-ust.h"
d0b96690 25#include "ust-registry.h"
44d3bd01 26
e0c7ec2b 27/* lttng-ust supported version. */
d0b96690
DG
28//#define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
29//#define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
e0c7ec2b 30
b551a063
DG
31#define UST_APP_EVENT_LIST_SIZE 32
32
d0b96690
DG
33/* Process name (short). Extra for the NULL byte. */
34#define UST_APP_PROCNAME_LEN 17
35
53a80697
MD
36struct lttng_filter_bytecode;
37struct lttng_ust_filter_bytecode;
38
7753dea8 39extern int ust_consumerd64_fd, ust_consumerd32_fd;
ba5d816e 40
18eace3b
DG
41struct ust_app_ht_key {
42 const char *name;
43 const struct lttng_ust_filter_bytecode *filter;
44 enum lttng_ust_loglevel_type loglevel;
45};
46
099e26bd
DG
47/*
48 * Application registration data structure.
49 */
50struct ust_register_msg {
d0b96690 51 enum ustctl_socket_type type;
099e26bd
DG
52 uint32_t major;
53 uint32_t minor;
d0b96690
DG
54 uint32_t abi_major;
55 uint32_t abi_minor;
099e26bd
DG
56 pid_t pid;
57 pid_t ppid;
58 uid_t uid;
59 gid_t gid;
0df502fd 60 uint32_t bits_per_long;
d0b96690
DG
61 uint32_t uint8_t_alignment;
62 uint32_t uint16_t_alignment;
63 uint32_t uint32_t_alignment;
64 uint32_t uint64_t_alignment;
65 uint32_t long_alignment;
66 int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */
67 char name[LTTNG_UST_ABI_PROCNAME_LEN];
099e26bd
DG
68};
69
48842b30 70/*
852d0037
DG
71 * Global applications HT used by the session daemon. This table is indexed by
72 * PID using the pid_n node and pid value of an ust_app.
48842b30 73 */
bec39940 74struct lttng_ht *ust_app_ht;
f6a9efaa 75
852d0037
DG
76/*
77 * Global applications HT used by the session daemon. This table is indexed by
78 * socket using the sock_n node and sock value of an ust_app.
79 */
80struct lttng_ht *ust_app_ht_by_sock;
91d76f53 81
d0b96690
DG
82/*
83 * Global applications HT used by the session daemon. This table is indexed by
84 * socket using the notify_sock_n node and notify_sock value of an ust_app.
85 */
86struct lttng_ht *ust_app_ht_by_notify_sock;
87
030a66fa
DG
88/* Stream list containing ust_app_stream. */
89struct ust_app_stream_list {
90 unsigned int count;
91 struct cds_list_head head;
92};
93
55cc08a6
DG
94struct ust_app_ctx {
95 int handle;
96 struct lttng_ust_context ctx;
97 struct lttng_ust_object_data *obj;
bec39940 98 struct lttng_ht_node_ulong node;
55cc08a6
DG
99};
100
48842b30
DG
101struct ust_app_event {
102 int enabled;
103 int handle;
13161846 104 struct lttng_ust_object_data *obj;
284d8f55 105 struct lttng_ust_event attr;
48842b30 106 char name[LTTNG_UST_SYM_NAME_LEN];
bec39940 107 struct lttng_ht_node_str node;
53a80697 108 struct lttng_ust_filter_bytecode *filter;
48842b30
DG
109};
110
030a66fa
DG
111struct ust_app_stream {
112 int handle;
113 char pathname[PATH_MAX];
114 /* Format is %s_%d respectively channel name and CPU number. */
115 char name[DEFAULT_STREAM_NAME_LEN];
116 struct lttng_ust_object_data *obj;
117 /* Using a list of streams to keep order. */
118 struct cds_list_head list;
119};
120
48842b30
DG
121struct ust_app_channel {
122 int enabled;
123 int handle;
ffe60014
DG
124 /* Channel and streams were sent to the UST tracer. */
125 int is_sent;
126 /* Unique key used to identify the channel on the consumer side. */
127 unsigned long key;
128 /* Number of stream that this channel is expected to receive. */
129 unsigned int expected_stream_count;
48842b30 130 char name[LTTNG_UST_SYM_NAME_LEN];
13161846 131 struct lttng_ust_object_data *obj;
ffe60014 132 struct ustctl_consumer_channel_attr attr;
030a66fa 133 struct ust_app_stream_list streams;
d0b96690
DG
134 /* Session pointer that owns this object. */
135 struct ust_app_session *session;
bec39940
DG
136 struct lttng_ht *ctx;
137 struct lttng_ht *events;
d0b96690
DG
138 /*
139 * UST event registry. The ONLY writer is the application thread.
140 */
141 struct ust_registry_channel registry;
142 /*
143 * Node indexed by channel name in the channels' hash table of a session.
144 */
bec39940 145 struct lttng_ht_node_str node;
d0b96690
DG
146 /*
147 * Node indexed by UST channel object descriptor (handle). Stored in the
148 * ust_objd hash table in the ust_app object.
149 */
150 struct lttng_ht_node_ulong ust_objd_node;
48842b30
DG
151};
152
153struct ust_app_session {
d0b96690
DG
154 /*
155 * Lock protecting this session's ust app interaction. Held
156 * across command send/recv to/from app. Never nests within the
157 * session registry lock.
158 */
159 pthread_mutex_t lock;
160
48842b30 161 int enabled;
8be98f9a
MD
162 /* started: has the session been in started state at any time ? */
163 int started; /* allows detection of start vs restart. */
a991f516
MD
164 int handle; /* used has unique identifier for app session */
165 int id; /* session unique identifier */
ffe60014 166 struct ust_app_channel *metadata;
d0b96690 167 struct ust_registry_session registry;
bec39940
DG
168 struct lttng_ht *channels; /* Registered channels */
169 struct lttng_ht_node_ulong node;
170 char path[PATH_MAX];
6df2e2c9
MD
171 /* UID/GID of the user owning the session */
172 uid_t uid;
173 gid_t gid;
d42f20df 174 struct cds_list_head teardown_node;
48842b30
DG
175};
176
f6a9efaa
DG
177/*
178 * Registered traceable applications. Libust registers to the session daemon
050349bb 179 * and a linked list is kept of all running traceable app.
91d76f53 180 */
56fff090 181struct ust_app {
852d0037 182 int sock;
d0b96690 183 int notify_sock;
852d0037 184 pid_t pid;
099e26bd
DG
185 pid_t ppid;
186 uid_t uid; /* User ID that owns the apps */
aea829b3 187 gid_t gid; /* Group ID that owns the apps */
d0b96690
DG
188
189 /* App ABI */
190 uint32_t bits_per_long;
191 uint32_t uint8_t_alignment;
192 uint32_t uint16_t_alignment;
193 uint32_t uint32_t_alignment;
194 uint32_t uint64_t_alignment;
195 uint32_t long_alignment;
196 int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */
197
e0c7ec2b
DG
198 int compatible; /* If the lttng-ust tracer version does not match the
199 supported version of the session daemon, this flag is
200 set to 0 (NOT compatible) else 1. */
201 struct lttng_ust_tracer_version version;
d0b96690
DG
202 uint32_t v_major; /* Version major number */
203 uint32_t v_minor; /* Version minor number */
204 char name[UST_APP_PROCNAME_LEN];
bec39940 205 struct lttng_ht *sessions;
852d0037
DG
206 struct lttng_ht_node_ulong pid_n;
207 struct lttng_ht_node_ulong sock_n;
d0b96690 208 struct lttng_ht_node_ulong notify_sock_n;
d42f20df
DG
209 /*
210 * This is a list of ust app session that, once the app is going into
211 * teardown mode, in the RCU call, each node in this list is removed and
212 * deleted.
213 *
214 * Element of the list are added when an application unregisters after each
215 * ht_del of ust_app_session associated to this app. This list is NOT used
216 * when a session is destroyed.
217 */
218 struct cds_list_head teardown_head;
d0b96690
DG
219 /*
220 * Hash table containing ust_app_channel indexed by channel objd.
221 */
222 struct lttng_ht *ust_objd;
91d76f53
DG
223};
224
74d0b642 225#ifdef HAVE_LIBLTTNG_UST_CTL
3bd1e081 226
56fff090 227int ust_app_register(struct ust_register_msg *msg, int sock);
f2ca2e25
GF
228static inline
229int ust_app_register_done(int sock)
230{
231 return ustctl_register_done(sock);
232}
d0b96690 233int ust_app_version(struct ust_app *app);
56fff090 234void ust_app_unregister(int sock);
f6a9efaa 235unsigned long ust_app_list_count(void);
421cb601 236int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
8be98f9a 237int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
421cb601 238int ust_app_start_trace_all(struct ltt_ust_session *usess);
8be98f9a 239int ust_app_stop_trace_all(struct ltt_ust_session *usess);
84cd17c6 240int ust_app_destroy_trace_all(struct ltt_ust_session *usess);
b551a063 241int ust_app_list_events(struct lttng_event **events);
f37d259d 242int ust_app_list_event_fields(struct lttng_event_field **fields);
35a9059d
DG
243int ust_app_create_channel_glb(struct ltt_ust_session *usess,
244 struct ltt_ust_channel *uchan);
245int ust_app_create_event_glb(struct ltt_ust_session *usess,
246 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
7f79d3a1
DG
247int ust_app_disable_event_pid(struct ltt_ust_session *usess,
248 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
249 pid_t pid);
76d45b40
DG
250int ust_app_enable_event_pid(struct ltt_ust_session *usess,
251 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
252 pid_t pid);
35a9059d 253int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
78f0bacd 254 struct ltt_ust_channel *uchan);
35a9059d 255int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
78f0bacd 256 struct ltt_ust_channel *uchan);
35a9059d 257int ust_app_enable_event_glb(struct ltt_ust_session *usess,
edb67388 258 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
35a9059d
DG
259int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
260 struct ltt_ust_channel *uchan);
261int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
9730260e 262 struct ltt_ust_channel *uchan);
35a9059d
DG
263int ust_app_disable_event_glb(struct ltt_ust_session *usess,
264 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
55cc08a6
DG
265int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
266 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx);
487cf67c 267void ust_app_global_update(struct ltt_ust_session *usess, int sock);
91d76f53 268
56fff090 269void ust_app_clean_list(void);
f6a9efaa 270void ust_app_ht_alloc(void);
bec39940 271struct lttng_ht *ust_app_get_ht(void);
f6a9efaa 272struct ust_app *ust_app_find_by_pid(pid_t pid);
4466912f 273int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate);
ffe60014 274struct ust_app_stream *ust_app_alloc_stream(void);
d0b96690
DG
275int ust_app_recv_registration(int sock, struct ust_register_msg *msg);
276int ust_app_recv_notify(int sock);
277void ust_app_add(struct ust_app *app);
278struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock);
44d3bd01 279
74d0b642 280#else /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 281
cc920def
DG
282static inline
283int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
284{
285 return 0;
286}
d974f197 287static inline
421cb601
DG
288int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
289{
290 return 0;
291}
292static inline
293int ust_app_start_trace_all(struct ltt_ust_session *usess)
d974f197 294{
5cf5d0e7 295 return 0;
d974f197 296}
3bd1e081 297static inline
cc920def
DG
298int ust_app_stop_trace_all(struct ltt_ust_session *usess)
299{
300 return 0;
301}
302static inline
b551a063
DG
303int ust_app_list_events(struct lttng_event **events)
304{
db7c0497 305 return -ENOSYS;
b551a063
DG
306}
307static inline
da0bdb87
MD
308int ust_app_list_event_fields(struct lttng_event_field **fields)
309{
310 return -ENOSYS;
311}
312static inline
3bd1e081
MD
313int ust_app_register(struct ust_register_msg *msg, int sock)
314{
315 return -ENOSYS;
316}
317static inline
f2ca2e25
GF
318int ust_app_register_done(int sock)
319{
320 return -ENOSYS;
321}
322static inline
d0b96690
DG
323int ust_app_version(struct ust_app *app)
324{
325 return -ENOSYS;
326}
327static inline
3bd1e081
MD
328void ust_app_unregister(int sock)
329{
330}
331static inline
332unsigned int ust_app_list_count(void)
333{
334 return 0;
335}
3bd1e081
MD
336static inline
337void ust_app_lock_list(void)
338{
339}
340static inline
341void ust_app_unlock_list(void)
342{
343}
344static inline
345void ust_app_clean_list(void)
346{
347}
348static inline
349struct ust_app_list *ust_app_get_list(void)
350{
351 return NULL;
352}
353static inline
354struct ust_app *ust_app_get_by_pid(pid_t pid)
355{
356 return NULL;
357}
48842b30 358static inline
bec39940 359struct lttng_ht *ust_app_get_ht(void)
d974f197
DG
360{
361 return NULL;
362}
363static inline
364void ust_app_ht_alloc(void)
cc920def
DG
365{}
366static inline
367void ust_app_global_update(struct ltt_ust_session *usess, int sock)
368{}
369static inline
35a9059d 370int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
cc920def 371 struct ltt_ust_channel *uchan)
d974f197 372{
cc920def 373 return 0;
d974f197 374}
487cf67c 375static inline
35a9059d 376int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
cc920def 377 struct ltt_ust_channel *uchan)
487cf67c 378{
cc920def
DG
379 return 0;
380}
381static inline
35a9059d 382int ust_app_create_channel_glb(struct ltt_ust_session *usess,
cc920def
DG
383 struct ltt_ust_channel *uchan)
384{
385 return 0;
386}
387static inline
35a9059d
DG
388int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
389 struct ltt_ust_channel *uchan)
cc920def
DG
390{
391 return 0;
392}
393static inline
35a9059d 394int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
cc920def
DG
395 struct ltt_ust_channel *uchan)
396{
397 return 0;
398}
399static inline
35a9059d
DG
400int ust_app_create_event_glb(struct ltt_ust_session *usess,
401 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
402{
403 return 0;
404}
405static inline
406int ust_app_disable_event_glb(struct ltt_ust_session *usess,
cc920def
DG
407 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
408{
409 return 0;
487cf67c 410}
edb67388 411static inline
35a9059d 412int ust_app_enable_event_glb(struct ltt_ust_session *usess,
edb67388
DG
413 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
414{
415 return 0;
416}
55cc08a6 417static inline
55cc08a6
DG
418int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
419 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx)
420{
421 return 0;
422}
76d45b40
DG
423static inline
424int ust_app_enable_event_pid(struct ltt_ust_session *usess,
425 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
426 pid_t pid)
427{
428 return 0;
429}
7f79d3a1
DG
430static inline
431int ust_app_disable_event_pid(struct ltt_ust_session *usess,
432 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
433 pid_t pid)
434{
435 return 0;
436}
e0c7ec2b 437static inline
d0b96690 438int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
e0c7ec2b
DG
439{
440 return 0;
441}
4466912f 442static inline
d0b96690
DG
443int ust_app_recv_registration(int sock, struct ust_register_msg *msg)
444{
445 return 0;
446}
447static inline
448int ust_app_recv_notify(int sock)
4466912f
DG
449{
450 return 0;
451}
d0b96690
DG
452static inline
453struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock)
454{
455 return NULL;
456}
457static inline
458void ust_app_add(struct ust_app *app)
459{
460}
48842b30 461
74d0b642 462#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 463
f6a9efaa 464#endif /* _LTT_UST_APP_H */
This page took 0.09668 seconds and 5 git commands to generate.