X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Flttng%2Ftrigger%2Ftrigger-internal.h;h=d917ffa011d13a4db5486cde3f27c46b99177552;hb=0f7c296359bf90005e1dadf2d7a02a4b223a8031;hp=59fe771aa32ef196ef3e89af5c87466dadf5cf21;hpb=c738df170902f40de6d8e53c9f214a5308e4182b;p=lttng-tools.git diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h index 59fe771aa..d917ffa01 100644 --- a/include/lttng/trigger/trigger-internal.h +++ b/include/lttng/trigger/trigger-internal.h @@ -8,18 +8,21 @@ #ifndef LTTNG_TRIGGER_INTERNAL_H #define LTTNG_TRIGGER_INTERNAL_H -#include #include #include #include #include -#include +#include +#include #include +#include #include #include struct lttng_payload; struct lttng_payload_view; +struct mi_writer; +struct mi_lttng_error_query_callbacks; struct lttng_trigger { /* Reference counting is only exposed to internal users. */ @@ -30,17 +33,31 @@ struct lttng_trigger { char *name; /* For now only the uid portion of the credentials is used. */ struct lttng_credentials creds; - struct { - enum lttng_trigger_firing_policy type; - uint64_t threshold; - uint64_t current_count; - } firing_policy; /* * Internal use only. * The unique token passed to the tracer to identify an event-rule * notification. */ LTTNG_OPTIONAL(uint64_t) tracer_token; + + /* + * Is the trigger registered? + * + * This is necessary since a reference holder might be interested in the + * overall state of the trigger from the point of view of its owner. + * + * The main user is the action executor since we want to prevent the + * execution of actions related to a trigger that is unregistered. + * + * Not considered for `is_equal`. + */ + bool registered; + + /* + * The lock is used to protect against concurrent trigger execution and + * trigger removal. + */ + pthread_mutex_t lock; }; struct lttng_triggers { @@ -60,10 +77,6 @@ struct lttng_trigger_comm { uint32_t length; /* Includes '\0' terminator. */ uint32_t name_length; - /* Firing policy. */ - /* Maps to enum lttng_trigger_firing_policy. */ - uint8_t firing_policy_type; - uint64_t firing_policy_threshold; /* A null-terminated name, a condition, and an action follow. */ char payload[]; } LTTNG_PACKED; @@ -111,6 +124,16 @@ void lttng_trigger_get(struct lttng_trigger *trigger); LTTNG_HIDDEN void lttng_trigger_put(struct lttng_trigger *trigger); +/* + * Serialize a trigger to a mi_writer. + * Return LTTNG_OK in success, other enum lttng_error_code on error. + */ +LTTNG_HIDDEN +enum lttng_error_code lttng_trigger_mi_serialize(const struct lttng_trigger *trigger, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks); + /* * Allocate a new set of triggers. * The returned object must be freed via lttng_triggers_destroy. @@ -154,6 +177,16 @@ LTTNG_HIDDEN ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view, struct lttng_triggers **triggers); +/* + * Serialize a trigger set to a mi_writer. + * Return LTTNG_OK in success, other enum lttng_error_code on error. + */ +LTTNG_HIDDEN +enum lttng_error_code lttng_triggers_mi_serialize(const struct lttng_triggers *triggers, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks); + LTTNG_HIDDEN const struct lttng_credentials *lttng_trigger_get_credentials( const struct lttng_trigger *trigger); @@ -162,20 +195,6 @@ LTTNG_HIDDEN void lttng_trigger_set_credentials(struct lttng_trigger *trigger, const struct lttng_credentials *creds); - -/* - * Fire the trigger. - * Increments the occurrence count. - */ -LTTNG_HIDDEN -void lttng_trigger_fire(struct lttng_trigger *trigger); - -/* - * Check if the trigger would fire. - */ -LTTNG_HIDDEN -bool lttng_trigger_should_fire(const struct lttng_trigger *trigger); - /* * Return the type of any underlying domain restriction. If no particular * requirement is present, returns LTTNG_DOMAIN_NONE. @@ -193,6 +212,12 @@ enum lttng_error_code lttng_trigger_generate_bytecode( struct lttng_trigger *trigger, const struct lttng_credentials *creds); +/* + * Note that the trigger object is not locked by "copy" as it is const and + * used with a number of 'const' triggers. If the trigger could be shared at + * the moment of the copy, it is the caller's responsability to lock it for + * the duration of the copy. + */ LTTNG_HIDDEN struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); @@ -205,4 +230,58 @@ struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); LTTNG_HIDDEN bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger); +LTTNG_HIDDEN +void lttng_trigger_set_as_registered(struct lttng_trigger *trigger); + +LTTNG_HIDDEN +void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger); + +/* + * The trigger must be locked before calling lttng_trigger_is_registered. + * + * The lock is necessary since a trigger can be unregistered at any time. + * + * Manipulations requiring that the trigger be registered must always acquire + * the trigger lock for the duration of the manipulation using + * `lttng_trigger_lock` and `lttng_trigger_unlock`. + */ +LTTNG_HIDDEN +bool lttng_trigger_is_registered(struct lttng_trigger *trigger); + +LTTNG_HIDDEN +void lttng_trigger_lock(struct lttng_trigger *trigger); + +LTTNG_HIDDEN +void lttng_trigger_unlock(struct lttng_trigger *trigger); + +LTTNG_HIDDEN +enum lttng_trigger_status lttng_trigger_add_error_results( + const struct lttng_trigger *trigger, + struct lttng_error_query_results *results); + +LTTNG_HIDDEN +enum lttng_trigger_status lttng_trigger_condition_add_error_results( + const struct lttng_trigger *trigger, + struct lttng_error_query_results *results); + +LTTNG_HIDDEN +enum lttng_trigger_status lttng_trigger_add_action_error_query_results( + struct lttng_trigger *trigger, + struct lttng_error_query_results *results); + +/* + * Set the trigger name. + * + * A name is optional. + * A name will be assigned on trigger registration if no name is set. + * + * The name is copied. + * + * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID + * if invalid parameters are passed. + */ +LTTNG_HIDDEN +enum lttng_trigger_status lttng_trigger_set_name( + struct lttng_trigger *trigger, const char *name); + #endif /* LTTNG_TRIGGER_INTERNAL_H */