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
) {
47 hash
^= hash_key_u64(&condition
->threshold_ratio
.value
, lttng_ht_seed
);
48 } else if (condition
->threshold_bytes
.set
) {
51 val
= condition
->threshold_bytes
.value
;
52 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
58 unsigned long lttng_condition_session_consumed_size_hash(
59 const struct lttng_condition
*_condition
)
62 unsigned long condition_type
=
63 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
;
64 struct lttng_condition_session_consumed_size
*condition
;
67 condition
= container_of(_condition
,
68 struct lttng_condition_session_consumed_size
, parent
);
70 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
71 if (condition
->session_name
) {
72 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
74 val
= condition
->consumed_threshold_bytes
.value
;
75 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
80 unsigned long lttng_condition_session_rotation_hash(
81 const struct lttng_condition
*_condition
)
83 unsigned long hash
, condition_type
;
84 struct lttng_condition_session_rotation
*condition
;
86 condition
= container_of(_condition
,
87 struct lttng_condition_session_rotation
, parent
);
88 condition_type
= (unsigned long) condition
->parent
.type
;
89 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
90 LTTNG_ASSERT(condition
->session_name
);
91 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
95 static unsigned long lttng_condition_event_rule_matches_hash(
96 const struct lttng_condition
*condition
)
98 unsigned long hash
, condition_type
;
99 enum lttng_condition_status condition_status
;
100 const struct lttng_event_rule
*event_rule
;
102 condition_type
= (unsigned long) condition
->type
;
103 condition_status
= lttng_condition_event_rule_matches_get_rule(
104 condition
, &event_rule
);
105 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
107 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
108 return hash
^ lttng_event_rule_hash(event_rule
);
112 * The lttng_condition hashing code is kept in this file (rather than
113 * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
114 * don't want to link in liblttng-ctl.
116 unsigned long lttng_condition_hash(const struct lttng_condition
*condition
)
118 switch (condition
->type
) {
119 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
120 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
121 return lttng_condition_buffer_usage_hash(condition
);
122 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
123 return lttng_condition_session_consumed_size_hash(condition
);
124 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
125 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
126 return lttng_condition_session_rotation_hash(condition
);
127 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
:
128 return lttng_condition_event_rule_matches_hash(condition
);
134 struct lttng_condition
*lttng_condition_copy(const struct lttng_condition
*condition
)
137 struct lttng_payload copy_buffer
;
138 struct lttng_condition
*copy
= NULL
;
140 lttng_payload_init(©_buffer
);
142 ret
= lttng_condition_serialize(condition
, ©_buffer
);
148 struct lttng_payload_view view
=
149 lttng_payload_view_from_payload(
150 ©_buffer
, 0, -1);
152 ret
= lttng_condition_create_from_payload(
161 lttng_payload_reset(©_buffer
);