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