Move UST registry into sessiond and implement notifiers
[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#include "ust-registry.h"
26
27/* lttng-ust supported version. */
28//#define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
29//#define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
30
31#define UST_APP_EVENT_LIST_SIZE 32
32
33/* Process name (short). Extra for the NULL byte. */
34#define UST_APP_PROCNAME_LEN 17
35
36struct lttng_filter_bytecode;
37struct lttng_ust_filter_bytecode;
38
39extern int ust_consumerd64_fd, ust_consumerd32_fd;
40
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
47/*
48 * Application registration data structure.
49 */
50struct ust_register_msg {
51 enum ustctl_socket_type type;
52 uint32_t major;
53 uint32_t minor;
54 uint32_t abi_major;
55 uint32_t abi_minor;
56 pid_t pid;
57 pid_t ppid;
58 uid_t uid;
59 gid_t gid;
60 uint32_t bits_per_long;
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];
68};
69
70/*
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.
73 */
74struct lttng_ht *ust_app_ht;
75
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;
81
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
88/* Stream list containing ust_app_stream. */
89struct ust_app_stream_list {
90 unsigned int count;
91 struct cds_list_head head;
92};
93
94struct ust_app_ctx {
95 int handle;
96 struct lttng_ust_context ctx;
97 struct lttng_ust_object_data *obj;
98 struct lttng_ht_node_ulong node;
99};
100
101struct ust_app_event {
102 int enabled;
103 int handle;
104 struct lttng_ust_object_data *obj;
105 struct lttng_ust_event attr;
106 char name[LTTNG_UST_SYM_NAME_LEN];
107 struct lttng_ht_node_str node;
108 struct lttng_ust_filter_bytecode *filter;
109};
110
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
121struct ust_app_channel {
122 int enabled;
123 int handle;
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;
130 char name[LTTNG_UST_SYM_NAME_LEN];
131 struct lttng_ust_object_data *obj;
132 struct ustctl_consumer_channel_attr attr;
133 struct ust_app_stream_list streams;
134 /* Session pointer that owns this object. */
135 struct ust_app_session *session;
136 struct lttng_ht *ctx;
137 struct lttng_ht *events;
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 */
145 struct lttng_ht_node_str node;
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;
151};
152
153struct ust_app_session {
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
161 int enabled;
162 /* started: has the session been in started state at any time ? */
163 int started; /* allows detection of start vs restart. */
164 int handle; /* used has unique identifier for app session */
165 int id; /* session unique identifier */
166 struct ust_app_channel *metadata;
167 struct ust_registry_session registry;
168 struct lttng_ht *channels; /* Registered channels */
169 struct lttng_ht_node_ulong node;
170 char path[PATH_MAX];
171 /* UID/GID of the user owning the session */
172 uid_t uid;
173 gid_t gid;
174 struct cds_list_head teardown_node;
175};
176
177/*
178 * Registered traceable applications. Libust registers to the session daemon
179 * and a linked list is kept of all running traceable app.
180 */
181struct ust_app {
182 int sock;
183 int notify_sock;
184 pid_t pid;
185 pid_t ppid;
186 uid_t uid; /* User ID that owns the apps */
187 gid_t gid; /* Group ID that owns the apps */
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
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;
202 uint32_t v_major; /* Version major number */
203 uint32_t v_minor; /* Version minor number */
204 char name[UST_APP_PROCNAME_LEN];
205 struct lttng_ht *sessions;
206 struct lttng_ht_node_ulong pid_n;
207 struct lttng_ht_node_ulong sock_n;
208 struct lttng_ht_node_ulong notify_sock_n;
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;
219 /*
220 * Hash table containing ust_app_channel indexed by channel objd.
221 */
222 struct lttng_ht *ust_objd;
223};
224
225#ifdef HAVE_LIBLTTNG_UST_CTL
226
227int ust_app_register(struct ust_register_msg *msg, int sock);
228static inline
229int ust_app_register_done(int sock)
230{
231 return ustctl_register_done(sock);
232}
233int ust_app_version(struct ust_app *app);
234void ust_app_unregister(int sock);
235unsigned long ust_app_list_count(void);
236int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
237int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
238int ust_app_start_trace_all(struct ltt_ust_session *usess);
239int ust_app_stop_trace_all(struct ltt_ust_session *usess);
240int ust_app_destroy_trace_all(struct ltt_ust_session *usess);
241int ust_app_list_events(struct lttng_event **events);
242int ust_app_list_event_fields(struct lttng_event_field **fields);
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);
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);
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);
253int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
254 struct ltt_ust_channel *uchan);
255int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
256 struct ltt_ust_channel *uchan);
257int ust_app_enable_event_glb(struct ltt_ust_session *usess,
258 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
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,
262 struct ltt_ust_channel *uchan);
263int ust_app_disable_event_glb(struct ltt_ust_session *usess,
264 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
265int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
266 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx);
267void ust_app_global_update(struct ltt_ust_session *usess, int sock);
268
269void ust_app_clean_list(void);
270void ust_app_ht_alloc(void);
271struct lttng_ht *ust_app_get_ht(void);
272struct ust_app *ust_app_find_by_pid(pid_t pid);
273int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate);
274struct ust_app_stream *ust_app_alloc_stream(void);
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);
279
280#else /* HAVE_LIBLTTNG_UST_CTL */
281
282static inline
283int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
284{
285 return 0;
286}
287static inline
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)
294{
295 return 0;
296}
297static inline
298int ust_app_stop_trace_all(struct ltt_ust_session *usess)
299{
300 return 0;
301}
302static inline
303int ust_app_list_events(struct lttng_event **events)
304{
305 return -ENOSYS;
306}
307static inline
308int ust_app_list_event_fields(struct lttng_event_field **fields)
309{
310 return -ENOSYS;
311}
312static inline
313int ust_app_register(struct ust_register_msg *msg, int sock)
314{
315 return -ENOSYS;
316}
317static inline
318int ust_app_register_done(int sock)
319{
320 return -ENOSYS;
321}
322static inline
323int ust_app_version(struct ust_app *app)
324{
325 return -ENOSYS;
326}
327static inline
328void ust_app_unregister(int sock)
329{
330}
331static inline
332unsigned int ust_app_list_count(void)
333{
334 return 0;
335}
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}
358static inline
359struct lttng_ht *ust_app_get_ht(void)
360{
361 return NULL;
362}
363static inline
364void ust_app_ht_alloc(void)
365{}
366static inline
367void ust_app_global_update(struct ltt_ust_session *usess, int sock)
368{}
369static inline
370int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
371 struct ltt_ust_channel *uchan)
372{
373 return 0;
374}
375static inline
376int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
377 struct ltt_ust_channel *uchan)
378{
379 return 0;
380}
381static inline
382int ust_app_create_channel_glb(struct ltt_ust_session *usess,
383 struct ltt_ust_channel *uchan)
384{
385 return 0;
386}
387static inline
388int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
389 struct ltt_ust_channel *uchan)
390{
391 return 0;
392}
393static inline
394int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
395 struct ltt_ust_channel *uchan)
396{
397 return 0;
398}
399static inline
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,
407 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
408{
409 return 0;
410}
411static inline
412int ust_app_enable_event_glb(struct ltt_ust_session *usess,
413 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
414{
415 return 0;
416}
417static inline
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}
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}
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}
437static inline
438int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
439{
440 return 0;
441}
442static inline
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)
449{
450 return 0;
451}
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}
461
462#endif /* HAVE_LIBLTTNG_UST_CTL */
463
464#endif /* _LTT_UST_APP_H */
This page took 0.02468 seconds and 5 git commands to generate.