Make the launch of the application registration thread blocking
[lttng-tools.git] / src / bin / lttng-sessiond / lttng-sessiond.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2013 - Raphaƫl Beamonte <raphael.beamonte@gmail.com>
4 *
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.
8 *
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.
13 *
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.
17 */
18
19#ifndef _LTT_SESSIOND_H
20#define _LTT_SESSIOND_H
21
22#include <urcu.h>
23#include <urcu/wfcqueue.h>
24
25#include <common/sessiond-comm/sessiond-comm.h>
26#include <common/compat/poll.h>
27#include <common/compat/socket.h>
28
29#include "session.h"
30#include "ust-app.h"
31#include "notification-thread.h"
32#include "sessiond-config.h"
33
34/*
35 * Consumer daemon state which is changed when spawning it, killing it or in
36 * case of a fatal error.
37 */
38enum consumerd_state {
39 CONSUMER_STARTED = 1,
40 CONSUMER_STOPPED = 2,
41 CONSUMER_ERROR = 3,
42};
43
44/*
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.
49 *
50 * The following example shows a possible race condition of this scheme:
51 *
52 * consumer thread error happens
53 * client cmd arrives
54 * client cmd checks state -> still OK
55 * consumer thread exit, sets error
56 * client cmd try to talk to consumer
57 * ...
58 *
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.
64 */
65extern enum consumerd_state ust_consumerd_state;
66extern enum consumerd_state kernel_consumerd_state;
67
68extern const char default_home_dir[],
69 default_tracing_group[],
70 default_ust_sock_dir[],
71 default_global_apps_pipe[];
72
73/* Set in main.c at boot time of the daemon */
74extern int kernel_tracer_fd;
75extern struct lttng_kernel_tracer_version kernel_tracer_version;
76extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version;
77
78/* Notification thread handle. */
79extern struct notification_thread_handle *notification_thread_handle;
80
81/*
82 * This contains extra data needed for processing a command received by the
83 * session daemon from the lttng client.
84 */
85struct command_ctx {
86 int ust_sock;
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;
92};
93
94struct ust_command {
95 int sock;
96 struct ust_register_msg reg_msg;
97 struct cds_wfcq_node node;
98};
99
100/*
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
103 */
104struct ust_cmd_queue {
105 int32_t futex;
106 struct cds_wfcq_head head;
107 struct cds_wfcq_tail tail;
108};
109
110/*
111 * This is the wait queue containing wait nodes during the application
112 * registration process.
113 */
114struct ust_reg_wait_queue {
115 unsigned long count;
116 struct cds_list_head head;
117};
118
119/*
120 * Use by the dispatch registration to queue UST command socket to wait for the
121 * notify socket.
122 */
123struct ust_reg_wait_node {
124 struct ust_app *app;
125 struct cds_list_head head;
126};
127
128/*
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).
134 */
135extern int ht_cleanup_pipe[2];
136
137extern int kernel_poll_pipe[2];
138
139/*
140 * Populated when the daemon starts with the current page size of the system.
141 * Set in main() with the current page size.
142 */
143extern long page_size;
144
145/* Application health monitoring */
146extern struct health_app *health_sessiond;
147
148extern struct sessiond_config config;
149
150extern int ust_consumerd64_fd, ust_consumerd32_fd;
151
152/* Parent PID for --sig-parent option */
153extern pid_t ppid;
154/* Internal parent PID use with daemonize. */
155extern pid_t child_ppid;
156
157/* Consumer daemon specific control data. */
158extern struct consumer_data ustconsumer32_data;
159extern struct consumer_data ustconsumer64_data;
160extern struct consumer_data kconsumer_data;
161
162int sessiond_init_thread_quit_pipe(void);
163int sessiond_check_thread_quit_pipe(int fd, uint32_t events);
164int sessiond_wait_for_quit_pipe(unsigned int timeout_us);
165int sessiond_notify_quit_pipe(void);
166void sessiond_close_quit_pipe(void);
167
168int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
169void sessiond_signal_parents(void);
170
171void sessiond_set_client_thread_state(bool running);
172void sessiond_wait_client_thread_stopped(void);
173
174void *thread_manage_consumer(void *data);
175
176#endif /* _LTT_SESSIOND_H */
This page took 0.022248 seconds and 4 git commands to generate.