2 * Copyright (C) 2017 - Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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
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
19 #ifndef LTTNG_ROTATION_H
20 #define LTTNG_ROTATION_H
23 #include <lttng/location.h>
30 * Return codes for lttng_rotation_handle_get_state()
32 enum lttng_rotation_state
{
34 * Session has not been rotated.
36 LTTNG_ROTATION_STATE_NO_ROTATION
= 0,
38 * Rotation is ongoing, but has not been completed yet.
40 LTTNG_ROTATION_STATE_ONGOING
= 1,
42 * Rotation has been completed and the resulting chunk
43 * can now safely be read.
45 LTTNG_ROTATION_STATE_COMPLETED
= 2,
47 * The rotation has expired.
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.
53 * Note that this state does not guarantee the the rotation was
54 * completed successfully.
56 LTTNG_ROTATION_STATE_EXPIRED
= 3,
58 * The rotation could not be completed due to an error.
60 LTTNG_ROTATION_STATE_ERROR
= -1,
63 enum lttng_rotation_status
{
64 LTTNG_ROTATION_STATUS_OK
= 0,
65 /* Information not available. */
66 LTTNG_ROTATION_STATUS_UNAVAILABLE
= 1,
68 LTTNG_ROTATION_STATUS_ERROR
= -1,
69 /* Invalid parameters provided. */
70 LTTNG_ROTATION_STATUS_INVALID
= -2,
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,
77 enum 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,
84 * Descriptor of an immediate session rotation to be performed as soon as
85 * possible by the tracers.
87 struct lttng_rotation_immediate_descriptor
;
90 * Session rotation schedule to add to a session.
92 struct lttng_rotation_schedule
;
95 * A set of lttng_rotation_schedule objects.
97 struct lttng_rotation_schedules
;
100 * Handle used to represent a specific rotation.
102 struct lttng_rotation_handle
;
105 * lttng rotate session handle functions.
109 * Get the current state of the rotation referenced by the handle.
111 * This will issue a request to the session daemon on every call. Hence,
112 * the result of this call may change over time.
114 extern enum lttng_rotation_status
lttng_rotation_handle_get_state(
115 struct lttng_rotation_handle
*rotation_handle
,
116 enum lttng_rotation_state
*rotation_state
);
119 * Get the location of the rotation's resulting archive.
121 * The rotation must be completed in order for this call to succeed.
122 * The location returned remains owned by the rotation handle.
124 * Note that location will not be set in case of error, or if the session
125 * rotation handle has expired.
127 extern enum lttng_rotation_status
lttng_rotation_handle_get_archive_location(
128 struct lttng_rotation_handle
*rotation_handle
,
129 const struct lttng_trace_archive_location
**location
);
132 * Destroy an lttng_rotate_session handle.
134 extern void lttng_rotation_handle_destroy(
135 struct lttng_rotation_handle
*rotation_handle
);
138 * Rotate the output folder of the session.
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().
144 * Passing NULL as the immediate rotation descriptor results in the default
145 * options being used.
147 * Return 0 if the rotate action was successfully launched or a negative
148 * LTTng error code on error.
150 extern int lttng_rotate_session(const char *session_name
,
151 struct lttng_rotation_immediate_descriptor
*descriptor
,
152 struct lttng_rotation_handle
**rotation_handle
);
155 * Get the type of a rotation schedule object.
157 extern enum lttng_rotation_schedule_type
lttng_rotation_schedule_get_type(
158 const struct lttng_rotation_schedule
*schedule
);
161 * Return a newly allocated size-based session rotation schedule or NULL on
164 extern struct lttng_rotation_schedule
*
165 lttng_rotation_schedule_size_threshold_create(void);
168 * Get a session rotation schedule's size threshold.
170 * Returns LTTNG_ROTATION_STATUS_OK on success.
171 * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset.
173 extern enum lttng_rotation_status
174 lttng_rotation_schedule_size_threshold_get_threshold(
175 const struct lttng_rotation_schedule
*schedule
,
176 uint64_t *size_threshold_bytes
);
179 * Set a session rotation schedule's size threshold.
181 extern enum lttng_rotation_status
182 lttng_rotation_schedule_size_threshold_set_threshold(
183 struct lttng_rotation_schedule
*schedule
,
184 uint64_t size_threshold_bytes
);
187 * Return a newly allocated periodic session rotation schedule or NULL on
190 extern struct lttng_rotation_schedule
*
191 lttng_rotation_schedule_periodic_create(void);
194 * Get a time-based session rotation schedule's period.
196 * Returns LTTNG_ROTATION_STATUS_OK on success.
197 * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset.
199 extern enum lttng_rotation_status
lttng_rotation_schedule_periodic_get_period(
200 const struct lttng_rotation_schedule
*schedule
,
201 uint64_t *period_us
);
204 * Set a time-based session rotation schedule's period.
206 extern enum lttng_rotation_status
lttng_rotation_schedule_periodic_set_period(
207 struct lttng_rotation_schedule
*schedule
,
211 * Destroy a rotation schedule.
213 extern void lttng_rotation_schedule_destroy(
214 struct lttng_rotation_schedule
*schedule
);
217 * Destroy a set of rotation schedules. Pointers to any schedule contained
218 * in this set become invalid after this call.
220 extern void lttng_rotation_schedules_destroy(
221 struct lttng_rotation_schedules
*schedules
);
224 * Get the number of schedules in a schedule set.
226 extern enum lttng_rotation_status
lttng_rotation_schedules_get_count(
227 const struct lttng_rotation_schedules
*schedules
,
228 unsigned int *count
);
231 * Get a schedule from the set at a given index.
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.
237 * Returns a rotation schedule, or NULL on error.
239 extern const struct lttng_rotation_schedule
*
240 lttng_rotation_schedules_get_at_index(
241 const struct lttng_rotation_schedules
*schedules
,
245 * Add a session rotation schedule to a session.
247 * Note that the current implementation currently limits the rotation schedules
248 * associated to a given session to one per type.
250 * Returns LTTNG_ROTATION_STATUS_OK on success,
251 * LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET if a rotation of the same type
254 extern enum lttng_rotation_status
lttng_session_add_rotation_schedule(
255 const char *session_name
,
256 const struct lttng_rotation_schedule
*schedule
);
259 * Remove a session rotation schedule from a session.
261 * Returns LTTNG_ROTATION_STATUS_OK on success,
262 * LTTNG_ROTATION_STATUS_SCHEDULE_INVALID if the provided schedule is
265 extern enum lttng_rotation_status
lttng_session_remove_rotation_schedule(
266 const char *session_name
,
267 const struct lttng_rotation_schedule
*schedule
);
270 * Get the rotation schedules associated with a given session.
272 * Returns LTTNG_OK on success, or a negative lttng error code on error.
274 extern int lttng_session_list_rotation_schedules(
275 const char *session_name
,
276 struct lttng_rotation_schedules
**schedules
);
282 #endif /* LTTNG_ROTATION_H */