#include <common/credentials.h>
#include <common/sessiond-comm/sessiond-comm.h>
#include <lttng/domain.h>
+#include <lttng/event.h>
#include <lttng/event-rule/event-rule.h>
#include <lttng/lttng-error.h>
#include <stdbool.h>
struct lttng_event_exclusion **exclusions);
typedef unsigned long (*event_rule_hash_cb)(
const struct lttng_event_rule *event_rule);
+typedef struct lttng_event *(*event_rule_generate_lttng_event_cb)(
+ const struct lttng_event_rule *event_rule);
struct lttng_event_rule {
struct urcu_ref ref;
event_rule_get_filter_bytecode_cb get_filter_bytecode;
event_rule_generate_exclusions_cb generate_exclusions;
event_rule_hash_cb hash;
+ event_rule_generate_lttng_event_cb generate_lttng_event;
};
struct lttng_event_rule_comm {
LTTNG_HIDDEN
unsigned long lttng_event_rule_hash(const struct lttng_event_rule *rule);
+/*
+ * This is a compatibility helper allowing us to generate a sessiond-side (not
+ * communication) `struct lttng_event` object from an event rule.
+ *
+ * This effectively bridges older parts of the code using those structures and
+ * new event-rule based code.
+ *
+ * The caller owns the returned object.
+ */
+LTTNG_HIDDEN
+struct lttng_event *lttng_event_rule_generate_lttng_event(
+ const struct lttng_event_rule *rule);
+
+/* Test if an event rule targets an agent domain. */
+LTTNG_HIDDEN
+bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule);
+
#endif /* LTTNG_EVENT_RULE_INTERNAL_H */
{
struct ltt_session *session, *stmp;
struct ltt_session_list *list;
+ struct agent *trigger_agent;
+ struct lttng_ht_iter iter;
list = session_get_list();
assert(list);
session_unlock(session);
session_put(session);
}
+
+ rcu_read_lock();
+ /*
+ * We are protected against the addition of new events by the session
+ * list lock being held.
+ */
+ cds_lfht_for_each_entry (trigger_agents_ht_by_domain->ht, &iter.iter,
+ trigger_agent, node.node) {
+ agent_update(trigger_agent, app);
+ }
+ rcu_read_unlock();
}
/*
#include <urcu/uatomic.h>
#include <urcu/rculist.h>
+#include <lttng/event-rule/event-rule.h>
+#include <lttng/event-rule/event-rule-internal.h>
+#include <lttng/event-rule/tracepoint.h>
+#include <lttng/condition/condition.h>
+#include <lttng/condition/event-rule.h>
+#include <lttng/domain-internal.h>
+
#include <common/common.h>
#include <common/sessiond-comm/agent.h>
}
/*
- * Match function for the events hash table lookup by name and loglevel.
+ * Match function for the events hash table lookup by name, log level and
+ * filter expression.
*/
static int ht_match_event(struct cds_lfht_node *node,
const void *_key)
}
}
- event->enabled = 1;
+ event->enabled_count++;
ret = LTTNG_OK;
error:
struct lttng_ht_iter iter;
assert(event);
- if (!event->enabled) {
+ if (!AGENT_EVENT_IS_ENABLED(event)) {
+ goto end;
+ }
+
+ if (--event->enabled_count != 0) {
+ /*
+ * Agent event still enabled. Disable the agent event only when
+ * all "users" have disabled it (event notifiers, event rules,
+ * etc.).
+ */
+ ret = LTTNG_OK;
goto end;
}
}
}
- event->enabled = 0;
+ /* event->enabled_count is now 0. */
+ assert(!AGENT_EVENT_IS_ENABLED(event));
error:
rcu_read_unlock();
ht_match_event_by_name, &key, &iter->iter);
}
+/*
+ * Find the agent event matching a trigger.
+ *
+ * RCU read side lock MUST be acquired. It must be held for as long as
+ * the returned agent_event is used.
+ *
+ * Return object if found else NULL.
+ */
+struct agent_event *agent_find_event_by_trigger(
+ const struct lttng_trigger *trigger, struct agent *agt)
+{
+ enum lttng_condition_status c_status;
+ enum lttng_event_rule_status er_status;
+ enum lttng_domain_type domain;
+ const struct lttng_condition *condition;
+ const struct lttng_event_rule *rule;
+ const char *name;
+ const char *filter_expression;
+ /* Unused when loglevel_type is 'ALL'. */
+ int loglevel_value = 0;
+ enum lttng_loglevel_type loglevel_type;
+
+ assert(agt);
+ assert(agt->events);
+
+ condition = lttng_trigger_get_const_condition(trigger);
+
+ assert(lttng_condition_get_type(condition) ==
+ LTTNG_CONDITION_TYPE_EVENT_RULE_HIT);
+
+ c_status = lttng_condition_event_rule_get_rule(condition, &rule);
+ assert(c_status == LTTNG_CONDITION_STATUS_OK);
+
+ assert(lttng_event_rule_get_type(rule) ==
+ LTTNG_EVENT_RULE_TYPE_TRACEPOINT);
+
+ domain = lttng_event_rule_get_domain_type(rule);
+ assert(domain == LTTNG_DOMAIN_JUL || domain == LTTNG_DOMAIN_LOG4J ||
+ domain == LTTNG_DOMAIN_PYTHON);
+
+ /* Get the event's pattern ('name' in the legacy terminology). */
+ er_status = lttng_event_rule_tracepoint_get_pattern(rule, &name);
+ assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ /* Get the internal filter expression. */
+ filter_expression = lttng_event_rule_get_filter(rule);
+
+ er_status = lttng_event_rule_tracepoint_get_log_level_type(
+ rule, &loglevel_type);
+ assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ if (loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
+ er_status = lttng_event_rule_tracepoint_get_log_level(
+ rule, &loglevel_value);
+ assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+ }
+
+ return agent_find_event(name, loglevel_type, loglevel_value,
+ filter_expression, agt);
+}
+
/*
* Get the next agent event duplicate by name. This should be called
* after a call to agent_find_events_by_name() to iterate on events.
* Return object if found else NULL.
*/
struct agent_event *agent_find_event(const char *name,
- enum lttng_loglevel_type loglevel_type, int loglevel_value,
- char *filter_expression, struct agent *agt)
+ enum lttng_loglevel_type loglevel_type,
+ int loglevel_value,
+ const char *filter_expression,
+ struct agent *agt)
{
struct lttng_ht_node_str *node;
struct lttng_ht_iter iter;
*/
int agent_app_ht_alloc(void)
{
- int ret = 0;
-
agent_apps_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
- if (!agent_apps_ht_by_sock) {
- ret = -1;
- }
-
- return ret;
+ return agent_apps_ht_by_sock ? 0 : -1;
}
/*
cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) {
/* Skip event if disabled. */
- if (!event->enabled) {
+ if (!AGENT_EVENT_IS_ENABLED(event)) {
continue;
}
rcu_read_unlock();
}
+
+/*
+ * Allocate the per-event notifier domain agent hash table. It is lazily
+ * populated as domains are used.
+ */
+int agent_by_event_notifier_domain_ht_create(void)
+{
+ trigger_agents_ht_by_domain = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
+ return trigger_agents_ht_by_domain ? 0 : -1;
+}
+
+/*
+ * Clean-up the per-event notifier domain agent hash table and destroy it.
+ */
+void agent_by_event_notifier_domain_ht_destroy(void)
+{
+ struct lttng_ht_node_u64 *node;
+ struct lttng_ht_iter iter;
+
+ if (!trigger_agents_ht_by_domain) {
+ return;
+ }
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry (trigger_agents_ht_by_domain->ht, &iter.iter,
+ node, node) {
+ struct agent *agent =
+ caa_container_of(node, struct agent, node);
+ const int ret = lttng_ht_del(
+ trigger_agents_ht_by_domain, &iter);
+
+ assert(ret == 0);
+ agent_destroy(agent);
+ }
+
+ rcu_read_unlock();
+ lttng_ht_destroy(trigger_agents_ht_by_domain);
+}
+
+struct agent *agent_find_by_event_notifier_domain(
+ enum lttng_domain_type domain_type)
+{
+ struct agent *agt = NULL;
+ struct lttng_ht_node_u64 *node;
+ struct lttng_ht_iter iter;
+ const uint64_t key = (uint64_t) domain_type;
+
+ assert(trigger_agents_ht_by_domain);
+
+ DBG3("Per-event notifier domain agent lookup for domain '%s'",
+ lttng_domain_type_str(domain_type));
+
+ lttng_ht_lookup(trigger_agents_ht_by_domain, &key, &iter);
+ node = lttng_ht_iter_get_node_u64(&iter);
+ if (!node) {
+ goto end;
+ }
+
+ agt = caa_container_of(node, struct agent, node);
+
+end:
+ return agt;
+}
*/
extern struct lttng_ht *agent_apps_ht_by_sock;
+/*
+ * Hash table that contains the trigger agents by domain */
+extern struct lttng_ht *trigger_agents_ht_by_domain;
+
struct agent_ht_key {
const char *name;
int loglevel_value;
enum lttng_loglevel_type loglevel_type;
- char *filter_expression;
+ const char *filter_expression;
};
/*
/*
* Agent event representation.
+ * Accesses to this structure are protected by the session list lock.
*/
struct agent_event {
/* Name of the event. */
enum lttng_loglevel_type loglevel_type;
/*
- * Tells if the event is enabled or not on the agent.
+ * Tells if the event is enabled or not on the agent. While this can be
+ * implicitly tested as a boolean, it is in fact a reference count and
+ * the AGENT_EVENT_IS_ENABLED macro should be used to prevent accidental
+ * comparisons to non-zero literals (e.g. '1').
+ *
+ * Multiple triggers and events can map to the same agent event as it
+ * is merely a "filter" in front of a user space tracer enabler.
+ *
+ * This count is updated to ensure an event is only disabled when all
+ * matching enablers are disabled.
*/
- unsigned int enabled:1;
+ unsigned int enabled_count;
/* Hash table node of the agent domain object. */
struct lttng_ht_node_str node;
struct lttng_event_exclusion *exclusion;
};
+#define AGENT_EVENT_IS_ENABLED(agent_event) (!!agent_event->enabled_count)
+
/*
- * Agent object containing events enabled/disabled for it.
+ * Agent object containing events enabled/disabled for a given domain in a
+ * scope. The scope is typically a session, but can also be "global" in the
+ * context of event notifiers: see event_notifiers_find_agent().
*/
struct agent {
/*
void agent_add_event(struct agent_event *event, struct agent *agt);
struct agent_event *agent_find_event(const char *name,
- enum lttng_loglevel_type loglevel_type, int loglevel_value,
- char *filter_expression, struct agent *agt);
+ enum lttng_loglevel_type loglevel_type,
+ int loglevel_value,
+ const char *filter_expression,
+ struct agent *agt);
void agent_find_events_by_name(const char *name, struct agent *agt,
struct lttng_ht_iter* iter);
void agent_event_next_duplicate(const char *name,
int agent_list_events(struct lttng_event **events,
enum lttng_domain_type domain);
+struct agent_event *agent_find_event_by_trigger(
+ const struct lttng_trigger *trigger, struct agent *agt);
+
+/* Global event notifier per-domain agents. */
+struct agent *agent_find_by_event_notifier_domain(
+ enum lttng_domain_type domain_type);
+void agent_by_event_notifier_domain_ht_destroy(void);
+int agent_by_event_notifier_domain_ht_create(void);
+
#endif /* LTTNG_SESSIOND_AGENT_H */
#include "utils.h"
#include "manage-consumer.h"
#include "clear.h"
+#include "agent-thread.h"
static bool is_root;
case LTTNG_DOMAIN_JUL:
case LTTNG_DOMAIN_LOG4J:
case LTTNG_DOMAIN_PYTHON:
+ if (!agent_tracing_is_enabled()) {
+ ret = LTTNG_ERR_AGENT_TRACING_DISABLED;
+ goto error;
+ }
+ /* Fallthrough */
case LTTNG_DOMAIN_UST:
{
if (!ust_app_supported()) {
cds_lfht_for_each_entry (
agt->events->ht, &iter.iter, agent_event, node.node) {
struct lttng_event event = {
- .enabled = agent_event->enabled,
+ .enabled = AGENT_EVENT_IS_ENABLED(agent_event),
.loglevel = agent_event->loglevel_value,
.loglevel_type = agent_event->loglevel_type,
};
if (ret_code != LTTNG_OK) {
DBG("Failed to register trigger to notification thread: trigger name = '%s', trigger owner uid = %d, error code = %d",
trigger_name, (int) trigger_owner, ret_code);
- goto end_notification_thread;
+ goto end;
}
trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
if (ret_code != LTTNG_OK) {
ERR("Failed to determine if event modifies event notifiers: trigger name = '%s', trigger owner uid = %d, error code = %d",
trigger_name, (int) trigger_owner, ret_code);
- goto end_notification_thread;
+ goto end;
}
/*
* Synchronize tracers if the trigger adds an event notifier.
*/
if (must_update_event_notifier) {
- if (lttng_trigger_get_underlying_domain_type_restriction(
- trigger) == LTTNG_DOMAIN_KERNEL) {
+ const enum lttng_domain_type trigger_domain =
+ lttng_trigger_get_underlying_domain_type_restriction(trigger);
+ switch (trigger_domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ {
ret_code = kernel_register_event_notifier(
trigger, cmd_creds);
if (ret_code != LTTNG_OK) {
(int) trigger_owner,
ret_code);
}
+ }
+ break;
+ }
+ case LTTNG_DOMAIN_UST:
+ ust_app_global_update_all_event_notifier_rules();
+ break;
+ case LTTNG_DOMAIN_NONE:
+ abort();
+ default:
+ {
+ /* Agent domains. */
+ struct agent *agt = agent_find_by_event_notifier_domain(
+ trigger_domain);
+
+ if (!agt) {
+ agt = agent_create(trigger_domain);
+ if (!agt) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ agent_add(agt, trigger_agents_ht_by_domain);
+ }
+ ret_code = trigger_agent_enable(trigger, agt);
+ if (ret_code != LTTNG_OK) {
goto end;
}
- } else {
- ust_app_global_update_all_event_notifier_rules();
+
+ break;
+ }
}
}
*/
lttng_trigger_get(trigger);
*return_trigger = trigger;
-
-end_notification_thread:
- /* Ownership of trigger was transferred. */
+ /* Ownership of trigger was transferred to caller. */
trigger = NULL;
end:
return ret_code;
/*
* Synchronize tracers if the trigger removes an event notifier.
+ * Do this even if the trigger unregistration failed to at least stop
+ * the tracers from producing notifications associated with this
+ * event notifier.
*/
if (must_update_event_notifier) {
- if (lttng_trigger_get_underlying_domain_type_restriction(
- trigger) == LTTNG_DOMAIN_KERNEL) {
+ const enum lttng_domain_type trigger_domain =
+ lttng_trigger_get_underlying_domain_type_restriction(
+ trigger);
+ switch (trigger_domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ {
ret_code = kernel_unregister_event_notifier(
trigger);
- } else {
+ break;
+ }
+ case LTTNG_DOMAIN_UST:
ust_app_global_update_all_event_notifier_rules();
+ break;
+ case LTTNG_DOMAIN_NONE:
+ abort();
+ default:
+ {
+ /* Agent domains. */
+ struct agent *agt = agent_find_by_event_notifier_domain(
+ trigger_domain);
+
+ if (!agt) {
+ agt = agent_create(trigger_domain);
+ if (!agt) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ agent_add(agt, trigger_agents_ht_by_domain);
+ }
+
+ ret_code = trigger_agent_disable(trigger, agt);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
+
+ break;
+ }
}
}
#include <common/compat/errno.h>
#include <lttng/lttng.h>
+#include <lttng/condition/condition.h>
+#include <lttng/condition/event-rule.h>
+#include <lttng/event-rule/event-rule.h>
+#include <lttng/event-rule/event-rule-internal.h>
#include <common/error.h>
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/filter.h>
#include "trace-kernel.h"
#include "trace-ust.h"
#include "agent.h"
+#include "utils.h"
/*
* Add unique UST event based on the event name, filter bytecode and loglevel.
return ret;
}
+static void agent_enable_all(struct agent *agt)
+{
+ struct agent_event *aevent;
+ struct lttng_ht_iter iter;
+
+ /* Flag every event as enabled. */
+ rcu_read_lock();
+ cds_lfht_for_each_entry (
+ agt->events->ht, &iter.iter, aevent, node.node) {
+ aevent->enabled_count++;
+ }
+ rcu_read_unlock();
+}
+
/*
* Enable all agent event for a given UST session.
*
struct lttng_filter_bytecode *filter ,char *filter_expression)
{
int ret;
- struct agent_event *aevent;
- struct lttng_ht_iter iter;
assert(usess);
goto error;
}
- /* Flag every event that they are now enabled. */
- rcu_read_lock();
- cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
- node.node) {
- aevent->enabled = 1;
- }
- rcu_read_unlock();
+ agent_enable_all(agt);
ret = LTTNG_OK;
return ret;
}
-/*
- * Enable a single agent event for a given UST session.
- *
- * Return LTTNG_OK on success or else a LTTNG_ERR* code.
- */
-int event_agent_enable(struct ltt_ust_session *usess,
- struct agent *agt, struct lttng_event *event,
+static int agent_enable(struct agent *agt,
+ struct lttng_event *event,
struct lttng_filter_bytecode *filter,
char *filter_expression)
{
int ret, created = 0;
struct agent_event *aevent;
- assert(usess);
assert(event);
assert(agt);
- DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d "
- ", loglevel %d and filter \"%s\"", event->name,
- usess->id, event->loglevel_type, event->loglevel,
- filter_expression ? filter_expression : "NULL");
-
aevent = agent_find_event(event->name, event->loglevel_type,
event->loglevel, filter_expression, agt);
if (!aevent) {
filter = NULL;
filter_expression = NULL;
created = 1;
- assert(!aevent->enabled);
+ assert(!AGENT_EVENT_IS_ENABLED(aevent));
}
if (created && aevent->filter) {
}
/* Already enabled? */
- if (aevent->enabled) {
+ if (AGENT_EVENT_IS_ENABLED(aevent)) {
ret = LTTNG_OK;
goto end;
}
return ret;
}
+/*
+ * Enable a single agent event for a given UST session.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int event_agent_enable(struct ltt_ust_session *usess,
+ struct agent *agt,
+ struct lttng_event *event,
+ struct lttng_filter_bytecode *filter,
+ char *filter_expression)
+{
+ assert(usess);
+ assert(event);
+ assert(agt);
+
+ DBG("Enabling agent event: event pattern = '%s', session id = %" PRIu64 ", loglevel type = %d, loglevel = %d, filter expression = '%s'",
+ event->name, usess->id, event->loglevel_type,
+ event->loglevel,
+ filter_expression ? filter_expression : "(none)");
+
+ return agent_enable(agt, event, filter, filter_expression);
+}
+
+/*
+ * Enable a single agent event for a trigger.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
+{
+ int ret;
+ enum lttng_condition_status c_status;
+ enum lttng_trigger_status t_status;
+ enum lttng_domain_type d_type;
+ const struct lttng_condition *condition;
+ const struct lttng_event_rule *rule;
+ const char *filter_expression;
+ char *filter_expression_copy = NULL;
+ const struct lttng_filter_bytecode *filter_bytecode;
+ struct lttng_filter_bytecode *filter_bytecode_copy = NULL;
+ struct lttng_event *event = NULL;
+ uid_t trigger_owner_uid = 0;
+ const char *trigger_name;
+
+ assert(trigger);
+ assert(agt);
+
+ t_status = lttng_trigger_get_name(trigger, &trigger_name);
+ if (t_status != LTTNG_TRIGGER_STATUS_OK) {
+ trigger_name = "(unnamed)";
+ }
+
+ t_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner_uid);
+ assert(t_status == LTTNG_TRIGGER_STATUS_OK);
+
+ condition = lttng_trigger_get_const_condition(trigger);
+
+ assert(lttng_condition_get_type(condition) ==
+ LTTNG_CONDITION_TYPE_EVENT_RULE_HIT);
+
+ c_status = lttng_condition_event_rule_get_rule(condition, &rule);
+ assert(c_status == LTTNG_CONDITION_STATUS_OK);
+
+ assert(lttng_event_rule_get_type(rule) ==
+ LTTNG_EVENT_RULE_TYPE_TRACEPOINT);
+
+ d_type = lttng_event_rule_get_domain_type(rule);
+ assert(d_type == agt->domain);
+
+ event = lttng_event_rule_generate_lttng_event(rule);
+ if (!event) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Get the internal filter expression and bytecode. */
+ filter_expression = lttng_event_rule_get_filter(rule);
+ if (filter_expression) {
+ filter_expression_copy = strdup(filter_expression);
+ if (!filter_expression_copy) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Get the filter bytecode */
+ filter_bytecode = lttng_event_rule_get_filter_bytecode(rule);
+ if (filter_bytecode) {
+ filter_bytecode_copy =
+ lttng_filter_bytecode_copy(filter_bytecode);
+ if (!filter_bytecode_copy) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+ }
+
+ DBG("Enabling agent event from trigger: trigger name = '%s', trigger owner uid = %d, token = %" PRIu64,
+ trigger_name, trigger_owner_uid,
+ lttng_trigger_get_tracer_token(trigger));
+
+ ret = agent_enable(agt, event, filter_bytecode_copy,
+ filter_expression_copy);
+ /* Ownership was passed even in case of error. */
+ filter_expression_copy = NULL;
+ filter_bytecode_copy = NULL;
+
+end:
+ free(filter_expression_copy);
+ free(filter_bytecode_copy);
+ free(event);
+ return ret;
+}
+
/*
* Return the default event name associated with the provided UST domain. Return
* NULL on error.
return default_event_name;
}
+static int trigger_agent_disable_one(const struct lttng_trigger *trigger,
+ struct agent *agt,
+ struct agent_event *aevent)
+
+{
+ int ret;
+
+ assert(agt);
+ assert(trigger);
+ assert(aevent);
+
+ /*
+ * Actual ust event un-registration happens on the trigger
+ * un-registration at that point.
+ */
+
+ DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for trigger %" PRIu64,
+ aevent->name, aevent->loglevel_type,
+ aevent->loglevel_value, lttng_trigger_get_tracer_token(trigger));
+
+ /* Already disabled? */
+ if (!AGENT_EVENT_IS_ENABLED(aevent)) {
+ goto end;
+ }
+
+ ret = agent_disable_event(aevent, agt->domain);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+
+end:
+ return LTTNG_OK;
+
+error:
+ return ret;
+}
+
/*
* Disable a given agent event for a given UST session.
*
usess->id);
/* Already disabled? */
- if (!aevent->enabled) {
+ if (!AGENT_EVENT_IS_ENABLED(aevent)) {
goto end;
}
return ret;
}
+/*
+ * Disable agent event matching a given trigger.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int trigger_agent_disable(
+ const struct lttng_trigger *trigger, struct agent *agt)
+{
+ int ret = LTTNG_OK;
+ struct agent_event *aevent;
+
+ assert(trigger);
+ assert(agt);
+
+ DBG("Event agent disabling for trigger %" PRIu64,
+ lttng_trigger_get_tracer_token(trigger));
+
+ rcu_read_lock();
+ aevent = agent_find_event_by_trigger(trigger, agt);
+
+ if (aevent == NULL) {
+ DBG2("Event agent NOT found by trigger %" PRIu64,
+ lttng_trigger_get_tracer_token(trigger));
+ ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
+ goto end;
+ }
+
+ ret = trigger_agent_disable_one(trigger, agt, aevent);
+
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
+end:
+ rcu_read_unlock();
+ return ret;
+}
+
/*
* Disable all agent events matching a given name for a given UST session.
*
rcu_read_lock();
cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
node.node) {
- if (!aevent->enabled) {
+ if (!AGENT_EVENT_IS_ENABLED(aevent)) {
continue;
}
const char *event_name);
int event_agent_disable_all(struct ltt_ust_session *usess, struct agent *agt);
+int trigger_agent_enable(
+ const struct lttng_trigger *trigger, struct agent *agt);
+int trigger_agent_disable(
+ const struct lttng_trigger *trigger, struct agent *agt);
+
const char *event_get_default_agent_ust_name(enum lttng_domain_type domain);
#endif /* _LTT_EVENT_H */
struct notification_thread_handle *notification_thread_handle;
struct lttng_ht *agent_apps_ht_by_sock = NULL;
+struct lttng_ht *trigger_agents_ht_by_domain = NULL;
struct lttng_kernel_tracer_version kernel_tracer_version;
struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version;
pthread_mutex_destroy(&session_list->lock);
+ DBG("Cleaning up all per-event notifier domain agents");
+ agent_by_event_notifier_domain_ht_destroy();
+
DBG("Cleaning up all agent apps");
agent_app_ht_clean();
DBG("Closing all UST sockets");
goto stop_threads;
}
+ if (agent_by_event_notifier_domain_ht_create()) {
+ ERR("Failed to allocate per-event notifier domain agent hash table");
+ retval = -1;
+ goto stop_threads;
+ }
/*
* These actions must be executed as root. We do that *after* setting up
* the sockets path because we MUST make the check for another daemon using
int ret;
enum lttng_ust_loglevel_type ust_loglevel_type;
- ust_event->enabled = agent_event->enabled;
+ ust_event->enabled = AGENT_EVENT_IS_ENABLED(agent_event);
ust_event->attr.instrumentation = LTTNG_UST_TRACEPOINT;
if (lttng_strncpy(ust_event->attr.name, agent_event->name,
LTTNG_SYMBOL_NAME_LEN)) {
#include "lttng-sessiond.h"
#include "notification-thread-commands.h"
#include "rotate.h"
+#include "event.h"
struct lttng_ht *ust_app_ht;
struct lttng_ht *ust_app_ht_by_sock;
return NULL;
}
-/*
- * Allocate a filter and copy the given original filter.
- *
- * Return allocated filter or NULL on error.
- */
-static struct lttng_filter_bytecode *copy_filter_bytecode(
- struct lttng_filter_bytecode *orig_f)
-{
- struct lttng_filter_bytecode *filter = NULL;
-
- /* Copy filter bytecode */
- filter = zmalloc(sizeof(*filter) + orig_f->len);
- if (!filter) {
- PERROR("zmalloc alloc filter bytecode");
- goto error;
- }
-
- memcpy(filter, orig_f, sizeof(*filter) + orig_f->len);
-
-error:
- return filter;
-}
-
/*
* Create a liblttng-ust filter bytecode from given bytecode.
*
memset(event_notifier, 0, sizeof(*event_notifier));
- status = lttng_event_rule_tracepoint_get_pattern(rule, &pattern);
- if (status != LTTNG_EVENT_RULE_STATUS_OK) {
- /* At this point, this is a fatal error. */
- abort();
- }
+ if (lttng_event_rule_targets_agent_domain(rule)) {
+ /*
+ * Special event for agents
+ * The actual meat of the event is in the filter that will be
+ * attached later on.
+ * Set the default values for the agent event.
+ */
+ pattern = event_get_default_agent_ust_name(
+ lttng_event_rule_get_domain_type(rule));
+ loglevel = 0;
+ ust_loglevel_type = LTTNG_UST_LOGLEVEL_ALL;
+ } else {
+ status = lttng_event_rule_tracepoint_get_pattern(
+ rule, &pattern);
+ if (status != LTTNG_EVENT_RULE_STATUS_OK) {
+ /* At this point, this is a fatal error. */
+ abort();
+ }
- status = lttng_event_rule_tracepoint_get_log_level_type(
- rule, &loglevel_type);
- if (status != LTTNG_EVENT_RULE_STATUS_OK) {
- /* At this point, this is a fatal error. */
- abort();
- }
+ status = lttng_event_rule_tracepoint_get_log_level_type(
+ rule, &loglevel_type);
+ if (status != LTTNG_EVENT_RULE_STATUS_OK) {
+ /* At this point, this is a fatal error. */
+ abort();
+ }
- switch (loglevel_type) {
- case LTTNG_EVENT_LOGLEVEL_ALL:
- ust_loglevel_type = LTTNG_UST_LOGLEVEL_ALL;
- break;
- case LTTNG_EVENT_LOGLEVEL_RANGE:
- ust_loglevel_type = LTTNG_UST_LOGLEVEL_RANGE;
- break;
- case LTTNG_EVENT_LOGLEVEL_SINGLE:
- ust_loglevel_type = LTTNG_UST_LOGLEVEL_SINGLE;
- break;
- default:
- /* Unknown log level specification type. */
- abort();
- }
+ switch (loglevel_type) {
+ case LTTNG_EVENT_LOGLEVEL_ALL:
+ ust_loglevel_type = LTTNG_UST_LOGLEVEL_ALL;
+ break;
+ case LTTNG_EVENT_LOGLEVEL_RANGE:
+ ust_loglevel_type = LTTNG_UST_LOGLEVEL_RANGE;
+ break;
+ case LTTNG_EVENT_LOGLEVEL_SINGLE:
+ ust_loglevel_type = LTTNG_UST_LOGLEVEL_SINGLE;
+ break;
+ default:
+ /* Unknown log level specification type. */
+ abort();
+ }
- if (loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
- status = lttng_event_rule_tracepoint_get_log_level(
- rule, &loglevel);
- assert(status == LTTNG_EVENT_RULE_STATUS_OK);
+ if (loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
+ status = lttng_event_rule_tracepoint_get_log_level(
+ rule, &loglevel);
+ assert(status == LTTNG_EVENT_RULE_STATUS_OK);
+ }
}
event_notifier->event.instrumentation = LTTNG_UST_TRACEPOINT;
ret = lttng_strncpy(event_notifier->event.name, pattern,
- LTTNG_UST_SYM_NAME_LEN - 1);
+ LTTNG_UST_SYM_NAME_LEN - 1);
if (ret) {
ERR("Failed to copy event rule pattern to notifier: pattern = '%s' ",
pattern);
/* Copy filter bytecode */
if (uevent->filter) {
- ua_event->filter = copy_filter_bytecode(uevent->filter);
+ ua_event->filter = lttng_filter_bytecode_copy(uevent->filter);
/* Filter might be NULL here in case of ENONEM. */
}
output->dst.session_root_path :
output->dst.net.base_dir;
}
+
+/*
+ * Allocate a filter and copy the given original filter.
+ *
+ * Return allocated filter or NULL on error.
+ */
+struct lttng_filter_bytecode *lttng_filter_bytecode_copy(
+ const struct lttng_filter_bytecode *orig_f)
+{
+ struct lttng_filter_bytecode *filter = NULL;
+
+ /* Copy filter bytecode */
+ filter = zmalloc(sizeof(*filter) + orig_f->len);
+ if (!filter) {
+ PERROR("zmalloc alloc filter bytecode");
+ goto error;
+ }
+
+ memcpy(filter, orig_f, sizeof(*filter) + orig_f->len);
+
+error:
+ return filter;
+}
int b_loglevel_type, int b_loglevel_value, int loglevel_all_type);
const char *session_get_base_path(const struct ltt_session *session);
const char *consumer_output_get_base_path(const struct consumer_output *output);
+struct lttng_filter_bytecode *lttng_filter_bytecode_copy(
+ const struct lttng_filter_bytecode *orig_f);
#endif /* _LTT_UTILS_H */
}
LTTNG_HIDDEN
+struct lttng_event *lttng_event_rule_generate_lttng_event(
+ const struct lttng_event_rule *rule)
+{
+ assert(rule->generate_lttng_event);
+ return rule->generate_lttng_event(rule);
+}
+
+LTTNG_HIDDEN
+bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule)
+{
+ bool targets_agent_domain = false;
+ enum lttng_domain_type type = lttng_event_rule_get_domain_type(rule);
+
+ switch (type) {
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ case LTTNG_DOMAIN_PYTHON:
+ targets_agent_domain = true;
+ break;
+ case LTTNG_DOMAIN_UST:
+ case LTTNG_DOMAIN_KERNEL:
+ targets_agent_domain = false;
+ break;
+ default:
+ abort();
+ };
+
+ return targets_agent_domain;
+}
+
const char *lttng_event_rule_type_str(enum lttng_event_rule_type type)
{
switch (type) {
#include <common/hashtable/utils.h>
#include <lttng/event-rule/event-rule-internal.h>
#include <lttng/event-rule/tracepoint-internal.h>
+#include <lttng/event.h>
#define IS_TRACEPOINT_EVENT_RULE(rule) \
(lttng_event_rule_get_type(rule) == LTTNG_EVENT_RULE_TYPE_TRACEPOINT)
return hash;
}
+static struct lttng_event *lttng_event_rule_tracepoint_generate_lttng_event(
+ const struct lttng_event_rule *rule)
+{
+ int ret;
+ const struct lttng_event_rule_tracepoint *tracepoint;
+ struct lttng_event *local_event = NULL;
+ struct lttng_event *event = NULL;
+
+ tracepoint = container_of(
+ rule, const struct lttng_event_rule_tracepoint, parent);
+
+ local_event = zmalloc(sizeof(*local_event));
+ if (!local_event) {
+ goto error;
+ }
+
+ local_event->type = LTTNG_EVENT_TRACEPOINT;
+ ret = lttng_strncpy(local_event->name, tracepoint->pattern,
+ sizeof(local_event->name));
+ if (ret) {
+ ERR("Truncation occurred when copying event rule pattern to `lttng_event` structure: pattern = '%s'",
+ tracepoint->pattern);
+ goto error;
+ }
+
+ local_event->loglevel_type = tracepoint->loglevel.type;
+ local_event->loglevel = tracepoint->loglevel.value;
+
+ event = local_event;
+ local_event = NULL;
+error:
+ free(local_event);
+ return event;
+}
+
struct lttng_event_rule *lttng_event_rule_tracepoint_create(
enum lttng_domain_type domain_type)
{
tp_rule->parent.generate_exclusions =
lttng_event_rule_tracepoint_generate_exclusions;
tp_rule->parent.hash = lttng_event_rule_tracepoint_hash;
+ tp_rule->parent.generate_lttng_event =
+ lttng_event_rule_tracepoint_generate_lttng_event;
tp_rule->domain = domain_type;
tp_rule->loglevel.type = LTTNG_EVENT_LOGLEVEL_ALL;