Commit | Line | Data |
---|---|---|
a58c490f | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
a58c490f | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
a58c490f | 5 | * |
a58c490f JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_TRIGGER_INTERNAL_H | |
9 | #define LTTNG_TRIGGER_INTERNAL_H | |
10 | ||
11 | #include <lttng/trigger/trigger.h> | |
3da864a9 | 12 | #include <common/credentials.h> |
2463b787 | 13 | #include <common/dynamic-array.h> |
a58c490f | 14 | #include <common/macros.h> |
3da864a9 | 15 | #include <common/optional.h> |
a58c490f JG |
16 | #include <stdint.h> |
17 | #include <stdbool.h> | |
72756a3f | 18 | #include <sys/types.h> |
f01d28b4 | 19 | #include <urcu/ref.h> |
a58c490f | 20 | |
c0a66c84 JG |
21 | struct lttng_payload; |
22 | struct lttng_payload_view; | |
23 | ||
a58c490f | 24 | struct lttng_trigger { |
f01d28b4 JR |
25 | /* Reference counting is only exposed to internal users. */ |
26 | struct urcu_ref ref; | |
27 | ||
a58c490f JG |
28 | struct lttng_condition *condition; |
29 | struct lttng_action *action; | |
2463b787 JR |
30 | char *name; |
31 | /* For now only the uid portion of the credentials is used. */ | |
32 | struct lttng_credentials creds; | |
33 | LTTNG_OPTIONAL(uint64_t) error_count; | |
34 | struct { | |
35 | enum lttng_trigger_firing_policy_type type; | |
36 | uint64_t threshold; | |
37 | uint64_t current_count; | |
38 | } firing_policy; | |
39 | /* | |
40 | * Internal use only. | |
41 | * The unique token passed to the tracer to identify a event-rule | |
42 | * notification. | |
43 | */ | |
44 | LTTNG_OPTIONAL(uint64_t) tracer_token; | |
45 | /* | |
46 | * Internal use only. | |
47 | * Error accounting counter index. | |
48 | */ | |
49 | LTTNG_OPTIONAL(uint64_t) error_counter_index; | |
50 | ||
51 | /* | |
52 | * This ordered set is used to hold the capture bytecodoes and their | |
53 | * expression. lttng_action_capture_bytecode_element. | |
54 | * We could only have bytecodes here... the expression are a left over | |
55 | * from the generation process of the set. They are used for comparison | |
56 | * during the gathering process. They are refcounted (TODO) and are the same | |
57 | * object that are present un the underlying action object/s | |
58 | */ | |
59 | struct lttng_dynamic_pointer_array capture_bytecode_set; | |
60 | }; | |
61 | ||
62 | struct lttng_triggers { | |
63 | struct lttng_dynamic_pointer_array array; | |
a58c490f JG |
64 | }; |
65 | ||
66 | struct lttng_trigger_comm { | |
67 | /* length excludes its own length. */ | |
2463b787 | 68 | uint32_t name_length /* Includes '\0' */; |
a58c490f | 69 | uint32_t length; |
2463b787 JR |
70 | /* Credentials, only the uid portion is used for now */ |
71 | int64_t uid; | |
72 | /* Policy */ | |
73 | /* Maps to enum lttng_trigger_firing_policy_type. */ | |
74 | uint8_t policy_type; | |
75 | uint64_t policy_threshold; | |
76 | uint64_t error_count; | |
77 | /* A name, condition and action object follow. */ | |
a58c490f JG |
78 | char payload[]; |
79 | } LTTNG_PACKED; | |
80 | ||
2463b787 JR |
81 | struct lttng_triggers_comm { |
82 | uint32_t count; | |
83 | uint32_t length; | |
84 | /* Count * lttng_trigger_comm structure */ | |
85 | char payload[]; | |
86 | }; | |
87 | ||
a58c490f | 88 | LTTNG_HIDDEN |
c0a66c84 | 89 | ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view, |
a58c490f JG |
90 | struct lttng_trigger **trigger); |
91 | ||
92 | LTTNG_HIDDEN | |
2463b787 | 93 | int lttng_trigger_serialize(const struct lttng_trigger *trigger, |
c0a66c84 | 94 | struct lttng_payload *payload); |
a58c490f | 95 | |
9b63a4aa | 96 | LTTNG_HIDDEN |
2463b787 JR |
97 | bool lttng_trigger_validate(const struct lttng_trigger *trigger); |
98 | ||
99 | LTTNG_HIDDEN | |
100 | int lttng_trigger_assign_name( | |
101 | struct lttng_trigger *dst, const struct lttng_trigger *src); | |
102 | ||
103 | LTTNG_HIDDEN | |
104 | void lttng_trigger_set_tracer_token( | |
105 | struct lttng_trigger *trigger, uint64_t token); | |
106 | ||
107 | LTTNG_HIDDEN | |
108 | uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger); | |
109 | ||
110 | LTTNG_HIDDEN | |
111 | void lttng_trigger_set_error_counter_index( | |
112 | struct lttng_trigger *trigger, uint64_t error_counter_index); | |
9b63a4aa JG |
113 | |
114 | LTTNG_HIDDEN | |
2463b787 | 115 | uint64_t lttng_trigger_get_error_counter_index( |
9b63a4aa JG |
116 | const struct lttng_trigger *trigger); |
117 | ||
a58c490f | 118 | LTTNG_HIDDEN |
2463b787 JR |
119 | int lttng_trigger_generate_name(struct lttng_trigger *trigger, uint64_t offset); |
120 | ||
121 | LTTNG_HIDDEN | |
122 | bool lttng_trigger_is_equal( | |
123 | const struct lttng_trigger *a, const struct lttng_trigger *b); | |
a58c490f | 124 | |
f01d28b4 JR |
125 | LTTNG_HIDDEN |
126 | void lttng_trigger_get(struct lttng_trigger *trigger); | |
127 | ||
128 | LTTNG_HIDDEN | |
129 | void lttng_trigger_put(struct lttng_trigger *trigger); | |
130 | ||
2463b787 JR |
131 | /* |
132 | * Allocate a new set of lttng_trigger. | |
133 | * The returned object must be freed via lttng_triggers_destroy. | |
134 | */ | |
135 | LTTNG_HIDDEN | |
136 | struct lttng_triggers *lttng_triggers_create(void); | |
137 | ||
138 | /* | |
139 | * Return the non-const pointer of an element at index "index" of a | |
140 | * lttng_triggers. | |
141 | * | |
142 | * The ownership of the lttng_triggers element is NOT transfered. | |
143 | * The returned object can NOT be freed via lttng_trigger_destroy. | |
144 | */ | |
145 | LTTNG_HIDDEN | |
146 | struct lttng_trigger *lttng_triggers_get_pointer_of_index( | |
147 | const struct lttng_triggers *triggers, unsigned int index); | |
148 | ||
149 | /* | |
150 | * Add a trigger to the triggers object. | |
151 | */ | |
152 | LTTNG_HIDDEN | |
153 | int lttng_triggers_add( | |
154 | struct lttng_triggers *triggers, struct lttng_trigger *trigger); | |
155 | ||
156 | /* | |
157 | * Serialize a trigger set to a lttng_payload object. | |
158 | * Return LTTNG_OK on success, negative lttng error code on error. | |
159 | */ | |
160 | LTTNG_HIDDEN | |
161 | int lttng_triggers_serialize(const struct lttng_triggers *triggers, | |
162 | struct lttng_payload *payload); | |
163 | ||
164 | LTTNG_HIDDEN | |
165 | ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view, | |
166 | struct lttng_triggers **triggers); | |
167 | ||
3da864a9 JR |
168 | LTTNG_HIDDEN |
169 | const struct lttng_credentials *lttng_trigger_get_credentials( | |
170 | const struct lttng_trigger *trigger); | |
171 | ||
172 | LTTNG_HIDDEN | |
2463b787 | 173 | void lttng_trigger_set_credentials(struct lttng_trigger *trigger, |
3da864a9 JR |
174 | const struct lttng_credentials *creds); |
175 | ||
2463b787 JR |
176 | |
177 | /* | |
178 | * Fire the trigger. | |
179 | * Increment the firing count. | |
180 | */ | |
181 | LTTNG_HIDDEN | |
182 | void lttng_trigger_fire(struct lttng_trigger *trigger); | |
183 | ||
184 | /* | |
185 | * Check if the trigger would fire. | |
186 | */ | |
187 | LTTNG_HIDDEN | |
188 | bool lttng_trigger_should_fire(const struct lttng_trigger *trigger); | |
189 | ||
190 | LTTNG_HIDDEN | |
191 | bool lttng_trigger_is_ready_to_fire( | |
192 | struct lttng_trigger *trigger); | |
193 | ||
194 | LTTNG_HIDDEN | |
195 | uint64_t lttng_trigger_get_error_count( | |
196 | const struct lttng_trigger *trigger); | |
197 | ||
198 | LTTNG_HIDDEN | |
199 | void lttng_trigger_set_error_count(struct lttng_trigger *trigger, | |
200 | uint64_t error_count); | |
201 | ||
202 | /* | |
203 | * Return the type of any uderlying domain requirement. If no particular | |
204 | * requirement is needed return LTTNG_DOMAIN_NONE. | |
205 | */ | |
206 | LTTNG_HIDDEN | |
207 | enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction( | |
208 | const struct lttng_trigger *trigger); | |
209 | ||
210 | LTTNG_HIDDEN | |
211 | struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); | |
212 | ||
213 | LTTNG_HIDDEN | |
214 | unsigned int lttng_trigger_get_capture_bytecode_count( | |
215 | const struct lttng_trigger *trigger); | |
216 | ||
217 | LTTNG_HIDDEN | |
218 | const struct lttng_bytecode * | |
219 | lttng_trigger_get_capture_bytecode_at_index( | |
220 | const struct lttng_trigger *trigger, unsigned int index); | |
221 | ||
a58c490f | 222 | #endif /* LTTNG_TRIGGER_INTERNAL_H */ |