Refactoring: use an opaque lttng_tracker_id type
[lttng-tools.git] / src / bin / lttng-sessiond / lttng-sessiond.h
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2013 - Raphaƫl Beamonte <raphael.beamonte@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #ifndef _LTT_SESSIOND_H
20 #define _LTT_SESSIOND_H
21
22 #include <urcu.h>
23 #include <urcu/wfcqueue.h>
24
25 #include <common/sessiond-comm/sessiond-comm.h>
26 #include <common/compat/poll.h>
27 #include <common/compat/socket.h>
28 #include <common/uuid.h>
29
30 #include "session.h"
31 #include "ust-app.h"
32 #include "notification-thread.h"
33 #include "sessiond-config.h"
34
35 /*
36 * Consumer daemon state which is changed when spawning it, killing it or in
37 * case of a fatal error.
38 */
39 enum consumerd_state {
40 CONSUMER_STARTED = 1,
41 CONSUMER_STOPPED = 2,
42 CONSUMER_ERROR = 3,
43 };
44
45 /* Unique identifier of a session daemon instance. */
46 extern lttng_uuid sessiond_uuid;
47
48 /*
49 * This consumer daemon state is used to validate if a client command will be
50 * able to reach the consumer. If not, the client is informed. For instance,
51 * doing a "lttng start" when the consumer state is set to ERROR will return an
52 * error to the client.
53 *
54 * The following example shows a possible race condition of this scheme:
55 *
56 * consumer thread error happens
57 * client cmd arrives
58 * client cmd checks state -> still OK
59 * consumer thread exit, sets error
60 * client cmd try to talk to consumer
61 * ...
62 *
63 * However, since the consumer is a different daemon, we have no way of making
64 * sure the command will reach it safely even with this state flag. This is why
65 * we consider that up to the state validation during command processing, the
66 * command is safe. After that, we can not guarantee the correctness of the
67 * client request vis-a-vis the consumer.
68 */
69 extern enum consumerd_state ust_consumerd_state;
70 extern enum consumerd_state kernel_consumerd_state;
71
72 extern const char default_home_dir[],
73 default_tracing_group[],
74 default_ust_sock_dir[],
75 default_global_apps_pipe[];
76
77 /* Set in main.c at boot time of the daemon */
78 extern struct lttng_kernel_tracer_version kernel_tracer_version;
79 extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version;
80
81 /* Notification thread handle. */
82 extern struct notification_thread_handle *notification_thread_handle;
83
84 /*
85 * This contains extra data needed for processing a command received by the
86 * session daemon from the lttng client.
87 */
88 struct command_ctx {
89 unsigned int lttng_msg_size;
90 struct ltt_session *session;
91 struct lttcomm_lttng_msg *llm;
92 struct lttcomm_session_msg *lsm;
93 lttng_sock_cred creds;
94 };
95
96 struct ust_command {
97 int sock;
98 struct ust_register_msg reg_msg;
99 struct cds_wfcq_node node;
100 };
101
102 /*
103 * Queue used to enqueue UST registration request (ust_command) and synchronized
104 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
105 */
106 struct ust_cmd_queue {
107 int32_t futex;
108 struct cds_wfcq_head head;
109 struct cds_wfcq_tail tail;
110 };
111
112 /*
113 * This is the wait queue containing wait nodes during the application
114 * registration process.
115 */
116 struct ust_reg_wait_queue {
117 unsigned long count;
118 struct cds_list_head head;
119 };
120
121 /*
122 * Use by the dispatch registration to queue UST command socket to wait for the
123 * notify socket.
124 */
125 struct ust_reg_wait_node {
126 struct ust_app *app;
127 struct cds_list_head head;
128 };
129
130 /*
131 * Used to notify that a hash table needs to be destroyed by dedicated
132 * thread. Required by design because we don't want to move destroy
133 * paths outside of large RCU read-side lock paths, and destroy cannot
134 * be called by call_rcu thread, because it may hang (waiting for
135 * call_rcu completion).
136 */
137 extern int ht_cleanup_pipe[2];
138
139 extern int kernel_poll_pipe[2];
140
141 /*
142 * Populated when the daemon starts with the current page size of the system.
143 * Set in main() with the current page size.
144 */
145 extern long page_size;
146
147 /* Application health monitoring */
148 extern struct health_app *health_sessiond;
149
150 extern struct sessiond_config config;
151
152 extern int ust_consumerd64_fd, ust_consumerd32_fd;
153
154 /* Parent PID for --sig-parent option */
155 extern pid_t ppid;
156 /* Internal parent PID use with daemonize. */
157 extern pid_t child_ppid;
158
159 /* Consumer daemon specific control data. */
160 extern struct consumer_data ustconsumer32_data;
161 extern struct consumer_data ustconsumer64_data;
162 extern struct consumer_data kconsumer_data;
163
164 int sessiond_init_thread_quit_pipe(void);
165 int sessiond_check_thread_quit_pipe(int fd, uint32_t events);
166 int sessiond_wait_for_quit_pipe(int timeout_ms);
167 int sessiond_notify_quit_pipe(void);
168 void sessiond_close_quit_pipe(void);
169
170 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
171 void sessiond_signal_parents(void);
172
173 void sessiond_set_client_thread_state(bool running);
174 void sessiond_wait_client_thread_stopped(void);
175
176 void *thread_manage_consumer(void *data);
177
178 #endif /* _LTT_SESSIOND_H */
This page took 0.03315 seconds and 4 git commands to generate.