actions: introduce function typedef for creating actions from buffer
[lttng-tools.git] / include / lttng / rotation.h
CommitLineData
db66e574 1/*
ab5be9fa
MJ
2 * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
db66e574 4 *
ab5be9fa 5 * SPDX-License-Identifier: LGPL-2.1-only
db66e574 6 *
db66e574
JD
7 */
8
9#ifndef LTTNG_ROTATION_H
10#define LTTNG_ROTATION_H
11
12#include <stdint.h>
dd73d57b 13#include <lttng/location.h>
db66e574
JD
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/*
d68c9a04 20 * Return codes for lttng_rotation_handle_get_state()
db66e574 21 */
d68c9a04 22enum lttng_rotation_state {
4f23c583
JG
23 /*
24 * Session has not been rotated.
25 */
26 LTTNG_ROTATION_STATE_NO_ROTATION = 0,
db66e574 27 /*
d68c9a04 28 * Rotation is ongoing, but has not been completed yet.
db66e574 29 */
4f23c583 30 LTTNG_ROTATION_STATE_ONGOING = 1,
db66e574 31 /*
d68c9a04
JD
32 * Rotation has been completed and the resulting chunk
33 * can now safely be read.
db66e574 34 */
4f23c583 35 LTTNG_ROTATION_STATE_COMPLETED = 2,
db66e574 36 /*
d68c9a04
JD
37 * The rotation has expired.
38 *
39 * The information associated with a given rotation is eventually
40 * purged by the session daemon. In such a case, the attributes of
41 * the rotation, such as its path, may no longer be available.
42 *
43 * Note that this state does not guarantee the the rotation was
44 * completed successfully.
db66e574 45 */
4f23c583 46 LTTNG_ROTATION_STATE_EXPIRED = 3,
db66e574 47 /*
d68c9a04 48 * The rotation could not be completed due to an error.
db66e574 49 */
0e5e4beb 50 LTTNG_ROTATION_STATE_ERROR = -1,
d68c9a04
JD
51};
52
53enum lttng_rotation_status {
54 LTTNG_ROTATION_STATUS_OK = 0,
55 /* Information not available. */
56 LTTNG_ROTATION_STATUS_UNAVAILABLE = 1,
57 /* Generic error. */
58 LTTNG_ROTATION_STATUS_ERROR = -1,
59 /* Invalid parameters provided. */
60 LTTNG_ROTATION_STATUS_INVALID = -2,
66ea93b1
JG
61 /* A schedule of this type is already set. */
62 LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET = -3,
63 /* No such rotation schedule set. */
64 LTTNG_ROTATION_STATUS_SCHEDULE_NOT_SET = -3,
db66e574
JD
65};
66
66ea93b1
JG
67enum lttng_rotation_schedule_type {
68 LTTNG_ROTATION_SCHEDULE_TYPE_UNKNOWN = -1,
69 LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD = 0,
70 LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC = 1,
71};
d68c9a04
JD
72
73/*
66ea93b1
JG
74 * Descriptor of an immediate session rotation to be performed as soon as
75 * possible by the tracers.
259c2674 76 */
66ea93b1 77struct lttng_rotation_immediate_descriptor;
259c2674 78
259c2674 79/*
66ea93b1 80 * Session rotation schedule to add to a session.
259c2674 81 */
66ea93b1 82struct lttng_rotation_schedule;
259c2674 83
d68c9a04 84/*
66ea93b1 85 * A set of lttng_rotation_schedule objects.
259c2674 86 */
66ea93b1 87struct lttng_rotation_schedules;
259c2674 88
90936dcf 89/*
66ea93b1 90 * Handle used to represent a specific rotation.
90936dcf 91 */
66ea93b1 92struct lttng_rotation_handle;
90936dcf 93
259c2674
JD
94/*
95 * lttng rotate session handle functions.
96 */
97
d68c9a04
JD
98/*
99 * Get the current state of the rotation referenced by the handle.
100 *
101 * This will issue a request to the session daemon on every call. Hence,
102 * the result of this call may change over time.
103 */
104extern enum lttng_rotation_status lttng_rotation_handle_get_state(
105 struct lttng_rotation_handle *rotation_handle,
106 enum lttng_rotation_state *rotation_state);
107
108/*
109 * Get the location of the rotation's resulting archive.
110 *
111 * The rotation must be completed in order for this call to succeed.
dd73d57b 112 * The location returned remains owned by the rotation handle.
d68c9a04 113 *
dd73d57b
JG
114 * Note that location will not be set in case of error, or if the session
115 * rotation handle has expired.
d68c9a04 116 */
dd73d57b 117extern enum lttng_rotation_status lttng_rotation_handle_get_archive_location(
d68c9a04 118 struct lttng_rotation_handle *rotation_handle,
dd73d57b 119 const struct lttng_trace_archive_location **location);
d68c9a04
JD
120
121/*
122 * Destroy an lttng_rotate_session handle.
123 */
124extern void lttng_rotation_handle_destroy(
125 struct lttng_rotation_handle *rotation_handle);
126
127/*
dbd512ea 128 * Rotate the output folder of the session.
d68c9a04
JD
129 *
130 * On success, handle is allocated and can be used to monitor the progress
131 * of the rotation with lttng_rotation_get_state(). The handle must be freed
132 * by the caller with lttng_rotation_handle_destroy().
133 *
66ea93b1 134 * Passing NULL as the immediate rotation descriptor results in the default
dbd512ea
JG
135 * options being used.
136 *
d68c9a04
JD
137 * Return 0 if the rotate action was successfully launched or a negative
138 * LTTng error code on error.
139 */
dbd512ea 140extern int lttng_rotate_session(const char *session_name,
66ea93b1 141 struct lttng_rotation_immediate_descriptor *descriptor,
d68c9a04
JD
142 struct lttng_rotation_handle **rotation_handle);
143
259c2674 144/*
66ea93b1
JG
145 * Get the type of a rotation schedule object.
146 */
147extern enum lttng_rotation_schedule_type lttng_rotation_schedule_get_type(
148 const struct lttng_rotation_schedule *schedule);
149
150/*
151 * Return a newly allocated size-based session rotation schedule or NULL on
152 * error.
153 */
154extern struct lttng_rotation_schedule *
155lttng_rotation_schedule_size_threshold_create(void);
156
157/*
158 * Get a session rotation schedule's size threshold.
159 *
160 * Returns LTTNG_ROTATION_STATUS_OK on success.
161 * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset.
162 */
163extern enum lttng_rotation_status
164lttng_rotation_schedule_size_threshold_get_threshold(
165 const struct lttng_rotation_schedule *schedule,
166 uint64_t *size_threshold_bytes);
167
168/*
169 * Set a session rotation schedule's size threshold.
170 */
171extern enum lttng_rotation_status
172lttng_rotation_schedule_size_threshold_set_threshold(
173 struct lttng_rotation_schedule *schedule,
174 uint64_t size_threshold_bytes);
175
176/*
177 * Return a newly allocated periodic session rotation schedule or NULL on
178 * error.
179 */
180extern struct lttng_rotation_schedule *
181lttng_rotation_schedule_periodic_create(void);
182
183/*
184 * Get a time-based session rotation schedule's period.
185 *
186 * Returns LTTNG_ROTATION_STATUS_OK on success.
187 * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset.
188 */
189extern enum lttng_rotation_status lttng_rotation_schedule_periodic_get_period(
190 const struct lttng_rotation_schedule *schedule,
191 uint64_t *period_us);
192
193/*
194 * Set a time-based session rotation schedule's period.
195 */
196extern enum lttng_rotation_status lttng_rotation_schedule_periodic_set_period(
197 struct lttng_rotation_schedule *schedule,
198 uint64_t period_us);
199
200/*
201 * Destroy a rotation schedule.
202 */
203extern void lttng_rotation_schedule_destroy(
204 struct lttng_rotation_schedule *schedule);
205
206/*
207 * Destroy a set of rotation schedules. Pointers to any schedule contained
208 * in this set become invalid after this call.
209 */
210extern void lttng_rotation_schedules_destroy(
211 struct lttng_rotation_schedules *schedules);
212
213/*
214 * Get the number of schedules in a schedule set.
215 */
216extern enum lttng_rotation_status lttng_rotation_schedules_get_count(
217 const struct lttng_rotation_schedules *schedules,
218 unsigned int *count);
219
220/*
221 * Get a schedule from the set at a given index.
222 *
223 * Note that the set maintains the ownership of the returned schedule.
224 * It must not be destroyed by the user, nor should it be held beyond
225 * the lifetime of the schedules set.
226 *
227 * Returns a rotation schedule, or NULL on error.
228 */
229extern const struct lttng_rotation_schedule *
230lttng_rotation_schedules_get_at_index(
231 const struct lttng_rotation_schedules *schedules,
232 unsigned int index);
233
234/*
235 * Add a session rotation schedule to a session.
236 *
237 * Note that the current implementation currently limits the rotation schedules
238 * associated to a given session to one per type.
239 *
240 * Returns LTTNG_ROTATION_STATUS_OK on success,
241 * LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET if a rotation of the same type
242 * is already set.
259c2674 243 */
66ea93b1
JG
244extern enum lttng_rotation_status lttng_session_add_rotation_schedule(
245 const char *session_name,
246 const struct lttng_rotation_schedule *schedule);
259c2674 247
329f3443 248/*
66ea93b1 249 * Remove a session rotation schedule from a session.
329f3443 250 *
66ea93b1
JG
251 * Returns LTTNG_ROTATION_STATUS_OK on success,
252 * LTTNG_ROTATION_STATUS_SCHEDULE_INVALID if the provided schedule is
253 * not set.
329f3443 254 */
66ea93b1
JG
255extern enum lttng_rotation_status lttng_session_remove_rotation_schedule(
256 const char *session_name,
257 const struct lttng_rotation_schedule *schedule);
329f3443
JD
258
259/*
66ea93b1 260 * Get the rotation schedules associated with a given session.
329f3443 261 *
66ea93b1 262 * Returns LTTNG_OK on success, or a negative lttng error code on error.
329f3443 263 */
66ea93b1
JG
264extern int lttng_session_list_rotation_schedules(
265 const char *session_name,
266 struct lttng_rotation_schedules **schedules);
329f3443 267
db66e574
JD
268#ifdef __cplusplus
269}
270#endif
271
272#endif /* LTTNG_ROTATION_H */
This page took 0.039507 seconds and 4 git commands to generate.