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