Fix: sessiond: size-based rotations never trigger
[lttng-tools.git] / include / lttng / trigger / trigger-internal.h
CommitLineData
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
3da864a9 11#include <common/credentials.h>
a02903c0 12#include <common/dynamic-array.h>
a58c490f 13#include <common/macros.h>
3da864a9 14#include <common/optional.h>
588c4b0d 15#include <lttng/lttng.h>
9c374932 16#include <pthread.h>
a58c490f 17#include <stdbool.h>
9c374932 18#include <stdint.h>
72756a3f 19#include <sys/types.h>
f01d28b4 20#include <urcu/ref.h>
a58c490f 21
c0a66c84
JG
22struct lttng_payload;
23struct lttng_payload_view;
0f7c2963
JR
24struct mi_writer;
25struct mi_lttng_error_query_callbacks;
c0a66c84 26
a58c490f 27struct lttng_trigger {
f01d28b4
JR
28 /* Reference counting is only exposed to internal users. */
29 struct urcu_ref ref;
30
a58c490f
JG
31 struct lttng_condition *condition;
32 struct lttng_action *action;
242388e4 33 char *name;
64eafdf6
JR
34 /* For now only the uid portion of the credentials is used. */
35 struct lttng_credentials creds;
e6887944
JR
36 /*
37 * Internal use only.
38 * The unique token passed to the tracer to identify an event-rule
39 * notification.
40 */
41 LTTNG_OPTIONAL(uint64_t) tracer_token;
9c374932
JR
42
43 /*
44 * Is the trigger registered?
45 *
46 * This is necessary since a reference holder might be interested in the
47 * overall state of the trigger from the point of view of its owner.
48 *
49 * The main user is the action executor since we want to prevent the
50 * execution of actions related to a trigger that is unregistered.
51 *
52 * Not considered for `is_equal`.
53 */
54 bool registered;
55
5682b2e6
JG
56 /*
57 * A "hidden" trigger is a trigger that is not externally listed.
58 * It is used to hide triggers that are used internally by the session
59 * daemon so that they can't be listed nor unregistered by external
60 * clients.
61 *
62 * This is a property that can only be set internally by the session
47d5bdf0 63 * daemon.
5682b2e6
JG
64 *
65 * The hidden property is preserved by copies.
66 *
67 * Note that notifications originating from an "hidden" trigger will not
68 * be sent to clients that are not within the session daemon's process.
69 */
70 bool is_hidden;
71
9c374932
JR
72 /*
73 * The lock is used to protect against concurrent trigger execution and
74 * trigger removal.
75 */
76 pthread_mutex_t lock;
a58c490f
JG
77};
78
a02903c0
JR
79struct lttng_triggers {
80 struct lttng_dynamic_pointer_array array;
81};
82
a58c490f 83struct lttng_trigger_comm {
64eafdf6
JR
84 /*
85 * Credentials, only the uid portion is used for now.
86 * Used as an override when desired by the root user.
87 */
88 uint64_t uid;
242388e4
JR
89 /*
90 * Length of the variable length payload (name, condition, and
91 * an action).
92 */
93 uint32_t length;
94 /* Includes '\0' terminator. */
95 uint32_t name_length;
47d5bdf0
JG
96 /* Hidden property. */
97 uint8_t is_hidden;
242388e4 98 /* A null-terminated name, a condition, and an action follow. */
a58c490f
JG
99 char payload[];
100} LTTNG_PACKED;
101
a02903c0
JR
102struct lttng_triggers_comm {
103 uint32_t count;
104 uint32_t length;
105 /* Count * lttng_trigger_comm structure */
106 char payload[];
107};
108
a58c490f 109LTTNG_HIDDEN
c0a66c84 110ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
a58c490f
JG
111 struct lttng_trigger **trigger);
112
113LTTNG_HIDDEN
a02903c0 114int lttng_trigger_serialize(const struct lttng_trigger *trigger,
c0a66c84 115 struct lttng_payload *payload);
a58c490f
JG
116
117LTTNG_HIDDEN
b61776fb 118bool lttng_trigger_validate(const struct lttng_trigger *trigger);
a58c490f 119
242388e4
JR
120LTTNG_HIDDEN
121int lttng_trigger_assign_name(
122 struct lttng_trigger *dst, const struct lttng_trigger *src);
123
e6887944
JR
124LTTNG_HIDDEN
125void lttng_trigger_set_tracer_token(
126 struct lttng_trigger *trigger, uint64_t token);
127
128LTTNG_HIDDEN
129uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
130
242388e4
JR
131LTTNG_HIDDEN
132int lttng_trigger_generate_name(struct lttng_trigger *trigger,
133 uint64_t unique_id);
134
85c06c44
JR
135LTTNG_HIDDEN
136bool lttng_trigger_is_equal(
137 const struct lttng_trigger *a, const struct lttng_trigger *b);
138
5682b2e6
JG
139LTTNG_HIDDEN
140bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger);
141
142LTTNG_HIDDEN
143void lttng_trigger_set_hidden(struct lttng_trigger *trigger);
144
f01d28b4
JR
145LTTNG_HIDDEN
146void lttng_trigger_get(struct lttng_trigger *trigger);
147
148LTTNG_HIDDEN
149void lttng_trigger_put(struct lttng_trigger *trigger);
150
0f7c2963
JR
151/*
152 * Serialize a trigger to a mi_writer.
153 * Return LTTNG_OK in success, other enum lttng_error_code on error.
154 */
155LTTNG_HIDDEN
156enum lttng_error_code lttng_trigger_mi_serialize(const struct lttng_trigger *trigger,
157 struct mi_writer *writer,
158 const struct mi_lttng_error_query_callbacks
159 *error_query_callbacks);
160
a02903c0
JR
161/*
162 * Allocate a new set of triggers.
163 * The returned object must be freed via lttng_triggers_destroy.
164 */
165LTTNG_HIDDEN
166struct lttng_triggers *lttng_triggers_create(void);
167
168/*
169 * Return the a pointer to a mutable element at index "index" of an
170 * lttng_triggers set.
171 *
172 * This differs from the public `lttng_triggers_get_at_index` in that
173 * the returned pointer to a mutable trigger.
174 *
175 * The ownership of the trigger set element is NOT transfered.
176 * The returned object can NOT be freed via lttng_trigger_destroy.
177 */
178LTTNG_HIDDEN
179struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
180 const struct lttng_triggers *triggers, unsigned int index);
181
182/*
183 * Add a trigger to the triggers set.
184 *
185 * A reference to the added trigger is acquired on behalf of the trigger set
186 * on success.
187 */
188LTTNG_HIDDEN
189int lttng_triggers_add(
190 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
191
5682b2e6
JG
192/*
193 * Remove all triggers marked as hidden from the provided trigger set.
194 */
195LTTNG_HIDDEN
196int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers);
197
a02903c0
JR
198/*
199 * Serialize a trigger set to an lttng_payload object.
200 * Return LTTNG_OK on success, negative lttng error code on error.
201 */
202LTTNG_HIDDEN
203int lttng_triggers_serialize(const struct lttng_triggers *triggers,
204 struct lttng_payload *payload);
205
206LTTNG_HIDDEN
207ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
208 struct lttng_triggers **triggers);
209
0f7c2963
JR
210/*
211 * Serialize a trigger set to a mi_writer.
212 * Return LTTNG_OK in success, other enum lttng_error_code on error.
213 */
214LTTNG_HIDDEN
215enum lttng_error_code lttng_triggers_mi_serialize(const struct lttng_triggers *triggers,
216 struct mi_writer *writer,
217 const struct mi_lttng_error_query_callbacks
218 *error_query_callbacks);
219
3da864a9
JR
220LTTNG_HIDDEN
221const struct lttng_credentials *lttng_trigger_get_credentials(
222 const struct lttng_trigger *trigger);
223
224LTTNG_HIDDEN
64eafdf6 225void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
3da864a9
JR
226 const struct lttng_credentials *creds);
227
91c96f62
JR
228/*
229 * Return the type of any underlying domain restriction. If no particular
230 * requirement is present, returns LTTNG_DOMAIN_NONE.
231 */
232LTTNG_HIDDEN
233enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
234 const struct lttng_trigger *trigger);
235
58daac01
JR
236/*
237 * Generate any bytecode related to the trigger.
238 * On success LTTNG_OK. On error, returns lttng_error code.
239 */
240LTTNG_HIDDEN
241enum lttng_error_code lttng_trigger_generate_bytecode(
242 struct lttng_trigger *trigger,
243 const struct lttng_credentials *creds);
244
94dbd8e4
JG
245/*
246 * Note that the trigger object is not locked by "copy" as it is const and
247 * used with a number of 'const' triggers. If the trigger could be shared at
248 * the moment of the copy, it is the caller's responsability to lock it for
249 * the duration of the copy.
250 */
b61776fb
SM
251LTTNG_HIDDEN
252struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger);
253
c738df17
FD
254/*
255 * A given trigger needs a tracer notifier if
256 * it has an event-rule condition,
257 * AND
258 * it has one or more sessiond-execution action.
259 */
260LTTNG_HIDDEN
261bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger);
262
9c374932
JR
263LTTNG_HIDDEN
264void lttng_trigger_set_as_registered(struct lttng_trigger *trigger);
265
266LTTNG_HIDDEN
267void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger);
268
269/*
270 * The trigger must be locked before calling lttng_trigger_is_registered.
271 *
272 * The lock is necessary since a trigger can be unregistered at any time.
273 *
274 * Manipulations requiring that the trigger be registered must always acquire
275 * the trigger lock for the duration of the manipulation using
276 * `lttng_trigger_lock` and `lttng_trigger_unlock`.
277 */
278LTTNG_HIDDEN
279bool lttng_trigger_is_registered(struct lttng_trigger *trigger);
280
281LTTNG_HIDDEN
282void lttng_trigger_lock(struct lttng_trigger *trigger);
283
284LTTNG_HIDDEN
285void lttng_trigger_unlock(struct lttng_trigger *trigger);
286
588c4b0d
JG
287LTTNG_HIDDEN
288enum lttng_trigger_status lttng_trigger_add_error_results(
289 const struct lttng_trigger *trigger,
290 struct lttng_error_query_results *results);
291
8ce7c93a
JG
292LTTNG_HIDDEN
293enum lttng_trigger_status lttng_trigger_condition_add_error_results(
294 const struct lttng_trigger *trigger,
295 struct lttng_error_query_results *results);
296
588c4b0d
JG
297LTTNG_HIDDEN
298enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
299 struct lttng_trigger *trigger,
300 struct lttng_error_query_results *results);
301
a5c2d2a7
JG
302/*
303 * Set the trigger name.
304 *
305 * A name is optional.
306 * A name will be assigned on trigger registration if no name is set.
307 *
308 * The name is copied.
309 *
310 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
311 * if invalid parameters are passed.
312 */
313LTTNG_HIDDEN
314enum lttng_trigger_status lttng_trigger_set_name(
315 struct lttng_trigger *trigger, const char *name);
316
a58c490f 317#endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.048737 seconds and 4 git commands to generate.