ac455230ac82244465a4b4ba29e1854529f46e3c
[lttng-tools.git] / src / bin / lttng-sessiond / lttng-sessiond.hpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2013 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef _LTT_SESSIOND_H
10 #define _LTT_SESSIOND_H
11
12 #include "notification-thread.hpp"
13 #include "rotation-thread.hpp"
14 #include "session.hpp"
15 #include "sessiond-config.hpp"
16 #include "ust-app.hpp"
17
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>
23
24 #include <urcu.h>
25 #include <urcu/wfcqueue.h>
26
27 /*
28 * Consumer daemon state which is changed when spawning it, killing it or in
29 * case of a fatal error.
30 */
31 enum consumerd_state {
32 CONSUMER_STARTED = 1,
33 CONSUMER_STOPPED = 2,
34 CONSUMER_ERROR = 3,
35 };
36
37 /* Unique identifier of a session daemon instance. */
38 extern lttng_uuid the_sessiond_uuid;
39
40 /*
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.
45 *
46 * The following example shows a possible race condition of this scheme:
47 *
48 * consumer thread error happens
49 * client cmd arrives
50 * client cmd checks state -> still OK
51 * consumer thread exit, sets error
52 * client cmd try to talk to consumer
53 * ...
54 *
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.
60 */
61 extern enum consumerd_state the_ust_consumerd_state;
62 extern enum consumerd_state the_kernel_consumerd_state;
63
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;
67
68 /* Notification thread handle. */
69 extern struct notification_thread_handle *the_notification_thread_handle;
70
71 /* Rotation thread handle. */
72 extern lttng::sessiond::rotation_thread::uptr the_rotation_thread_handle;
73
74 /*
75 * This contains extra data needed for processing a command received by the
76 * session daemon from the lttng client.
77 */
78 struct command_ctx {
79 unsigned int lttng_msg_size;
80 /* Input message */
81 struct lttcomm_session_msg lsm;
82 /* Reply content, starts with an lttcomm_lttng_msg header. */
83 struct lttng_payload reply_payload;
84 lttng_sock_cred creds;
85 };
86
87 struct ust_command {
88 int sock;
89 struct ust_register_msg reg_msg;
90 struct cds_wfcq_node node;
91 };
92
93 /*
94 * Queue used to enqueue UST registration request (ust_command) and synchronized
95 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
96 */
97 struct ust_cmd_queue {
98 int32_t futex;
99 struct cds_wfcq_head head;
100 struct cds_wfcq_tail tail;
101 };
102
103 /*
104 * This is the wait queue containing wait nodes during the application
105 * registration process.
106 */
107 struct ust_reg_wait_queue {
108 unsigned long count;
109 struct cds_list_head head;
110 };
111
112 /*
113 * Use by the dispatch registration to queue UST command socket to wait for the
114 * notify socket.
115 */
116 struct ust_reg_wait_node {
117 struct ust_app *app;
118 struct cds_list_head head;
119 };
120
121 extern int the_kernel_poll_pipe[2];
122
123 /*
124 * Populated when the daemon starts with the current page size of the system.
125 * Set in main() with the current page size.
126 */
127 extern long the_page_size;
128
129 /* Application health monitoring */
130 extern struct health_app *the_health_sessiond;
131
132 extern struct sessiond_config the_config;
133
134 extern int the_ust_consumerd64_fd, the_ust_consumerd32_fd;
135
136 /* Parent PID for --sig-parent option */
137 extern pid_t the_ppid;
138 /* Internal parent PID use with daemonize. */
139 extern pid_t the_child_ppid;
140
141 /* Consumer daemon specific control data. */
142 extern struct consumer_data the_ustconsumer32_data;
143 extern struct consumer_data the_ustconsumer64_data;
144 extern struct consumer_data the_kconsumer_data;
145
146 int sessiond_init_main_quit_pipe();
147 int sessiond_wait_for_main_quit_pipe(int timeout_ms);
148 int sessiond_notify_main_quit_pipe();
149 void sessiond_close_main_quit_pipe();
150
151 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
152 void sessiond_signal_parents();
153
154 void sessiond_set_client_thread_state(bool running);
155 void sessiond_wait_client_thread_stopped();
156
157 void *thread_manage_consumer(void *data);
158
159 #endif /* _LTT_SESSIOND_H */
This page took 0.034259 seconds and 5 git commands to generate.