SoW-2019-0002: Dynamic Snapshot
[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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef _LTT_SESSIOND_H
10 #define _LTT_SESSIOND_H
11
12 #include <urcu.h>
13 #include <urcu/wfcqueue.h>
14
15 #include <common/sessiond-comm/sessiond-comm.h>
16 #include <common/compat/poll.h>
17 #include <common/compat/socket.h>
18 #include <common/uuid.h>
19
20 #include "session.h"
21 #include "ust-app.h"
22 #include "notification-thread.h"
23 #include "sessiond-config.h"
24
25 /*
26 * Consumer daemon state which is changed when spawning it, killing it or in
27 * case of a fatal error.
28 */
29 enum consumerd_state {
30 CONSUMER_STARTED = 1,
31 CONSUMER_STOPPED = 2,
32 CONSUMER_ERROR = 3,
33 };
34
35 /* Unique identifier of a session daemon instance. */
36 extern lttng_uuid sessiond_uuid;
37
38 /*
39 * This consumer daemon state is used to validate if a client command will be
40 * able to reach the consumer. If not, the client is informed. For instance,
41 * doing a "lttng start" when the consumer state is set to ERROR will return an
42 * error to the client.
43 *
44 * The following example shows a possible race condition of this scheme:
45 *
46 * consumer thread error happens
47 * client cmd arrives
48 * client cmd checks state -> still OK
49 * consumer thread exit, sets error
50 * client cmd try to talk to consumer
51 * ...
52 *
53 * However, since the consumer is a different daemon, we have no way of making
54 * sure the command will reach it safely even with this state flag. This is why
55 * we consider that up to the state validation during command processing, the
56 * command is safe. After that, we can not guarantee the correctness of the
57 * client request vis-a-vis the consumer.
58 */
59 extern enum consumerd_state ust_consumerd_state;
60 extern enum consumerd_state kernel_consumerd_state;
61
62 extern const char default_home_dir[],
63 default_tracing_group[],
64 default_ust_sock_dir[],
65 default_global_apps_pipe[];
66
67 /* Set in main.c at boot time of the daemon */
68 extern struct lttng_kernel_tracer_version kernel_tracer_version;
69 extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version;
70
71 /* Notification thread handle. */
72 extern struct notification_thread_handle *notification_thread_handle;
73 extern pthread_mutex_t notification_trigger_tokens_ht_lock;
74
75 /*
76 * This contains extra data needed for processing a command received by the
77 * session daemon from the lttng client.
78 */
79 struct command_ctx {
80 unsigned int lttng_msg_size;
81 struct ltt_session *session;
82 struct lttcomm_lttng_msg *llm;
83 struct lttcomm_session_msg *lsm;
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 /*
122 * Used to notify that a hash table needs to be destroyed by dedicated
123 * thread. Required by design because we don't want to move destroy
124 * paths outside of large RCU read-side lock paths, and destroy cannot
125 * be called by call_rcu thread, because it may hang (waiting for
126 * call_rcu completion).
127 */
128 extern int ht_cleanup_pipe[2];
129
130 extern int kernel_poll_pipe[2];
131
132 /*
133 * Populated when the daemon starts with the current page size of the system.
134 * Set in main() with the current page size.
135 */
136 extern long page_size;
137
138 /* Application health monitoring */
139 extern struct health_app *health_sessiond;
140
141 extern struct sessiond_config config;
142
143 extern int ust_consumerd64_fd, ust_consumerd32_fd;
144
145 /* Parent PID for --sig-parent option */
146 extern pid_t ppid;
147 /* Internal parent PID use with daemonize. */
148 extern pid_t child_ppid;
149
150 /* Consumer daemon specific control data. */
151 extern struct consumer_data ustconsumer32_data;
152 extern struct consumer_data ustconsumer64_data;
153 extern struct consumer_data kconsumer_data;
154
155 int sessiond_init_thread_quit_pipe(void);
156 int sessiond_check_thread_quit_pipe(int fd, uint32_t events);
157 int sessiond_wait_for_quit_pipe(int timeout_ms);
158 int sessiond_notify_quit_pipe(void);
159 void sessiond_close_quit_pipe(void);
160
161 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
162 void sessiond_signal_parents(void);
163
164 void sessiond_set_client_thread_state(bool running);
165 void sessiond_wait_client_thread_stopped(void);
166
167 void *thread_manage_consumer(void *data);
168
169 #endif /* _LTT_SESSIOND_H */
This page took 0.033022 seconds and 5 git commands to generate.