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
;
30 enum lttng_loglevel_type loglevel_type
;
31 char *filter_expression
;
35 * Registration message payload from an agent application. The PID is used to
36 * find back the corresponding UST app object so both socket can be linked.
38 struct agent_register_msg
{
39 /* This maps to a lttng_domain_type. */
42 uint32_t major_version
;
43 uint32_t minor_version
;
47 * Agent application object created after a successful registration. This
48 * object is linked to its associated UST app by their PID through hash table
53 * PID sent during registration of an agent application.
57 /* Domain of the application. */
58 enum lttng_domain_type domain
;
61 * AGENT TCP socket that was created upon registration.
63 struct lttcomm_sock
*sock
;
65 /* Initialized with the AGENT sock value. */
66 struct lttng_ht_node_ulong node
;
70 * Agent event representation.
73 /* Name of the event. */
74 char name
[LTTNG_SYMBOL_NAME_LEN
];
76 enum lttng_loglevel_type loglevel_type
;
79 * Tells if the event is enabled or not on the agent.
81 unsigned int enabled
:1;
83 /* Hash table node of the agent domain object. */
84 struct lttng_ht_node_str node
;
86 /* Filter associated with the event. NULL if none. */
87 struct lttng_filter_bytecode
*filter
;
88 char *filter_expression
;
89 struct lttng_event_exclusion
*exclusion
;
93 * Agent object containing events enabled/disabled for it.
97 * This indicates if that domain is being used meaning if at least one
98 * event has been at some point in time added to it. This is used so when
99 * listing domains for a session, we can tell or not if the agent is
102 unsigned int being_used
:1;
104 /* What domain this agent is. */
105 enum lttng_domain_type domain
;
107 /* Contains event indexed by name. */
108 struct lttng_ht
*events
;
110 /* Application context list (struct agent_app_ctx). */
111 struct cds_list_head app_ctx_list
;
113 /* Node used for the hash table indexed by domain type. */
114 struct lttng_ht_node_u64 node
;
117 /* Allocate agent apps hash table */
118 int agent_app_ht_alloc(void);
119 /* Clean-up agent apps hash table */
120 void agent_app_ht_clean(void);
122 /* Initialize an already allocated agent domain. */
123 int agent_init(struct agent
*agt
);
124 struct agent
*agent_create(enum lttng_domain_type domain
);
125 void agent_destroy(struct agent
*agt
);
126 void agent_add(struct agent
*agt
, struct lttng_ht
*ht
);
128 /* Agent event API. */
129 struct agent_event
*agent_create_event(const char *name
,
130 enum lttng_loglevel_type loglevel_type
, int loglevel_value
,
131 struct lttng_filter_bytecode
*filter
,
132 char *filter_expression
);
133 void agent_add_event(struct agent_event
*event
, struct agent
*agt
);
135 struct agent_event
*agent_find_event(const char *name
,
136 enum lttng_loglevel_type loglevel_type
, int loglevel_value
,
137 char *filter_expression
, struct agent
*agt
);
138 void agent_find_events_by_name(const char *name
, struct agent
*agt
,
139 struct lttng_ht_iter
* iter
);
140 void agent_event_next_duplicate(const char *name
,
141 struct agent
*agt
, struct lttng_ht_iter
* iter
);
142 void agent_delete_event(struct agent_event
*event
, struct agent
*agt
);
143 void agent_destroy_event(struct agent_event
*event
);
145 /* Agent context API.*/
146 int agent_enable_context(const struct lttng_event_context
*ctx
,
147 enum lttng_domain_type domain
);
148 int agent_add_context(const struct lttng_event_context
*ctx
,
152 struct agent_app
*agent_create_app(pid_t pid
, enum lttng_domain_type domain
,
153 struct lttcomm_sock
*sock
);
154 void agent_add_app(struct agent_app
*app
);
155 void agent_delete_app(struct agent_app
*app
);
156 struct agent_app
*agent_find_app_by_sock(int sock
);
157 void agent_destroy_app(struct agent_app
*app
);
158 void agent_destroy_app_by_sock(int sock
);
159 int agent_send_registration_done(struct agent_app
*app
);
161 /* Agent action API */
162 int agent_enable_event(struct agent_event
*event
,
163 enum lttng_domain_type domain
);
164 int agent_disable_event(struct agent_event
*event
,
165 enum lttng_domain_type domain
);
166 void agent_update(const struct agent
*agt
, const struct agent_app
*app
);
167 int agent_list_events(struct lttng_event
**events
,
168 enum lttng_domain_type domain
);
170 #endif /* LTTNG_SESSIOND_AGENT_H */