| 1 | /* |
| 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_ACTION_INTERNAL_H |
| 9 | #define LTTNG_ACTION_INTERNAL_H |
| 10 | |
| 11 | #include <common/buffer-view.h> |
| 12 | #include <common/dynamic-buffer.h> |
| 13 | #include <common/macros.h> |
| 14 | #include <common/payload-view.h> |
| 15 | #include <common/payload.h> |
| 16 | #include <lttng/lttng.h> |
| 17 | #include <pthread.h> |
| 18 | #include <stdbool.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <urcu/ref.h> |
| 21 | |
| 22 | struct lttng_rate_policy; |
| 23 | |
| 24 | typedef bool (*action_validate_cb)(struct lttng_action *action); |
| 25 | typedef void (*action_destroy_cb)(struct lttng_action *action); |
| 26 | typedef int (*action_serialize_cb)(struct lttng_action *action, |
| 27 | struct lttng_payload *payload); |
| 28 | typedef bool (*action_equal_cb)(const struct lttng_action *a, |
| 29 | const struct lttng_action *b); |
| 30 | typedef ssize_t (*action_create_from_payload_cb)( |
| 31 | struct lttng_payload_view *view, |
| 32 | struct lttng_action **action); |
| 33 | typedef const struct lttng_rate_policy *(*action_get_rate_policy_cb)( |
| 34 | const struct lttng_action *action); |
| 35 | typedef enum lttng_action_status (*action_add_error_query_results_cb)( |
| 36 | const struct lttng_action *action, |
| 37 | struct lttng_error_query_results *results); |
| 38 | |
| 39 | struct lttng_action { |
| 40 | struct urcu_ref ref; |
| 41 | enum lttng_action_type type; |
| 42 | action_validate_cb validate; |
| 43 | action_serialize_cb serialize; |
| 44 | action_equal_cb equal; |
| 45 | action_destroy_cb destroy; |
| 46 | action_get_rate_policy_cb get_rate_policy; |
| 47 | action_add_error_query_results_cb add_error_query_results; |
| 48 | |
| 49 | /* Internal use only. */ |
| 50 | |
| 51 | /* The number of time the actions was enqueued for execution. */ |
| 52 | uint64_t execution_request_counter; |
| 53 | /* |
| 54 | * The number of time the action was actually executed. |
| 55 | * Action rate policy can impact on this number. |
| 56 | * */ |
| 57 | uint64_t execution_counter; |
| 58 | /* |
| 59 | * The number of time the action execution failed. |
| 60 | * An unsigned long is used to use a type which makes atomic |
| 61 | * operations possible. |
| 62 | */ |
| 63 | unsigned long execution_failure_counter; |
| 64 | }; |
| 65 | |
| 66 | struct lttng_action_comm { |
| 67 | /* enum lttng_action_type */ |
| 68 | int8_t action_type; |
| 69 | } LTTNG_PACKED; |
| 70 | |
| 71 | LTTNG_HIDDEN |
| 72 | void lttng_action_init(struct lttng_action *action, |
| 73 | enum lttng_action_type type, |
| 74 | action_validate_cb validate, |
| 75 | action_serialize_cb serialize, |
| 76 | action_equal_cb equal, |
| 77 | action_destroy_cb destroy, |
| 78 | action_get_rate_policy_cb get_rate_policy, |
| 79 | action_add_error_query_results_cb add_error_query_results); |
| 80 | |
| 81 | LTTNG_HIDDEN |
| 82 | bool lttng_action_validate(struct lttng_action *action); |
| 83 | |
| 84 | LTTNG_HIDDEN |
| 85 | int lttng_action_serialize(struct lttng_action *action, |
| 86 | struct lttng_payload *buf); |
| 87 | |
| 88 | LTTNG_HIDDEN |
| 89 | ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view, |
| 90 | struct lttng_action **action); |
| 91 | |
| 92 | LTTNG_HIDDEN |
| 93 | bool lttng_action_is_equal(const struct lttng_action *a, |
| 94 | const struct lttng_action *b); |
| 95 | |
| 96 | LTTNG_HIDDEN |
| 97 | void lttng_action_get(struct lttng_action *action); |
| 98 | |
| 99 | LTTNG_HIDDEN |
| 100 | void lttng_action_put(struct lttng_action *action); |
| 101 | |
| 102 | LTTNG_HIDDEN |
| 103 | const char* lttng_action_type_string(enum lttng_action_type action_type); |
| 104 | |
| 105 | LTTNG_HIDDEN |
| 106 | void lttng_action_increase_execution_request_count(struct lttng_action *action); |
| 107 | |
| 108 | LTTNG_HIDDEN |
| 109 | void lttng_action_increase_execution_count(struct lttng_action *action); |
| 110 | |
| 111 | LTTNG_HIDDEN |
| 112 | void lttng_action_increase_execution_failure_count(struct lttng_action *action); |
| 113 | |
| 114 | LTTNG_HIDDEN |
| 115 | bool lttng_action_should_execute(const struct lttng_action *action); |
| 116 | |
| 117 | LTTNG_HIDDEN |
| 118 | enum lttng_action_status lttng_action_add_error_query_results( |
| 119 | const struct lttng_action *action, |
| 120 | struct lttng_error_query_results *results); |
| 121 | |
| 122 | /* |
| 123 | * For use by the various lttng_action implementation. Implements the default |
| 124 | * behavior to the generic error "execution failure counter" that all actions |
| 125 | * (except group, which passes-through) provide. |
| 126 | */ |
| 127 | LTTNG_HIDDEN |
| 128 | enum lttng_action_status lttng_action_generic_add_error_query_results( |
| 129 | const struct lttng_action *action, |
| 130 | struct lttng_error_query_results *results); |
| 131 | |
| 132 | #endif /* LTTNG_ACTION_INTERNAL_H */ |