Commit | Line | Data |
---|---|---|
8c0faa1d DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
88564da0 | 3 | * Copyright (C) 2013 - Raphaël Beamonte <raphael.beamonte@gmail.com> |
fac6795d | 4 | * |
d14d33bf AM |
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. | |
8c0faa1d | 8 | * |
fac6795d DG |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
d14d33bf | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fac6795d | 12 | * GNU General Public License for more details. |
8c0faa1d | 13 | * |
d14d33bf AM |
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. | |
fac6795d DG |
17 | */ |
18 | ||
19 | #ifndef _LTT_SESSIOND_H | |
20 | #define _LTT_SESSIOND_H | |
21 | ||
f6a9efaa | 22 | #include <urcu.h> |
8bdee6e2 | 23 | #include <urcu/wfcqueue.h> |
099e26bd | 24 | |
10a8a223 | 25 | #include <common/sessiond-comm/sessiond-comm.h> |
d0b96690 | 26 | #include <common/compat/poll.h> |
730389d9 | 27 | #include <common/compat/socket.h> |
52a0e931 | 28 | #include <common/compat/uuid.h> |
10a8a223 DG |
29 | |
30 | #include "session.h" | |
56fff090 | 31 | #include "ust-app.h" |
e9404c27 | 32 | #include "notification-thread.h" |
e6142f2e | 33 | #include "sessiond-config.h" |
099e26bd | 34 | |
917a718d JG |
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 | ||
52a0e931 JG |
45 | /* Unique identifier of a session daemon instance. */ |
46 | extern lttng_uuid sessiond_uuid; | |
47 | ||
917a718d JG |
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 | ||
686204ab MD |
72 | extern const char default_home_dir[], |
73 | default_tracing_group[], | |
74 | default_ust_sock_dir[], | |
75 | default_global_apps_pipe[]; | |
fac6795d | 76 | |
2f77fc4b | 77 | /* Set in main.c at boot time of the daemon */ |
917a718d JG |
78 | extern struct lttng_kernel_tracer_version kernel_tracer_version; |
79 | extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version; | |
2f77fc4b | 80 | |
a7333da7 | 81 | /* Notification thread handle. */ |
e9404c27 JG |
82 | extern struct notification_thread_handle *notification_thread_handle; |
83 | ||
5461b305 DG |
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 { | |
5461b305 DG |
89 | unsigned int lttng_msg_size; |
90 | struct ltt_session *session; | |
91 | struct lttcomm_lttng_msg *llm; | |
92 | struct lttcomm_session_msg *lsm; | |
730389d9 | 93 | lttng_sock_cred creds; |
5461b305 DG |
94 | }; |
95 | ||
099e26bd DG |
96 | struct ust_command { |
97 | int sock; | |
98 | struct ust_register_msg reg_msg; | |
8bdee6e2 | 99 | struct cds_wfcq_node node; |
099e26bd DG |
100 | }; |
101 | ||
102 | /* | |
7a44d6f1 | 103 | * Queue used to enqueue UST registration request (ust_command) and synchronized |
099e26bd DG |
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; | |
8bdee6e2 SM |
108 | struct cds_wfcq_head head; |
109 | struct cds_wfcq_tail tail; | |
099e26bd DG |
110 | }; |
111 | ||
f45e313d DG |
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 | ||
0b2dc8df MD |
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 | ||
e32d7f27 JG |
139 | extern int kernel_poll_pipe[2]; |
140 | ||
12744796 DG |
141 | /* |
142 | * Populated when the daemon starts with the current page size of the system. | |
a7333da7 | 143 | * Set in main() with the current page size. |
12744796 DG |
144 | */ |
145 | extern long page_size; | |
146 | ||
5e97de00 JG |
147 | /* Application health monitoring */ |
148 | extern struct health_app *health_sessiond; | |
149 | ||
a7333da7 | 150 | extern struct sessiond_config config; |
26296c48 | 151 | |
a7333da7 JG |
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; | |
e9404c27 | 158 | |
917a718d JG |
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 | ||
a7333da7 | 164 | int sessiond_init_thread_quit_pipe(void); |
d0b96690 | 165 | int sessiond_check_thread_quit_pipe(int fd, uint32_t events); |
2d54bfb6 | 166 | int sessiond_wait_for_quit_pipe(int timeout_ms); |
a7333da7 JG |
167 | int sessiond_notify_quit_pipe(void); |
168 | void sessiond_close_quit_pipe(void); | |
169 | ||
5e97de00 | 170 | int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size); |
9cc1ba3b | 171 | void sessiond_signal_parents(void); |
ef367a93 | 172 | |
99d688f2 JG |
173 | void sessiond_set_client_thread_state(bool running); |
174 | void sessiond_wait_client_thread_stopped(void); | |
175 | ||
917a718d JG |
176 | void *thread_manage_consumer(void *data); |
177 | ||
fac6795d | 178 | #endif /* _LTT_SESSIOND_H */ |