2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2013 - Raphaƫl Beamonte <raphael.beamonte@gmail.com>
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.
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.
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.
19 #ifndef _LTT_SESSIOND_H
20 #define _LTT_SESSIOND_H
23 #include <urcu/wfcqueue.h>
25 #include <common/sessiond-comm/sessiond-comm.h>
26 #include <common/compat/poll.h>
27 #include <common/compat/socket.h>
31 #include "notification-thread.h"
32 #include "sessiond-config.h"
35 * Consumer daemon state which is changed when spawning it, killing it or in
36 * case of a fatal error.
38 enum consumerd_state
{
45 * This consumer daemon state is used to validate if a client command will be
46 * able to reach the consumer. If not, the client is informed. For instance,
47 * doing a "lttng start" when the consumer state is set to ERROR will return an
48 * error to the client.
50 * The following example shows a possible race condition of this scheme:
52 * consumer thread error happens
54 * client cmd checks state -> still OK
55 * consumer thread exit, sets error
56 * client cmd try to talk to consumer
59 * However, since the consumer is a different daemon, we have no way of making
60 * sure the command will reach it safely even with this state flag. This is why
61 * we consider that up to the state validation during command processing, the
62 * command is safe. After that, we can not guarantee the correctness of the
63 * client request vis-a-vis the consumer.
65 extern enum consumerd_state ust_consumerd_state
;
66 extern enum consumerd_state kernel_consumerd_state
;
68 extern const char default_home_dir
[],
69 default_tracing_group
[],
70 default_ust_sock_dir
[],
71 default_global_apps_pipe
[];
73 /* Set in main.c at boot time of the daemon */
74 extern int kernel_tracer_fd
;
75 extern struct lttng_kernel_tracer_version kernel_tracer_version
;
76 extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version
;
78 /* Notification thread handle. */
79 extern struct notification_thread_handle
*notification_thread_handle
;
82 * This contains extra data needed for processing a command received by the
83 * session daemon from the lttng client.
87 unsigned int lttng_msg_size
;
88 struct ltt_session
*session
;
89 struct lttcomm_lttng_msg
*llm
;
90 struct lttcomm_session_msg
*lsm
;
91 lttng_sock_cred creds
;
96 struct ust_register_msg reg_msg
;
97 struct cds_wfcq_node node
;
101 * Queue used to enqueue UST registration request (ust_command) and synchronized
102 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
104 struct ust_cmd_queue
{
106 struct cds_wfcq_head head
;
107 struct cds_wfcq_tail tail
;
111 * This is the wait queue containing wait nodes during the application
112 * registration process.
114 struct ust_reg_wait_queue
{
116 struct cds_list_head head
;
120 * Use by the dispatch registration to queue UST command socket to wait for the
123 struct ust_reg_wait_node
{
125 struct cds_list_head head
;
129 * Used to notify that a hash table needs to be destroyed by dedicated
130 * thread. Required by design because we don't want to move destroy
131 * paths outside of large RCU read-side lock paths, and destroy cannot
132 * be called by call_rcu thread, because it may hang (waiting for
133 * call_rcu completion).
135 extern int ht_cleanup_pipe
[2];
137 extern int kernel_poll_pipe
[2];
140 * Populated when the daemon starts with the current page size of the system.
141 * Set in main() with the current page size.
143 extern long page_size
;
145 /* Application health monitoring */
146 extern struct health_app
*health_sessiond
;
148 extern struct sessiond_config config
;
150 extern int ust_consumerd64_fd
, ust_consumerd32_fd
;
152 /* Parent PID for --sig-parent option */
154 /* Internal parent PID use with daemonize. */
155 extern pid_t child_ppid
;
157 /* Consumer daemon specific control data. */
158 extern struct consumer_data ustconsumer32_data
;
159 extern struct consumer_data ustconsumer64_data
;
160 extern struct consumer_data kconsumer_data
;
162 int sessiond_init_thread_quit_pipe(void);
163 int sessiond_check_thread_quit_pipe(int fd
, uint32_t events
);
164 int sessiond_wait_for_quit_pipe(unsigned int timeout_us
);
165 int sessiond_notify_quit_pipe(void);
166 void sessiond_close_quit_pipe(void);
168 int sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
);
169 void sessiond_signal_parents(void);
171 void sessiond_set_client_thread_state(bool running
);
172 void sessiond_wait_client_thread_stopped(void);
174 void *thread_manage_consumer(void *data
);
176 #endif /* _LTT_SESSIOND_H */