2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <urcu/rculfhash.h>
22 #include <common/defaults.h>
23 #include <common/error.h>
24 #include <common/futex.h>
25 #include <common/unix.h>
26 #include <common/dynamic-buffer.h>
27 #include <common/hashtable/utils.h>
28 #include <common/sessiond-comm/sessiond-comm.h>
29 #include <common/macros.h>
30 #include <lttng/condition/condition.h>
31 #include <lttng/action/action.h>
32 #include <lttng/notification/notification-internal.h>
33 #include <lttng/condition/condition-internal.h>
34 #include <lttng/condition/buffer-usage-internal.h>
35 #include <lttng/notification/channel-internal.h>
43 #include "notification-thread.h"
44 #include "notification-thread-events.h"
45 #include "notification-thread-commands.h"
46 #include "lttng-sessiond.h"
49 #define CLIENT_POLL_MASK_IN (LPOLLIN | LPOLLERR | LPOLLHUP | LPOLLRDHUP)
50 #define CLIENT_POLL_MASK_IN_OUT (CLIENT_POLL_MASK_IN | LPOLLOUT)
52 struct lttng_trigger_list_element
{
53 struct lttng_trigger
*trigger
;
54 struct cds_list_head node
;
57 struct lttng_channel_trigger_list
{
58 struct channel_key channel_key
;
59 struct cds_list_head list
;
60 struct cds_lfht_node channel_triggers_ht_node
;
63 struct lttng_trigger_ht_element
{
64 struct lttng_trigger
*trigger
;
65 struct cds_lfht_node node
;
68 struct lttng_condition_list_element
{
69 struct lttng_condition
*condition
;
70 struct cds_list_head node
;
73 struct notification_client_list_element
{
74 struct notification_client
*client
;
75 struct cds_list_head node
;
78 struct notification_client_list
{
79 struct lttng_trigger
*trigger
;
80 struct cds_list_head list
;
81 struct cds_lfht_node notification_trigger_ht_node
;
84 struct notification_client
{
86 /* Client protocol version. */
91 * Indicates if the credentials and versions of the client have been
96 * Conditions to which the client's notification channel is subscribed.
97 * List of struct lttng_condition_list_node. The condition member is
98 * owned by the client.
100 struct cds_list_head condition_list
;
101 struct cds_lfht_node client_socket_ht_node
;
105 * During the reception of a message, the reception
106 * buffers' "size" is set to contain the current
107 * message's complete payload.
109 struct lttng_dynamic_buffer buffer
;
110 /* Bytes left to receive for the current message. */
111 size_t bytes_to_receive
;
112 /* Type of the message being received. */
113 enum lttng_notification_channel_message_type msg_type
;
115 * Indicates whether or not credentials are expected
120 * Indicates whether or not credentials were received
124 /* Only used during credentials reception. */
125 lttng_sock_cred creds
;
129 * Indicates whether or not a notification addressed to
130 * this client was dropped because a command reply was
133 * A notification is dropped whenever the buffer is not
136 bool dropped_notification
;
138 * Indicates whether or not a command reply is already
139 * buffered. In this case, it means that the client is
140 * not consuming command replies before emitting a new
141 * one. This could be caused by a protocol error or a
142 * misbehaving/malicious client.
144 bool queued_command_reply
;
145 struct lttng_dynamic_buffer buffer
;
150 struct channel_state_sample
{
151 struct channel_key key
;
152 struct cds_lfht_node channel_state_ht_node
;
153 uint64_t highest_usage
;
154 uint64_t lowest_usage
;
157 static unsigned long hash_channel_key(struct channel_key
*key
);
158 static int evaluate_condition(struct lttng_condition
*condition
,
159 struct lttng_evaluation
**evaluation
,
160 struct notification_thread_state
*state
,
161 struct channel_state_sample
*previous_sample
,
162 struct channel_state_sample
*latest_sample
,
163 uint64_t buffer_capacity
);
165 int send_evaluation_to_clients(struct lttng_trigger
*trigger
,
166 struct lttng_evaluation
*evaluation
,
167 struct notification_client_list
*client_list
,
168 struct notification_thread_state
*state
,
169 uid_t channel_uid
, gid_t channel_gid
);
173 void session_info_destroy(void *_data
);
175 void session_info_get(struct session_info
*session_info
);
177 void session_info_put(struct session_info
*session_info
);
179 struct session_info
*session_info_create(const char *name
,
180 uid_t uid
, gid_t gid
);
182 void session_info_add_channel(struct session_info
*session_info
,
183 struct channel_info
*channel_info
);
185 void session_info_remove_channel(struct session_info
*session_info
,
186 struct channel_info
*channel_info
);
189 int match_client(struct cds_lfht_node
*node
, const void *key
)
191 /* This double-cast is intended to supress pointer-to-cast warning. */
192 int socket
= (int) (intptr_t) key
;
193 struct notification_client
*client
;
195 client
= caa_container_of(node
, struct notification_client
,
196 client_socket_ht_node
);
198 return !!(client
->socket
== socket
);
202 int match_channel_trigger_list(struct cds_lfht_node
*node
, const void *key
)
204 struct channel_key
*channel_key
= (struct channel_key
*) key
;
205 struct lttng_channel_trigger_list
*trigger_list
;
207 trigger_list
= caa_container_of(node
, struct lttng_channel_trigger_list
,
208 channel_triggers_ht_node
);
210 return !!((channel_key
->key
== trigger_list
->channel_key
.key
) &&
211 (channel_key
->domain
== trigger_list
->channel_key
.domain
));
215 int match_channel_state_sample(struct cds_lfht_node
*node
, const void *key
)
217 struct channel_key
*channel_key
= (struct channel_key
*) key
;
218 struct channel_state_sample
*sample
;
220 sample
= caa_container_of(node
, struct channel_state_sample
,
221 channel_state_ht_node
);
223 return !!((channel_key
->key
== sample
->key
.key
) &&
224 (channel_key
->domain
== sample
->key
.domain
));
228 int match_channel_info(struct cds_lfht_node
*node
, const void *key
)
230 struct channel_key
*channel_key
= (struct channel_key
*) key
;
231 struct channel_info
*channel_info
;
233 channel_info
= caa_container_of(node
, struct channel_info
,
236 return !!((channel_key
->key
== channel_info
->key
.key
) &&
237 (channel_key
->domain
== channel_info
->key
.domain
));
241 int match_condition(struct cds_lfht_node
*node
, const void *key
)
243 struct lttng_condition
*condition_key
= (struct lttng_condition
*) key
;
244 struct lttng_trigger_ht_element
*trigger
;
245 struct lttng_condition
*condition
;
247 trigger
= caa_container_of(node
, struct lttng_trigger_ht_element
,
249 condition
= lttng_trigger_get_condition(trigger
->trigger
);
252 return !!lttng_condition_is_equal(condition_key
, condition
);
256 int match_client_list(struct cds_lfht_node
*node
, const void *key
)
258 struct lttng_trigger
*trigger_key
= (struct lttng_trigger
*) key
;
259 struct notification_client_list
*client_list
;
260 struct lttng_condition
*condition
;
261 struct lttng_condition
*condition_key
= lttng_trigger_get_condition(
264 assert(condition_key
);
266 client_list
= caa_container_of(node
, struct notification_client_list
,
267 notification_trigger_ht_node
);
268 condition
= lttng_trigger_get_condition(client_list
->trigger
);
270 return !!lttng_condition_is_equal(condition_key
, condition
);
274 int match_client_list_condition(struct cds_lfht_node
*node
, const void *key
)
276 struct lttng_condition
*condition_key
= (struct lttng_condition
*) key
;
277 struct notification_client_list
*client_list
;
278 struct lttng_condition
*condition
;
280 assert(condition_key
);
282 client_list
= caa_container_of(node
, struct notification_client_list
,
283 notification_trigger_ht_node
);
284 condition
= lttng_trigger_get_condition(client_list
->trigger
);
286 return !!lttng_condition_is_equal(condition_key
, condition
);
290 unsigned long lttng_condition_buffer_usage_hash(
291 struct lttng_condition
*_condition
)
293 unsigned long hash
= 0;
294 struct lttng_condition_buffer_usage
*condition
;
296 condition
= container_of(_condition
,
297 struct lttng_condition_buffer_usage
, parent
);
299 if (condition
->session_name
) {
300 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
302 if (condition
->channel_name
) {
303 hash
^= hash_key_str(condition
->channel_name
, lttng_ht_seed
);
305 if (condition
->domain
.set
) {
306 hash
^= hash_key_ulong(
307 (void *) condition
->domain
.type
,
310 if (condition
->threshold_ratio
.set
) {
313 val
= condition
->threshold_ratio
.value
* (double) UINT32_MAX
;
314 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
315 } else if (condition
->threshold_bytes
.set
) {
318 val
= condition
->threshold_bytes
.value
;
319 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
325 * The lttng_condition hashing code is kept in this file (rather than
326 * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
327 * don't want to link in liblttng-ctl.
330 unsigned long lttng_condition_hash(struct lttng_condition
*condition
)
332 switch (condition
->type
) {
333 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
334 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
335 return lttng_condition_buffer_usage_hash(condition
);
337 ERR("[notification-thread] Unexpected condition type caught");
343 unsigned long hash_channel_key(struct channel_key
*key
)
345 unsigned long key_hash
= hash_key_u64(&key
->key
, lttng_ht_seed
);
346 unsigned long domain_hash
= hash_key_ulong(
347 (void *) (unsigned long) key
->domain
, lttng_ht_seed
);
349 return key_hash
^ domain_hash
;
353 void channel_info_destroy(struct channel_info
*channel_info
)
359 if (channel_info
->session_info
) {
360 session_info_remove_channel(channel_info
->session_info
,
362 session_info_put(channel_info
->session_info
);
364 if (channel_info
->name
) {
365 free(channel_info
->name
);
370 /* Don't call directly, use the ref-counting mechanism. */
372 void session_info_destroy(void *_data
)
374 struct session_info
*session_info
= _data
;
376 assert(session_info
);
377 if (session_info
->channel_infos_ht
) {
378 cds_lfht_destroy(session_info
->channel_infos_ht
, NULL
);
380 free(session_info
->name
);
385 void session_info_get(struct session_info
*session_info
)
390 lttng_ref_get(&session_info
->ref
);
394 void session_info_put(struct session_info
*session_info
)
399 lttng_ref_put(&session_info
->ref
);
403 struct session_info
*session_info_create(const char *name
, uid_t uid
, gid_t gid
)
405 struct session_info
*session_info
;
409 session_info
= zmalloc(sizeof(*session_info
));
413 lttng_ref_init(&session_info
->ref
, session_info_destroy
);
415 session_info
->channel_infos_ht
= cds_lfht_new(DEFAULT_HT_SIZE
,
416 1, 0, CDS_LFHT_AUTO_RESIZE
| CDS_LFHT_ACCOUNTING
, NULL
);
417 if (!session_info
->channel_infos_ht
) {
421 cds_lfht_node_init(&session_info
->sessions_ht_node
);
422 session_info
->name
= strdup(name
);
423 if (!session_info
->name
) {
426 session_info
->uid
= uid
;
427 session_info
->gid
= gid
;
431 session_info_put(session_info
);
436 void session_info_add_channel(struct session_info
*session_info
,
437 struct channel_info
*channel_info
)
440 cds_lfht_add(session_info
->channel_infos_ht
,
441 hash_channel_key(&channel_info
->key
),
442 &channel_info
->session_info_channels_ht_node
);
447 void session_info_remove_channel(struct session_info
*session_info
,
448 struct channel_info
*channel_info
)
451 cds_lfht_del(session_info
->channel_infos_ht
,
452 &channel_info
->session_info_channels_ht_node
);
457 struct channel_info
*channel_info_create(const char *channel_name
,
458 struct channel_key
*channel_key
, uint64_t channel_capacity
,
459 struct session_info
*session_info
)
461 struct channel_info
*channel_info
= zmalloc(sizeof(*channel_info
));
467 cds_lfht_node_init(&channel_info
->channels_ht_node
);
468 cds_lfht_node_init(&channel_info
->session_info_channels_ht_node
);
469 memcpy(&channel_info
->key
, channel_key
, sizeof(*channel_key
));
470 channel_info
->capacity
= channel_capacity
;
472 channel_info
->name
= strdup(channel_name
);
473 if (!channel_info
->name
) {
478 * Set the references between session and channel infos:
479 * - channel_info holds a strong reference to session_info
480 * - session_info holds a weak reference to channel_info
482 session_info_get(session_info
);
483 session_info_add_channel(session_info
, channel_info
);
484 channel_info
->session_info
= session_info
;
488 channel_info_destroy(channel_info
);
492 /* This function must be called with the RCU read lock held. */
494 int evaluate_condition_for_client(struct lttng_trigger
*trigger
,
495 struct lttng_condition
*condition
,
496 struct notification_client
*client
,
497 struct notification_thread_state
*state
)
500 struct cds_lfht_iter iter
;
501 struct cds_lfht_node
*node
;
502 struct channel_info
*channel_info
= NULL
;
503 struct channel_key
*channel_key
= NULL
;
504 struct channel_state_sample
*last_sample
= NULL
;
505 struct lttng_channel_trigger_list
*channel_trigger_list
= NULL
;
506 struct lttng_evaluation
*evaluation
= NULL
;
507 struct notification_client_list client_list
= { 0 };
508 struct notification_client_list_element client_list_element
= { 0 };
515 /* Find the channel associated with the trigger. */
516 cds_lfht_for_each_entry(state
->channel_triggers_ht
, &iter
,
517 channel_trigger_list
, channel_triggers_ht_node
) {
518 struct lttng_trigger_list_element
*element
;
520 cds_list_for_each_entry(element
, &channel_trigger_list
->list
, node
) {
521 struct lttng_condition
*current_condition
=
522 lttng_trigger_get_condition(
525 assert(current_condition
);
526 if (!lttng_condition_is_equal(condition
,
527 current_condition
)) {
531 /* Found the trigger, save the channel key. */
532 channel_key
= &channel_trigger_list
->channel_key
;
536 /* The channel key was found stop iteration. */
542 /* No channel found; normal exit. */
543 DBG("[notification-thread] No channel associated with newly subscribed-to condition");
548 /* Fetch channel info for the matching channel. */
549 cds_lfht_lookup(state
->channels_ht
,
550 hash_channel_key(channel_key
),
554 node
= cds_lfht_iter_get_node(&iter
);
556 channel_info
= caa_container_of(node
, struct channel_info
,
559 /* Retrieve the channel's last sample, if it exists. */
560 cds_lfht_lookup(state
->channel_state_ht
,
561 hash_channel_key(channel_key
),
562 match_channel_state_sample
,
565 node
= cds_lfht_iter_get_node(&iter
);
567 last_sample
= caa_container_of(node
,
568 struct channel_state_sample
,
569 channel_state_ht_node
);
571 /* Nothing to evaluate, no sample was ever taken. Normal exit */
572 DBG("[notification-thread] No channel sample associated with newly subscribed-to condition");
577 ret
= evaluate_condition(condition
, &evaluation
, state
, NULL
,
578 last_sample
, channel_info
->capacity
);
580 WARN("[notification-thread] Fatal error occurred while evaluating a newly subscribed-to condition");
585 /* Evaluation yielded nothing. Normal exit. */
586 DBG("[notification-thread] Newly subscribed-to condition evaluated to false, nothing to report to client");
592 * Create a temporary client list with the client currently
595 cds_lfht_node_init(&client_list
.notification_trigger_ht_node
);
596 CDS_INIT_LIST_HEAD(&client_list
.list
);
597 client_list
.trigger
= trigger
;
599 CDS_INIT_LIST_HEAD(&client_list_element
.node
);
600 client_list_element
.client
= client
;
601 cds_list_add(&client_list_element
.node
, &client_list
.list
);
603 /* Send evaluation result to the newly-subscribed client. */
604 DBG("[notification-thread] Newly subscribed-to condition evaluated to true, notifying client");
605 ret
= send_evaluation_to_clients(trigger
, evaluation
, &client_list
,
606 state
, channel_info
->session_info
->uid
,
607 channel_info
->session_info
->gid
);
614 int notification_thread_client_subscribe(struct notification_client
*client
,
615 struct lttng_condition
*condition
,
616 struct notification_thread_state
*state
,
617 enum lttng_notification_channel_status
*_status
)
620 struct cds_lfht_iter iter
;
621 struct cds_lfht_node
*node
;
622 struct notification_client_list
*client_list
;
623 struct lttng_condition_list_element
*condition_list_element
= NULL
;
624 struct notification_client_list_element
*client_list_element
= NULL
;
625 enum lttng_notification_channel_status status
=
626 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
;
629 * Ensure that the client has not already subscribed to this condition
632 cds_list_for_each_entry(condition_list_element
, &client
->condition_list
, node
) {
633 if (lttng_condition_is_equal(condition_list_element
->condition
,
635 status
= LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
;
640 condition_list_element
= zmalloc(sizeof(*condition_list_element
));
641 if (!condition_list_element
) {
645 client_list_element
= zmalloc(sizeof(*client_list_element
));
646 if (!client_list_element
) {
654 * Add the newly-subscribed condition to the client's subscription list.
656 CDS_INIT_LIST_HEAD(&condition_list_element
->node
);
657 condition_list_element
->condition
= condition
;
658 cds_list_add(&condition_list_element
->node
, &client
->condition_list
);
660 cds_lfht_lookup(state
->notification_trigger_clients_ht
,
661 lttng_condition_hash(condition
),
662 match_client_list_condition
,
665 node
= cds_lfht_iter_get_node(&iter
);
668 * No notification-emiting trigger registered with this
669 * condition. We don't evaluate the condition right away
670 * since this trigger is not registered yet.
672 free(client_list_element
);
676 client_list
= caa_container_of(node
, struct notification_client_list
,
677 notification_trigger_ht_node
);
679 * The condition to which the client just subscribed is evaluated
680 * at this point so that conditions that are already TRUE result
681 * in a notification being sent out.
683 if (evaluate_condition_for_client(client_list
->trigger
, condition
,
685 WARN("[notification-thread] Evaluation of a condition on client subscription failed, aborting.");
691 * Add the client to the list of clients interested in a given trigger
692 * if a "notification" trigger with a corresponding condition was
695 client_list_element
->client
= client
;
696 CDS_INIT_LIST_HEAD(&client_list_element
->node
);
697 cds_list_add(&client_list_element
->node
, &client_list
->list
);
706 free(condition_list_element
);
707 free(client_list_element
);
712 int notification_thread_client_unsubscribe(
713 struct notification_client
*client
,
714 struct lttng_condition
*condition
,
715 struct notification_thread_state
*state
,
716 enum lttng_notification_channel_status
*_status
)
718 struct cds_lfht_iter iter
;
719 struct cds_lfht_node
*node
;
720 struct notification_client_list
*client_list
;
721 struct lttng_condition_list_element
*condition_list_element
,
723 struct notification_client_list_element
*client_list_element
,
725 bool condition_found
= false;
726 enum lttng_notification_channel_status status
=
727 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
;
729 /* Remove the condition from the client's condition list. */
730 cds_list_for_each_entry_safe(condition_list_element
, condition_tmp
,
731 &client
->condition_list
, node
) {
732 if (!lttng_condition_is_equal(condition_list_element
->condition
,
737 cds_list_del(&condition_list_element
->node
);
739 * The caller may be iterating on the client's conditions to
740 * tear down a client's connection. In this case, the condition
741 * will be destroyed at the end.
743 if (condition
!= condition_list_element
->condition
) {
744 lttng_condition_destroy(
745 condition_list_element
->condition
);
747 free(condition_list_element
);
748 condition_found
= true;
752 if (!condition_found
) {
753 status
= LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
;
758 * Remove the client from the list of clients interested the trigger
759 * matching the condition.
762 cds_lfht_lookup(state
->notification_trigger_clients_ht
,
763 lttng_condition_hash(condition
),
764 match_client_list_condition
,
767 node
= cds_lfht_iter_get_node(&iter
);
772 client_list
= caa_container_of(node
, struct notification_client_list
,
773 notification_trigger_ht_node
);
774 cds_list_for_each_entry_safe(client_list_element
, client_tmp
,
775 &client_list
->list
, node
) {
776 if (client_list_element
->client
->socket
!= client
->socket
) {
779 cds_list_del(&client_list_element
->node
);
780 free(client_list_element
);
786 lttng_condition_destroy(condition
);
794 void notification_client_destroy(struct notification_client
*client
,
795 struct notification_thread_state
*state
)
797 struct lttng_condition_list_element
*condition_list_element
, *tmp
;
803 /* Release all conditions to which the client was subscribed. */
804 cds_list_for_each_entry_safe(condition_list_element
, tmp
,
805 &client
->condition_list
, node
) {
806 (void) notification_thread_client_unsubscribe(client
,
807 condition_list_element
->condition
, state
, NULL
);
810 if (client
->socket
>= 0) {
811 (void) lttcomm_close_unix_sock(client
->socket
);
813 lttng_dynamic_buffer_reset(&client
->communication
.inbound
.buffer
);
814 lttng_dynamic_buffer_reset(&client
->communication
.outbound
.buffer
);
819 * Call with rcu_read_lock held (and hold for the lifetime of the returned
823 struct notification_client
*get_client_from_socket(int socket
,
824 struct notification_thread_state
*state
)
826 struct cds_lfht_iter iter
;
827 struct cds_lfht_node
*node
;
828 struct notification_client
*client
= NULL
;
830 cds_lfht_lookup(state
->client_socket_ht
,
831 hash_key_ulong((void *) (unsigned long) socket
, lttng_ht_seed
),
833 (void *) (unsigned long) socket
,
835 node
= cds_lfht_iter_get_node(&iter
);
840 client
= caa_container_of(node
, struct notification_client
,
841 client_socket_ht_node
);
847 bool trigger_applies_to_channel(struct lttng_trigger
*trigger
,
848 struct channel_info
*channel_info
)
850 enum lttng_condition_status status
;
851 struct lttng_condition
*condition
;
852 const char *trigger_session_name
= NULL
;
853 const char *trigger_channel_name
= NULL
;
854 enum lttng_domain_type trigger_domain
;
856 condition
= lttng_trigger_get_condition(trigger
);
861 switch (lttng_condition_get_type(condition
)) {
862 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
863 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
869 status
= lttng_condition_buffer_usage_get_domain_type(condition
,
871 assert(status
== LTTNG_CONDITION_STATUS_OK
);
872 if (channel_info
->key
.domain
!= trigger_domain
) {
876 status
= lttng_condition_buffer_usage_get_session_name(
877 condition
, &trigger_session_name
);
878 assert((status
== LTTNG_CONDITION_STATUS_OK
) && trigger_session_name
);
880 status
= lttng_condition_buffer_usage_get_channel_name(
881 condition
, &trigger_channel_name
);
882 assert((status
== LTTNG_CONDITION_STATUS_OK
) && trigger_channel_name
);
884 if (strcmp(channel_info
->session_info
->name
, trigger_session_name
)) {
887 if (strcmp(channel_info
->name
, trigger_channel_name
)) {
897 bool trigger_applies_to_client(struct lttng_trigger
*trigger
,
898 struct notification_client
*client
)
900 bool applies
= false;
901 struct lttng_condition_list_element
*condition_list_element
;
903 cds_list_for_each_entry(condition_list_element
, &client
->condition_list
,
905 applies
= lttng_condition_is_equal(
906 condition_list_element
->condition
,
907 lttng_trigger_get_condition(trigger
));
916 int match_session(struct cds_lfht_node
*node
, const void *key
)
918 const char *name
= key
;
919 struct session_info
*session_info
= caa_container_of(
920 node
, struct session_info
, sessions_ht_node
);
922 return !strcmp(session_info
->name
, name
);
926 struct session_info
*find_or_create_session_info(
927 struct notification_thread_state
*state
,
928 const char *name
, uid_t uid
, gid_t gid
)
930 struct session_info
*session
= NULL
;
931 struct cds_lfht_node
*node
;
932 struct cds_lfht_iter iter
;
935 cds_lfht_lookup(state
->sessions_ht
,
936 hash_key_str(name
, lttng_ht_seed
),
940 node
= cds_lfht_iter_get_node(&iter
);
942 DBG("[notification-thread] Found session info of session \"%s\" (uid = %i, gid = %i)",
944 session
= caa_container_of(node
, struct session_info
,
946 assert(session
->uid
== uid
);
947 assert(session
->gid
== gid
);
951 session
= session_info_create(name
, uid
, gid
);
953 ERR("[notification-thread] Failed to allocation session info for session \"%s\" (uid = %i, gid = %i)",
963 int handle_notification_thread_command_add_channel(
964 struct notification_thread_state
*state
,
965 const char *session_name
, uid_t session_uid
, gid_t session_gid
,
966 const char *channel_name
, enum lttng_domain_type channel_domain
,
967 uint64_t channel_key_int
, uint64_t channel_capacity
,
968 enum lttng_error_code
*cmd_result
)
970 struct cds_list_head trigger_list
;
971 struct channel_info
*new_channel_info
= NULL
;
972 struct channel_key channel_key
= {
973 .key
= channel_key_int
,
974 .domain
= channel_domain
,
976 struct lttng_channel_trigger_list
*channel_trigger_list
= NULL
;
977 struct lttng_trigger_ht_element
*trigger_ht_element
= NULL
;
978 int trigger_count
= 0;
979 struct cds_lfht_iter iter
;
980 struct session_info
*session_info
= NULL
;
982 DBG("[notification-thread] Adding channel %s from session %s, channel key = %" PRIu64
" in %s domain",
983 channel_name
, session_name
, channel_key_int
,
984 channel_domain
== LTTNG_DOMAIN_KERNEL
? "kernel" : "user space");
986 CDS_INIT_LIST_HEAD(&trigger_list
);
988 session_info
= find_or_create_session_info(state
, session_name
,
989 session_uid
, session_gid
);
991 /* Allocation error or an internal error occured. */
995 new_channel_info
= channel_info_create(channel_name
, &channel_key
,
996 channel_capacity
, session_info
);
997 if (!new_channel_info
) {
1001 /* Build a list of all triggers applying to the new channel. */
1002 cds_lfht_for_each_entry(state
->triggers_ht
, &iter
, trigger_ht_element
,
1004 struct lttng_trigger_list_element
*new_element
;
1006 if (!trigger_applies_to_channel(trigger_ht_element
->trigger
,
1007 new_channel_info
)) {
1011 new_element
= zmalloc(sizeof(*new_element
));
1015 CDS_INIT_LIST_HEAD(&new_element
->node
);
1016 new_element
->trigger
= trigger_ht_element
->trigger
;
1017 cds_list_add(&new_element
->node
, &trigger_list
);
1021 DBG("[notification-thread] Found %i triggers that apply to newly added channel",
1023 channel_trigger_list
= zmalloc(sizeof(*channel_trigger_list
));
1024 if (!channel_trigger_list
) {
1027 channel_trigger_list
->channel_key
= new_channel_info
->key
;
1028 CDS_INIT_LIST_HEAD(&channel_trigger_list
->list
);
1029 cds_lfht_node_init(&channel_trigger_list
->channel_triggers_ht_node
);
1030 cds_list_splice(&trigger_list
, &channel_trigger_list
->list
);
1033 /* Add channel to the channel_ht which owns the channel_infos. */
1034 cds_lfht_add(state
->channels_ht
,
1035 hash_channel_key(&new_channel_info
->key
),
1036 &new_channel_info
->channels_ht_node
);
1038 * Add the list of triggers associated with this channel to the
1039 * channel_triggers_ht.
1041 cds_lfht_add(state
->channel_triggers_ht
,
1042 hash_channel_key(&new_channel_info
->key
),
1043 &channel_trigger_list
->channel_triggers_ht_node
);
1045 *cmd_result
= LTTNG_OK
;
1048 channel_info_destroy(new_channel_info
);
1049 session_info_put(session_info
);
1054 int handle_notification_thread_command_remove_channel(
1055 struct notification_thread_state
*state
,
1056 uint64_t channel_key
, enum lttng_domain_type domain
,
1057 enum lttng_error_code
*cmd_result
)
1059 struct cds_lfht_node
*node
;
1060 struct cds_lfht_iter iter
;
1061 struct lttng_channel_trigger_list
*trigger_list
;
1062 struct lttng_trigger_list_element
*trigger_list_element
, *tmp
;
1063 struct channel_key key
= { .key
= channel_key
, .domain
= domain
};
1064 struct channel_info
*channel_info
;
1066 DBG("[notification-thread] Removing channel key = %" PRIu64
" in %s domain",
1067 channel_key
, domain
== LTTNG_DOMAIN_KERNEL
? "kernel" : "user space");
1071 cds_lfht_lookup(state
->channel_triggers_ht
,
1072 hash_channel_key(&key
),
1073 match_channel_trigger_list
,
1076 node
= cds_lfht_iter_get_node(&iter
);
1078 * There is a severe internal error if we are being asked to remove a
1079 * channel that doesn't exist.
1082 ERR("[notification-thread] Channel being removed is unknown to the notification thread");
1086 /* Free the list of triggers associated with this channel. */
1087 trigger_list
= caa_container_of(node
, struct lttng_channel_trigger_list
,
1088 channel_triggers_ht_node
);
1089 cds_list_for_each_entry_safe(trigger_list_element
, tmp
,
1090 &trigger_list
->list
, node
) {
1091 cds_list_del(&trigger_list_element
->node
);
1092 free(trigger_list_element
);
1094 cds_lfht_del(state
->channel_triggers_ht
, node
);
1097 /* Free sampled channel state. */
1098 cds_lfht_lookup(state
->channel_state_ht
,
1099 hash_channel_key(&key
),
1100 match_channel_state_sample
,
1103 node
= cds_lfht_iter_get_node(&iter
);
1105 * This is expected to be NULL if the channel is destroyed before we
1106 * received a sample.
1109 struct channel_state_sample
*sample
= caa_container_of(node
,
1110 struct channel_state_sample
,
1111 channel_state_ht_node
);
1113 cds_lfht_del(state
->channel_state_ht
, node
);
1117 /* Remove the channel from the channels_ht and free it. */
1118 cds_lfht_lookup(state
->channels_ht
,
1119 hash_channel_key(&key
),
1123 node
= cds_lfht_iter_get_node(&iter
);
1125 channel_info
= caa_container_of(node
, struct channel_info
,
1127 cds_lfht_del(state
->channels_ht
, node
);
1128 channel_info_destroy(channel_info
);
1131 *cmd_result
= LTTNG_OK
;
1136 int condition_is_supported(struct lttng_condition
*condition
)
1140 switch (lttng_condition_get_type(condition
)) {
1141 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
1142 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
1144 enum lttng_domain_type domain
;
1146 ret
= lttng_condition_buffer_usage_get_domain_type(condition
,
1153 if (domain
!= LTTNG_DOMAIN_KERNEL
) {
1159 * Older kernel tracers don't expose the API to monitor their
1160 * buffers. Therefore, we reject triggers that require that
1161 * mechanism to be available to be evaluated.
1163 ret
= kernel_supports_ring_buffer_snapshot_sample_positions(
1175 * FIXME A client's credentials are not checked when registering a trigger, nor
1176 * are they stored alongside with the trigger.
1178 * The effects of this are benign since:
1179 * - The client will succeed in registering the trigger, as it is valid,
1180 * - The trigger will, internally, be bound to the channel,
1181 * - The notifications will not be sent since the client's credentials
1182 * are checked against the channel at that moment.
1184 * If this function returns a non-zero value, it means something is
1185 * fundamentally broken and the whole subsystem/thread will be torn down.
1187 * If a non-fatal error occurs, just set the cmd_result to the appropriate
1191 int handle_notification_thread_command_register_trigger(
1192 struct notification_thread_state
*state
,
1193 struct lttng_trigger
*trigger
,
1194 enum lttng_error_code
*cmd_result
)
1197 struct lttng_condition
*condition
;
1198 struct notification_client
*client
;
1199 struct notification_client_list
*client_list
= NULL
;
1200 struct lttng_trigger_ht_element
*trigger_ht_element
= NULL
;
1201 struct notification_client_list_element
*client_list_element
, *tmp
;
1202 struct cds_lfht_node
*node
;
1203 struct cds_lfht_iter iter
;
1204 struct channel_info
*channel
;
1205 bool free_trigger
= true;
1209 condition
= lttng_trigger_get_condition(trigger
);
1212 ret
= condition_is_supported(condition
);
1215 } else if (ret
== 0) {
1216 *cmd_result
= LTTNG_ERR_NOT_SUPPORTED
;
1219 /* Feature is supported, continue. */
1223 trigger_ht_element
= zmalloc(sizeof(*trigger_ht_element
));
1224 if (!trigger_ht_element
) {
1229 /* Add trigger to the trigger_ht. */
1230 cds_lfht_node_init(&trigger_ht_element
->node
);
1231 trigger_ht_element
->trigger
= trigger
;
1233 node
= cds_lfht_add_unique(state
->triggers_ht
,
1234 lttng_condition_hash(condition
),
1237 &trigger_ht_element
->node
);
1238 if (node
!= &trigger_ht_element
->node
) {
1239 /* Not a fatal error, simply report it to the client. */
1240 *cmd_result
= LTTNG_ERR_TRIGGER_EXISTS
;
1241 goto error_free_ht_element
;
1245 * Ownership of the trigger and of its wrapper was transfered to
1248 trigger_ht_element
= NULL
;
1249 free_trigger
= false;
1252 * The rest only applies to triggers that have a "notify" action.
1253 * It is not skipped as this is the only action type currently
1256 client_list
= zmalloc(sizeof(*client_list
));
1259 goto error_free_ht_element
;
1261 cds_lfht_node_init(&client_list
->notification_trigger_ht_node
);
1262 CDS_INIT_LIST_HEAD(&client_list
->list
);
1263 client_list
->trigger
= trigger
;
1265 /* Build a list of clients to which this new trigger applies. */
1266 cds_lfht_for_each_entry(state
->client_socket_ht
, &iter
, client
,
1267 client_socket_ht_node
) {
1268 if (!trigger_applies_to_client(trigger
, client
)) {
1272 client_list_element
= zmalloc(sizeof(*client_list_element
));
1273 if (!client_list_element
) {
1275 goto error_free_client_list
;
1277 CDS_INIT_LIST_HEAD(&client_list_element
->node
);
1278 client_list_element
->client
= client
;
1279 cds_list_add(&client_list_element
->node
, &client_list
->list
);
1282 cds_lfht_add(state
->notification_trigger_clients_ht
,
1283 lttng_condition_hash(condition
),
1284 &client_list
->notification_trigger_ht_node
);
1287 * Add the trigger to list of triggers bound to the channels currently
1290 cds_lfht_for_each_entry(state
->channels_ht
, &iter
, channel
,
1292 struct lttng_trigger_list_element
*trigger_list_element
;
1293 struct lttng_channel_trigger_list
*trigger_list
;
1295 if (!trigger_applies_to_channel(trigger
, channel
)) {
1299 cds_lfht_lookup(state
->channel_triggers_ht
,
1300 hash_channel_key(&channel
->key
),
1301 match_channel_trigger_list
,
1304 node
= cds_lfht_iter_get_node(&iter
);
1306 trigger_list
= caa_container_of(node
,
1307 struct lttng_channel_trigger_list
,
1308 channel_triggers_ht_node
);
1310 trigger_list_element
= zmalloc(sizeof(*trigger_list_element
));
1311 if (!trigger_list_element
) {
1313 goto error_free_client_list
;
1315 CDS_INIT_LIST_HEAD(&trigger_list_element
->node
);
1316 trigger_list_element
->trigger
= trigger
;
1317 cds_list_add(&trigger_list_element
->node
, &trigger_list
->list
);
1319 /* A trigger can only apply to one channel. */
1324 * Since there is nothing preventing clients from subscribing to a
1325 * condition before the corresponding trigger is registered, we have
1326 * to evaluate this new condition right away.
1328 * At some point, we were waiting for the next "evaluation" (e.g. on
1329 * reception of a channel sample) to evaluate this new condition, but
1332 * The reason it was broken is that waiting for the next sample
1333 * does not allow us to properly handle transitions for edge-triggered
1336 * Consider this example: when we handle a new channel sample, we
1337 * evaluate each conditions twice: once with the previous state, and
1338 * again with the newest state. We then use those two results to
1339 * determine whether a state change happened: a condition was false and
1340 * became true. If a state change happened, we have to notify clients.
1342 * Now, if a client subscribes to a given notification and registers
1343 * a trigger *after* that subscription, we have to make sure the
1344 * condition is evaluated at this point while considering only the
1345 * current state. Otherwise, the next evaluation cycle may only see
1346 * that the evaluations remain the same (true for samples n-1 and n) and
1347 * the client will never know that the condition has been met.
1349 cds_list_for_each_entry_safe(client_list_element
, tmp
,
1350 &client_list
->list
, node
) {
1351 ret
= evaluate_condition_for_client(trigger
, condition
,
1352 client_list_element
->client
, state
);
1354 goto error_free_client_list
;
1359 * Client list ownership transferred to the
1360 * notification_trigger_clients_ht.
1364 *cmd_result
= LTTNG_OK
;
1365 error_free_client_list
:
1367 cds_list_for_each_entry_safe(client_list_element
, tmp
,
1368 &client_list
->list
, node
) {
1369 free(client_list_element
);
1373 error_free_ht_element
:
1374 free(trigger_ht_element
);
1377 struct lttng_action
*action
= lttng_trigger_get_action(trigger
);
1379 lttng_condition_destroy(condition
);
1380 lttng_action_destroy(action
);
1381 lttng_trigger_destroy(trigger
);
1388 int handle_notification_thread_command_unregister_trigger(
1389 struct notification_thread_state
*state
,
1390 struct lttng_trigger
*trigger
,
1391 enum lttng_error_code
*_cmd_reply
)
1393 struct cds_lfht_iter iter
;
1394 struct cds_lfht_node
*node
, *triggers_ht_node
;
1395 struct lttng_channel_trigger_list
*trigger_list
;
1396 struct notification_client_list
*client_list
;
1397 struct notification_client_list_element
*client_list_element
, *tmp
;
1398 struct lttng_trigger_ht_element
*trigger_ht_element
= NULL
;
1399 struct lttng_condition
*condition
= lttng_trigger_get_condition(
1401 struct lttng_action
*action
;
1402 enum lttng_error_code cmd_reply
;
1406 cds_lfht_lookup(state
->triggers_ht
,
1407 lttng_condition_hash(condition
),
1411 triggers_ht_node
= cds_lfht_iter_get_node(&iter
);
1412 if (!triggers_ht_node
) {
1413 cmd_reply
= LTTNG_ERR_TRIGGER_NOT_FOUND
;
1416 cmd_reply
= LTTNG_OK
;
1419 /* Remove trigger from channel_triggers_ht. */
1420 cds_lfht_for_each_entry(state
->channel_triggers_ht
, &iter
, trigger_list
,
1421 channel_triggers_ht_node
) {
1422 struct lttng_trigger_list_element
*trigger_element
, *tmp
;
1424 cds_list_for_each_entry_safe(trigger_element
, tmp
,
1425 &trigger_list
->list
, node
) {
1426 struct lttng_condition
*current_condition
=
1427 lttng_trigger_get_condition(
1428 trigger_element
->trigger
);
1430 assert(current_condition
);
1431 if (!lttng_condition_is_equal(condition
,
1432 current_condition
)) {
1436 DBG("[notification-thread] Removed trigger from channel_triggers_ht");
1437 cds_list_del(&trigger_element
->node
);
1438 /* A trigger can only appear once per channel */
1444 * Remove and release the client list from
1445 * notification_trigger_clients_ht.
1447 cds_lfht_lookup(state
->notification_trigger_clients_ht
,
1448 lttng_condition_hash(condition
),
1452 node
= cds_lfht_iter_get_node(&iter
);
1454 client_list
= caa_container_of(node
, struct notification_client_list
,
1455 notification_trigger_ht_node
);
1456 cds_list_for_each_entry_safe(client_list_element
, tmp
,
1457 &client_list
->list
, node
) {
1458 free(client_list_element
);
1460 cds_lfht_del(state
->notification_trigger_clients_ht
, node
);
1463 /* Remove trigger from triggers_ht. */
1464 trigger_ht_element
= caa_container_of(triggers_ht_node
,
1465 struct lttng_trigger_ht_element
, node
);
1466 cds_lfht_del(state
->triggers_ht
, triggers_ht_node
);
1468 condition
= lttng_trigger_get_condition(trigger_ht_element
->trigger
);
1469 lttng_condition_destroy(condition
);
1470 action
= lttng_trigger_get_action(trigger_ht_element
->trigger
);
1471 lttng_action_destroy(action
);
1472 lttng_trigger_destroy(trigger_ht_element
->trigger
);
1473 free(trigger_ht_element
);
1477 *_cmd_reply
= cmd_reply
;
1482 /* Returns 0 on success, 1 on exit requested, negative value on error. */
1483 int handle_notification_thread_command(
1484 struct notification_thread_handle
*handle
,
1485 struct notification_thread_state
*state
)
1489 struct notification_thread_command
*cmd
;
1491 /* Read the event pipe to put it back into a quiescent state. */
1492 ret
= read(lttng_pipe_get_readfd(handle
->cmd_queue
.event_pipe
), &counter
,
1498 pthread_mutex_lock(&handle
->cmd_queue
.lock
);
1499 cmd
= cds_list_first_entry(&handle
->cmd_queue
.list
,
1500 struct notification_thread_command
, cmd_list_node
);
1501 switch (cmd
->type
) {
1502 case NOTIFICATION_COMMAND_TYPE_REGISTER_TRIGGER
:
1503 DBG("[notification-thread] Received register trigger command");
1504 ret
= handle_notification_thread_command_register_trigger(
1505 state
, cmd
->parameters
.trigger
,
1508 case NOTIFICATION_COMMAND_TYPE_UNREGISTER_TRIGGER
:
1509 DBG("[notification-thread] Received unregister trigger command");
1510 ret
= handle_notification_thread_command_unregister_trigger(
1511 state
, cmd
->parameters
.trigger
,
1514 case NOTIFICATION_COMMAND_TYPE_ADD_CHANNEL
:
1515 DBG("[notification-thread] Received add channel command");
1516 ret
= handle_notification_thread_command_add_channel(
1518 cmd
->parameters
.add_channel
.session
.name
,
1519 cmd
->parameters
.add_channel
.session
.uid
,
1520 cmd
->parameters
.add_channel
.session
.gid
,
1521 cmd
->parameters
.add_channel
.channel
.name
,
1522 cmd
->parameters
.add_channel
.channel
.domain
,
1523 cmd
->parameters
.add_channel
.channel
.key
,
1524 cmd
->parameters
.add_channel
.channel
.capacity
,
1527 case NOTIFICATION_COMMAND_TYPE_REMOVE_CHANNEL
:
1528 DBG("[notification-thread] Received remove channel command");
1529 ret
= handle_notification_thread_command_remove_channel(
1530 state
, cmd
->parameters
.remove_channel
.key
,
1531 cmd
->parameters
.remove_channel
.domain
,
1534 case NOTIFICATION_COMMAND_TYPE_QUIT
:
1535 DBG("[notification-thread] Received quit command");
1536 cmd
->reply_code
= LTTNG_OK
;
1540 ERR("[notification-thread] Unknown internal command received");
1548 cds_list_del(&cmd
->cmd_list_node
);
1549 lttng_waiter_wake_up(&cmd
->reply_waiter
);
1550 pthread_mutex_unlock(&handle
->cmd_queue
.lock
);
1553 /* Wake-up and return a fatal error to the calling thread. */
1554 lttng_waiter_wake_up(&cmd
->reply_waiter
);
1555 pthread_mutex_unlock(&handle
->cmd_queue
.lock
);
1556 cmd
->reply_code
= LTTNG_ERR_FATAL
;
1558 /* Indicate a fatal error to the caller. */
1563 unsigned long hash_client_socket(int socket
)
1565 return hash_key_ulong((void *) (unsigned long) socket
, lttng_ht_seed
);
1569 int socket_set_non_blocking(int socket
)
1573 /* Set the pipe as non-blocking. */
1574 ret
= fcntl(socket
, F_GETFL
, 0);
1576 PERROR("fcntl get socket flags");
1581 ret
= fcntl(socket
, F_SETFL
, flags
| O_NONBLOCK
);
1583 PERROR("fcntl set O_NONBLOCK socket flag");
1586 DBG("Client socket (fd = %i) set as non-blocking", socket
);
1592 int client_reset_inbound_state(struct notification_client
*client
)
1596 ret
= lttng_dynamic_buffer_set_size(
1597 &client
->communication
.inbound
.buffer
, 0);
1600 client
->communication
.inbound
.bytes_to_receive
=
1601 sizeof(struct lttng_notification_channel_message
);
1602 client
->communication
.inbound
.msg_type
=
1603 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN
;
1604 LTTNG_SOCK_SET_UID_CRED(&client
->communication
.inbound
.creds
, -1);
1605 LTTNG_SOCK_SET_GID_CRED(&client
->communication
.inbound
.creds
, -1);
1606 ret
= lttng_dynamic_buffer_set_size(
1607 &client
->communication
.inbound
.buffer
,
1608 client
->communication
.inbound
.bytes_to_receive
);
1612 int handle_notification_thread_client_connect(
1613 struct notification_thread_state
*state
)
1616 struct notification_client
*client
;
1618 DBG("[notification-thread] Handling new notification channel client connection");
1620 client
= zmalloc(sizeof(*client
));
1626 CDS_INIT_LIST_HEAD(&client
->condition_list
);
1627 lttng_dynamic_buffer_init(&client
->communication
.inbound
.buffer
);
1628 lttng_dynamic_buffer_init(&client
->communication
.outbound
.buffer
);
1629 client
->communication
.inbound
.expect_creds
= true;
1630 ret
= client_reset_inbound_state(client
);
1632 ERR("[notification-thread] Failed to reset client communication's inbound state");
1637 ret
= lttcomm_accept_unix_sock(state
->notification_channel_socket
);
1639 ERR("[notification-thread] Failed to accept new notification channel client connection");
1644 client
->socket
= ret
;
1646 ret
= socket_set_non_blocking(client
->socket
);
1648 ERR("[notification-thread] Failed to set new notification channel client connection socket as non-blocking");
1652 ret
= lttcomm_setsockopt_creds_unix_sock(client
->socket
);
1654 ERR("[notification-thread] Failed to set socket options on new notification channel client socket");
1659 ret
= lttng_poll_add(&state
->events
, client
->socket
,
1660 LPOLLIN
| LPOLLERR
|
1661 LPOLLHUP
| LPOLLRDHUP
);
1663 ERR("[notification-thread] Failed to add notification channel client socket to poll set");
1667 DBG("[notification-thread] Added new notification channel client socket (%i) to poll set",
1671 cds_lfht_add(state
->client_socket_ht
,
1672 hash_client_socket(client
->socket
),
1673 &client
->client_socket_ht_node
);
1678 notification_client_destroy(client
, state
);
1682 int handle_notification_thread_client_disconnect(
1684 struct notification_thread_state
*state
)
1687 struct notification_client
*client
;
1690 DBG("[notification-thread] Closing client connection (socket fd = %i)",
1692 client
= get_client_from_socket(client_socket
, state
);
1694 /* Internal state corruption, fatal error. */
1695 ERR("[notification-thread] Unable to find client (socket fd = %i)",
1701 ret
= lttng_poll_del(&state
->events
, client_socket
);
1703 ERR("[notification-thread] Failed to remove client socket from poll set");
1705 cds_lfht_del(state
->client_socket_ht
,
1706 &client
->client_socket_ht_node
);
1707 notification_client_destroy(client
, state
);
1713 int handle_notification_thread_client_disconnect_all(
1714 struct notification_thread_state
*state
)
1716 struct cds_lfht_iter iter
;
1717 struct notification_client
*client
;
1718 bool error_encoutered
= false;
1721 DBG("[notification-thread] Closing all client connections");
1722 cds_lfht_for_each_entry(state
->client_socket_ht
, &iter
, client
,
1723 client_socket_ht_node
) {
1726 ret
= handle_notification_thread_client_disconnect(
1727 client
->socket
, state
);
1729 error_encoutered
= true;
1733 return error_encoutered
? 1 : 0;
1736 int handle_notification_thread_trigger_unregister_all(
1737 struct notification_thread_state
*state
)
1739 bool error_occurred
= false;
1740 struct cds_lfht_iter iter
;
1741 struct lttng_trigger_ht_element
*trigger_ht_element
;
1743 cds_lfht_for_each_entry(state
->triggers_ht
, &iter
, trigger_ht_element
,
1745 int ret
= handle_notification_thread_command_unregister_trigger(
1746 state
, trigger_ht_element
->trigger
, NULL
);
1748 error_occurred
= true;
1751 return error_occurred
? -1 : 0;
1755 int client_flush_outgoing_queue(struct notification_client
*client
,
1756 struct notification_thread_state
*state
)
1759 size_t to_send_count
;
1761 assert(client
->communication
.outbound
.buffer
.size
!= 0);
1762 to_send_count
= client
->communication
.outbound
.buffer
.size
;
1763 DBG("[notification-thread] Flushing client (socket fd = %i) outgoing queue",
1766 ret
= lttcomm_send_unix_sock_non_block(client
->socket
,
1767 client
->communication
.outbound
.buffer
.data
,
1769 if ((ret
< 0 && (errno
== EAGAIN
|| errno
== EWOULDBLOCK
)) ||
1770 (ret
> 0 && ret
< to_send_count
)) {
1771 DBG("[notification-thread] Client (socket fd = %i) outgoing queue could not be completely flushed",
1773 to_send_count
-= max(ret
, 0);
1775 memcpy(client
->communication
.outbound
.buffer
.data
,
1776 client
->communication
.outbound
.buffer
.data
+
1777 client
->communication
.outbound
.buffer
.size
- to_send_count
,
1779 ret
= lttng_dynamic_buffer_set_size(
1780 &client
->communication
.outbound
.buffer
,
1787 * We want to be notified whenever there is buffer space
1788 * available to send the rest of the payload.
1790 ret
= lttng_poll_mod(&state
->events
, client
->socket
,
1791 CLIENT_POLL_MASK_IN_OUT
);
1795 } else if (ret
< 0) {
1796 /* Generic error, disconnect the client. */
1797 ERR("[notification-thread] Failed to send flush outgoing queue, disconnecting client (socket fd = %i)",
1799 ret
= handle_notification_thread_client_disconnect(
1800 client
->socket
, state
);
1805 /* No error and flushed the queue completely. */
1806 ret
= lttng_dynamic_buffer_set_size(
1807 &client
->communication
.outbound
.buffer
, 0);
1811 ret
= lttng_poll_mod(&state
->events
, client
->socket
,
1812 CLIENT_POLL_MASK_IN
);
1817 client
->communication
.outbound
.queued_command_reply
= false;
1818 client
->communication
.outbound
.dropped_notification
= false;
1827 int client_send_command_reply(struct notification_client
*client
,
1828 struct notification_thread_state
*state
,
1829 enum lttng_notification_channel_status status
)
1832 struct lttng_notification_channel_command_reply reply
= {
1833 .status
= (int8_t) status
,
1835 struct lttng_notification_channel_message msg
= {
1836 .type
= (int8_t) LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_COMMAND_REPLY
,
1837 .size
= sizeof(reply
),
1839 char buffer
[sizeof(msg
) + sizeof(reply
)];
1841 if (client
->communication
.outbound
.queued_command_reply
) {
1842 /* Protocol error. */
1846 memcpy(buffer
, &msg
, sizeof(msg
));
1847 memcpy(buffer
+ sizeof(msg
), &reply
, sizeof(reply
));
1848 DBG("[notification-thread] Send command reply (%i)", (int) status
);
1850 /* Enqueue buffer to outgoing queue and flush it. */
1851 ret
= lttng_dynamic_buffer_append(
1852 &client
->communication
.outbound
.buffer
,
1853 buffer
, sizeof(buffer
));
1858 ret
= client_flush_outgoing_queue(client
, state
);
1863 if (client
->communication
.outbound
.buffer
.size
!= 0) {
1864 /* Queue could not be emptied. */
1865 client
->communication
.outbound
.queued_command_reply
= true;
1874 int client_dispatch_message(struct notification_client
*client
,
1875 struct notification_thread_state
*state
)
1879 if (client
->communication
.inbound
.msg_type
!=
1880 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE
&&
1881 client
->communication
.inbound
.msg_type
!=
1882 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN
&&
1883 !client
->validated
) {
1884 WARN("[notification-thread] client attempted a command before handshake");
1889 switch (client
->communication
.inbound
.msg_type
) {
1890 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN
:
1893 * Receiving message header. The function will be called again
1894 * once the rest of the message as been received and can be
1897 const struct lttng_notification_channel_message
*msg
;
1899 assert(sizeof(*msg
) ==
1900 client
->communication
.inbound
.buffer
.size
);
1901 msg
= (const struct lttng_notification_channel_message
*)
1902 client
->communication
.inbound
.buffer
.data
;
1904 if (msg
->size
== 0 || msg
->size
> DEFAULT_MAX_NOTIFICATION_CLIENT_MESSAGE_PAYLOAD_SIZE
) {
1905 ERR("[notification-thread] Invalid notification channel message: length = %u", msg
->size
);
1910 switch (msg
->type
) {
1911 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE
:
1912 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNSUBSCRIBE
:
1913 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE
:
1917 ERR("[notification-thread] Invalid notification channel message: unexpected message type");
1921 client
->communication
.inbound
.bytes_to_receive
= msg
->size
;
1922 client
->communication
.inbound
.msg_type
=
1923 (enum lttng_notification_channel_message_type
) msg
->type
;
1924 ret
= lttng_dynamic_buffer_set_size(
1925 &client
->communication
.inbound
.buffer
, msg
->size
);
1931 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE
:
1933 struct lttng_notification_channel_command_handshake
*handshake_client
;
1934 struct lttng_notification_channel_command_handshake handshake_reply
= {
1935 .major
= LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR
,
1936 .minor
= LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR
,
1938 struct lttng_notification_channel_message msg_header
= {
1939 .type
= LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE
,
1940 .size
= sizeof(handshake_reply
),
1942 enum lttng_notification_channel_status status
=
1943 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
;
1944 char send_buffer
[sizeof(msg_header
) + sizeof(handshake_reply
)];
1946 memcpy(send_buffer
, &msg_header
, sizeof(msg_header
));
1947 memcpy(send_buffer
+ sizeof(msg_header
), &handshake_reply
,
1948 sizeof(handshake_reply
));
1951 (struct lttng_notification_channel_command_handshake
*)
1952 client
->communication
.inbound
.buffer
.data
;
1953 client
->major
= handshake_client
->major
;
1954 client
->minor
= handshake_client
->minor
;
1955 if (!client
->communication
.inbound
.creds_received
) {
1956 ERR("[notification-thread] No credentials received from client");
1961 client
->uid
= LTTNG_SOCK_GET_UID_CRED(
1962 &client
->communication
.inbound
.creds
);
1963 client
->gid
= LTTNG_SOCK_GET_GID_CRED(
1964 &client
->communication
.inbound
.creds
);
1965 DBG("[notification-thread] Received handshake from client (uid = %u, gid = %u) with version %i.%i",
1966 client
->uid
, client
->gid
, (int) client
->major
,
1967 (int) client
->minor
);
1969 if (handshake_client
->major
!= LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR
) {
1970 status
= LTTNG_NOTIFICATION_CHANNEL_STATUS_UNSUPPORTED_VERSION
;
1973 ret
= lttng_dynamic_buffer_append(&client
->communication
.outbound
.buffer
,
1974 send_buffer
, sizeof(send_buffer
));
1976 ERR("[notification-thread] Failed to send protocol version to notification channel client");
1980 ret
= client_flush_outgoing_queue(client
, state
);
1985 ret
= client_send_command_reply(client
, state
, status
);
1987 ERR("[notification-thread] Failed to send reply to notification channel client");
1991 /* Set reception state to receive the next message header. */
1992 ret
= client_reset_inbound_state(client
);
1994 ERR("[notification-thread] Failed to reset client communication's inbound state");
1997 client
->validated
= true;
2000 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE
:
2001 case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNSUBSCRIBE
:
2003 struct lttng_condition
*condition
;
2004 enum lttng_notification_channel_status status
=
2005 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
;
2006 const struct lttng_buffer_view condition_view
=
2007 lttng_buffer_view_from_dynamic_buffer(
2008 &client
->communication
.inbound
.buffer
,
2010 size_t expected_condition_size
=
2011 client
->communication
.inbound
.buffer
.size
;
2013 ret
= lttng_condition_create_from_buffer(&condition_view
,
2015 if (ret
!= expected_condition_size
) {
2016 ERR("[notification-thread] Malformed condition received from client");
2020 if (client
->communication
.inbound
.msg_type
==
2021 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE
) {
2022 ret
= notification_thread_client_subscribe(client
,
2023 condition
, state
, &status
);
2025 ret
= notification_thread_client_unsubscribe(client
,
2026 condition
, state
, &status
);
2032 ret
= client_send_command_reply(client
, state
, status
);
2034 ERR("[notification-thread] Failed to send reply to notification channel client");
2038 /* Set reception state to receive the next message header. */
2039 ret
= client_reset_inbound_state(client
);
2041 ERR("[notification-thread] Failed to reset client communication's inbound state");
2053 /* Incoming data from client. */
2054 int handle_notification_thread_client_in(
2055 struct notification_thread_state
*state
, int socket
)
2058 struct notification_client
*client
;
2062 client
= get_client_from_socket(socket
, state
);
2064 /* Internal error, abort. */
2069 offset
= client
->communication
.inbound
.buffer
.size
-
2070 client
->communication
.inbound
.bytes_to_receive
;
2071 if (client
->communication
.inbound
.expect_creds
) {
2072 recv_ret
= lttcomm_recv_creds_unix_sock(socket
,
2073 client
->communication
.inbound
.buffer
.data
+ offset
,
2074 client
->communication
.inbound
.bytes_to_receive
,
2075 &client
->communication
.inbound
.creds
);
2077 client
->communication
.inbound
.expect_creds
= false;
2078 client
->communication
.inbound
.creds_received
= true;
2081 recv_ret
= lttcomm_recv_unix_sock_non_block(socket
,
2082 client
->communication
.inbound
.buffer
.data
+ offset
,
2083 client
->communication
.inbound
.bytes_to_receive
);
2086 goto error_disconnect_client
;
2089 client
->communication
.inbound
.bytes_to_receive
-= recv_ret
;
2090 if (client
->communication
.inbound
.bytes_to_receive
== 0) {
2091 ret
= client_dispatch_message(client
, state
);
2094 * Only returns an error if this client must be
2097 goto error_disconnect_client
;
2104 error_disconnect_client
:
2105 ret
= handle_notification_thread_client_disconnect(socket
, state
);
2109 /* Client ready to receive outgoing data. */
2110 int handle_notification_thread_client_out(
2111 struct notification_thread_state
*state
, int socket
)
2114 struct notification_client
*client
;
2116 client
= get_client_from_socket(socket
, state
);
2118 /* Internal error, abort. */
2123 ret
= client_flush_outgoing_queue(client
, state
);
2132 bool evaluate_buffer_usage_condition(struct lttng_condition
*condition
,
2133 struct channel_state_sample
*sample
, uint64_t buffer_capacity
)
2135 bool result
= false;
2137 enum lttng_condition_type condition_type
;
2138 struct lttng_condition_buffer_usage
*use_condition
= container_of(
2139 condition
, struct lttng_condition_buffer_usage
,
2146 if (use_condition
->threshold_bytes
.set
) {
2147 threshold
= use_condition
->threshold_bytes
.value
;
2150 * Threshold was expressed as a ratio.
2152 * TODO the threshold (in bytes) of conditions expressed
2153 * as a ratio of total buffer size could be cached to
2154 * forego this double-multiplication or it could be performed
2155 * as fixed-point math.
2157 * Note that caching should accomodate the case where the
2158 * condition applies to multiple channels (i.e. don't assume
2159 * that all channels matching my_chann* have the same size...)
2161 threshold
= (uint64_t) (use_condition
->threshold_ratio
.value
*
2162 (double) buffer_capacity
);
2165 condition_type
= lttng_condition_get_type(condition
);
2166 if (condition_type
== LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
) {
2167 DBG("[notification-thread] Low buffer usage condition being evaluated: threshold = %" PRIu64
", highest usage = %" PRIu64
,
2168 threshold
, sample
->highest_usage
);
2171 * The low condition should only be triggered once _all_ of the
2172 * streams in a channel have gone below the "low" threshold.
2174 if (sample
->highest_usage
<= threshold
) {
2178 DBG("[notification-thread] High buffer usage condition being evaluated: threshold = %" PRIu64
", highest usage = %" PRIu64
,
2179 threshold
, sample
->highest_usage
);
2182 * For high buffer usage scenarios, we want to trigger whenever
2183 * _any_ of the streams has reached the "high" threshold.
2185 if (sample
->highest_usage
>= threshold
) {
2194 int evaluate_condition(struct lttng_condition
*condition
,
2195 struct lttng_evaluation
**evaluation
,
2196 struct notification_thread_state
*state
,
2197 struct channel_state_sample
*previous_sample
,
2198 struct channel_state_sample
*latest_sample
,
2199 uint64_t buffer_capacity
)
2202 enum lttng_condition_type condition_type
;
2203 bool previous_sample_result
;
2204 bool latest_sample_result
;
2206 condition_type
= lttng_condition_get_type(condition
);
2207 /* No other condition type supported for the moment. */
2208 assert(condition_type
== LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
||
2209 condition_type
== LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
);
2211 previous_sample_result
= evaluate_buffer_usage_condition(condition
,
2212 previous_sample
, buffer_capacity
);
2213 latest_sample_result
= evaluate_buffer_usage_condition(condition
,
2214 latest_sample
, buffer_capacity
);
2216 if (!latest_sample_result
||
2217 (previous_sample_result
== latest_sample_result
)) {
2219 * Only trigger on a condition evaluation transition.
2221 * NOTE: This edge-triggered logic may not be appropriate for
2222 * future condition types.
2227 if (evaluation
&& latest_sample_result
) {
2228 *evaluation
= lttng_evaluation_buffer_usage_create(
2230 latest_sample
->highest_usage
,
2242 int client_enqueue_dropped_notification(struct notification_client
*client
,
2243 struct notification_thread_state
*state
)
2246 struct lttng_notification_channel_message msg
= {
2247 .type
= (int8_t) LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED
,
2251 ret
= lttng_dynamic_buffer_append(
2252 &client
->communication
.outbound
.buffer
, &msg
,
2258 int send_evaluation_to_clients(struct lttng_trigger
*trigger
,
2259 struct lttng_evaluation
*evaluation
,
2260 struct notification_client_list
* client_list
,
2261 struct notification_thread_state
*state
,
2262 uid_t channel_uid
, gid_t channel_gid
)
2265 struct lttng_dynamic_buffer msg_buffer
;
2266 struct notification_client_list_element
*client_list_element
, *tmp
;
2267 struct lttng_notification
*notification
;
2268 struct lttng_condition
*condition
;
2269 ssize_t expected_notification_size
, notification_size
;
2270 struct lttng_notification_channel_message msg
;
2272 lttng_dynamic_buffer_init(&msg_buffer
);
2274 condition
= lttng_trigger_get_condition(trigger
);
2277 notification
= lttng_notification_create(condition
, evaluation
);
2278 if (!notification
) {
2283 expected_notification_size
= lttng_notification_serialize(notification
,
2285 if (expected_notification_size
< 0) {
2286 ERR("[notification-thread] Failed to get size of serialized notification");
2291 msg
.type
= (int8_t) LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION
;
2292 msg
.size
= (uint32_t) expected_notification_size
;
2293 ret
= lttng_dynamic_buffer_append(&msg_buffer
, &msg
, sizeof(msg
));
2298 ret
= lttng_dynamic_buffer_set_size(&msg_buffer
,
2299 msg_buffer
.size
+ expected_notification_size
);
2304 notification_size
= lttng_notification_serialize(notification
,
2305 msg_buffer
.data
+ sizeof(msg
));
2306 if (notification_size
!= expected_notification_size
) {
2307 ERR("[notification-thread] Failed to serialize notification");
2312 cds_list_for_each_entry_safe(client_list_element
, tmp
,
2313 &client_list
->list
, node
) {
2314 struct notification_client
*client
=
2315 client_list_element
->client
;
2317 if (client
->uid
!= channel_uid
&& client
->gid
!= channel_gid
&&
2319 /* Client is not allowed to monitor this channel. */
2320 DBG("[notification-thread] Skipping client at it does not have the permission to receive notification for this channel");
2324 DBG("[notification-thread] Sending notification to client (fd = %i, %zu bytes)",
2325 client
->socket
, msg_buffer
.size
);
2326 if (client
->communication
.outbound
.buffer
.size
) {
2328 * Outgoing data is already buffered for this client;
2329 * drop the notification and enqueue a "dropped
2330 * notification" message if this is the first dropped
2331 * notification since the socket spilled-over to the
2334 DBG("[notification-thread] Dropping notification addressed to client (socket fd = %i)",
2336 if (!client
->communication
.outbound
.dropped_notification
) {
2337 client
->communication
.outbound
.dropped_notification
= true;
2338 ret
= client_enqueue_dropped_notification(
2347 ret
= lttng_dynamic_buffer_append_buffer(
2348 &client
->communication
.outbound
.buffer
,
2354 ret
= client_flush_outgoing_queue(client
, state
);
2361 lttng_notification_destroy(notification
);
2362 lttng_dynamic_buffer_reset(&msg_buffer
);
2366 int handle_notification_thread_channel_sample(
2367 struct notification_thread_state
*state
, int pipe
,
2368 enum lttng_domain_type domain
)
2371 struct lttcomm_consumer_channel_monitor_msg sample_msg
;
2372 struct channel_state_sample previous_sample
, latest_sample
;
2373 struct channel_info
*channel_info
;
2374 struct cds_lfht_node
*node
;
2375 struct cds_lfht_iter iter
;
2376 struct lttng_channel_trigger_list
*trigger_list
;
2377 struct lttng_trigger_list_element
*trigger_list_element
;
2378 bool previous_sample_available
= false;
2381 * The monitoring pipe only holds messages smaller than PIPE_BUF,
2382 * ensuring that read/write of sampling messages are atomic.
2384 ret
= lttng_read(pipe
, &sample_msg
, sizeof(sample_msg
));
2385 if (ret
!= sizeof(sample_msg
)) {
2386 ERR("[notification-thread] Failed to read from monitoring pipe (fd = %i)",
2393 latest_sample
.key
.key
= sample_msg
.key
;
2394 latest_sample
.key
.domain
= domain
;
2395 latest_sample
.highest_usage
= sample_msg
.highest
;
2396 latest_sample
.lowest_usage
= sample_msg
.lowest
;
2400 /* Retrieve the channel's informations */
2401 cds_lfht_lookup(state
->channels_ht
,
2402 hash_channel_key(&latest_sample
.key
),
2406 node
= cds_lfht_iter_get_node(&iter
);
2407 if (caa_unlikely(!node
)) {
2409 * Not an error since the consumer can push a sample to the pipe
2410 * and the rest of the session daemon could notify us of the
2411 * channel's destruction before we get a chance to process that
2414 DBG("[notification-thread] Received a sample for an unknown channel from consumerd, key = %" PRIu64
" in %s domain",
2415 latest_sample
.key
.key
,
2416 domain
== LTTNG_DOMAIN_KERNEL
? "kernel" :
2420 channel_info
= caa_container_of(node
, struct channel_info
,
2422 DBG("[notification-thread] Handling channel sample for channel %s (key = %" PRIu64
") in session %s (highest usage = %" PRIu64
", lowest usage = %" PRIu64
")",
2424 latest_sample
.key
.key
,
2425 channel_info
->session_info
->name
,
2426 latest_sample
.highest_usage
,
2427 latest_sample
.lowest_usage
);
2429 /* Retrieve the channel's last sample, if it exists, and update it. */
2430 cds_lfht_lookup(state
->channel_state_ht
,
2431 hash_channel_key(&latest_sample
.key
),
2432 match_channel_state_sample
,
2435 node
= cds_lfht_iter_get_node(&iter
);
2436 if (caa_likely(node
)) {
2437 struct channel_state_sample
*stored_sample
;
2439 /* Update the sample stored. */
2440 stored_sample
= caa_container_of(node
,
2441 struct channel_state_sample
,
2442 channel_state_ht_node
);
2443 memcpy(&previous_sample
, stored_sample
,
2444 sizeof(previous_sample
));
2445 stored_sample
->highest_usage
= latest_sample
.highest_usage
;
2446 stored_sample
->lowest_usage
= latest_sample
.lowest_usage
;
2447 previous_sample_available
= true;
2450 * This is the channel's first sample, allocate space for and
2451 * store the new sample.
2453 struct channel_state_sample
*stored_sample
;
2455 stored_sample
= zmalloc(sizeof(*stored_sample
));
2456 if (!stored_sample
) {
2461 memcpy(stored_sample
, &latest_sample
, sizeof(*stored_sample
));
2462 cds_lfht_node_init(&stored_sample
->channel_state_ht_node
);
2463 cds_lfht_add(state
->channel_state_ht
,
2464 hash_channel_key(&stored_sample
->key
),
2465 &stored_sample
->channel_state_ht_node
);
2468 /* Find triggers associated with this channel. */
2469 cds_lfht_lookup(state
->channel_triggers_ht
,
2470 hash_channel_key(&latest_sample
.key
),
2471 match_channel_trigger_list
,
2474 node
= cds_lfht_iter_get_node(&iter
);
2475 if (caa_likely(!node
)) {
2479 trigger_list
= caa_container_of(node
, struct lttng_channel_trigger_list
,
2480 channel_triggers_ht_node
);
2481 cds_list_for_each_entry(trigger_list_element
, &trigger_list
->list
,
2483 struct lttng_condition
*condition
;
2484 struct lttng_action
*action
;
2485 struct lttng_trigger
*trigger
;
2486 struct notification_client_list
*client_list
;
2487 struct lttng_evaluation
*evaluation
= NULL
;
2489 trigger
= trigger_list_element
->trigger
;
2490 condition
= lttng_trigger_get_condition(trigger
);
2492 action
= lttng_trigger_get_action(trigger
);
2494 /* Notify actions are the only type currently supported. */
2495 assert(lttng_action_get_type(action
) ==
2496 LTTNG_ACTION_TYPE_NOTIFY
);
2499 * Check if any client is subscribed to the result of this
2502 cds_lfht_lookup(state
->notification_trigger_clients_ht
,
2503 lttng_condition_hash(condition
),
2507 node
= cds_lfht_iter_get_node(&iter
);
2510 client_list
= caa_container_of(node
,
2511 struct notification_client_list
,
2512 notification_trigger_ht_node
);
2513 if (cds_list_empty(&client_list
->list
)) {
2515 * No clients interested in the evaluation's result,
2521 ret
= evaluate_condition(condition
, &evaluation
, state
,
2522 previous_sample_available
? &previous_sample
: NULL
,
2523 &latest_sample
, channel_info
->capacity
);
2532 /* Dispatch evaluation result to all clients. */
2533 ret
= send_evaluation_to_clients(trigger_list_element
->trigger
,
2534 evaluation
, client_list
, state
,
2535 channel_info
->session_info
->uid
,
2536 channel_info
->session_info
->gid
);
2537 lttng_evaluation_destroy(evaluation
);
2538 if (caa_unlikely(ret
)) {