Make the launch of the application registration thread blocking
[lttng-tools.git] / src / bin / lttng-sessiond / lttng-sessiond.h
CommitLineData
8c0faa1d
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
88564da0 3 * Copyright (C) 2013 - Raphaël Beamonte <raphael.beamonte@gmail.com>
fac6795d 4 *
d14d33bf
AM
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.
8c0faa1d 8 *
fac6795d
DG
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d14d33bf 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fac6795d 12 * GNU General Public License for more details.
8c0faa1d 13 *
d14d33bf
AM
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.
fac6795d
DG
17 */
18
19#ifndef _LTT_SESSIOND_H
20#define _LTT_SESSIOND_H
21
f6a9efaa 22#include <urcu.h>
8bdee6e2 23#include <urcu/wfcqueue.h>
099e26bd 24
10a8a223 25#include <common/sessiond-comm/sessiond-comm.h>
d0b96690 26#include <common/compat/poll.h>
730389d9 27#include <common/compat/socket.h>
10a8a223
DG
28
29#include "session.h"
56fff090 30#include "ust-app.h"
e9404c27 31#include "notification-thread.h"
e6142f2e 32#include "sessiond-config.h"
099e26bd 33
917a718d
JG
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
686204ab
MD
68extern const char default_home_dir[],
69 default_tracing_group[],
70 default_ust_sock_dir[],
71 default_global_apps_pipe[];
fac6795d 72
2f77fc4b
DG
73/* Set in main.c at boot time of the daemon */
74extern int kernel_tracer_fd;
917a718d
JG
75extern struct lttng_kernel_tracer_version kernel_tracer_version;
76extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version;
2f77fc4b 77
a7333da7 78/* Notification thread handle. */
e9404c27
JG
79extern struct notification_thread_handle *notification_thread_handle;
80
5461b305
DG
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;
730389d9 91 lttng_sock_cred creds;
5461b305
DG
92};
93
099e26bd
DG
94struct ust_command {
95 int sock;
96 struct ust_register_msg reg_msg;
8bdee6e2 97 struct cds_wfcq_node node;
099e26bd
DG
98};
99
100/*
7a44d6f1 101 * Queue used to enqueue UST registration request (ust_command) and synchronized
099e26bd
DG
102 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
103 */
104struct ust_cmd_queue {
105 int32_t futex;
8bdee6e2
SM
106 struct cds_wfcq_head head;
107 struct cds_wfcq_tail tail;
099e26bd
DG
108};
109
f45e313d
DG
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
0b2dc8df
MD
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
e32d7f27
JG
137extern int kernel_poll_pipe[2];
138
12744796
DG
139/*
140 * Populated when the daemon starts with the current page size of the system.
a7333da7 141 * Set in main() with the current page size.
12744796
DG
142 */
143extern long page_size;
144
5e97de00
JG
145/* Application health monitoring */
146extern struct health_app *health_sessiond;
147
a7333da7 148extern struct sessiond_config config;
26296c48 149
a7333da7
JG
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;
e9404c27 156
917a718d
JG
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
a7333da7 162int sessiond_init_thread_quit_pipe(void);
d0b96690 163int sessiond_check_thread_quit_pipe(int fd, uint32_t events);
a7333da7
JG
164int sessiond_wait_for_quit_pipe(unsigned int timeout_us);
165int sessiond_notify_quit_pipe(void);
166void sessiond_close_quit_pipe(void);
167
5e97de00 168int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
9cc1ba3b 169void sessiond_signal_parents(void);
ef367a93 170
99d688f2
JG
171void sessiond_set_client_thread_state(bool running);
172void sessiond_wait_client_thread_stopped(void);
173
917a718d
JG
174void *thread_manage_consumer(void *data);
175
fac6795d 176#endif /* _LTT_SESSIOND_H */
This page took 0.059954 seconds and 4 git commands to generate.