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