Commit | Line | Data |
---|---|---|
022d91ba | 1 | /* |
ab5be9fa MJ |
2 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
3 | * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
022d91ba | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: GPL-2.0-only |
022d91ba | 6 | * |
022d91ba DG |
7 | */ |
8 | ||
9 | #ifndef LTTNG_SESSIOND_AGENT_H | |
10 | #define LTTNG_SESSIOND_AGENT_H | |
11 | ||
c9e313bc | 12 | #include <common/hashtable/hashtable.hpp> |
28f23191 | 13 | |
022d91ba DG |
14 | #include <lttng/lttng.h> |
15 | ||
28f23191 JG |
16 | #include <inttypes.h> |
17 | ||
9474416f | 18 | /* Agent protocol version that is verified during the agent registration. */ |
28f23191 JG |
19 | #define AGENT_MAJOR_VERSION 2 |
20 | #define AGENT_MINOR_VERSION 0 | |
9474416f | 21 | |
022d91ba DG |
22 | /* |
23 | * Hash table that contains the agent app created upon registration indexed by | |
7c1d2758 | 24 | * socket. Global to the session daemon. |
022d91ba | 25 | */ |
412d7227 | 26 | extern struct lttng_ht *the_agent_apps_ht_by_sock; |
022d91ba | 27 | |
44760c20 JR |
28 | /* |
29 | * Hash table that contains the trigger agents by domain */ | |
412d7227 | 30 | extern struct lttng_ht *the_trigger_agents_ht_by_domain; |
44760c20 | 31 | |
022d91ba DG |
32 | struct agent_ht_key { |
33 | const char *name; | |
2106efa0 | 34 | int loglevel_value; |
a9319624 | 35 | enum lttng_loglevel_type loglevel_type; |
44760c20 | 36 | const char *filter_expression; |
022d91ba DG |
37 | }; |
38 | ||
39 | /* | |
40 | * Registration message payload from an agent application. The PID is used to | |
41 | * find back the corresponding UST app object so both socket can be linked. | |
42 | */ | |
43 | struct agent_register_msg { | |
fefd409b DG |
44 | /* This maps to a lttng_domain_type. */ |
45 | uint32_t domain; | |
022d91ba | 46 | uint32_t pid; |
9474416f DG |
47 | uint32_t major_version; |
48 | uint32_t minor_version; | |
022d91ba DG |
49 | }; |
50 | ||
51 | /* | |
52 | * Agent application object created after a successful registration. This | |
53 | * object is linked to its associated UST app by their PID through hash table | |
54 | * lookups. | |
55 | */ | |
56 | struct agent_app { | |
57 | /* | |
d53e2992 | 58 | * PID sent during registration of an agent application. |
022d91ba DG |
59 | */ |
60 | pid_t pid; | |
61 | ||
fefd409b DG |
62 | /* Domain of the application. */ |
63 | enum lttng_domain_type domain; | |
64 | ||
022d91ba DG |
65 | /* |
66 | * AGENT TCP socket that was created upon registration. | |
67 | */ | |
68 | struct lttcomm_sock *sock; | |
69 | ||
70 | /* Initialized with the AGENT sock value. */ | |
71 | struct lttng_ht_node_ulong node; | |
72 | }; | |
73 | ||
74 | /* | |
75 | * Agent event representation. | |
44760c20 | 76 | * Accesses to this structure are protected by the session list lock. |
022d91ba DG |
77 | */ |
78 | struct agent_event { | |
79 | /* Name of the event. */ | |
80 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
2106efa0 | 81 | int loglevel_value; |
022d91ba DG |
82 | enum lttng_loglevel_type loglevel_type; |
83 | ||
84 | /* | |
44760c20 JR |
85 | * Tells if the event is enabled or not on the agent. While this can be |
86 | * implicitly tested as a boolean, it is in fact a reference count and | |
87 | * the AGENT_EVENT_IS_ENABLED macro should be used to prevent accidental | |
88 | * comparisons to non-zero literals (e.g. '1'). | |
89 | * | |
90 | * Multiple triggers and events can map to the same agent event as it | |
91 | * is merely a "filter" in front of a user space tracer enabler. | |
92 | * | |
93 | * This count is updated to ensure an event is only disabled when all | |
94 | * matching enablers are disabled. | |
022d91ba | 95 | */ |
44760c20 | 96 | unsigned int enabled_count; |
022d91ba DG |
97 | |
98 | /* Hash table node of the agent domain object. */ | |
99 | struct lttng_ht_node_str node; | |
100 | ||
51755dc8 | 101 | /* Filter associated with the event. NULL if none. */ |
2b00d462 | 102 | struct lttng_bytecode *filter; |
51755dc8 JG |
103 | char *filter_expression; |
104 | struct lttng_event_exclusion *exclusion; | |
022d91ba DG |
105 | }; |
106 | ||
0f4aa1a8 | 107 | #define AGENT_EVENT_IS_ENABLED(agent_event) (!!(agent_event)->enabled_count) |
44760c20 | 108 | |
022d91ba | 109 | /* |
44760c20 JR |
110 | * Agent object containing events enabled/disabled for a given domain in a |
111 | * scope. The scope is typically a session, but can also be "global" in the | |
112 | * context of event notifiers: see event_notifiers_find_agent(). | |
022d91ba DG |
113 | */ |
114 | struct agent { | |
115 | /* | |
116 | * This indicates if that domain is being used meaning if at least one | |
117 | * event has been at some point in time added to it. This is used so when | |
118 | * listing domains for a session, we can tell or not if the agent is | |
119 | * actually enabled. | |
120 | */ | |
121 | unsigned int being_used:1; | |
fefd409b DG |
122 | |
123 | /* What domain this agent is. */ | |
124 | enum lttng_domain_type domain; | |
125 | ||
022d91ba DG |
126 | /* Contains event indexed by name. */ |
127 | struct lttng_ht *events; | |
fefd409b | 128 | |
bdf64013 JG |
129 | /* Application context list (struct agent_app_ctx). */ |
130 | struct cds_list_head app_ctx_list; | |
131 | ||
fefd409b DG |
132 | /* Node used for the hash table indexed by domain type. */ |
133 | struct lttng_ht_node_u64 node; | |
022d91ba DG |
134 | }; |
135 | ||
6a4e4039 | 136 | /* Allocate agent apps hash table */ |
0f4aa1a8 | 137 | int agent_app_ht_alloc(); |
6a4e4039 | 138 | /* Clean-up agent apps hash table */ |
0f4aa1a8 | 139 | void agent_app_ht_clean(); |
022d91ba DG |
140 | |
141 | /* Initialize an already allocated agent domain. */ | |
142 | int agent_init(struct agent *agt); | |
fefd409b | 143 | struct agent *agent_create(enum lttng_domain_type domain); |
022d91ba | 144 | void agent_destroy(struct agent *agt); |
fefd409b | 145 | void agent_add(struct agent *agt, struct lttng_ht *ht); |
022d91ba DG |
146 | |
147 | /* Agent event API. */ | |
a9319624 | 148 | struct agent_event *agent_create_event(const char *name, |
28f23191 JG |
149 | enum lttng_loglevel_type loglevel_type, |
150 | int loglevel_value, | |
151 | struct lttng_bytecode *filter, | |
152 | char *filter_expression); | |
022d91ba DG |
153 | void agent_add_event(struct agent_event *event, struct agent *agt); |
154 | ||
a9319624 | 155 | struct agent_event *agent_find_event(const char *name, |
28f23191 JG |
156 | enum lttng_loglevel_type loglevel_type, |
157 | int loglevel_value, | |
158 | const char *filter_expression, | |
159 | struct agent *agt); | |
160 | void agent_find_events_by_name(const char *name, struct agent *agt, struct lttng_ht_iter *iter); | |
161 | void agent_event_next_duplicate(const char *name, struct agent *agt, struct lttng_ht_iter *iter); | |
022d91ba DG |
162 | void agent_delete_event(struct agent_event *event, struct agent *agt); |
163 | void agent_destroy_event(struct agent_event *event); | |
164 | ||
bdf64013 | 165 | /* Agent context API.*/ |
28f23191 JG |
166 | int agent_enable_context(const struct lttng_event_context *ctx, enum lttng_domain_type domain); |
167 | int agent_add_context(const struct lttng_event_context *ctx, struct agent *agt); | |
bdf64013 | 168 | |
022d91ba | 169 | /* Agent app API. */ |
28f23191 JG |
170 | struct agent_app * |
171 | agent_create_app(pid_t pid, enum lttng_domain_type domain, struct lttcomm_sock *sock); | |
022d91ba DG |
172 | void agent_add_app(struct agent_app *app); |
173 | void agent_delete_app(struct agent_app *app); | |
174 | struct agent_app *agent_find_app_by_sock(int sock); | |
175 | void agent_destroy_app(struct agent_app *app); | |
6a4e4039 | 176 | void agent_destroy_app_by_sock(int sock); |
022d91ba DG |
177 | int agent_send_registration_done(struct agent_app *app); |
178 | ||
179 | /* Agent action API */ | |
28f23191 JG |
180 | int agent_enable_event(struct agent_event *event, enum lttng_domain_type domain); |
181 | int agent_disable_event(struct agent_event *event, enum lttng_domain_type domain); | |
733c9165 | 182 | void agent_update(const struct agent *agt, const struct agent_app *app); |
28f23191 | 183 | int agent_list_events(struct lttng_event **events, enum lttng_domain_type domain); |
022d91ba | 184 | |
28f23191 JG |
185 | struct agent_event *agent_find_event_by_trigger(const struct lttng_trigger *trigger, |
186 | struct agent *agt); | |
44760c20 JR |
187 | |
188 | /* Global event notifier per-domain agents. */ | |
28f23191 | 189 | struct agent *agent_find_by_event_notifier_domain(enum lttng_domain_type domain_type); |
0f4aa1a8 JG |
190 | void agent_by_event_notifier_domain_ht_destroy(); |
191 | int agent_by_event_notifier_domain_ht_create(); | |
44760c20 | 192 | |
022d91ba | 193 | #endif /* LTTNG_SESSIOND_AGENT_H */ |