condition: buffer usage: validation does not check for ratio and bytes threshold
[lttng-tools.git] / src / common / conditions / buffer-usage.c
index 5f68608001a43d3559d527541c974e8edc0eef73..a97f6d59f74b36b6d9eb9f1ef5c4994968659a00 100644 (file)
        lttng_condition_get_type(condition) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH   \
        )
 
-static
-double fixed_to_double(uint32_t val)
-{
-       return (double) val / (double) UINT32_MAX;
-}
-
-static
-uint64_t double_to_fixed(double val)
-{
-       return (val * (double) UINT32_MAX);
-}
-
 static
 bool is_usage_evaluation(const struct lttng_evaluation *evaluation)
 {
@@ -74,8 +62,8 @@ bool lttng_condition_buffer_usage_validate(
                ERR("Invalid buffer condition: a target channel name must be set.");
                goto end;
        }
-       if (!usage->threshold_ratio.set && !usage->threshold_bytes.set) {
-               ERR("Invalid buffer condition: a threshold must be set.");
+       if (usage->threshold_ratio.set == usage->threshold_bytes.set) {
+               ERR("Invalid buffer condition: a threshold must be set or both type cannot be used simultaneously.");
                goto end;
        }
        if (!usage->domain.set) {
@@ -96,7 +84,7 @@ int lttng_condition_buffer_usage_serialize(
        int ret;
        struct lttng_condition_buffer_usage *usage;
        size_t session_name_len, channel_name_len;
-       struct lttng_condition_buffer_usage_comm usage_comm;
+       struct lttng_condition_buffer_usage_comm usage_comm = {};
 
        if (!condition || !IS_USAGE_CONDITION(condition)) {
                ret = -1;
@@ -121,17 +109,9 @@ int lttng_condition_buffer_usage_serialize(
        usage_comm.domain_type = (int8_t) usage->domain.type;
 
        if (usage->threshold_bytes.set) {
-               usage_comm.threshold = usage->threshold_bytes.value;
+               usage_comm.threshold_bytes = usage->threshold_bytes.value;
        } else {
-               uint64_t val = double_to_fixed(
-                               usage->threshold_ratio.value);
-
-               if (val > UINT32_MAX) {
-                       /* overflow. */
-                       ret = -1;
-                       goto end;
-               }
-               usage_comm.threshold = val;
+               usage_comm.threshold_ratio = usage->threshold_ratio.value;
        }
 
        ret = lttng_dynamic_buffer_append(&payload->buffer, &usage_comm,
@@ -285,11 +265,10 @@ ssize_t init_condition_from_payload(struct lttng_condition *condition,
 
        if (condition_comm->threshold_set_in_bytes) {
                status = lttng_condition_buffer_usage_set_threshold(condition,
-                               condition_comm->threshold);
+                               condition_comm->threshold_bytes);
        } else {
                status = lttng_condition_buffer_usage_set_threshold_ratio(
-                               condition,
-                               fixed_to_double(condition_comm->threshold));
+                               condition, condition_comm->threshold_ratio);
        }
 
        if (status != LTTNG_CONDITION_STATUS_OK) {
This page took 0.026434 seconds and 5 git commands to generate.