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