Remove LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.h
CommitLineData
f1e16794 1/*
ab5be9fa 2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
f1e16794 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
f1e16794 5 *
f1e16794
DG
6 */
7
8#ifndef _CONSUMER_H
9#define _CONSUMER_H
10
c8fea79c 11#include <common/consumer/consumer.h>
173af62f 12#include <common/hashtable/hashtable.h>
00e2e675 13#include <lttng/lttng.h>
6addfa37 14#include <urcu/ref.h>
00e2e675 15
6dc3064a
DG
16#include "snapshot.h"
17
18struct snapshot;
19struct snapshot_output;
b178f53e 20struct ltt_session;
6dc3064a 21
00e2e675
DG
22enum consumer_dst_type {
23 CONSUMER_DST_LOCAL,
24 CONSUMER_DST_NET,
25};
f1e16794 26
d2956687
JG
27enum consumer_trace_chunk_exists_status {
28 CONSUMER_TRACE_CHUNK_EXISTS_STATUS_EXISTS_LOCAL,
29 CONSUMER_TRACE_CHUNK_EXISTS_STATUS_EXISTS_REMOTE,
30 CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK,
31};
32
173af62f 33struct consumer_socket {
4ce514c4
DG
34 /*
35 * File descriptor. This is just a reference to the consumer data meaning
9363801e
DG
36 * that every access must be locked and checked for a possible invalid
37 * value.
4ce514c4 38 */
9363801e 39 int *fd_ptr;
4ce514c4 40
173af62f
DG
41 /*
42 * To use this socket (send/recv), this lock MUST be acquired.
43 */
44 pthread_mutex_t *lock;
2f77fc4b
DG
45
46 /*
47 * Indicates if the socket was registered by a third part
48 * (REGISTER_CONSUMER) or is the spawn consumer of the session daemon.
49 * During the destroy phase of a consumer output, we close the socket if
50 * this flag is set to 1 since we don't need the fd anymore.
51 */
52 unsigned int registered;
53
ffe60014
DG
54 /* Flag if network sockets were sent to the consumer. */
55 unsigned int control_sock_sent;
56 unsigned int data_sock_sent;
57
173af62f 58 struct lttng_ht_node_ulong node;
6dc3064a
DG
59
60 enum lttng_consumer_type type;
173af62f
DG
61};
62
f1e16794
DG
63struct consumer_data {
64 enum lttng_consumer_type type;
65
f1e16794
DG
66 /* Mutex to control consumerd pid assignation */
67 pthread_mutex_t pid_mutex;
68 pid_t pid;
69
70 int err_sock;
331744e3 71 /* These two sockets uses the cmd_unix_sock_path. */
f1e16794 72 int cmd_sock;
e9404c27
JG
73 /*
74 * Write-end of the channel monitoring pipe to be passed to the
75 * consumer.
76 */
77 int channel_monitor_pipe;
4ce514c4
DG
78 /*
79 * The metadata socket object is handled differently and only created
80 * locally in this object thus it's the only reference available in the
9363801e
DG
81 * session daemon. For that reason, a variable for the fd is required and
82 * the metadata socket fd points to it.
4ce514c4
DG
83 */
84 int metadata_fd;
331744e3 85 struct consumer_socket metadata_sock;
f1e16794
DG
86
87 /* consumer error and command Unix socket path */
e6142f2e
JG
88 const char *err_unix_sock_path;
89 const char *cmd_unix_sock_path;
44a5e5eb 90
92db7cdc
DG
91 /*
92 * This lock has two purposes. It protects any change to the consumer
93 * socket and make sure only one thread uses this object for read/write
94 * operations.
95 */
173af62f 96 pthread_mutex_t lock;
f1e16794
DG
97};
98
00e2e675
DG
99/*
100 * Network URIs
101 */
102struct consumer_net {
103 /*
104 * Indicate if URI type is set. Those flags should only be set when the
105 * created URI is done AND valid.
106 */
107 int control_isset;
108 int data_isset;
109
110 /*
111 * The following two URIs MUST have the same destination address for
112 * network streaming to work. Network hop are not yet supported.
113 */
114
115 /* Control path for network streaming. */
116 struct lttng_uri control;
117
118 /* Data path for network streaming. */
119 struct lttng_uri data;
2b29c638
JD
120
121 /* <hostname>/<session-name> */
122 char base_dir[PATH_MAX];
00e2e675
DG
123};
124
125/*
126 * Consumer output object describing where and how to send data.
127 */
128struct consumer_output {
6addfa37
MD
129 struct urcu_ref ref; /* Refcount */
130
00e2e675
DG
131 /* If the consumer is enabled meaning that should be used */
132 unsigned int enabled;
133 enum consumer_dst_type type;
173af62f 134
00e2e675
DG
135 /*
136 * The net_seq_index is the index of the network stream on the consumer
3f8e211f
DG
137 * side. It tells the consumer which streams goes to which relayd with this
138 * index. The relayd sockets are index with it on the consumer side.
00e2e675 139 */
d88aee68 140 uint64_t net_seq_index;
b31610f2
JD
141 /* Store the relay protocol in use if the session is remote. */
142 uint32_t relay_major_version;
143 uint32_t relay_minor_version;
173af62f 144
eacb7b6f
MD
145 /* True if relayd supports the clear feature. */
146 bool relay_allows_clear;
147
00e2e675 148 /*
366a9222 149 * Subdirectory path name used for both local and network
d2956687 150 * consumer ("kernel", "ust", or empty).
00e2e675 151 */
b178f53e
JG
152 char domain_subdir[max(sizeof(DEFAULT_KERNEL_TRACE_DIR),
153 sizeof(DEFAULT_UST_TRACE_DIR))];
173af62f
DG
154
155 /*
156 * Hashtable of consumer_socket index by the file descriptor value. For
b178f53e
JG
157 * multiarch consumer support, we can have more than one consumer (ex:
158 * 32 and 64 bit).
173af62f
DG
159 */
160 struct lttng_ht *socks;
161
7d2f7452
DG
162 /* Tell if this output is used for snapshot. */
163 unsigned int snapshot:1;
164
00e2e675 165 union {
61ba6b6d 166 char session_root_path[LTTNG_PATH_MAX];
00e2e675
DG
167 struct consumer_net net;
168 } dst;
366a9222
JD
169
170 /*
171 * Sub-directory below the session_root_path where the next chunk of
172 * trace will be stored (\0 before the first session rotation).
173 */
61ba6b6d 174 char chunk_path[LTTNG_PATH_MAX];
00e2e675
DG
175};
176
173af62f 177struct consumer_socket *consumer_find_socket(int key,
348a81dc 178 const struct consumer_output *consumer);
7972aab2 179struct consumer_socket *consumer_find_socket_by_bitness(int bits,
348a81dc 180 const struct consumer_output *consumer);
4ce514c4 181struct consumer_socket *consumer_allocate_socket(int *fd);
173af62f
DG
182void consumer_add_socket(struct consumer_socket *sock,
183 struct consumer_output *consumer);
184void consumer_del_socket(struct consumer_socket *sock,
185 struct consumer_output *consumer);
186void consumer_destroy_socket(struct consumer_socket *sock);
6dc3064a
DG
187int consumer_copy_sockets(struct consumer_output *dst,
188 struct consumer_output *src);
af706bb7 189void consumer_destroy_output_sockets(struct consumer_output *obj);
04ed9e10 190int consumer_socket_send(struct consumer_socket *socket, const void *msg,
52898cb1
DG
191 size_t len);
192int consumer_socket_recv(struct consumer_socket *socket, void *msg,
193 size_t len);
173af62f 194
00e2e675
DG
195struct consumer_output *consumer_create_output(enum consumer_dst_type type);
196struct consumer_output *consumer_copy_output(struct consumer_output *obj);
6addfa37
MD
197void consumer_output_get(struct consumer_output *obj);
198void consumer_output_put(struct consumer_output *obj);
b178f53e
JG
199int consumer_set_network_uri(const struct ltt_session *session,
200 struct consumer_output *obj,
00e2e675 201 struct lttng_uri *uri);
ac2f30af
JG
202int consumer_send_fds(struct consumer_socket *sock, const int *fds,
203 size_t nb_fd);
ffe60014 204int consumer_send_msg(struct consumer_socket *sock,
04ed9e10 205 const struct lttcomm_consumer_msg *msg);
f50f23d9
DG
206int consumer_send_stream(struct consumer_socket *sock,
207 struct consumer_output *dst, struct lttcomm_consumer_msg *msg,
ac2f30af 208 const int *fds, size_t nb_fd);
f50f23d9
DG
209int consumer_send_channel(struct consumer_socket *sock,
210 struct lttcomm_consumer_msg *msg);
211int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
6151a90f 212 struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer,
d3e2ba59 213 enum lttng_stream_type type, uint64_t session_id,
fb9a95c4 214 const char *session_name, const char *hostname,
6fa5fe7c 215 const char *base_path, int session_live_timer,
46ef2188
MD
216 const uint64_t *current_chunk_id, time_t session_creation_time,
217 bool session_name_contains_creation_time);
e9404c27
JG
218int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
219 int pipe);
173af62f
DG
220int consumer_send_destroy_relayd(struct consumer_socket *sock,
221 struct consumer_output *consumer);
f50f23d9 222int consumer_recv_status_reply(struct consumer_socket *sock);
ffe60014 223int consumer_recv_status_channel(struct consumer_socket *sock,
d88aee68 224 uint64_t *key, unsigned int *stream_count);
2f77fc4b 225void consumer_output_send_destroy_relayd(struct consumer_output *consumer);
a4b92340
DG
226int consumer_create_socket(struct consumer_data *data,
227 struct consumer_output *output);
37278a1e 228
ffe60014
DG
229void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
230 uint64_t subbuf_size,
231 uint64_t num_subbuf,
232 int overwrite,
233 unsigned int switch_timer_interval,
234 unsigned int read_timer_interval,
ecc48a90 235 unsigned int live_timer_interval,
a2814ea7 236 bool is_in_live_session,
e9404c27 237 unsigned int monitor_timer_interval,
ffe60014
DG
238 int output,
239 int type,
240 uint64_t session_id,
241 const char *pathname,
242 const char *name,
d88aee68
DG
243 uint64_t relayd_id,
244 uint64_t key,
7972aab2 245 unsigned char *uuid,
1624d5b7
JD
246 uint32_t chan_id,
247 uint64_t tracefile_size,
2bba9e53 248 uint64_t tracefile_count,
1950109e 249 uint64_t session_id_per_pid,
567eb353 250 unsigned int monitor,
d7ba1388 251 uint32_t ust_app_uid,
491d1539 252 int64_t blocking_timeout,
3d071855 253 const char *root_shm_path,
e098433c 254 const char *shm_path,
1b0bebcb
JG
255 struct lttng_trace_chunk *trace_chunk,
256 const struct lttng_credentials *buffer_credentials);
e098433c 257void consumer_init_add_stream_comm_msg(struct lttcomm_consumer_msg *msg,
d88aee68
DG
258 uint64_t channel_key,
259 uint64_t stream_key,
d2956687 260 int32_t cpu);
a4baae1b
JD
261void consumer_init_streams_sent_comm_msg(struct lttcomm_consumer_msg *msg,
262 enum lttng_consumer_command cmd,
263 uint64_t channel_key, uint64_t net_seq_idx);
638e7b4e 264void consumer_init_add_channel_comm_msg(struct lttcomm_consumer_msg *msg,
d88aee68 265 uint64_t channel_key,
ffe60014
DG
266 uint64_t session_id,
267 const char *pathname,
268 uid_t uid,
269 gid_t gid,
d88aee68 270 uint64_t relayd_id,
c30aaa51 271 const char *name,
ffe60014
DG
272 unsigned int nb_init_streams,
273 enum lttng_event_output output,
1624d5b7
JD
274 int type,
275 uint64_t tracefile_size,
2bba9e53 276 uint64_t tracefile_count,
ecc48a90 277 unsigned int monitor,
e9404c27 278 unsigned int live_timer_interval,
a2814ea7 279 bool is_in_live_session,
d2956687
JG
280 unsigned int monitor_timer_interval,
281 struct lttng_trace_chunk *trace_chunk);
d88aee68 282int consumer_is_data_pending(uint64_t session_id,
806e2684 283 struct consumer_output *consumer);
7972aab2
DG
284int consumer_close_metadata(struct consumer_socket *socket,
285 uint64_t metadata_key);
286int consumer_setup_metadata(struct consumer_socket *socket,
287 uint64_t metadata_key);
288int consumer_push_metadata(struct consumer_socket *socket,
289 uint64_t metadata_key, char *metadata_str, size_t len,
93ec662e 290 size_t target_offset, uint64_t version);
7972aab2 291int consumer_flush_channel(struct consumer_socket *socket, uint64_t key);
0dd01979 292int consumer_clear_quiescent_channel(struct consumer_socket *socket, uint64_t key);
fb83fe64
JD
293int consumer_get_discarded_events(uint64_t session_id, uint64_t channel_key,
294 struct consumer_output *consumer, uint64_t *discarded);
295int consumer_get_lost_packets(uint64_t session_id, uint64_t channel_key,
296 struct consumer_output *consumer, uint64_t *lost);
00e2e675 297
6dc3064a 298/* Snapshot command. */
9a654598 299enum lttng_error_code consumer_snapshot_channel(struct consumer_socket *socket,
348a81dc 300 uint64_t key, const struct consumer_output *output, int metadata,
d2956687
JG
301 uid_t uid, gid_t gid, const char *channel_path, int wait,
302 uint64_t nb_packets_per_stream);
6dc3064a 303
92816cc3 304/* Rotation commands. */
5c408ad8
JD
305int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key,
306 uid_t uid, gid_t gid, struct consumer_output *output,
d2956687 307 bool is_metadata_channel);
09ede842
JG
308int consumer_init(struct consumer_socket *socket,
309 const lttng_uuid sessiond_uuid);
a1ae2ea5 310
d2956687
JG
311int consumer_create_trace_chunk(struct consumer_socket *socket,
312 uint64_t relayd_id, uint64_t session_id,
5da88b0f
MD
313 struct lttng_trace_chunk *chunk,
314 const char *domain_subdir);
d2956687
JG
315int consumer_close_trace_chunk(struct consumer_socket *socket,
316 uint64_t relayd_id, uint64_t session_id,
ecd1a12f
MD
317 struct lttng_trace_chunk *chunk,
318 char *closed_trace_chunk_path);
d2956687
JG
319int consumer_trace_chunk_exists(struct consumer_socket *socket,
320 uint64_t relayd_id, uint64_t session_id,
321 struct lttng_trace_chunk *chunk,
322 enum consumer_trace_chunk_exists_status *result);
04ed9e10 323int consumer_open_channel_packets(struct consumer_socket *socket, uint64_t key);
d2956687 324
3b967712 325char *setup_channel_trace_path(struct consumer_output *consumer,
5da88b0f 326 const char *session_path, size_t *consumer_path_offset);
3b967712 327
51a4828f
MD
328/* Clear command */
329int consumer_clear_channel(struct consumer_socket *socket, uint64_t key);
330
f1e16794 331#endif /* _CONSUMER_H */
This page took 0.07581 seconds and 4 git commands to generate.