Fix: liblttng-ctl: leak of tracker handle in lttng_[un]track_pid
[lttng-tools.git] / include / lttng / rotation.h
index 6091a7b988078039f73d641a6329cd6045f21701..316f2cdb52c5700e5dd42dd409d910cbd98f04f5 100644 (file)
@@ -1,19 +1,9 @@
 /*
- * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
- * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
+ * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License, version 2.1 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifndef LTTNG_ROTATION_H
@@ -57,7 +47,7 @@ enum lttng_rotation_state {
        /*
         * The rotation could not be completed due to an error.
         */
-       LTTNG_ROTATION_STATE_ERROR = 4,
+       LTTNG_ROTATION_STATE_ERROR = -1,
 };
 
 enum lttng_rotation_status {
@@ -68,51 +58,38 @@ enum lttng_rotation_status {
        LTTNG_ROTATION_STATUS_ERROR = -1,
        /* Invalid parameters provided. */
        LTTNG_ROTATION_STATUS_INVALID = -2,
+       /* A schedule of this type is already set. */
+       LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET = -3,
+       /* No such rotation schedule set. */
+       LTTNG_ROTATION_STATUS_SCHEDULE_NOT_SET = -3,
 };
 
-/*
- * Input parameter to the lttng_rotate_session command.
- *
- * An immediate rotation is performed as soon as possible by the tracers.
- */
-struct lttng_rotation_immediate_attr;
-
-/*
- * Input parameter to the lttng_rotate_schedule command.
- */
-struct lttng_rotation_schedule_attr;
-
-/*
- * Handle used to represent a specific rotation.
- */
-struct lttng_rotation_handle;
+enum lttng_rotation_schedule_type {
+       LTTNG_ROTATION_SCHEDULE_TYPE_UNKNOWN = -1,
+       LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD = 0,
+       LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC = 1,
+};
 
 /*
- * Return a newly allocated session rotation schedule descriptor object or NULL
- * on error.
- *
- * The rotation schedule may be expressed as a size or as a time period.
+ * Descriptor of an immediate session rotation to be performed as soon as
+ * possible by the tracers.
  */
-extern struct lttng_rotation_schedule_attr *
-lttng_rotation_schedule_attr_create(void);
+struct lttng_rotation_immediate_descriptor;
 
 /*
- * Destroy a given scheduled rotate session descriptor object.
+ * Session rotation schedule to add to a session.
  */
-extern void lttng_rotation_schedule_attr_destroy(
-               struct lttng_rotation_schedule_attr *attr);
+struct lttng_rotation_schedule;
 
 /*
- * Set the timer to periodically rotate the session (in µs).
+ * A set of lttng_rotation_schedule objects.
  */
-extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
-               struct lttng_rotation_schedule_attr *attr, uint64_t timer);
+struct lttng_rotation_schedules;
 
 /*
- * Set the size to rotate the session (in bytes).
+ * Handle used to represent a specific rotation.
  */
-void lttng_rotation_schedule_attr_set_size(
-               struct lttng_rotation_schedule_attr *attr, uint64_t size);
+struct lttng_rotation_handle;
 
 /*
  * lttng rotate session handle functions.
@@ -154,41 +131,139 @@ extern void lttng_rotation_handle_destroy(
  * of the rotation with lttng_rotation_get_state(). The handle must be freed
  * by the caller with lttng_rotation_handle_destroy().
  *
- * Passing NULL as the immediate rotation attribute results in the default
+ * Passing NULL as the immediate rotation descriptor results in the default
  * options being used.
  *
  * Return 0 if the rotate action was successfully launched or a negative
  * LTTng error code on error.
  */
 extern int lttng_rotate_session(const char *session_name,
-               struct lttng_rotation_immediate_attr *attr,
+               struct lttng_rotation_immediate_descriptor *descriptor,
                struct lttng_rotation_handle **rotation_handle);
 
 /*
- * Configure a session to rotate according to a given schedule.
+ * Get the type of a rotation schedule object.
+ */
+extern enum lttng_rotation_schedule_type lttng_rotation_schedule_get_type(
+               const struct lttng_rotation_schedule *schedule);
+
+/*
+ * Return a newly allocated size-based session rotation schedule or NULL on
+ * error.
+ */
+extern struct lttng_rotation_schedule *
+lttng_rotation_schedule_size_threshold_create(void);
+
+/*
+ * Get a session rotation schedule's size threshold.
+ *
+ * Returns LTTNG_ROTATION_STATUS_OK on success.
+ * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset.
+ */
+extern enum lttng_rotation_status
+lttng_rotation_schedule_size_threshold_get_threshold(
+               const struct lttng_rotation_schedule *schedule,
+               uint64_t *size_threshold_bytes);
+
+/*
+ * Set a session rotation schedule's size threshold.
+ */
+extern enum lttng_rotation_status
+lttng_rotation_schedule_size_threshold_set_threshold(
+               struct lttng_rotation_schedule *schedule,
+               uint64_t size_threshold_bytes);
+
+/*
+ * Return a newly allocated periodic session rotation schedule or NULL on
+ * error.
+ */
+extern struct lttng_rotation_schedule *
+lttng_rotation_schedule_periodic_create(void);
+
+/*
+ * Get a time-based session rotation schedule's period.
+ *
+ * Returns LTTNG_ROTATION_STATUS_OK on success.
+ * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset.
+ */
+extern enum lttng_rotation_status lttng_rotation_schedule_periodic_get_period(
+               const struct lttng_rotation_schedule *schedule,
+               uint64_t *period_us);
+
+/*
+ * Set a time-based session rotation schedule's period.
+ */
+extern enum lttng_rotation_status lttng_rotation_schedule_periodic_set_period(
+               struct lttng_rotation_schedule *schedule,
+               uint64_t period_us);
+
+/*
+ * Destroy a rotation schedule.
+ */
+extern void lttng_rotation_schedule_destroy(
+               struct lttng_rotation_schedule *schedule);
+
+/*
+ * Destroy a set of rotation schedules. Pointers to any schedule contained
+ * in this set become invalid after this call.
+ */
+extern void lttng_rotation_schedules_destroy(
+               struct lttng_rotation_schedules *schedules);
+
+/*
+ * Get the number of schedules in a schedule set.
+ */
+extern enum lttng_rotation_status lttng_rotation_schedules_get_count(
+               const struct lttng_rotation_schedules *schedules,
+               unsigned int *count);
+
+/*
+ * Get a schedule from the set at a given index.
+ *
+ * Note that the set maintains the ownership of the returned schedule.
+ * It must not be destroyed by the user, nor should it be held beyond
+ * the lifetime of the schedules set.
+ *
+ * Returns a rotation schedule, or NULL on error.
+ */
+extern const struct lttng_rotation_schedule *
+lttng_rotation_schedules_get_at_index(
+               const struct lttng_rotation_schedules *schedules,
+               unsigned int index);
+
+/*
+ * Add a session rotation schedule to a session.
+ *
+ * Note that the current implementation currently limits the rotation schedules
+ * associated to a given session to one per type.
+ *
+ * Returns LTTNG_ROTATION_STATUS_OK on success,
+ * LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET if a rotation of the same type
+ * is already set.
  */
-extern int lttng_rotation_set_schedule(const char *session_name,
-               struct lttng_rotation_schedule_attr *attr);
+extern enum lttng_rotation_status lttng_session_add_rotation_schedule(
+               const char *session_name,
+               const struct lttng_rotation_schedule *schedule);
 
 /*
- * Ask the sessiond for the value of the rotate timer (in micro-seconds) of the
- * session.
+ * Remove a session rotation schedule from a session.
  *
- * On success, return 0 and set the value or rotate_timer, on error return a
- * negative value.
+ * Returns LTTNG_ROTATION_STATUS_OK on success,
+ * LTTNG_ROTATION_STATUS_SCHEDULE_INVALID if the provided schedule is
+ * not set.
  */
-extern int lttng_rotation_schedule_get_timer_period(const char *session_name,
-               uint64_t *rotate_timer);
+extern enum lttng_rotation_status lttng_session_remove_rotation_schedule(
+               const char *session_name,
+               const struct lttng_rotation_schedule *schedule);
 
 /*
- * Ask the sessiond for the value of the rotate size (in micro-seconds) of the
- * session.
+ * Get the rotation schedules associated with a given session.
  *
- * On success, return 0 and set the value or rotate_size, on error return
- * a negative value.
+ * Returns LTTNG_OK on success, or a negative lttng error code on error.
  */
-extern int lttng_rotation_schedule_get_size(const char *session_name,
-               uint64_t *rotate_size);
+extern int lttng_session_list_rotation_schedules(
+               const char *session_name,
+               struct lttng_rotation_schedules **schedules);
 
 #ifdef __cplusplus
 }
This page took 0.026367 seconds and 5 git commands to generate.