2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef NOTIFICATION_THREAD_INTERNAL_H
9 #define NOTIFICATION_THREAD_INTERNAL_H
11 #include <common/compat/socket.h>
12 #include <common/credentials.h>
13 #include <lttng/notification/channel-internal.h>
14 #include <lttng/ref-internal.h>
17 #include <urcu/rculfhash.h>
19 #include <urcu/call-rcu.h>
20 #include "notification-thread.h"
22 struct lttng_evaluation
;
23 struct notification_thread_handle
;
27 enum lttng_domain_type domain
;
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 *).
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
;
45 * Weak reference to the thread state's sessions_ht. Used for removal on
48 struct cds_lfht
*sessions_ht
;
49 uint64_t consumed_data_size
;
51 /* Whether a rotation is ongoing for this session. */
53 /* Identifier of the currently ongoing rotation. */
56 /* call_rcu delayed reclaim. */
57 struct rcu_head rcu_node
;
61 struct channel_key key
;
65 * A channel info holds a reference (lttng_ref) on session_info.
66 * session_info, in return, holds a weak reference to the channel.
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
;
77 struct notification_client_list_element
{
78 struct notification_client
*client
;
79 struct cds_list_head node
;
83 * Thread safety of notification_client and notification_client_list.
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.
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.
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
101 struct notification_client_list
{
102 pthread_mutex_t lock
;
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
;
113 struct notification_client
{
114 /* Nests within the notification_client_list lock. */
115 pthread_mutex_t lock
;
116 notification_client_id id
;
118 /* Client protocol version. */
119 uint8_t major
, minor
;
123 * Indicates if the credentials and versions of the client have been
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.
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
;
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
146 * During the reception of a message, the reception
147 * buffers' "size" is set to contain the current
148 * message's complete payload.
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
;
156 * Indicates whether or not credentials are expected
161 * Indicates whether or not credentials were received
165 /* Only used during credentials reception. */
166 lttng_sock_cred creds
;
170 * Indicates whether or not a notification addressed to
171 * this client was dropped because a command reply was
174 * A notification is dropped whenever the buffer is not
177 bool dropped_notification
;
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.
185 bool queued_command_reply
;
186 struct lttng_dynamic_buffer buffer
;
189 /* call_rcu delayed reclaim. */
190 struct rcu_head rcu_node
;
193 enum client_transmission_status
{
194 CLIENT_TRANSMISSION_STATUS_COMPLETE
,
195 CLIENT_TRANSMISSION_STATUS_QUEUED
,
196 /* Communication failure. */
197 CLIENT_TRANSMISSION_STATUS_FAIL
,
199 CLIENT_TRANSMISSION_STATUS_ERROR
,
203 bool notification_client_list_get(struct notification_client_list
*list
);
206 void notification_client_list_put(struct notification_client_list
*list
);
208 typedef int (*report_client_transmission_result_cb
)(
209 struct notification_client
*client
,
210 enum client_transmission_status status
,
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
,
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
);
229 #endif /* NOTIFICATION_THREAD_INTERNAL_H */