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/credentials.h>
12 #include <lttng/notification/channel-internal.h>
13 #include <lttng/ref-internal.h>
16 #include <urcu/rculfhash.h>
21 enum lttng_domain_type domain
;
30 * Hashtable containing back-refs (weak) to all channels in this session.
31 * The hashtable's key is a hash of (struct channel_key) and
32 * the value is of type (struct channel_info *).
34 struct cds_lfht
*channel_infos_ht
;
35 struct lttng_session_trigger_list
*trigger_list
;
36 /* Node in the notification thread state's sessions_ht. */
37 struct cds_lfht_node sessions_ht_node
;
39 * Weak reference to the thread state's sessions_ht. Used for removal on
42 struct cds_lfht
*sessions_ht
;
43 uint64_t consumed_data_size
;
45 /* Whether a rotation is ongoing for this session. */
47 /* Identifier of the currently ongoing rotation. */
50 /* call_rcu delayed reclaim. */
51 struct rcu_head rcu_node
;
55 struct channel_key key
;
59 * A channel info holds a reference (lttng_ref) on session_info.
60 * session_info, in return, holds a weak reference to the channel.
62 struct session_info
*session_info
;
63 /* Node in the notification thread state's channels_ht. */
64 struct cds_lfht_node channels_ht_node
;
65 /* Node in the session_info's channels_ht. */
66 struct cds_lfht_node session_info_channels_ht_node
;
67 /* call_rcu delayed reclaim. */
68 struct rcu_head rcu_node
;
71 struct notification_client_list_element
{
72 struct notification_client
*client
;
73 struct cds_list_head node
;
77 * Thread safety of notification_client and notification_client_list.
79 * The notification thread (main thread) and the action executor
80 * interact through client lists. Hence, when the action executor
81 * thread looks-up the list of clients subscribed to a given
82 * condition, it will acquire a reference to the list and lock it
83 * while attempting to communicate with the various clients.
85 * It is not necessary to reference-count clients as they are guaranteed
86 * to be 'alive' if they are present in a list and that list is locked. Indeed,
87 * removing references to the client from those subscription lists is part of
88 * the work performed on destruction of a client.
90 * No provision for other access scenarios are taken into account;
91 * this is the bare minimum to make these accesses safe and the
92 * notification thread's state is _not_ "thread-safe" in any general
95 struct notification_client_list
{
98 const struct lttng_trigger
*trigger
;
99 struct cds_list_head list
;
100 /* Weak reference to container. */
101 struct cds_lfht
*notification_trigger_clients_ht
;
102 struct cds_lfht_node notification_trigger_clients_ht_node
;
103 /* call_rcu delayed reclaim. */
104 struct rcu_head rcu_node
;
107 struct notification_client
{
108 /* Nests within the notification_client_list lock. */
109 pthread_mutex_t lock
;
110 notification_client_id id
;
112 /* Client protocol version. */
113 uint8_t major
, minor
;
117 * Indicates if the credentials and versions of the client have been
122 * Conditions to which the client's notification channel is subscribed.
123 * List of struct lttng_condition_list_node. The condition member is
124 * owned by the client.
126 struct cds_list_head condition_list
;
127 struct cds_lfht_node client_socket_ht_node
;
128 struct cds_lfht_node client_id_ht_node
;
131 * If a client's communication is inactive, it means that a
132 * fatal error has occurred (could be either a protocol error or
133 * the socket API returned a fatal error). No further
134 * communication should be attempted; the client is queued for
140 * During the reception of a message, the reception
141 * buffers' "size" is set to contain the current
142 * message's complete payload.
144 struct lttng_dynamic_buffer buffer
;
145 /* Bytes left to receive for the current message. */
146 size_t bytes_to_receive
;
147 /* Type of the message being received. */
148 enum lttng_notification_channel_message_type msg_type
;
150 * Indicates whether or not credentials are expected
155 * Indicates whether or not credentials were received
159 /* Only used during credentials reception. */
160 lttng_sock_cred creds
;
164 * Indicates whether or not a notification addressed to
165 * this client was dropped because a command reply was
168 * A notification is dropped whenever the buffer is not
171 bool dropped_notification
;
173 * Indicates whether or not a command reply is already
174 * buffered. In this case, it means that the client is
175 * not consuming command replies before emitting a new
176 * one. This could be caused by a protocol error or a
177 * misbehaving/malicious client.
179 bool queued_command_reply
;
180 struct lttng_dynamic_buffer buffer
;
183 /* call_rcu delayed reclaim. */
184 struct rcu_head rcu_node
;
187 enum client_transmission_status
{
188 CLIENT_TRANSMISSION_STATUS_COMPLETE
,
189 CLIENT_TRANSMISSION_STATUS_QUEUED
,
190 /* Communication failure. */
191 CLIENT_TRANSMISSION_STATUS_FAIL
,
193 CLIENT_TRANSMISSION_STATUS_ERROR
,
197 bool notification_client_list_get(struct notification_client_list
*list
);
200 void notification_client_list_put(struct notification_client_list
*list
);
202 typedef int (*report_client_transmission_result_cb
)(
203 struct notification_client
*client
,
204 enum client_transmission_status status
,
208 int notification_client_list_send_evaluation(
209 struct notification_client_list
*list
,
210 const struct lttng_condition
*condition
,
211 const struct lttng_evaluation
*evaluation
,
212 const struct lttng_credentials
*trigger_creds
,
213 const struct lttng_credentials
*source_object_creds
,
214 report_client_transmission_result_cb client_report
,
217 #endif /* NOTIFICATION_THREAD_INTERNAL_H */