Add lttng-error.h containing every API err. code
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.h
CommitLineData
f1e16794
DG
1/*
2 * Copyright (C) 2012 - 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 _CONSUMER_H
19#define _CONSUMER_H
20
21#include <semaphore.h>
22
23#include <common/consumer.h>
173af62f 24#include <common/hashtable/hashtable.h>
00e2e675
DG
25#include <lttng/lttng.h>
26
44a5e5eb
DG
27#include "health.h"
28
00e2e675
DG
29enum consumer_dst_type {
30 CONSUMER_DST_LOCAL,
31 CONSUMER_DST_NET,
32};
f1e16794 33
173af62f
DG
34struct consumer_socket {
35 /* File descriptor */
36 int fd;
37 /*
38 * To use this socket (send/recv), this lock MUST be acquired.
39 */
40 pthread_mutex_t *lock;
2f77fc4b
DG
41
42 /*
43 * Indicates if the socket was registered by a third part
44 * (REGISTER_CONSUMER) or is the spawn consumer of the session daemon.
45 * During the destroy phase of a consumer output, we close the socket if
46 * this flag is set to 1 since we don't need the fd anymore.
47 */
48 unsigned int registered;
49
173af62f
DG
50 struct lttng_ht_node_ulong node;
51};
52
f1e16794
DG
53struct consumer_data {
54 enum lttng_consumer_type type;
55
56 pthread_t thread; /* Worker thread interacting with the consumer */
57 sem_t sem;
58
59 /* Mutex to control consumerd pid assignation */
60 pthread_mutex_t pid_mutex;
61 pid_t pid;
62
63 int err_sock;
64 int cmd_sock;
65
66 /* consumer error and command Unix socket path */
67 char err_unix_sock_path[PATH_MAX];
68 char cmd_unix_sock_path[PATH_MAX];
44a5e5eb
DG
69
70 /* Health check of the thread */
71 struct health_state health;
173af62f
DG
72
73 /* communication lock */
74 pthread_mutex_t lock;
f1e16794
DG
75};
76
00e2e675
DG
77/*
78 * Network URIs
79 */
80struct consumer_net {
81 /*
82 * Indicate if URI type is set. Those flags should only be set when the
83 * created URI is done AND valid.
84 */
85 int control_isset;
86 int data_isset;
87
88 /*
89 * The following two URIs MUST have the same destination address for
90 * network streaming to work. Network hop are not yet supported.
91 */
92
93 /* Control path for network streaming. */
94 struct lttng_uri control;
95
96 /* Data path for network streaming. */
97 struct lttng_uri data;
3f8e211f
DG
98
99 /* Flag if network sockets were sent to the consumer. */
100 unsigned int relayd_socks_sent;
00e2e675
DG
101};
102
103/*
104 * Consumer output object describing where and how to send data.
105 */
106struct consumer_output {
00e2e675
DG
107 /* If the consumer is enabled meaning that should be used */
108 unsigned int enabled;
109 enum consumer_dst_type type;
173af62f 110
00e2e675
DG
111 /*
112 * The net_seq_index is the index of the network stream on the consumer
3f8e211f
DG
113 * side. It tells the consumer which streams goes to which relayd with this
114 * index. The relayd sockets are index with it on the consumer side.
00e2e675
DG
115 */
116 int net_seq_index;
173af62f 117
00e2e675
DG
118 /*
119 * Subdirectory path name used for both local and network consumer.
120 */
121 char subdir[PATH_MAX];
173af62f
DG
122
123 /*
124 * Hashtable of consumer_socket index by the file descriptor value. For
125 * multiarch consumer support, we can have more than one consumer (ex: 32
126 * and 64 bit).
127 */
128 struct lttng_ht *socks;
129
00e2e675
DG
130 union {
131 char trace_path[PATH_MAX];
132 struct consumer_net net;
133 } dst;
134};
135
173af62f
DG
136struct consumer_socket *consumer_find_socket(int key,
137 struct consumer_output *consumer);
138struct consumer_socket *consumer_allocate_socket(int fd);
139void consumer_add_socket(struct consumer_socket *sock,
140 struct consumer_output *consumer);
141void consumer_del_socket(struct consumer_socket *sock,
142 struct consumer_output *consumer);
143void consumer_destroy_socket(struct consumer_socket *sock);
144
00e2e675
DG
145struct consumer_output *consumer_create_output(enum consumer_dst_type type);
146struct consumer_output *consumer_copy_output(struct consumer_output *obj);
147void consumer_destroy_output(struct consumer_output *obj);
148int consumer_set_network_uri(struct consumer_output *obj,
149 struct lttng_uri *uri);
150int consumer_send_fds(int sock, int *fds, size_t nb_fd);
151int consumer_send_stream(int sock, struct consumer_output *dst,
152 struct lttcomm_consumer_msg *msg, int *fds, size_t nb_fd);
153int consumer_send_channel(int sock, struct lttcomm_consumer_msg *msg);
37278a1e
DG
154int consumer_send_relayd_socket(int consumer_sock,
155 struct lttcomm_sock *sock, struct consumer_output *consumer,
156 enum lttng_stream_type type);
173af62f
DG
157int consumer_send_destroy_relayd(struct consumer_socket *sock,
158 struct consumer_output *consumer);
2f77fc4b 159void consumer_output_send_destroy_relayd(struct consumer_output *consumer);
a4b92340
DG
160int consumer_create_socket(struct consumer_data *data,
161 struct consumer_output *output);
2f77fc4b
DG
162int consumer_set_subdir(struct consumer_output *consumer,
163 const char *session_name);
37278a1e 164
00e2e675
DG
165void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg *msg,
166 enum lttng_consumer_command cmd,
167 int channel_key,
168 int stream_key,
169 uint32_t state,
170 enum lttng_event_output output,
171 uint64_t mmap_len,
172 uid_t uid,
173 gid_t gid,
174 int net_index,
175 unsigned int metadata_flag,
176 const char *name,
177 const char *pathname);
178void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg,
179 enum lttng_consumer_command cmd,
180 int channel_key,
181 uint64_t max_sb_size,
182 uint64_t mmap_len,
183 const char *name);
184
f1e16794 185#endif /* _CONSUMER_H */
This page took 0.029645 seconds and 4 git commands to generate.