vscode: Add configurations to run the executables under the debugger
[lttng-tools.git] / src / bin / lttng-sessiond / notification-thread-internal.hpp
CommitLineData
8abe313a 1/*
ab5be9fa 2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8abe313a 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
8abe313a 5 *
8abe313a
JG
6 */
7
8#ifndef NOTIFICATION_THREAD_INTERNAL_H
9#define NOTIFICATION_THREAD_INTERNAL_H
10
28f23191
JG
11#include "notification-thread.hpp"
12
c9e313bc
SM
13#include <common/compat/socket.hpp>
14#include <common/credentials.hpp>
15#include <common/payload.hpp>
28f23191 16
c9e313bc
SM
17#include <lttng/notification/channel-internal.hpp>
18#include <lttng/ref-internal.hpp>
28f23191 19
f2b3ef9f 20#include <stdbool.h>
ae0a823f 21#include <unistd.h>
28f23191 22#include <urcu/call-rcu.h>
f2b3ef9f
JG
23#include <urcu/rculfhash.h>
24#include <urcu/ref.h>
f2b3ef9f
JG
25
26struct lttng_evaluation;
27struct notification_thread_handle;
8abe313a
JG
28
29struct channel_key {
30 uint64_t key;
31 enum lttng_domain_type domain;
32};
33
319dcddc
JG
34struct session_state_sample {
35 uint64_t consumed_data_size;
36 struct {
37 /* Whether a rotation is ongoing for this session. */
38 bool ongoing;
39 /* Identifier of the currently ongoing rotation. */
40 uint64_t id;
41 /* Location of last completed rotation. */
42 struct lttng_trace_archive_location *location;
43 } rotation;
44};
45
8abe313a
JG
46struct session_info {
47 struct lttng_ref ref;
139a8d25 48 uint64_t id;
8abe313a
JG
49 char *name;
50 uid_t uid;
51 gid_t gid;
52 /*
c7283958 53 * Hashtable containing back-refs (weak) to all channels in this session.
8abe313a
JG
54 * The hashtable's key is a hash of (struct channel_key) and
55 * the value is of type (struct channel_info *).
56 */
57 struct cds_lfht *channel_infos_ht;
ea9a44f0 58 struct lttng_session_trigger_list *trigger_list;
8abe313a
JG
59 /* Node in the notification thread state's sessions_ht. */
60 struct cds_lfht_node sessions_ht_node;
1eee26c5
JG
61 /*
62 * Weak reference to the thread state's sessions_ht. Used for removal on
63 * destruction.
64 */
65 struct cds_lfht *sessions_ht;
319dcddc
JG
66 /* Session's state as of the latest update. */
67 struct session_state_sample last_state_sample;
83b934ad
MD
68 /* call_rcu delayed reclaim. */
69 struct rcu_head rcu_node;
8abe313a
JG
70};
71
72struct channel_info {
73 struct channel_key key;
74 char *name;
75 uint64_t capacity;
76 /*
77 * A channel info holds a reference (lttng_ref) on session_info.
78 * session_info, in return, holds a weak reference to the channel.
79 */
80 struct session_info *session_info;
81 /* Node in the notification thread state's channels_ht. */
82 struct cds_lfht_node channels_ht_node;
83 /* Node in the session_info's channels_ht. */
84 struct cds_lfht_node session_info_channels_ht_node;
83b934ad
MD
85 /* call_rcu delayed reclaim. */
86 struct rcu_head rcu_node;
8abe313a
JG
87};
88
b9a8d78f
FD
89/*
90 * Facilities to carry the different notifications type in the action
91 * processing code path.
92 */
93struct lttng_event_notifier_notification {
94 uint64_t tracer_token;
95 enum lttng_domain_type type;
82b3cbf4
JR
96 size_t capture_buf_size;
97 char *capture_buffer;
b9a8d78f
FD
98};
99
f2b3ef9f
JG
100struct notification_client_list_element {
101 struct notification_client *client;
102 struct cds_list_head node;
103};
104
105/*
106 * Thread safety of notification_client and notification_client_list.
107 *
108 * The notification thread (main thread) and the action executor
109 * interact through client lists. Hence, when the action executor
110 * thread looks-up the list of clients subscribed to a given
111 * condition, it will acquire a reference to the list and lock it
112 * while attempting to communicate with the various clients.
113 *
114 * It is not necessary to reference-count clients as they are guaranteed
115 * to be 'alive' if they are present in a list and that list is locked. Indeed,
116 * removing references to the client from those subscription lists is part of
117 * the work performed on destruction of a client.
118 *
119 * No provision for other access scenarios are taken into account;
120 * this is the bare minimum to make these accesses safe and the
121 * notification thread's state is _not_ "thread-safe" in any general
122 * sense.
123 */
124struct notification_client_list {
125 pthread_mutex_t lock;
126 struct urcu_ref ref;
091fa780 127 struct lttng_condition *condition;
57644a7f 128 /* List of triggers that have an identical condition than `condition`. */
091fa780
FD
129 struct cds_list_head triggers_list;
130 struct cds_list_head clients_list;
f2b3ef9f
JG
131 /* Weak reference to container. */
132 struct cds_lfht *notification_trigger_clients_ht;
133 struct cds_lfht_node notification_trigger_clients_ht_node;
134 /* call_rcu delayed reclaim. */
135 struct rcu_head rcu_node;
136};
137
138struct notification_client {
6c24d3fd
JG
139 /*
140 * Nests within the notification_client_list lock.
141 *
142 * Protects the outbound communication and the active flag which
143 * is used by both the notification and action executor threads.
144 *
145 * The remaining fields of the object can be used without any
146 * synchronization as they are either immutable (id, creds, version) or
147 * only accessed by the notification thread.
148 */
f2b3ef9f
JG
149 pthread_mutex_t lock;
150 notification_client_id id;
151 int socket;
152 /* Client protocol version. */
153 uint8_t major, minor;
154 uid_t uid;
155 gid_t gid;
f2bda80e 156 bool is_sessiond;
f2b3ef9f
JG
157 /*
158 * Indicates if the credentials and versions of the client have been
159 * checked.
160 */
161 bool validated;
162 /*
163 * Conditions to which the client's notification channel is subscribed.
164 * List of struct lttng_condition_list_node. The condition member is
165 * owned by the client.
166 */
167 struct cds_list_head condition_list;
168 struct cds_lfht_node client_socket_ht_node;
169 struct cds_lfht_node client_id_ht_node;
170 struct {
171 /*
172 * If a client's communication is inactive, it means that a
173 * fatal error has occurred (could be either a protocol error or
174 * the socket API returned a fatal error). No further
175 * communication should be attempted; the client is queued for
176 * clean-up.
177 */
178 bool active;
9016dbfc 179 int current_poll_events;
f2b3ef9f
JG
180 struct {
181 /*
182 * During the reception of a message, the reception
183 * buffers' "size" is set to contain the current
184 * message's complete payload.
185 */
882093ee 186 struct lttng_payload payload;
f2b3ef9f
JG
187 /* Bytes left to receive for the current message. */
188 size_t bytes_to_receive;
882093ee
JR
189 /* FDs left to receive for the current message. */
190 int fds_to_receive;
f2b3ef9f
JG
191 /* Type of the message being received. */
192 enum lttng_notification_channel_message_type msg_type;
193 /*
194 * Indicates whether or not credentials are expected
195 * from the client.
196 */
197 bool expect_creds;
198 /*
199 * Indicates whether or not credentials were received
200 * from the client.
201 */
202 bool creds_received;
203 /* Only used during credentials reception. */
204 lttng_sock_cred creds;
205 } inbound;
206 struct {
207 /*
208 * Indicates whether or not a notification addressed to
209 * this client was dropped because a command reply was
210 * already buffered.
211 *
212 * A notification is dropped whenever the buffer is not
213 * empty.
214 */
215 bool dropped_notification;
216 /*
217 * Indicates whether or not a command reply is already
218 * buffered. In this case, it means that the client is
219 * not consuming command replies before emitting a new
220 * one. This could be caused by a protocol error or a
221 * misbehaving/malicious client.
222 */
223 bool queued_command_reply;
882093ee 224 struct lttng_payload payload;
f2b3ef9f
JG
225 } outbound;
226 } communication;
227 /* call_rcu delayed reclaim. */
228 struct rcu_head rcu_node;
229};
230
dd877ea6
JG
231enum client_transmission_status {
232 CLIENT_TRANSMISSION_STATUS_COMPLETE,
233 CLIENT_TRANSMISSION_STATUS_QUEUED,
234 /* Communication failure. */
235 CLIENT_TRANSMISSION_STATUS_FAIL,
236 /* Fatal error. */
237 CLIENT_TRANSMISSION_STATUS_ERROR,
238};
f2b3ef9f 239
f2b3ef9f
JG
240bool notification_client_list_get(struct notification_client_list *list);
241
f2b3ef9f
JG
242void notification_client_list_put(struct notification_client_list *list);
243
6c24d3fd 244/* Only returns a non-zero value if a fatal error occurred. */
e665dfbc
JG
245using report_client_transmission_result_cb = int (*)(struct notification_client *,
246 enum client_transmission_status,
247 void *);
f2b3ef9f 248
28f23191
JG
249int notification_client_list_send_evaluation(struct notification_client_list *list,
250 const struct lttng_trigger *trigger,
251 const struct lttng_evaluation *evaluation,
252 const struct lttng_credentials *source_object_creds,
253 report_client_transmission_result_cb client_report,
254 void *user_data);
f2b3ef9f 255
f2b3ef9f 256int notification_thread_client_communication_update(
28f23191
JG
257 struct notification_thread_handle *handle,
258 notification_client_id id,
259 enum client_transmission_status transmission_status);
f2b3ef9f 260
82b3cbf4
JR
261/*
262 * Takes ownership of the payload if present.
263 */
b9a8d78f 264struct lttng_event_notifier_notification *lttng_event_notifier_notification_create(
28f23191 265 uint64_t tracer_token, enum lttng_domain_type domain, char *payload, size_t payload_size);
b9a8d78f 266
b9a8d78f 267void lttng_event_notifier_notification_destroy(
28f23191 268 struct lttng_event_notifier_notification *event_notifier_notification);
b9a8d78f 269
8abe313a 270#endif /* NOTIFICATION_THREAD_INTERNAL_H */
This page took 0.076359 seconds and 4 git commands to generate.