#define LTTNG_ACTION_ROTATE_SESSION_H
struct lttng_action;
+struct lttng_firing_policy;
#ifdef __cplusplus
extern "C" {
extern enum lttng_action_status lttng_action_rotate_session_get_session_name(
const struct lttng_action *action, const char **session_name);
+/*
+ * Set the firing policy of a rotate session action.
+ *
+ * Returns LTTNG_ACTION_STATUS_OK on success,
+ * LTTNG_ACTION_STATUS_ERROR on internal error,
+ * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
+ */
+extern enum lttng_action_status lttng_action_rotate_session_set_firing_policy(
+ struct lttng_action *action,
+ const struct lttng_firing_policy *policy);
+
+/*
+ * Get the firing policy of a rotate session action.
+ *
+ * Returns LTTNG_ACTION_STATUS_OK on success,
+ * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
+ */
+extern enum lttng_action_status lttng_action_rotate_session_get_firing_policy(
+ const struct lttng_action *action,
+ const struct lttng_firing_policy **policy);
+
#ifdef __cplusplus
}
#endif
#include <common/error.h>
#include <common/macros.h>
#include <lttng/action/action-internal.h>
+#include <lttng/action/firing-policy-internal.h>
+#include <lttng/action/firing-policy.h>
#include <lttng/action/rotate-session-internal.h>
#include <lttng/action/rotate-session.h>
/* Owned by this. */
char *session_name;
+ struct lttng_firing_policy *policy;
};
struct lttng_action_rotate_session_comm {
* Variable data:
*
* - session name (null terminated)
+ * - policy
*/
char data[];
} LTTNG_PACKED;
goto end;
}
- is_equal = true;
+ is_equal = lttng_firing_policy_is_equal(a->policy, b->policy);
end:
return is_equal;
}
goto end;
}
- ret = 0;
+ ret = lttng_firing_policy_serialize(
+ action_rotate_session->policy, payload);
+ if (ret) {
+ ret = -1;
+ goto end;
+ }
end:
return ret;
}
action_rotate_session = action_rotate_session_from_action(action);
+ lttng_firing_policy_destroy(action_rotate_session->policy);
free(action_rotate_session->session_name);
free(action_rotate_session);
struct lttng_payload_view *view,
struct lttng_action **p_action)
{
- ssize_t consumed_len;
+ ssize_t consumed_len, ret;
const struct lttng_action_rotate_session_comm *comm;
const char *session_name;
struct lttng_action *action;
enum lttng_action_status status;
+ struct lttng_firing_policy *policy = NULL;
action = lttng_action_rotate_session_create();
if (!action) {
consumed_len = -1;
goto end;
}
+ consumed_len = sizeof(*comm) + comm->session_name_len;
+
+ /* Firing policy. */
+ {
+ struct lttng_payload_view policy_view =
+ lttng_payload_view_from_view(
+ view, consumed_len, -1);
+ ret = lttng_firing_policy_create_from_payload(
+ &policy_view, &policy);
+ if (ret < 0) {
+ consumed_len = -1;
+ goto end;
+ }
+ consumed_len += ret;
+ }
status = lttng_action_rotate_session_set_session_name(
action, session_name);
goto end;
}
- consumed_len = sizeof(*comm) + comm->session_name_len;
+ assert(policy);
+ status = lttng_action_rotate_session_set_firing_policy(action, policy);
+ if (status != LTTNG_ACTION_STATUS_OK) {
+ consumed_len = -1;
+ goto end;
+ }
+
*p_action = action;
action = NULL;
end:
+ lttng_firing_policy_destroy(policy);
lttng_action_rotate_session_destroy(action);
return consumed_len;
struct lttng_action *lttng_action_rotate_session_create(void)
{
- struct lttng_action *action;
+ struct lttng_action *action = NULL;
+ struct lttng_firing_policy *policy = NULL;
+ enum lttng_action_status status;
+
+ /* Create a every N = 1 firing policy. */
+ policy = lttng_firing_policy_every_n_create(1);
+ if (!policy) {
+ goto end;
+ }
action = zmalloc(sizeof(struct lttng_action_rotate_session));
if (!action) {
lttng_action_rotate_session_is_equal,
lttng_action_rotate_session_destroy);
+ status = lttng_action_rotate_session_set_firing_policy(action, policy);
+ if (status != LTTNG_ACTION_STATUS_OK) {
+ free(action);
+ action = NULL;
+ goto end;
+ }
+
end:
+ lttng_firing_policy_destroy(policy);
return action;
}
end:
return status;
}
+
+enum lttng_action_status lttng_action_rotate_session_set_firing_policy(
+ struct lttng_action *action,
+ const struct lttng_firing_policy *policy)
+{
+ enum lttng_action_status status;
+ struct lttng_action_rotate_session *rotate_session_action;
+ struct lttng_firing_policy *copy = NULL;
+
+ if (!action || !policy || !IS_ROTATE_SESSION_ACTION(action)) {
+ status = LTTNG_ACTION_STATUS_INVALID;
+ goto end;
+ }
+
+ copy = lttng_firing_policy_copy(policy);
+ if (!copy) {
+ status = LTTNG_ACTION_STATUS_ERROR;
+ goto end;
+ }
+
+ rotate_session_action = action_rotate_session_from_action(action);
+
+ /* Free the previous firing policy .*/
+ lttng_firing_policy_destroy(rotate_session_action->policy);
+
+ /* Assign the policy. */
+ rotate_session_action->policy = copy;
+ status = LTTNG_ACTION_STATUS_OK;
+ copy = NULL;
+
+end:
+ lttng_firing_policy_destroy(copy);
+ return status;
+}
+
+enum lttng_action_status lttng_action_rotate_session_get_firing_policy(
+ const struct lttng_action *action,
+ const struct lttng_firing_policy **policy)
+{
+ enum lttng_action_status status;
+ const struct lttng_action_rotate_session *rotate_session_action;
+
+ if (!action || !policy || !IS_ROTATE_SESSION_ACTION(action)) {
+ status = LTTNG_ACTION_STATUS_INVALID;
+ goto end;
+ }
+
+ rotate_session_action = action_rotate_session_from_action_const(action);
+
+ *policy = rotate_session_action->policy;
+ status = LTTNG_ACTION_STATUS_OK;
+end:
+ return status;
+}