Clean-up: sessiond: change space to tabs
[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 struct agent_ht_key {
28 const char *name;
29 int loglevel_value;
30 enum lttng_loglevel_type loglevel_type;
31 char *filter_expression;
32 };
33
34 /*
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.
37 */
38 struct agent_register_msg {
39 /* This maps to a lttng_domain_type. */
40 uint32_t domain;
41 uint32_t pid;
42 uint32_t major_version;
43 uint32_t minor_version;
44 };
45
46 /*
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
49 * lookups.
50 */
51 struct agent_app {
52 /*
53 * PID sent during registration of an agent application.
54 */
55 pid_t pid;
56
57 /* Domain of the application. */
58 enum lttng_domain_type domain;
59
60 /*
61 * AGENT TCP socket that was created upon registration.
62 */
63 struct lttcomm_sock *sock;
64
65 /* Initialized with the AGENT sock value. */
66 struct lttng_ht_node_ulong node;
67 };
68
69 /*
70 * Agent event representation.
71 */
72 struct agent_event {
73 /* Name of the event. */
74 char name[LTTNG_SYMBOL_NAME_LEN];
75 int loglevel_value;
76 enum lttng_loglevel_type loglevel_type;
77
78 /*
79 * Tells if the event is enabled or not on the agent.
80 */
81 unsigned int enabled:1;
82
83 /* Hash table node of the agent domain object. */
84 struct lttng_ht_node_str node;
85
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;
90 };
91
92 /*
93 * Agent object containing events enabled/disabled for it.
94 */
95 struct agent {
96 /*
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
100 * actually enabled.
101 */
102 unsigned int being_used:1;
103
104 /* What domain this agent is. */
105 enum lttng_domain_type domain;
106
107 /* Contains event indexed by name. */
108 struct lttng_ht *events;
109
110 /* Application context list (struct agent_app_ctx). */
111 struct cds_list_head app_ctx_list;
112
113 /* Node used for the hash table indexed by domain type. */
114 struct lttng_ht_node_u64 node;
115 };
116
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);
121
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);
127
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);
134
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);
144
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,
149 struct agent *agt);
150
151 /* Agent app API. */
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);
160
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);
169
170 #endif /* LTTNG_SESSIOND_AGENT_H */
This page took 0.044604 seconds and 4 git commands to generate.