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 | ||
022d91ba DG |
12 | #include <inttypes.h> |
13 | ||
14 | #include <common/hashtable/hashtable.h> | |
15 | #include <lttng/lttng.h> | |
16 | ||
9474416f | 17 | /* Agent protocol version that is verified during the agent registration. */ |
a0ba721c | 18 | #define AGENT_MAJOR_VERSION 2 |
9474416f DG |
19 | #define AGENT_MINOR_VERSION 0 |
20 | ||
022d91ba DG |
21 | /* |
22 | * Hash table that contains the agent app created upon registration indexed by | |
7c1d2758 | 23 | * socket. Global to the session daemon. |
022d91ba | 24 | */ |
7c1d2758 | 25 | extern struct lttng_ht *agent_apps_ht_by_sock; |
022d91ba | 26 | |
5024c2ac JR |
27 | /* |
28 | * Hash table that contains the trigger agents by domain */ | |
29 | extern struct lttng_ht *trigger_agents_ht_by_domain; | |
30 | ||
022d91ba DG |
31 | struct agent_ht_key { |
32 | const char *name; | |
2106efa0 | 33 | int loglevel_value; |
a9319624 | 34 | enum lttng_loglevel_type loglevel_type; |
5024c2ac | 35 | const char *filter_expression; |
022d91ba DG |
36 | }; |
37 | ||
38 | /* | |
39 | * Registration message payload from an agent application. The PID is used to | |
40 | * find back the corresponding UST app object so both socket can be linked. | |
41 | */ | |
42 | struct agent_register_msg { | |
fefd409b DG |
43 | /* This maps to a lttng_domain_type. */ |
44 | uint32_t domain; | |
022d91ba | 45 | uint32_t pid; |
9474416f DG |
46 | uint32_t major_version; |
47 | uint32_t minor_version; | |
022d91ba DG |
48 | }; |
49 | ||
50 | /* | |
51 | * Agent application object created after a successful registration. This | |
52 | * object is linked to its associated UST app by their PID through hash table | |
53 | * lookups. | |
54 | */ | |
55 | struct agent_app { | |
56 | /* | |
d53e2992 | 57 | * PID sent during registration of an agent application. |
022d91ba DG |
58 | */ |
59 | pid_t pid; | |
60 | ||
fefd409b DG |
61 | /* Domain of the application. */ |
62 | enum lttng_domain_type domain; | |
63 | ||
022d91ba DG |
64 | /* |
65 | * AGENT TCP socket that was created upon registration. | |
66 | */ | |
67 | struct lttcomm_sock *sock; | |
68 | ||
69 | /* Initialized with the AGENT sock value. */ | |
70 | struct lttng_ht_node_ulong node; | |
71 | }; | |
72 | ||
73 | /* | |
74 | * Agent event representation. | |
75 | */ | |
76 | struct agent_event { | |
77 | /* Name of the event. */ | |
78 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
2106efa0 | 79 | int loglevel_value; |
022d91ba DG |
80 | enum lttng_loglevel_type loglevel_type; |
81 | ||
82 | /* | |
83 | * Tells if the event is enabled or not on the agent. | |
84 | */ | |
85 | unsigned int enabled:1; | |
86 | ||
87 | /* Hash table node of the agent domain object. */ | |
88 | struct lttng_ht_node_str node; | |
89 | ||
51755dc8 | 90 | /* Filter associated with the event. NULL if none. */ |
5024c2ac | 91 | struct lttng_bytecode *filter; |
51755dc8 JG |
92 | char *filter_expression; |
93 | struct lttng_event_exclusion *exclusion; | |
5024c2ac JR |
94 | |
95 | /* | |
96 | * Multiple triggers and events can use this agent event. | |
97 | * The event can only be disabled when the count is zero. | |
98 | */ | |
99 | unsigned int user_refcount; | |
022d91ba DG |
100 | }; |
101 | ||
102 | /* | |
103 | * Agent object containing events enabled/disabled for it. | |
104 | */ | |
105 | struct agent { | |
106 | /* | |
107 | * This indicates if that domain is being used meaning if at least one | |
108 | * event has been at some point in time added to it. This is used so when | |
109 | * listing domains for a session, we can tell or not if the agent is | |
110 | * actually enabled. | |
111 | */ | |
112 | unsigned int being_used:1; | |
fefd409b DG |
113 | |
114 | /* What domain this agent is. */ | |
115 | enum lttng_domain_type domain; | |
116 | ||
022d91ba DG |
117 | /* Contains event indexed by name. */ |
118 | struct lttng_ht *events; | |
fefd409b | 119 | |
bdf64013 JG |
120 | /* Application context list (struct agent_app_ctx). */ |
121 | struct cds_list_head app_ctx_list; | |
122 | ||
fefd409b DG |
123 | /* Node used for the hash table indexed by domain type. */ |
124 | struct lttng_ht_node_u64 node; | |
022d91ba DG |
125 | }; |
126 | ||
6a4e4039 JG |
127 | /* Allocate agent apps hash table */ |
128 | int agent_app_ht_alloc(void); | |
129 | /* Clean-up agent apps hash table */ | |
130 | void agent_app_ht_clean(void); | |
022d91ba DG |
131 | |
132 | /* Initialize an already allocated agent domain. */ | |
133 | int agent_init(struct agent *agt); | |
fefd409b | 134 | struct agent *agent_create(enum lttng_domain_type domain); |
022d91ba | 135 | void agent_destroy(struct agent *agt); |
fefd409b | 136 | void agent_add(struct agent *agt, struct lttng_ht *ht); |
022d91ba DG |
137 | |
138 | /* Agent event API. */ | |
a9319624 PP |
139 | struct agent_event *agent_create_event(const char *name, |
140 | enum lttng_loglevel_type loglevel_type, int loglevel_value, | |
5024c2ac | 141 | struct lttng_bytecode *filter, |
51755dc8 | 142 | char *filter_expression); |
022d91ba DG |
143 | void agent_add_event(struct agent_event *event, struct agent *agt); |
144 | ||
a9319624 | 145 | struct agent_event *agent_find_event(const char *name, |
5024c2ac JR |
146 | enum lttng_loglevel_type loglevel_type, |
147 | int loglevel_value, | |
148 | const char *filter_expression, | |
149 | struct agent *agt); | |
e261a6cc PP |
150 | void agent_find_events_by_name(const char *name, struct agent *agt, |
151 | struct lttng_ht_iter* iter); | |
152 | void agent_event_next_duplicate(const char *name, | |
153 | struct agent *agt, struct lttng_ht_iter* iter); | |
022d91ba DG |
154 | void agent_delete_event(struct agent_event *event, struct agent *agt); |
155 | void agent_destroy_event(struct agent_event *event); | |
156 | ||
bdf64013 | 157 | /* Agent context API.*/ |
df4f5a87 | 158 | int agent_enable_context(const struct lttng_event_context *ctx, |
bdf64013 | 159 | enum lttng_domain_type domain); |
df4f5a87 JG |
160 | int agent_add_context(const struct lttng_event_context *ctx, |
161 | struct agent *agt); | |
bdf64013 | 162 | |
022d91ba | 163 | /* Agent app API. */ |
fefd409b DG |
164 | struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, |
165 | struct lttcomm_sock *sock); | |
022d91ba DG |
166 | void agent_add_app(struct agent_app *app); |
167 | void agent_delete_app(struct agent_app *app); | |
168 | struct agent_app *agent_find_app_by_sock(int sock); | |
169 | void agent_destroy_app(struct agent_app *app); | |
6a4e4039 | 170 | void agent_destroy_app_by_sock(int sock); |
022d91ba DG |
171 | int agent_send_registration_done(struct agent_app *app); |
172 | ||
173 | /* Agent action API */ | |
fefd409b DG |
174 | int agent_enable_event(struct agent_event *event, |
175 | enum lttng_domain_type domain); | |
176 | int agent_disable_event(struct agent_event *event, | |
177 | enum lttng_domain_type domain); | |
733c9165 | 178 | void agent_update(const struct agent *agt, const struct agent_app *app); |
f60140a1 DG |
179 | int agent_list_events(struct lttng_event **events, |
180 | enum lttng_domain_type domain); | |
022d91ba | 181 | |
5024c2ac JR |
182 | struct agent_event *agent_find_event_by_trigger( |
183 | const struct lttng_trigger *trigger, struct agent *agt); | |
184 | ||
185 | /* todo: find a better place for this */ | |
186 | struct agent *trigger_find_agent(enum lttng_domain_type domain_type); | |
187 | void trigger_agent_ht_clean(void); | |
188 | int trigger_agent_ht_alloc(void); | |
189 | ||
022d91ba | 190 | #endif /* LTTNG_SESSIOND_AGENT_H */ |