2 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include <common/hashtable/utils.h>
9 #include <common/hashtable/hashtable.h>
11 #include <lttng/condition/condition.h>
12 #include <lttng/condition/condition-internal.h>
13 #include <lttng/condition/buffer-usage-internal.h>
14 #include <lttng/condition/session-consumed-size-internal.h>
15 #include <lttng/condition/session-rotation-internal.h>
16 #include <lttng/condition/event-rule-matches-internal.h>
17 #include <lttng/condition/event-rule-matches.h>
18 #include <lttng/event-rule/event-rule-internal.h>
19 #include <lttng/condition/event-rule-matches-internal.h>
20 #include "condition-internal.h"
23 unsigned long lttng_condition_buffer_usage_hash(
24 const struct lttng_condition
*_condition
)
27 unsigned long condition_type
;
28 struct lttng_condition_buffer_usage
*condition
;
30 condition
= container_of(_condition
,
31 struct lttng_condition_buffer_usage
, parent
);
33 condition_type
= (unsigned long) condition
->parent
.type
;
34 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
35 if (condition
->session_name
) {
36 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
38 if (condition
->channel_name
) {
39 hash
^= hash_key_str(condition
->channel_name
, lttng_ht_seed
);
41 if (condition
->domain
.set
) {
42 hash
^= hash_key_ulong(
43 (void *) condition
->domain
.type
,
46 if (condition
->threshold_ratio
.set
) {
49 val
= condition
->threshold_ratio
.value
* (double) UINT32_MAX
;
50 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
51 } else if (condition
->threshold_bytes
.set
) {
54 val
= condition
->threshold_bytes
.value
;
55 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
61 unsigned long lttng_condition_session_consumed_size_hash(
62 const struct lttng_condition
*_condition
)
65 unsigned long condition_type
=
66 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
;
67 struct lttng_condition_session_consumed_size
*condition
;
70 condition
= container_of(_condition
,
71 struct lttng_condition_session_consumed_size
, parent
);
73 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
74 if (condition
->session_name
) {
75 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
77 val
= condition
->consumed_threshold_bytes
.value
;
78 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
83 unsigned long lttng_condition_session_rotation_hash(
84 const struct lttng_condition
*_condition
)
86 unsigned long hash
, condition_type
;
87 struct lttng_condition_session_rotation
*condition
;
89 condition
= container_of(_condition
,
90 struct lttng_condition_session_rotation
, parent
);
91 condition_type
= (unsigned long) condition
->parent
.type
;
92 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
93 assert(condition
->session_name
);
94 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
98 static unsigned long lttng_condition_event_rule_matches_hash(
99 const struct lttng_condition
*condition
)
101 unsigned long hash
, condition_type
;
102 enum lttng_condition_status condition_status
;
103 const struct lttng_event_rule
*event_rule
;
105 condition_type
= (unsigned long) condition
->type
;
106 condition_status
= lttng_condition_event_rule_matches_get_rule(
107 condition
, &event_rule
);
108 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
110 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
111 return hash
^ lttng_event_rule_hash(event_rule
);
115 * The lttng_condition hashing code is kept in this file (rather than
116 * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
117 * don't want to link in liblttng-ctl.
119 unsigned long lttng_condition_hash(const struct lttng_condition
*condition
)
121 switch (condition
->type
) {
122 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
123 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
124 return lttng_condition_buffer_usage_hash(condition
);
125 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
126 return lttng_condition_session_consumed_size_hash(condition
);
127 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
128 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
129 return lttng_condition_session_rotation_hash(condition
);
130 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
:
131 return lttng_condition_event_rule_matches_hash(condition
);
133 //ERR("[notification-thread] Unexpected condition type caught");
139 struct lttng_condition
*lttng_condition_copy(const struct lttng_condition
*condition
)
142 struct lttng_payload copy_buffer
;
143 struct lttng_condition
*copy
= NULL
;
145 lttng_payload_init(©_buffer
);
147 ret
= lttng_condition_serialize(condition
, ©_buffer
);
153 struct lttng_payload_view view
=
154 lttng_payload_view_from_payload(
155 ©_buffer
, 0, -1);
157 ret
= lttng_condition_create_from_payload(
166 lttng_payload_reset(©_buffer
);