2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #ifndef LTTNG_SESSIOND_AGENT_H
10 #define LTTNG_SESSIOND_AGENT_H
14 #include <common/hashtable/hashtable.h>
15 #include <lttng/lttng.h>
17 /* Agent protocol version that is verified during the agent registration. */
18 #define AGENT_MAJOR_VERSION 2
19 #define AGENT_MINOR_VERSION 0
22 * Hash table that contains the agent app created upon registration indexed by
23 * socket. Global to the session daemon.
25 extern struct lttng_ht
*agent_apps_ht_by_sock
;
28 * Hash table that contains the trigger agents by domain */
29 extern struct lttng_ht
*trigger_agents_ht_by_domain
;
34 enum lttng_loglevel_type loglevel_type
;
35 const char *filter_expression
;
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.
42 struct agent_register_msg
{
43 /* This maps to a lttng_domain_type. */
46 uint32_t major_version
;
47 uint32_t minor_version
;
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
57 * PID sent during registration of an agent application.
61 /* Domain of the application. */
62 enum lttng_domain_type domain
;
65 * AGENT TCP socket that was created upon registration.
67 struct lttcomm_sock
*sock
;
69 /* Initialized with the AGENT sock value. */
70 struct lttng_ht_node_ulong node
;
74 * Agent event representation.
77 /* Name of the event. */
78 char name
[LTTNG_SYMBOL_NAME_LEN
];
80 enum lttng_loglevel_type loglevel_type
;
83 * Tells if the event is enabled or not on the agent.
85 unsigned int enabled
:1;
87 /* Hash table node of the agent domain object. */
88 struct lttng_ht_node_str node
;
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
;
96 * Multiple triggers and events can use this agent event.
97 * The event can only be disabled when the count is zero.
99 unsigned int user_refcount
;
103 * Agent object containing events enabled/disabled for it.
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
112 unsigned int being_used
:1;
114 /* What domain this agent is. */
115 enum lttng_domain_type domain
;
117 /* Contains event indexed by name. */
118 struct lttng_ht
*events
;
120 /* Application context list (struct agent_app_ctx). */
121 struct cds_list_head app_ctx_list
;
123 /* Node used for the hash table indexed by domain type. */
124 struct lttng_ht_node_u64 node
;
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);
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
);
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
);
145 struct agent_event
*agent_find_event(const char *name
,
146 enum lttng_loglevel_type loglevel_type
,
148 const char *filter_expression
,
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
);
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
,
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
);
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
);
182 struct agent_event
*agent_find_event_by_trigger(
183 const struct lttng_trigger
*trigger
, struct agent
*agt
);
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);
190 #endif /* LTTNG_SESSIOND_AGENT_H */