From 65f649784e948615ec369db9eba40847a75ccaf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 6 Apr 2021 22:05:26 -0400 Subject: [PATCH] on-event evaluation: remove trigger name accessor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The trigger name accessor on an on-event evaluation is no longer needed as the originating trigger is now accessible on a notification. The tests are adapted to use the name of the trigger as returned by the lttng_notification received by the client. Signed-off-by: Jérémie Galarneau Change-Id: I57bd64d7f5ec35f015dfb115ecfadd75806b9a75 --- include/lttng/condition/on-event-internal.h | 9 --- include/lttng/condition/on-event.h | 17 +--- .../notification-thread-events.c | 1 - src/common/conditions/on-event.c | 79 +------------------ .../tools/notification/notification.c | 33 +++----- .../tools/trigger/utils/notification-client.c | 49 +++++------- 6 files changed, 33 insertions(+), 155 deletions(-) diff --git a/include/lttng/condition/on-event-internal.h b/include/lttng/condition/on-event-internal.h index cc8f1cdf9..1ccabf3f4 100644 --- a/include/lttng/condition/on-event-internal.h +++ b/include/lttng/condition/on-event-internal.h @@ -38,7 +38,6 @@ struct lttng_condition_on_event { struct lttng_evaluation_on_event { struct lttng_evaluation parent; - char *name; /* MessagePack-encoded captured event field values. */ struct lttng_dynamic_buffer capture_payload; @@ -53,13 +52,6 @@ struct lttng_evaluation_on_event { struct lttng_event_field_value *captured_values; }; -struct lttng_evaluation_on_event_comm { - /* Includes the null terminator. */ - uint32_t trigger_name_length; - /* Trigger name. */ - char payload[]; -} LTTNG_PACKED; - LTTNG_HIDDEN ssize_t lttng_condition_on_event_create_from_payload( struct lttng_payload_view *view, @@ -90,7 +82,6 @@ void lttng_condition_on_event_set_error_count(struct lttng_condition *condition, LTTNG_HIDDEN struct lttng_evaluation *lttng_evaluation_on_event_create( const struct lttng_condition_on_event *condition, - const char* trigger_name, const char *capture_payload, size_t capture_payload_size, bool decode_capture_payload); diff --git a/include/lttng/condition/on-event.h b/include/lttng/condition/on-event.h index 5114ec1fc..18c4155a2 100644 --- a/include/lttng/condition/on-event.h +++ b/include/lttng/condition/on-event.h @@ -64,23 +64,10 @@ extern enum lttng_condition_status lttng_condition_on_event_get_rule( * allow users to query a number of properties resulting from the evaluation * of a condition which evaluated to true. * - * The evaluation of a on event hit yields two different results: - * TEMPORARY - The name of the triggers associated with the condition. - * TODO - The captured event payload if any + * The evaluation of an on event condition contains the captured event + * payload fields that were specified by the condition. */ -/* - * Get the trigger name property of a on event hit evaluation. - * - * Returns LTTNG_EVALUATION_STATUS_OK on success and a trigger name - * or LTTNG_EVALUATION_STATUS_INVALID if - * an invalid parameter is passed. - */ -extern enum lttng_evaluation_status -lttng_evaluation_on_event_get_trigger_name( - const struct lttng_evaluation *evaluation, - const char **name); - /* * Sets `*field_val` to the array event field value of the on event * condition evaluation `evaluation` which contains its captured values. diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index 59b10e9db..6d153f16d 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -4550,7 +4550,6 @@ int dispatch_one_event_notifier_notification(struct notification_thread_state *s element->trigger), struct lttng_condition_on_event, parent), - trigger_name, notification->capture_buffer, notification->capture_buf_size, false); diff --git a/src/common/conditions/on-event.c b/src/common/conditions/on-event.c index fa37a3540..9a9e7620a 100644 --- a/src/common/conditions/on-event.c +++ b/src/common/conditions/on-event.c @@ -1045,12 +1045,7 @@ ssize_t lttng_evaluation_on_event_create_from_payload( struct lttng_evaluation **_evaluation) { ssize_t ret, offset = 0; - const char *trigger_name; struct lttng_evaluation *evaluation = NULL; - const struct lttng_evaluation_on_event_comm *header; - const struct lttng_payload_view header_view = - lttng_payload_view_from_view( - view, 0, sizeof(*header)); uint32_t capture_payload_size; const char *capture_payload = NULL; @@ -1059,37 +1054,6 @@ ssize_t lttng_evaluation_on_event_create_from_payload( goto error; } - if (!lttng_payload_view_is_valid(&header_view)) { - ERR("Failed to initialize from malformed event rule evaluation: buffer too short to contain header"); - ret = -1; - goto error; - } - - header = (typeof(header)) header_view.buffer.data; - - /* Map the originating trigger's name. */ - offset += sizeof(*header); - { - const struct lttng_payload_view current_view = - lttng_payload_view_from_view(view, offset, - header->trigger_name_length); - - if (!lttng_payload_view_is_valid(¤t_view)) { - ERR("Failed to initialize from malformed event rule evaluation: buffer too short to contain trigger name"); - ret = -1; - goto error; - } - - trigger_name = current_view.buffer.data; - if (!lttng_buffer_view_contains_string(¤t_view.buffer, - trigger_name, header->trigger_name_length)) { - ERR("Failed to initialize from malformed event rule evaluation: invalid trigger name"); - ret = -1; - goto error; - } - } - - offset += header->trigger_name_length; { const struct lttng_payload_view current_view = lttng_payload_view_from_view(view, offset, -1); @@ -1116,7 +1080,7 @@ ssize_t lttng_evaluation_on_event_create_from_payload( capture_payload = current_view.buffer.data; } - evaluation = lttng_evaluation_on_event_create(condition, trigger_name, + evaluation = lttng_evaluation_on_event_create(condition, capture_payload, capture_payload_size, true); if (!evaluation) { ret = -1; @@ -1139,27 +1103,11 @@ static int lttng_evaluation_on_event_serialize( { int ret = 0; struct lttng_evaluation_on_event *hit; - struct lttng_evaluation_on_event_comm comm; uint32_t capture_payload_size; hit = container_of( evaluation, struct lttng_evaluation_on_event, parent); - assert(hit->name); - comm.trigger_name_length = strlen(hit->name) + 1; - - ret = lttng_dynamic_buffer_append( - &payload->buffer, &comm, sizeof(comm)); - if (ret) { - goto end; - } - - ret = lttng_dynamic_buffer_append( - &payload->buffer, hit->name, comm.trigger_name_length); - if (ret) { - goto end; - } - capture_payload_size = (uint32_t) hit->capture_payload.size; ret = lttng_dynamic_buffer_append(&payload->buffer, &capture_payload_size, sizeof(capture_payload_size)); @@ -1229,7 +1177,6 @@ static void lttng_evaluation_on_event_destroy( hit = container_of( evaluation, struct lttng_evaluation_on_event, parent); - free(hit->name); lttng_dynamic_buffer_reset(&hit->capture_payload); lttng_event_field_value_destroy(hit->captured_values); free(hit); @@ -1517,7 +1464,6 @@ end: LTTNG_HIDDEN struct lttng_evaluation *lttng_evaluation_on_event_create( const struct lttng_condition_on_event *condition, - const char *trigger_name, const char *capture_payload, size_t capture_payload_size, bool decode_capture_payload) { @@ -1529,11 +1475,6 @@ struct lttng_evaluation *lttng_evaluation_on_event_create( goto error; } - hit->name = strdup(trigger_name); - if (!hit->name) { - goto error; - } - lttng_dynamic_buffer_init(&hit->capture_payload); if (capture_payload) { @@ -1602,24 +1543,6 @@ end: return status; } -enum lttng_evaluation_status lttng_evaluation_on_event_get_trigger_name( - const struct lttng_evaluation *evaluation, const char **name) -{ - struct lttng_evaluation_on_event *hit; - enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK; - - if (!evaluation || !is_on_event_evaluation(evaluation) || !name) { - status = LTTNG_EVALUATION_STATUS_INVALID; - goto end; - } - - hit = container_of( - evaluation, struct lttng_evaluation_on_event, parent); - *name = hit->name; -end: - return status; -} - LTTNG_HIDDEN enum lttng_error_code lttng_condition_on_event_generate_capture_descriptor_bytecode( diff --git a/tests/regression/tools/notification/notification.c b/tests/regression/tools/notification/notification.c index e7101bb9f..e26c99d03 100644 --- a/tests/regression/tools/notification/notification.c +++ b/tests/regression/tools/notification/notification.c @@ -579,33 +579,24 @@ struct capture_base_field_tuple test_capture_base_fields[] = { static const char *get_notification_trigger_name( struct lttng_notification *notification) { - const char *name = NULL; - enum lttng_evaluation_status status; - const struct lttng_evaluation *evaluation; - evaluation = lttng_notification_get_evaluation(notification); - if (evaluation == NULL) { - fail("lttng_notification_get_evaluation"); + const char *trigger_name = NULL; + enum lttng_trigger_status trigger_status; + const struct lttng_trigger *trigger; + + trigger = lttng_notification_get_trigger(notification); + if (!trigger) { + fail("Failed to get trigger from notification"); goto end; } - switch (lttng_evaluation_get_type(evaluation)) { - case LTTNG_CONDITION_TYPE_ON_EVENT: - { - status = lttng_evaluation_on_event_get_trigger_name( - evaluation, &name); - if (status != LTTNG_EVALUATION_STATUS_OK) { - fail("lttng_evaluation_on_event_get_trigger_name"); - name = NULL; - goto end; - } - break; - } - default: - fail("Wrong notification evaluation type \n"); + trigger_status = lttng_trigger_get_name(trigger, &trigger_name); + if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { + fail("Failed to get name from notification's trigger"); goto end; } + end: - return name; + return trigger_name; } static int validator_notification_trigger_name( diff --git a/tests/regression/tools/trigger/utils/notification-client.c b/tests/regression/tools/trigger/utils/notification-client.c index 2c7c896d8..688775a6e 100644 --- a/tests/regression/tools/trigger/utils/notification-client.c +++ b/tests/regression/tools/trigger/utils/notification-client.c @@ -56,41 +56,28 @@ static bool action_group_contains_notify( static bool is_expected_trigger_name(const char *expected_trigger_name, struct lttng_notification *notification) { - int ret = false; - const struct lttng_evaluation *evaluation = - lttng_notification_get_evaluation(notification); - const enum lttng_condition_type type = - lttng_evaluation_get_type(evaluation); - - switch (type) { - case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: - case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: - case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: - case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: - case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: - break; - case LTTNG_CONDITION_TYPE_ON_EVENT: - { - const char *trigger_name; - enum lttng_evaluation_status evaluation_status; - - evaluation_status = - lttng_evaluation_on_event_get_trigger_name( - evaluation, &trigger_name); - if (evaluation_status != LTTNG_EVALUATION_STATUS_OK) { - fprintf(stderr, "Failed to get trigger name of event rule notification\n"); - ret = -1; - break; - } + const char *trigger_name = NULL; + enum lttng_trigger_status trigger_status; + const struct lttng_trigger *trigger; + bool names_match; - ret = true; - break; + trigger = lttng_notification_get_trigger(notification); + if (!trigger) { + fprintf(stderr, "Failed to get trigger from notification\n"); + names_match = false; + goto end; } - default: - fprintf(stderr, "Unknown notification type (%d)\n", type); + + trigger_status = lttng_trigger_get_name(trigger, &trigger_name); + if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { + fprintf(stderr, "Failed to get name from notification's trigger\n"); + names_match = false; + goto end; } - return ret; + names_match = strcmp(expected_trigger_name, trigger_name) == 0; +end: + return names_match; } int main(int argc, char **argv) -- 2.34.1