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