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