2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2013 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #ifndef _LTT_SESSIOND_H
10 #define _LTT_SESSIOND_H
12 #include "notification-thread.hpp"
13 #include "rotation-thread.hpp"
14 #include "session.hpp"
15 #include "sessiond-config.hpp"
16 #include "ust-app.hpp"
18 #include <common/compat/poll.hpp>
19 #include <common/compat/socket.hpp>
20 #include <common/payload.hpp>
21 #include <common/sessiond-comm/sessiond-comm.hpp>
22 #include <common/uuid.hpp>
25 #include <urcu/wfcqueue.h>
28 * Consumer daemon state which is changed when spawning it, killing it or in
29 * case of a fatal error.
31 enum consumerd_state {
37 /* Unique identifier of a session daemon instance. */
38 extern lttng_uuid the_sessiond_uuid;
41 * This consumer daemon state is used to validate if a client command will be
42 * able to reach the consumer. If not, the client is informed. For instance,
43 * doing a "lttng start" when the consumer state is set to ERROR will return an
44 * error to the client.
46 * The following example shows a possible race condition of this scheme:
48 * consumer thread error happens
50 * client cmd checks state -> still OK
51 * consumer thread exit, sets error
52 * client cmd try to talk to consumer
55 * However, since the consumer is a different daemon, we have no way of making
56 * sure the command will reach it safely even with this state flag. This is why
57 * we consider that up to the state validation during command processing, the
58 * command is safe. After that, we can not guarantee the correctness of the
59 * client request vis-a-vis the consumer.
61 extern enum consumerd_state the_ust_consumerd_state;
62 extern enum consumerd_state the_kernel_consumerd_state;
64 /* Set in main.c at boot time of the daemon */
65 extern struct lttng_kernel_abi_tracer_version the_kernel_tracer_version;
66 extern struct lttng_kernel_abi_tracer_abi_version the_kernel_tracer_abi_version;
68 /* Notification thread handle. */
69 extern struct notification_thread_handle *the_notification_thread_handle;
71 /* Rotation thread handle. */
72 extern lttng::sessiond::rotation_thread::uptr the_rotation_thread_handle;
75 * This contains extra data needed for processing a command received by the
76 * session daemon from the lttng client.
79 unsigned int lttng_msg_size;
80 struct ltt_session *session;
82 struct lttcomm_session_msg lsm;
83 /* Reply content, starts with an lttcomm_lttng_msg header. */
84 struct lttng_payload reply_payload;
85 lttng_sock_cred creds;
90 struct ust_register_msg reg_msg;
91 struct cds_wfcq_node node;
95 * Queue used to enqueue UST registration request (ust_command) and synchronized
96 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
98 struct ust_cmd_queue {
100 struct cds_wfcq_head head;
101 struct cds_wfcq_tail tail;
105 * This is the wait queue containing wait nodes during the application
106 * registration process.
108 struct ust_reg_wait_queue {
110 struct cds_list_head head;
114 * Use by the dispatch registration to queue UST command socket to wait for the
117 struct ust_reg_wait_node {
119 struct cds_list_head head;
122 extern int the_kernel_poll_pipe[2];
125 * Populated when the daemon starts with the current page size of the system.
126 * Set in main() with the current page size.
128 extern long the_page_size;
130 /* Application health monitoring */
131 extern struct health_app *the_health_sessiond;
133 extern struct sessiond_config the_config;
135 extern int the_ust_consumerd64_fd, the_ust_consumerd32_fd;
137 /* Parent PID for --sig-parent option */
138 extern pid_t the_ppid;
139 /* Internal parent PID use with daemonize. */
140 extern pid_t the_child_ppid;
142 /* Consumer daemon specific control data. */
143 extern struct consumer_data the_ustconsumer32_data;
144 extern struct consumer_data the_ustconsumer64_data;
145 extern struct consumer_data the_kconsumer_data;
147 int sessiond_init_main_quit_pipe();
148 int sessiond_wait_for_main_quit_pipe(int timeout_ms);
149 int sessiond_notify_main_quit_pipe();
150 void sessiond_close_main_quit_pipe();
152 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
153 void sessiond_signal_parents();
155 void sessiond_set_client_thread_state(bool running);
156 void sessiond_wait_client_thread_stopped();
158 void *thread_manage_consumer(void *data);
160 #endif /* _LTT_SESSIOND_H */