Commit | Line | Data |
---|---|---|
022d91ba DG |
1 | /* |
2 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License, version 2 only, as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
16 | */ | |
17 | ||
18 | #ifndef LTTNG_SESSIOND_AGENT_H | |
19 | #define LTTNG_SESSIOND_AGENT_H | |
20 | ||
21 | #define _GNU_SOURCE | |
22 | #include <inttypes.h> | |
23 | ||
24 | #include <common/hashtable/hashtable.h> | |
25 | #include <lttng/lttng.h> | |
26 | ||
9474416f DG |
27 | /* Agent protocol version that is verified during the agent registration. */ |
28 | #define AGENT_MAJOR_VERSION 1 | |
29 | #define AGENT_MINOR_VERSION 0 | |
30 | ||
022d91ba DG |
31 | /* |
32 | * Hash table that contains the agent app created upon registration indexed by | |
33 | * socket. | |
34 | */ | |
35 | struct lttng_ht *agent_apps_ht_by_sock; | |
36 | ||
37 | struct agent_ht_key { | |
38 | const char *name; | |
79a065a0 | 39 | int loglevel_value; |
15f57f85 | 40 | enum lttng_loglevel_type loglevel_type; |
ade8d7e3 | 41 | char *filter_expression; |
022d91ba DG |
42 | }; |
43 | ||
44 | /* | |
45 | * Registration message payload from an agent application. The PID is used to | |
46 | * find back the corresponding UST app object so both socket can be linked. | |
47 | */ | |
48 | struct agent_register_msg { | |
fefd409b DG |
49 | /* This maps to a lttng_domain_type. */ |
50 | uint32_t domain; | |
022d91ba | 51 | uint32_t pid; |
9474416f DG |
52 | uint32_t major_version; |
53 | uint32_t minor_version; | |
022d91ba DG |
54 | }; |
55 | ||
56 | /* | |
57 | * Agent application object created after a successful registration. This | |
58 | * object is linked to its associated UST app by their PID through hash table | |
59 | * lookups. | |
60 | */ | |
61 | struct agent_app { | |
62 | /* | |
63 | * PID sent during registration of a AGENT application. | |
64 | */ | |
65 | pid_t pid; | |
66 | ||
fefd409b DG |
67 | /* Domain of the application. */ |
68 | enum lttng_domain_type domain; | |
69 | ||
022d91ba DG |
70 | /* |
71 | * AGENT TCP socket that was created upon registration. | |
72 | */ | |
73 | struct lttcomm_sock *sock; | |
74 | ||
75 | /* Initialized with the AGENT sock value. */ | |
76 | struct lttng_ht_node_ulong node; | |
77 | }; | |
78 | ||
79 | /* | |
80 | * Agent event representation. | |
81 | */ | |
82 | struct agent_event { | |
83 | /* Name of the event. */ | |
84 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
79a065a0 | 85 | int loglevel_value; |
022d91ba DG |
86 | enum lttng_loglevel_type loglevel_type; |
87 | ||
88 | /* | |
89 | * Tells if the event is enabled or not on the agent. | |
90 | */ | |
91 | unsigned int enabled:1; | |
92 | ||
93 | /* Hash table node of the agent domain object. */ | |
94 | struct lttng_ht_node_str node; | |
95 | ||
0a3fca4d | 96 | /* Filter associated with the event. NULL if none. */ |
022d91ba | 97 | struct lttng_filter_bytecode *filter; |
0a3fca4d JG |
98 | char *filter_expression; |
99 | struct lttng_event_exclusion *exclusion; | |
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 DG |
119 | |
120 | /* Node used for the hash table indexed by domain type. */ | |
121 | struct lttng_ht_node_u64 node; | |
022d91ba DG |
122 | }; |
123 | ||
5642e70b JG |
124 | /* Allocate agent apps hash table */ |
125 | int agent_app_ht_alloc(void); | |
126 | /* Clean-up agent apps hash table */ | |
127 | void agent_app_ht_clean(void); | |
022d91ba DG |
128 | |
129 | /* Initialize an already allocated agent domain. */ | |
130 | int agent_init(struct agent *agt); | |
fefd409b | 131 | struct agent *agent_create(enum lttng_domain_type domain); |
022d91ba | 132 | void agent_destroy(struct agent *agt); |
fefd409b | 133 | void agent_add(struct agent *agt, struct lttng_ht *ht); |
022d91ba DG |
134 | |
135 | /* Agent event API. */ | |
15f57f85 PP |
136 | struct agent_event *agent_create_event(const char *name, |
137 | enum lttng_loglevel_type loglevel_type, int loglevel_value, | |
0a3fca4d JG |
138 | struct lttng_filter_bytecode *filter, |
139 | char *filter_expression); | |
022d91ba DG |
140 | void agent_add_event(struct agent_event *event, struct agent *agt); |
141 | ||
15f57f85 PP |
142 | struct agent_event *agent_find_event(const char *name, |
143 | enum lttng_loglevel_type loglevel_type, int loglevel_value, | |
ade8d7e3 | 144 | char *filter_expression, struct agent *agt); |
442a3c6e PP |
145 | void agent_find_events_by_name(const char *name, struct agent *agt, |
146 | struct lttng_ht_iter* iter); | |
147 | void agent_event_next_duplicate(const char *name, | |
148 | struct agent *agt, struct lttng_ht_iter* iter); | |
022d91ba DG |
149 | void agent_delete_event(struct agent_event *event, struct agent *agt); |
150 | void agent_destroy_event(struct agent_event *event); | |
151 | ||
152 | /* Agent app API. */ | |
fefd409b DG |
153 | struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, |
154 | struct lttcomm_sock *sock); | |
022d91ba DG |
155 | void agent_add_app(struct agent_app *app); |
156 | void agent_delete_app(struct agent_app *app); | |
157 | struct agent_app *agent_find_app_by_sock(int sock); | |
158 | void agent_destroy_app(struct agent_app *app); | |
5642e70b | 159 | void agent_destroy_app_by_sock(int sock); |
022d91ba DG |
160 | int agent_send_registration_done(struct agent_app *app); |
161 | ||
162 | /* Agent action API */ | |
fefd409b DG |
163 | int agent_enable_event(struct agent_event *event, |
164 | enum lttng_domain_type domain); | |
165 | int agent_disable_event(struct agent_event *event, | |
166 | enum lttng_domain_type domain); | |
022d91ba | 167 | void agent_update(struct agent *agt, int sock); |
f60140a1 DG |
168 | int agent_list_events(struct lttng_event **events, |
169 | enum lttng_domain_type domain); | |
022d91ba DG |
170 | |
171 | #endif /* LTTNG_SESSIOND_AGENT_H */ |