Add session rotation ongoing/completed conditions
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Aug 2018 17:25:44 +0000 (13:25 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 Aug 2018 01:15:03 +0000 (21:15 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/Makefile.am
include/lttng/condition/condition.h
include/lttng/condition/evaluation-internal.h
include/lttng/condition/session-rotation-internal.h [new file with mode: 0644]
include/lttng/condition/session-rotation.h [new file with mode: 0644]
include/lttng/lttng.h
src/common/Makefile.am
src/common/condition.c
src/common/evaluation.c
src/common/session-rotation.c [new file with mode: 0644]

index 2c0019870f205787f940be1453dc286e953cdbe0..2da03f493b4eef18eecda6681b101195ebd2348f 100644 (file)
@@ -92,6 +92,7 @@ lttngconditioninclude_HEADERS= \
        lttng/condition/condition.h \
        lttng/condition/buffer-usage.h \
        lttng/condition/session-consumed-size.h \
+       lttng/condition/session-rotation.h \
        lttng/condition/evaluation.h
 
 lttngnotificationinclude_HEADERS= \
@@ -112,6 +113,7 @@ noinst_HEADERS = \
        lttng/condition/buffer-usage-internal.h \
        lttng/condition/session-consumed-size-internal.h \
        lttng/condition/evaluation-internal.h \
+       lttng/condition/session-rotation-internal.h \
        lttng/notification/notification-internal.h \
        lttng/trigger/trigger-internal.h \
        lttng/endpoint-internal.h \
index f179856e2a7c28fc4805297ec0334b2504c01365..3cecfc1dd8b3f99f3afdb505935775dd901ef4f8 100644 (file)
@@ -26,9 +26,11 @@ struct lttng_condition;
 
 enum lttng_condition_type {
        LTTNG_CONDITION_TYPE_UNKNOWN = -1,
-       LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW = 102,
-       LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH = 101,
        LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE = 100,
+       LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH = 101,
+       LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW = 102,
+       LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING = 103,
+       LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED = 104,
 };
 
 enum lttng_condition_status {
index 95119b37e97ea6bdab84d2814d6a42baa9653a5d..b88a0f712ab69aa9e0b508653fbb456f74db62a0 100644 (file)
@@ -41,6 +41,10 @@ struct lttng_evaluation {
        evaluation_destroy_cb destroy;
 };
 
+LTTNG_HIDDEN
+void lttng_evaluation_init(struct lttng_evaluation *evaluation,
+               enum lttng_condition_type type);
+
 LTTNG_HIDDEN
 ssize_t lttng_evaluation_create_from_buffer(const struct lttng_buffer_view *view,
                struct lttng_evaluation **evaluation);
diff --git a/include/lttng/condition/session-rotation-internal.h b/include/lttng/condition/session-rotation-internal.h
new file mode 100644 (file)
index 0000000..0afac8d
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 - 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.
+ *
+ * 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_CONDITION_SESSION_ROTATION_INTERNAL_H
+#define LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H
+
+#include <lttng/condition/session-rotation.h>
+#include <lttng/condition/condition-internal.h>
+#include <lttng/condition/evaluation-internal.h>
+#include "common/buffer-view.h"
+#include <lttng/location.h>
+
+struct lttng_condition_session_rotation {
+       struct lttng_condition parent;
+       char *session_name;
+};
+
+struct lttng_condition_session_rotation_comm {
+       /* Length includes the trailing \0. */
+       uint32_t session_name_len;
+       char session_name[];
+} LTTNG_PACKED;
+
+struct lttng_evaluation_session_rotation {
+       struct lttng_evaluation parent;
+       uint64_t id;
+       struct lttng_trace_archive_location *location;
+};
+
+struct lttng_evaluation_session_rotation_comm {
+       uint64_t id;
+       uint8_t has_location;
+} LTTNG_PACKED;
+
+LTTNG_HIDDEN
+ssize_t lttng_condition_session_rotation_ongoing_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_condition **condition);
+
+LTTNG_HIDDEN
+ssize_t lttng_condition_session_rotation_completed_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_condition **condition);
+
+LTTNG_HIDDEN
+struct lttng_evaluation *lttng_evaluation_session_rotation_ongoing_create(
+                uint64_t id);
+
+/* Ownership of location is transferred to the evaluation. */
+LTTNG_HIDDEN
+struct lttng_evaluation *lttng_evaluation_session_rotation_completed_create(
+               uint64_t id,
+               struct lttng_trace_archive_location *location);
+
+LTTNG_HIDDEN
+ssize_t lttng_evaluation_session_rotation_ongoing_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_evaluation **evaluation);
+
+LTTNG_HIDDEN
+ssize_t lttng_evaluation_session_rotation_completed_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_evaluation **evaluation);
+
+#endif /* LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H */
diff --git a/include/lttng/condition/session-rotation.h b/include/lttng/condition/session-rotation.h
new file mode 100644 (file)
index 0000000..5ed71fa
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2017 - 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.
+ *
+ * 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_CONDITION_SESSION_ROTATION_H
+#define LTTNG_CONDITION_SESSION_ROTATION_H
+
+#include <lttng/condition/evaluation.h>
+#include <lttng/condition/condition.h>
+#include <stdint.h>
+#include <lttng/domain.h>
+#include <lttng/location.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Session rotation conditions allow an action to be taken whenever a
+ * session rotation is ongoing or completed.
+ *
+ * Session rotation conditions have the following properties:
+ *   - the exact name of the session to be monitored for rotations
+ *
+ * Wildcards, regular expressions or other globbing mechanisms are not supported
+ * in session rotation condition properties.
+ */
+
+/*
+ * Create a newly allocated session rotation in progress condition.
+ *
+ * A session rotation ongoing condition evaluates to true whenever a rotation
+ * is ongoing for a given session.
+ *
+ * Returns a new condition on success, NULL on failure. This condition must be
+ * destroyed using lttng_condition_destroy().
+ */
+extern struct lttng_condition *
+lttng_condition_session_rotation_ongoing_create(void);
+
+/*
+ * Create a newly allocated session rotation completion condition.
+ *
+ * A session rotation completed condition evaluates to true whenever a rotation
+ * is completed for a given session. This condition is not evaluated on
+ * subscription or registration of a trigger. This means that a trigger
+ * using this condition will only fire when the next session rotation completes.
+ * Previously completed rotations will have no effect.
+ *
+ * Returns a new condition on success, NULL on failure. This condition must be
+ * destroyed using lttng_condition_destroy().
+ */
+ extern struct lttng_condition *
+ lttng_condition_session_rotation_completed_create(void);
+
+/*
+ * Get the session name property of a session rotation condition.
+ *
+ * The caller does not assume the ownership of the returned session name. The
+ * session name shall only only be used for the duration of the condition's
+ * lifetime, or before a different session name is set.
+ *
+ * Returns LTTNG_CONDITION_STATUS_OK and a pointer to the condition's session
+ * name on success, LTTNG_CONDITION_STATUS_INVALID if an invalid
+ * parameter is passed, or LTTNG_CONDITION_STATUS_UNSET if a session name
+ * was not set prior to this call.
+ */
+extern enum lttng_condition_status
+lttng_condition_session_rotation_get_session_name(
+               const struct lttng_condition *condition,
+               const char **session_name);
+
+/*
+ * Set the session name property of a session rotation condition.
+ *
+ * The passed session name parameter will be copied to the condition.
+ *
+ * Returns LTTNG_CONDITION_STATUS_OK on success, LTTNG_CONDITION_STATUS_INVALID
+ * if invalid paramenters are passed.
+ */
+extern enum lttng_condition_status
+lttng_condition_session_rotation_set_session_name(
+               struct lttng_condition *condition,
+               const char *session_name);
+
+/**
+ * lttng_evaluation_session_rotation are specialised lttng_evaluations
+ * which allow users to query a number of properties resulting from the
+ * evaluation of a condition which evaluated to true.
+ */
+
+/*
+ * Get the session rotation id property of a session rotation evaluation.
+ *
+ * Returns LTTNG_EVALUATION_STATUS_OK on success and the id of the session
+ * rotation, or LTTNG_EVALUATION_STATUS_INVALID if an invalid parameter is
+ * passed.
+ */
+extern enum lttng_evaluation_status
+lttng_evaluation_session_rotation_get_id(
+               const struct lttng_evaluation *evaluation, uint64_t *id);
+
+/*
+ * Get the session rotation location property of a session rotation completed
+ * evaluation.
+ *
+ * The caller does not assume the ownership of the returned location. The
+ * location shall only only be used for the duration of the evaluation's
+ * lifetime.
+ *
+ * Returns LTTNG_EVALUATION_STATUS_OK and set location on success.
+ * A NULL location may be returned if a rotation chunk's location
+ * has expired.
+ *
+ * LTTNG_EVALUATION_STATUS_INVALID is returned if an invalid parameter is
+ * passed.
+ */
+extern enum lttng_evaluation_status
+lttng_evaluation_session_rotation_completed_get_location(
+               const struct lttng_evaluation *evaluation,
+               const struct lttng_trace_archive_location **location);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LTTNG_CONDITION_SESSION_ROTATION_H */
index d13f9639f2c39814806fd20c936f2606f630ba5e..5c17fe37ec51c5a9eccd4ec4efeebccf3234587c 100644 (file)
@@ -40,6 +40,7 @@
 #include <lttng/condition/condition.h>
 #include <lttng/condition/buffer-usage.h>
 #include <lttng/condition/session-consumed-size.h>
+#include <lttng/condition/session-rotation.h>
 #include <lttng/condition/evaluation.h>
 #include <lttng/notification/channel.h>
 #include <lttng/notification/notification.h>
index c6b42e4dd77236bf3e2e8ed5231b2bb6ff5c5bfd..f39aeaa5f430b05b3b0788e2a69f3d9542a8645c 100644 (file)
@@ -73,6 +73,7 @@ libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.c runas.h \
                        filter.c filter.h context.c context.h \
                        action.c notify.c condition.c buffer-usage.c \
                        session-consumed-size.c \
+                       session-rotation.c \
                        evaluation.c notification.c trigger.c endpoint.c \
                        dynamic-buffer.h dynamic-buffer.c \
                        buffer-view.h buffer-view.c \
index 6cebeb03f7bb9d35e651a9a110bb36f087cfd1fe..c777fb9c553f759ed57e44d0e51fa44e41d4e9cc 100644 (file)
@@ -18,6 +18,7 @@
 #include <lttng/condition/condition-internal.h>
 #include <lttng/condition/buffer-usage-internal.h>
 #include <lttng/condition/session-consumed-size-internal.h>
+#include <lttng/condition/session-rotation-internal.h>
 #include <common/macros.h>
 #include <common/error.h>
 #include <common/dynamic-buffer.h>
@@ -142,6 +143,12 @@ ssize_t lttng_condition_create_from_buffer(
        case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
                create_from_buffer = lttng_condition_session_consumed_size_create_from_buffer;
                break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+               create_from_buffer = lttng_condition_session_rotation_ongoing_create_from_buffer;
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+               create_from_buffer = lttng_condition_session_rotation_completed_create_from_buffer;
+               break;
        default:
                ERR("Attempted to create condition of unknown type (%i)",
                                (int) condition_comm->condition_type);
index f07c81b18cf9747250bc3284ff04cf713d4ebbb7..91d5c0b1d8de7edbe397449784a264c873f9b923 100644 (file)
 #include <lttng/condition/evaluation-internal.h>
 #include <lttng/condition/buffer-usage-internal.h>
 #include <lttng/condition/session-consumed-size-internal.h>
+#include <lttng/condition/session-rotation-internal.h>
 #include <common/macros.h>
 #include <common/error.h>
 #include <stdbool.h>
 #include <assert.h>
 
+LTTNG_HIDDEN
+void lttng_evaluation_init(struct lttng_evaluation *evaluation,
+               enum lttng_condition_type type)
+{
+       evaluation->type = type;
+}
+
 LTTNG_HIDDEN
 int lttng_evaluation_serialize(struct lttng_evaluation *evaluation,
                struct lttng_dynamic_buffer *buf)
@@ -92,6 +100,22 @@ ssize_t lttng_evaluation_create_from_buffer(
                }
                evaluation_size += ret;
                break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+               ret = lttng_evaluation_session_rotation_ongoing_create_from_buffer(
+                               &evaluation_view, evaluation);
+               if (ret < 0) {
+                       goto end;
+               }
+               evaluation_size += ret;
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+               ret = lttng_evaluation_session_rotation_completed_create_from_buffer(
+                               &evaluation_view, evaluation);
+               if (ret < 0) {
+                       goto end;
+               }
+               evaluation_size += ret;
+               break;
        default:
                ERR("Attempted to create evaluation of unknown type (%i)",
                                (int) evaluation_comm->type);
diff --git a/src/common/session-rotation.c b/src/common/session-rotation.c
new file mode 100644 (file)
index 0000000..be48a99
--- /dev/null
@@ -0,0 +1,591 @@
+/*
+ * Copyright (C) 2017 - 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.
+ *
+ * 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
+ */
+
+#include <lttng/condition/condition-internal.h>
+#include <lttng/condition/session-rotation-internal.h>
+#include <lttng/location-internal.h>
+#include <common/macros.h>
+#include <common/error.h>
+#include <assert.h>
+#include <stdbool.h>
+
+static
+bool lttng_condition_session_rotation_validate(
+               const struct lttng_condition *condition);
+static
+int lttng_condition_session_rotation_serialize(
+               const struct lttng_condition *condition,
+               struct lttng_dynamic_buffer *buf);
+static
+bool lttng_condition_session_rotation_is_equal(const struct lttng_condition *_a,
+               const struct lttng_condition *_b);
+static
+void lttng_condition_session_rotation_destroy(
+               struct lttng_condition *condition);
+
+static const
+struct lttng_condition rotation_condition_template = {
+       /* .type omitted; shall be set on creation. */
+       .validate = lttng_condition_session_rotation_validate,
+       .serialize = lttng_condition_session_rotation_serialize,
+       .equal = lttng_condition_session_rotation_is_equal,
+       .destroy = lttng_condition_session_rotation_destroy,
+};
+
+static
+int lttng_evaluation_session_rotation_serialize(
+               const struct lttng_evaluation *evaluation,
+               struct lttng_dynamic_buffer *buf);
+static
+void lttng_evaluation_session_rotation_destroy(
+               struct lttng_evaluation *evaluation);
+
+static const
+struct lttng_evaluation rotation_evaluation_template = {
+       /* .type omitted; shall be set on creation. */
+       .serialize = lttng_evaluation_session_rotation_serialize,
+       .destroy = lttng_evaluation_session_rotation_destroy,
+};
+
+static
+bool is_rotation_condition(const struct lttng_condition *condition)
+{
+       enum lttng_condition_type type = lttng_condition_get_type(condition);
+
+       return type == LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING ||
+                       type == LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED;
+}
+
+static
+bool is_rotation_evaluation(const struct lttng_evaluation *evaluation)
+{
+       enum lttng_condition_type type = lttng_evaluation_get_type(evaluation);
+
+       return type == LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING ||
+                       type == LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED;
+}
+
+static
+bool lttng_condition_session_rotation_validate(
+               const struct lttng_condition *condition)
+{
+       bool valid = false;
+       struct lttng_condition_session_rotation *rotation;
+
+       if (!condition) {
+               goto end;
+       }
+
+       rotation = container_of(condition,
+                       struct lttng_condition_session_rotation, parent);
+       if (!rotation->session_name) {
+               ERR("Invalid session rotation condition: a target session name must be set.");
+               goto end;
+       }
+
+       valid = true;
+end:
+       return valid;
+}
+
+static
+int lttng_condition_session_rotation_serialize(
+               const struct lttng_condition *condition,
+               struct lttng_dynamic_buffer *buf)
+{
+       int ret;
+       size_t session_name_len;
+       struct lttng_condition_session_rotation *rotation;
+       struct lttng_condition_session_rotation_comm rotation_comm;
+
+       if (!condition || !is_rotation_condition(condition)) {
+               ret = -1;
+               goto end;
+       }
+
+       DBG("Serializing session rotation condition");
+       rotation = container_of(condition, struct lttng_condition_session_rotation,
+                       parent);
+
+       session_name_len = strlen(rotation->session_name) + 1;
+       if (session_name_len > LTTNG_NAME_MAX) {
+               ret = -1;
+               goto end;
+       }
+
+       rotation_comm.session_name_len = session_name_len;
+       ret = lttng_dynamic_buffer_append(buf, &rotation_comm,
+                       sizeof(rotation_comm));
+       if (ret) {
+               goto end;
+       }
+       ret = lttng_dynamic_buffer_append(buf, rotation->session_name,
+                       session_name_len);
+       if (ret) {
+               goto end;
+       }
+end:
+       return ret;
+}
+
+static
+bool lttng_condition_session_rotation_is_equal(const struct lttng_condition *_a,
+               const struct lttng_condition *_b)
+{
+       bool is_equal = false;
+       struct lttng_condition_session_rotation *a, *b;
+
+       a = container_of(_a, struct lttng_condition_session_rotation, parent);
+       b = container_of(_b, struct lttng_condition_session_rotation, parent);
+
+       /* Both session names must be set or both must be unset. */
+       if ((a->session_name && !b->session_name) ||
+                       (!a->session_name && b->session_name)) {
+               WARN("Comparing session rotation conditions with uninitialized session names.");
+               goto end;
+       }
+
+       if (a->session_name && b->session_name &&
+                       strcmp(a->session_name, b->session_name)) {
+               goto end;
+       }
+
+       is_equal = true;
+end:
+       return is_equal;
+}
+
+static
+void lttng_condition_session_rotation_destroy(
+               struct lttng_condition *condition)
+{
+       struct lttng_condition_session_rotation *rotation;
+
+       rotation = container_of(condition,
+                       struct lttng_condition_session_rotation, parent);
+
+       free(rotation->session_name);
+       free(rotation);
+}
+
+static
+struct lttng_condition *lttng_condition_session_rotation_create(
+               enum lttng_condition_type type)
+{
+       struct lttng_condition_session_rotation *condition;
+
+       condition = zmalloc(sizeof(struct lttng_condition_session_rotation));
+       if (!condition) {
+               return NULL;
+       }
+
+       memcpy(&condition->parent, &rotation_condition_template,
+                       sizeof(*condition));
+       lttng_condition_init(&condition->parent, type);
+       return &condition->parent;
+}
+
+struct lttng_condition *lttng_condition_session_rotation_ongoing_create(void)
+{
+       return lttng_condition_session_rotation_create(
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING);
+}
+
+struct lttng_condition *lttng_condition_session_rotation_completed_create(void)
+{
+       return lttng_condition_session_rotation_create(
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED);
+}
+
+static
+ssize_t init_condition_from_buffer(struct lttng_condition *condition,
+               const struct lttng_buffer_view *src_view)
+{
+       ssize_t ret, condition_size;
+       enum lttng_condition_status status;
+       const struct lttng_condition_session_rotation_comm *condition_comm;
+       const char *session_name;
+       struct lttng_buffer_view name_view;
+
+       if (src_view->size < sizeof(*condition_comm)) {
+               ERR("Failed to initialize from malformed condition buffer: buffer too short to contain header");
+               ret = -1;
+               goto end;
+       }
+
+       condition_comm = (const struct lttng_condition_session_rotation_comm *) src_view->data;
+       name_view = lttng_buffer_view_from_view(src_view,
+                       sizeof(*condition_comm), -1);
+
+       if (condition_comm->session_name_len > LTTNG_NAME_MAX) {
+               ERR("Failed to initialize from malformed condition buffer: name exceeds LTTNG_MAX_NAME");
+               ret = -1;
+               goto end;
+       }
+
+       if (name_view.size < condition_comm->session_name_len) {
+               ERR("Failed to initialize from malformed condition buffer: buffer too short to contain session name");
+               ret = -1;
+               goto end;
+       }
+
+       session_name = name_view.data;
+       if (*(session_name + condition_comm->session_name_len - 1) != '\0') {
+               ERR("Malformed session name encountered in condition buffer");
+               ret = -1;
+               goto end;
+       }
+
+       status = lttng_condition_session_rotation_set_session_name(condition,
+                       session_name);
+       if (status != LTTNG_CONDITION_STATUS_OK) {
+               ERR("Failed to set buffer consumed session name");
+               ret = -1;
+               goto end;
+       }
+
+       if (!lttng_condition_validate(condition)) {
+               ret = -1;
+               goto end;
+       }
+
+       condition_size = sizeof(*condition_comm) +
+                       (ssize_t) condition_comm->session_name_len;
+       ret = condition_size;
+end:
+       return ret;
+}
+
+static
+ssize_t lttng_condition_session_rotation_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_condition **_condition,
+               enum lttng_condition_type type)
+{
+       ssize_t ret;
+       struct lttng_condition *condition = NULL;
+
+       switch (type) {
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+               condition = lttng_condition_session_rotation_ongoing_create();
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+               condition = lttng_condition_session_rotation_completed_create();
+               break;
+       default:
+               ret = -1;
+               goto error;
+       }
+
+       if (!_condition || !condition) {
+               ret = -1;
+               goto error;
+       }
+
+       ret = init_condition_from_buffer(condition, view);
+       if (ret < 0) {
+               goto error;
+       }
+
+       *_condition = condition;
+       return ret;
+error:
+       lttng_condition_destroy(condition);
+       return ret;
+}
+
+LTTNG_HIDDEN
+ssize_t lttng_condition_session_rotation_ongoing_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_condition **condition)
+{
+       return lttng_condition_session_rotation_create_from_buffer(view,
+                       condition,
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING);
+}
+
+LTTNG_HIDDEN
+ssize_t lttng_condition_session_rotation_completed_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_condition **condition)
+{
+       return lttng_condition_session_rotation_create_from_buffer(view,
+                       condition,
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED);
+}
+
+static
+struct lttng_evaluation *lttng_evaluation_session_rotation_create(
+               enum lttng_condition_type type, uint64_t id,
+               struct lttng_trace_archive_location *location)
+{
+       struct lttng_evaluation_session_rotation *evaluation;
+
+       evaluation = zmalloc(sizeof(struct lttng_evaluation_session_rotation));
+       if (!evaluation) {
+               return NULL;
+       }
+
+       memcpy(&evaluation->parent, &rotation_evaluation_template,
+                       sizeof(*evaluation));
+       lttng_evaluation_init(&evaluation->parent, type);
+       evaluation->id = id;
+       evaluation->location = location;
+       return &evaluation->parent;
+}
+
+static
+ssize_t create_evaluation_from_buffer(
+               enum lttng_condition_type type,
+               const struct lttng_buffer_view *view,
+               struct lttng_evaluation **_evaluation)
+{
+       ssize_t ret, size;
+       struct lttng_evaluation *evaluation = NULL;
+       struct lttng_trace_archive_location *location = NULL;
+       const struct lttng_evaluation_session_rotation_comm *comm =
+                       (const struct lttng_evaluation_session_rotation_comm *) view->data;
+        struct lttng_buffer_view location_view;
+
+       if (view->size < sizeof(*comm)) {
+               goto error;
+       }
+
+       size = sizeof(*comm);
+       if (comm->has_location) {
+               location_view = lttng_buffer_view_from_view(view, sizeof(*comm),
+                               -1);
+               if (!location_view.data) {
+                       goto error;
+               }
+
+               ret = lttng_trace_archive_location_create_from_buffer(
+                               &location_view, &location);
+               if (ret < 0) {
+                       goto error;
+               }
+               size += ret;
+       }
+
+       evaluation = lttng_evaluation_session_rotation_create(type, comm->id,
+                       location);
+       if (!evaluation) {
+               goto error;
+       }
+
+       ret = size;
+       *_evaluation = evaluation;
+       return ret;
+error:
+       lttng_trace_archive_location_destroy(location);
+       evaluation = NULL;
+       return -1;
+}
+
+static
+ssize_t lttng_evaluation_session_rotation_create_from_buffer(
+               enum lttng_condition_type type,
+               const struct lttng_buffer_view *view,
+               struct lttng_evaluation **_evaluation)
+{
+       ssize_t ret;
+       struct lttng_evaluation *evaluation = NULL;
+
+       if (!_evaluation) {
+               ret = -1;
+               goto error;
+       }
+
+       ret = create_evaluation_from_buffer(type, view, &evaluation);
+       if (ret < 0) {
+               goto error;
+       }
+
+       *_evaluation = evaluation;
+       return ret;
+error:
+       lttng_evaluation_destroy(evaluation);
+       return ret;
+}
+
+LTTNG_HIDDEN
+ssize_t lttng_evaluation_session_rotation_ongoing_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_evaluation **evaluation)
+{
+       return lttng_evaluation_session_rotation_create_from_buffer(
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING,
+                       view, evaluation);
+}
+
+LTTNG_HIDDEN
+ssize_t lttng_evaluation_session_rotation_completed_create_from_buffer(
+               const struct lttng_buffer_view *view,
+               struct lttng_evaluation **evaluation)
+{
+       return lttng_evaluation_session_rotation_create_from_buffer(
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED,
+                       view, evaluation);
+}
+
+LTTNG_HIDDEN
+struct lttng_evaluation *lttng_evaluation_session_rotation_ongoing_create(
+               uint64_t id)
+{
+       return lttng_evaluation_session_rotation_create(
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING, id,
+                       NULL);
+}
+
+LTTNG_HIDDEN
+struct lttng_evaluation *lttng_evaluation_session_rotation_completed_create(
+               uint64_t id, struct lttng_trace_archive_location *location)
+{
+       return lttng_evaluation_session_rotation_create(
+                       LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED, id,
+                       location);
+}
+
+enum lttng_condition_status
+lttng_condition_session_rotation_get_session_name(
+               const struct lttng_condition *condition,
+               const char **session_name)
+{
+       struct lttng_condition_session_rotation *rotation;
+       enum lttng_condition_status status = LTTNG_CONDITION_STATUS_OK;
+
+       if (!condition || !is_rotation_condition(condition) || !session_name) {
+               status = LTTNG_CONDITION_STATUS_INVALID;
+               goto end;
+       }
+
+       rotation = container_of(condition, struct lttng_condition_session_rotation,
+                       parent);
+       if (!rotation->session_name) {
+               status = LTTNG_CONDITION_STATUS_UNSET;
+               goto end;
+       }
+       *session_name = rotation->session_name;
+end:
+       return status;
+}
+
+enum lttng_condition_status
+lttng_condition_session_rotation_set_session_name(
+               struct lttng_condition *condition, const char *session_name)
+{
+       char *session_name_copy;
+       struct lttng_condition_session_rotation *rotation;
+       enum lttng_condition_status status = LTTNG_CONDITION_STATUS_OK;
+
+       if (!condition || !is_rotation_condition(condition) ||
+                       !session_name || strlen(session_name) == 0) {
+               status = LTTNG_CONDITION_STATUS_INVALID;
+               goto end;
+       }
+
+       rotation = container_of(condition,
+                       struct lttng_condition_session_rotation, parent);
+       session_name_copy = strdup(session_name);
+       if (!session_name_copy) {
+               status = LTTNG_CONDITION_STATUS_ERROR;
+               goto end;
+       }
+
+       free(rotation->session_name);
+       rotation->session_name = session_name_copy;
+end:
+       return status;
+}
+
+static
+int lttng_evaluation_session_rotation_serialize(
+               const struct lttng_evaluation *evaluation,
+               struct lttng_dynamic_buffer *buf)
+{
+       int ret;
+       struct lttng_evaluation_session_rotation *rotation;
+       struct lttng_evaluation_session_rotation_comm comm = { 0 };
+
+       rotation = container_of(evaluation,
+                       struct lttng_evaluation_session_rotation, parent);
+       comm.id = rotation->id;
+       comm.has_location = !!rotation->location;
+        ret = lttng_dynamic_buffer_append(buf, &comm, sizeof(comm));
+       if (ret) {
+               goto end;
+       }
+       if (!rotation->location) {
+               goto end;
+       }
+       ret = lttng_trace_archive_location_serialize(rotation->location,
+                       buf);
+end:
+       return ret;
+}
+
+static
+void lttng_evaluation_session_rotation_destroy(
+               struct lttng_evaluation *evaluation)
+{
+       struct lttng_evaluation_session_rotation *rotation;
+
+       rotation = container_of(evaluation,
+                       struct lttng_evaluation_session_rotation, parent);
+       lttng_trace_archive_location_destroy(rotation->location);
+       free(rotation);
+}
+
+enum lttng_evaluation_status
+lttng_evaluation_session_rotation_get_id(
+               const struct lttng_evaluation *evaluation, uint64_t *id)
+{
+       const struct lttng_evaluation_session_rotation *rotation;
+       enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK;
+
+       if (!evaluation || !id || !is_rotation_evaluation(evaluation)) {
+               status = LTTNG_EVALUATION_STATUS_INVALID;
+               goto end;
+       }
+
+       rotation = container_of(evaluation,
+                       struct lttng_evaluation_session_rotation, parent);
+       *id = rotation->id;
+end:
+       return status;
+}
+
+enum lttng_evaluation_status
+lttng_evaluation_session_rotation_completed_get_location(
+               const struct lttng_evaluation *evaluation,
+               const struct lttng_trace_archive_location **location)
+{
+       const struct lttng_evaluation_session_rotation *rotation;
+       enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK;
+
+       if (!evaluation || !location ||
+                       evaluation->type != LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED) {
+               status = LTTNG_EVALUATION_STATUS_INVALID;
+               goto end;
+       }
+
+       rotation = container_of(evaluation,
+                       struct lttng_evaluation_session_rotation, parent);
+       *location = rotation->location;
+end:
+       return status;
+}
This page took 0.035638 seconds and 4 git commands to generate.