sessiond: use epoll()/poll() instead of select()
[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/compat/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 int kernel_tracer_fd;
79 extern struct lttng_kernel_tracer_version kernel_tracer_version;
80 extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version;
81
82 /* Notification thread handle. */
83 extern struct notification_thread_handle *notification_thread_handle;
84
85 /*
86 * This contains extra data needed for processing a command received by the
87 * session daemon from the lttng client.
88 */
89 struct command_ctx {
90 unsigned int lttng_msg_size;
91 struct ltt_session *session;
92 struct lttcomm_lttng_msg *llm;
93 struct lttcomm_session_msg *lsm;
94 lttng_sock_cred creds;
95 };
96
97 struct ust_command {
98 int sock;
99 struct ust_register_msg reg_msg;
100 struct cds_wfcq_node node;
101 };
102
103 /*
104 * Queue used to enqueue UST registration request (ust_command) and synchronized
105 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
106 */
107 struct ust_cmd_queue {
108 int32_t futex;
109 struct cds_wfcq_head head;
110 struct cds_wfcq_tail tail;
111 };
112
113 /*
114 * This is the wait queue containing wait nodes during the application
115 * registration process.
116 */
117 struct ust_reg_wait_queue {
118 unsigned long count;
119 struct cds_list_head head;
120 };
121
122 /*
123 * Use by the dispatch registration to queue UST command socket to wait for the
124 * notify socket.
125 */
126 struct ust_reg_wait_node {
127 struct ust_app *app;
128 struct cds_list_head head;
129 };
130
131 /*
132 * Used to notify that a hash table needs to be destroyed by dedicated
133 * thread. Required by design because we don't want to move destroy
134 * paths outside of large RCU read-side lock paths, and destroy cannot
135 * be called by call_rcu thread, because it may hang (waiting for
136 * call_rcu completion).
137 */
138 extern int ht_cleanup_pipe[2];
139
140 extern int kernel_poll_pipe[2];
141
142 /*
143 * Populated when the daemon starts with the current page size of the system.
144 * Set in main() with the current page size.
145 */
146 extern long page_size;
147
148 /* Application health monitoring */
149 extern struct health_app *health_sessiond;
150
151 extern struct sessiond_config config;
152
153 extern int ust_consumerd64_fd, ust_consumerd32_fd;
154
155 /* Parent PID for --sig-parent option */
156 extern pid_t ppid;
157 /* Internal parent PID use with daemonize. */
158 extern pid_t child_ppid;
159
160 /* Consumer daemon specific control data. */
161 extern struct consumer_data ustconsumer32_data;
162 extern struct consumer_data ustconsumer64_data;
163 extern struct consumer_data kconsumer_data;
164
165 int sessiond_init_thread_quit_pipe(void);
166 int sessiond_check_thread_quit_pipe(int fd, uint32_t events);
167 int sessiond_wait_for_quit_pipe(int timeout_ms);
168 int sessiond_notify_quit_pipe(void);
169 void sessiond_close_quit_pipe(void);
170
171 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
172 void sessiond_signal_parents(void);
173
174 void sessiond_set_client_thread_state(bool running);
175 void sessiond_wait_client_thread_stopped(void);
176
177 void *thread_manage_consumer(void *data);
178
179 #endif /* _LTT_SESSIOND_H */
This page took 0.047983 seconds and 4 git commands to generate.