Tests: ns_contexts: discarded events result in test failure
[lttng-tools.git] / src / common / buffer-usage.c
index 3d0026081e1f98e3450f4b0f843b2ca213f5bb17..ad6fb84169e03bd1b99cf72c74eb2e5d9bbd5c46 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * 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.
+ * 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
  */
 
 #include <lttng/condition/condition-internal.h>
@@ -88,6 +78,10 @@ bool lttng_condition_buffer_usage_validate(
                ERR("Invalid buffer condition: a threshold must be set.");
                goto end;
        }
+       if (!usage->domain.set) {
+               ERR("Invalid buffer usage condition: a domain must be set.");
+               goto end;
+       }
 
        valid = true;
 end:
@@ -97,7 +91,7 @@ end:
 static
 int lttng_condition_buffer_usage_serialize(
                const struct lttng_condition *condition,
-               struct lttng_dynamic_buffer *buf)
+               struct lttng_payload *payload)
 {
        int ret;
        struct lttng_condition_buffer_usage *usage;
@@ -140,17 +134,19 @@ int lttng_condition_buffer_usage_serialize(
                usage_comm.threshold = val;
        }
 
-       ret = lttng_dynamic_buffer_append(buf, &usage_comm,
+       ret = lttng_dynamic_buffer_append(&payload->buffer, &usage_comm,
                        sizeof(usage_comm));
        if (ret) {
                goto end;
        }
-       ret = lttng_dynamic_buffer_append(buf, usage->session_name,
+
+       ret = lttng_dynamic_buffer_append(&payload->buffer, usage->session_name,
                        session_name_len);
        if (ret) {
                goto end;
        }
-       ret = lttng_dynamic_buffer_append(buf, usage->channel_name,
+
+       ret = lttng_dynamic_buffer_append(&payload->buffer, usage->channel_name,
                        channel_name_len);
        if (ret) {
                goto end;
@@ -194,36 +190,24 @@ bool lttng_condition_buffer_usage_is_equal(const struct lttng_condition *_a,
                }
        }
 
-       if ((a->session_name && !b->session_name) ||
-                       (!a->session_name && b->session_name)) {
+       /* Condition is not valid if this is not true. */
+       assert(a->session_name);
+       assert(b->session_name);
+       if (strcmp(a->session_name, b->session_name)) {
                goto end;
        }
 
-       if (a->channel_name && b->channel_name) {
-               if (strcmp(a->channel_name, b->channel_name)) {
-                       goto end;
-               }
-       }       if ((a->channel_name && !b->channel_name) ||
-                       (!a->channel_name && b->channel_name)) {
+       assert(a->channel_name);
+       assert(b->channel_name);
+       if (strcmp(a->channel_name, b->channel_name)) {
                goto end;
        }
 
-       if (a->channel_name && b->channel_name) {
-               if (strcmp(a->channel_name, b->channel_name)) {
-                       goto end;
-               }
-       }
-
-       if ((a->domain.set && !b->domain.set) ||
-                       (!a->domain.set && b->domain.set)) {
+       assert(a->domain.set);
+       assert(b->domain.set);
+       if (a->domain.type != b->domain.type) {
                goto end;
        }
-
-       if (a->domain.set && b->domain.set) {
-               if (a->domain.type != b->domain.type) {
-                       goto end;
-               }
-       }
        is_equal = true;
 end:
        return is_equal;
@@ -261,8 +245,8 @@ struct lttng_condition *lttng_condition_buffer_usage_high_create(void)
 }
 
 static
-ssize_t init_condition_from_buffer(struct lttng_condition *condition,
-               const struct lttng_buffer_view *src_view)
+ssize_t init_condition_from_payload(struct lttng_condition *condition,
+               struct lttng_payload_view *src_view)
 {
        ssize_t ret, condition_size;
        enum lttng_condition_status status;
@@ -271,14 +255,14 @@ ssize_t init_condition_from_buffer(struct lttng_condition *condition,
        const char *session_name, *channel_name;
        struct lttng_buffer_view names_view;
 
-       if (src_view->size < sizeof(*condition_comm)) {
+       if (src_view->buffer.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_buffer_usage_comm *) src_view->data;
-       names_view = lttng_buffer_view_from_view(src_view,
+       condition_comm = (typeof(condition_comm)) src_view->buffer.data;
+       names_view = lttng_buffer_view_from_view(&src_view->buffer,
                        sizeof(*condition_comm), -1);
 
        if (condition_comm->session_name_len > LTTNG_NAME_MAX ||
@@ -304,6 +288,7 @@ ssize_t init_condition_from_buffer(struct lttng_condition *condition,
                                condition,
                                fixed_to_double(condition_comm->threshold));
        }
+
        if (status != LTTNG_CONDITION_STATUS_OK) {
                ERR("Failed to initialize buffer usage condition threshold");
                ret = -1;
@@ -372,8 +357,8 @@ end:
 }
 
 LTTNG_HIDDEN
-ssize_t lttng_condition_buffer_usage_low_create_from_buffer(
-               const struct lttng_buffer_view *view,
+ssize_t lttng_condition_buffer_usage_low_create_from_payload(
+               struct lttng_payload_view *view,
                struct lttng_condition **_condition)
 {
        ssize_t ret;
@@ -385,7 +370,7 @@ ssize_t lttng_condition_buffer_usage_low_create_from_buffer(
                goto error;
        }
 
-       ret = init_condition_from_buffer(condition, view);
+       ret = init_condition_from_payload(condition, view);
        if (ret < 0) {
                goto error;
        }
@@ -398,8 +383,8 @@ error:
 }
 
 LTTNG_HIDDEN
-ssize_t lttng_condition_buffer_usage_high_create_from_buffer(
-               const struct lttng_buffer_view *view,
+ssize_t lttng_condition_buffer_usage_high_create_from_payload(
+               struct lttng_payload_view *view,
                struct lttng_condition **_condition)
 {
        ssize_t ret;
@@ -411,7 +396,7 @@ ssize_t lttng_condition_buffer_usage_high_create_from_buffer(
                goto error;
        }
 
-       ret = init_condition_from_buffer(condition, view);
+       ret = init_condition_from_payload(condition, view);
        if (ret < 0) {
                goto error;
        }
@@ -424,15 +409,15 @@ error:
 }
 
 static
-struct lttng_evaluation *create_evaluation_from_buffer(
+struct lttng_evaluation *create_evaluation_from_payload(
                enum lttng_condition_type type,
-               const struct lttng_buffer_view *view)
+               struct lttng_payload_view *view)
 {
        const struct lttng_evaluation_buffer_usage_comm *comm =
-                       (const struct lttng_evaluation_buffer_usage_comm *) view->data;
+                       (typeof(comm)) view->buffer.data;
        struct lttng_evaluation *evaluation = NULL;
 
-       if (view->size < sizeof(*comm)) {
+       if (view->buffer.size < sizeof(*comm)) {
                goto end;
        }
 
@@ -443,8 +428,8 @@ end:
 }
 
 LTTNG_HIDDEN
-ssize_t lttng_evaluation_buffer_usage_low_create_from_buffer(
-               const struct lttng_buffer_view *view,
+ssize_t lttng_evaluation_buffer_usage_low_create_from_payload(
+               struct lttng_payload_view *view,
                struct lttng_evaluation **_evaluation)
 {
        ssize_t ret;
@@ -455,7 +440,7 @@ ssize_t lttng_evaluation_buffer_usage_low_create_from_buffer(
                goto error;
        }
 
-       evaluation = create_evaluation_from_buffer(
+       evaluation = create_evaluation_from_payload(
                        LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW, view);
        if (!evaluation) {
                ret = -1;
@@ -471,8 +456,8 @@ error:
 }
 
 LTTNG_HIDDEN
-ssize_t lttng_evaluation_buffer_usage_high_create_from_buffer(
-               const struct lttng_buffer_view *view,
+ssize_t lttng_evaluation_buffer_usage_high_create_from_payload(
+               struct lttng_payload_view *view,
                struct lttng_evaluation **_evaluation)
 {
        ssize_t ret;
@@ -483,7 +468,7 @@ ssize_t lttng_evaluation_buffer_usage_high_create_from_buffer(
                goto error;
        }
 
-       evaluation = create_evaluation_from_buffer(
+       evaluation = create_evaluation_from_payload(
                        LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, view);
        if (!evaluation) {
                ret = -1;
@@ -747,8 +732,8 @@ end:
 
 static
 int lttng_evaluation_buffer_usage_serialize(
-               struct lttng_evaluation *evaluation,
-               struct lttng_dynamic_buffer *buf)
+               const struct lttng_evaluation *evaluation,
+               struct lttng_payload *payload)
 {
        struct lttng_evaluation_buffer_usage *usage;
        struct lttng_evaluation_buffer_usage_comm comm;
@@ -758,7 +743,8 @@ int lttng_evaluation_buffer_usage_serialize(
        comm.buffer_use = usage->buffer_use;
        comm.buffer_capacity = usage->buffer_capacity;
 
-       return lttng_dynamic_buffer_append(buf, &comm, sizeof(comm));
+       return lttng_dynamic_buffer_append(
+                       &payload->buffer, &comm, sizeof(comm));
 }
 
 static
This page took 0.028101 seconds and 5 git commands to generate.