SoW-2019-0002: Dynamic Snapshot
[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 */
76 struct agent_event {
77 /* Name of the event. */
78 char name[LTTNG_SYMBOL_NAME_LEN];
79 int loglevel_value;
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
90 /* Filter associated with the event. NULL if none. */
91 struct lttng_filter_bytecode *filter;
92 char *filter_expression;
93 struct lttng_event_exclusion *exclusion;
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;
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;
113
114 /* What domain this agent is. */
115 enum lttng_domain_type domain;
116
117 /* Contains event indexed by name. */
118 struct lttng_ht *events;
119
120 /* Application context list (struct agent_app_ctx). */
121 struct cds_list_head app_ctx_list;
122
123 /* Node used for the hash table indexed by domain type. */
124 struct lttng_ht_node_u64 node;
125 };
126
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);
131
132 /* Initialize an already allocated agent domain. */
133 int agent_init(struct agent *agt);
134 struct agent *agent_create(enum lttng_domain_type domain);
135 void agent_destroy(struct agent *agt);
136 void agent_add(struct agent *agt, struct lttng_ht *ht);
137
138 /* Agent event API. */
139 struct agent_event *agent_create_event(const char *name,
140 enum lttng_loglevel_type loglevel_type, int loglevel_value,
141 struct lttng_filter_bytecode *filter,
142 char *filter_expression);
143 void agent_add_event(struct agent_event *event, struct agent *agt);
144
145 struct agent_event *agent_find_event(const char *name,
146 enum lttng_loglevel_type loglevel_type,
147 int loglevel_value,
148 const char *filter_expression,
149 struct agent *agt);
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);
154 void agent_delete_event(struct agent_event *event, struct agent *agt);
155 void agent_destroy_event(struct agent_event *event);
156
157 /* Agent context API.*/
158 int agent_enable_context(const struct lttng_event_context *ctx,
159 enum lttng_domain_type domain);
160 int agent_add_context(const struct lttng_event_context *ctx,
161 struct agent *agt);
162
163 /* Agent app API. */
164 struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
165 struct lttcomm_sock *sock);
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);
170 void agent_destroy_app_by_sock(int sock);
171 int agent_send_registration_done(struct agent_app *app);
172
173 /* Agent action API */
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);
178 void agent_update(struct agent *agt, int sock);
179 int agent_list_events(struct lttng_event **events,
180 enum lttng_domain_type domain);
181
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
190 #endif /* LTTNG_SESSIOND_AGENT_H */
This page took 0.034178 seconds and 5 git commands to generate.