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> |
a02903c0 | 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; | |
242388e4 | 30 | char *name; |
64eafdf6 JR |
31 | /* For now only the uid portion of the credentials is used. */ |
32 | struct lttng_credentials creds; | |
5c504c41 JR |
33 | struct { |
34 | enum lttng_trigger_firing_policy type; | |
35 | uint64_t threshold; | |
36 | uint64_t current_count; | |
37 | } firing_policy; | |
e6887944 JR |
38 | /* |
39 | * Internal use only. | |
40 | * The unique token passed to the tracer to identify an event-rule | |
41 | * notification. | |
42 | */ | |
43 | LTTNG_OPTIONAL(uint64_t) tracer_token; | |
a58c490f JG |
44 | }; |
45 | ||
a02903c0 JR |
46 | struct lttng_triggers { |
47 | struct lttng_dynamic_pointer_array array; | |
48 | }; | |
49 | ||
a58c490f | 50 | struct lttng_trigger_comm { |
64eafdf6 JR |
51 | /* |
52 | * Credentials, only the uid portion is used for now. | |
53 | * Used as an override when desired by the root user. | |
54 | */ | |
55 | uint64_t uid; | |
242388e4 JR |
56 | /* |
57 | * Length of the variable length payload (name, condition, and | |
58 | * an action). | |
59 | */ | |
60 | uint32_t length; | |
61 | /* Includes '\0' terminator. */ | |
62 | uint32_t name_length; | |
5c504c41 JR |
63 | /* Firing policy. */ |
64 | /* Maps to enum lttng_trigger_firing_policy. */ | |
65 | uint8_t firing_policy_type; | |
66 | uint64_t firing_policy_threshold; | |
242388e4 | 67 | /* A null-terminated name, a condition, and an action follow. */ |
a58c490f JG |
68 | char payload[]; |
69 | } LTTNG_PACKED; | |
70 | ||
a02903c0 JR |
71 | struct lttng_triggers_comm { |
72 | uint32_t count; | |
73 | uint32_t length; | |
74 | /* Count * lttng_trigger_comm structure */ | |
75 | char payload[]; | |
76 | }; | |
77 | ||
a58c490f | 78 | LTTNG_HIDDEN |
c0a66c84 | 79 | ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view, |
a58c490f JG |
80 | struct lttng_trigger **trigger); |
81 | ||
82 | LTTNG_HIDDEN | |
a02903c0 | 83 | int lttng_trigger_serialize(const struct lttng_trigger *trigger, |
c0a66c84 | 84 | struct lttng_payload *payload); |
a58c490f JG |
85 | |
86 | LTTNG_HIDDEN | |
b61776fb | 87 | bool lttng_trigger_validate(const struct lttng_trigger *trigger); |
a58c490f | 88 | |
242388e4 JR |
89 | LTTNG_HIDDEN |
90 | int lttng_trigger_assign_name( | |
91 | struct lttng_trigger *dst, const struct lttng_trigger *src); | |
92 | ||
e6887944 JR |
93 | LTTNG_HIDDEN |
94 | void lttng_trigger_set_tracer_token( | |
95 | struct lttng_trigger *trigger, uint64_t token); | |
96 | ||
97 | LTTNG_HIDDEN | |
98 | uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger); | |
99 | ||
242388e4 JR |
100 | LTTNG_HIDDEN |
101 | int lttng_trigger_generate_name(struct lttng_trigger *trigger, | |
102 | uint64_t unique_id); | |
103 | ||
85c06c44 JR |
104 | LTTNG_HIDDEN |
105 | bool lttng_trigger_is_equal( | |
106 | const struct lttng_trigger *a, const struct lttng_trigger *b); | |
107 | ||
f01d28b4 JR |
108 | LTTNG_HIDDEN |
109 | void lttng_trigger_get(struct lttng_trigger *trigger); | |
110 | ||
111 | LTTNG_HIDDEN | |
112 | void lttng_trigger_put(struct lttng_trigger *trigger); | |
113 | ||
a02903c0 JR |
114 | /* |
115 | * Allocate a new set of triggers. | |
116 | * The returned object must be freed via lttng_triggers_destroy. | |
117 | */ | |
118 | LTTNG_HIDDEN | |
119 | struct lttng_triggers *lttng_triggers_create(void); | |
120 | ||
121 | /* | |
122 | * Return the a pointer to a mutable element at index "index" of an | |
123 | * lttng_triggers set. | |
124 | * | |
125 | * This differs from the public `lttng_triggers_get_at_index` in that | |
126 | * the returned pointer to a mutable trigger. | |
127 | * | |
128 | * The ownership of the trigger set element is NOT transfered. | |
129 | * The returned object can NOT be freed via lttng_trigger_destroy. | |
130 | */ | |
131 | LTTNG_HIDDEN | |
132 | struct lttng_trigger *lttng_triggers_borrow_mutable_at_index( | |
133 | const struct lttng_triggers *triggers, unsigned int index); | |
134 | ||
135 | /* | |
136 | * Add a trigger to the triggers set. | |
137 | * | |
138 | * A reference to the added trigger is acquired on behalf of the trigger set | |
139 | * on success. | |
140 | */ | |
141 | LTTNG_HIDDEN | |
142 | int lttng_triggers_add( | |
143 | struct lttng_triggers *triggers, struct lttng_trigger *trigger); | |
144 | ||
145 | /* | |
146 | * Serialize a trigger set to an lttng_payload object. | |
147 | * Return LTTNG_OK on success, negative lttng error code on error. | |
148 | */ | |
149 | LTTNG_HIDDEN | |
150 | int lttng_triggers_serialize(const struct lttng_triggers *triggers, | |
151 | struct lttng_payload *payload); | |
152 | ||
153 | LTTNG_HIDDEN | |
154 | ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view, | |
155 | struct lttng_triggers **triggers); | |
156 | ||
3da864a9 JR |
157 | LTTNG_HIDDEN |
158 | const struct lttng_credentials *lttng_trigger_get_credentials( | |
159 | const struct lttng_trigger *trigger); | |
160 | ||
161 | LTTNG_HIDDEN | |
64eafdf6 | 162 | void lttng_trigger_set_credentials(struct lttng_trigger *trigger, |
3da864a9 JR |
163 | const struct lttng_credentials *creds); |
164 | ||
5c504c41 JR |
165 | |
166 | /* | |
167 | * Fire the trigger. | |
168 | * Increments the occurrence count. | |
169 | */ | |
170 | LTTNG_HIDDEN | |
171 | void lttng_trigger_fire(struct lttng_trigger *trigger); | |
172 | ||
173 | /* | |
174 | * Check if the trigger would fire. | |
175 | */ | |
176 | LTTNG_HIDDEN | |
177 | bool lttng_trigger_should_fire(const struct lttng_trigger *trigger); | |
178 | ||
91c96f62 JR |
179 | /* |
180 | * Return the type of any underlying domain restriction. If no particular | |
181 | * requirement is present, returns LTTNG_DOMAIN_NONE. | |
182 | */ | |
183 | LTTNG_HIDDEN | |
184 | enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction( | |
185 | const struct lttng_trigger *trigger); | |
186 | ||
58daac01 JR |
187 | /* |
188 | * Generate any bytecode related to the trigger. | |
189 | * On success LTTNG_OK. On error, returns lttng_error code. | |
190 | */ | |
191 | LTTNG_HIDDEN | |
192 | enum lttng_error_code lttng_trigger_generate_bytecode( | |
193 | struct lttng_trigger *trigger, | |
194 | const struct lttng_credentials *creds); | |
195 | ||
b61776fb SM |
196 | LTTNG_HIDDEN |
197 | struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); | |
198 | ||
a58c490f | 199 | #endif /* LTTNG_TRIGGER_INTERNAL_H */ |