Add lttng-error.h containing every API err. code
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.h
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>
24 #include <common/hashtable/hashtable.h>
25 #include <lttng/lttng.h>
26
27 #include "health.h"
28
29 enum consumer_dst_type {
30 CONSUMER_DST_LOCAL,
31 CONSUMER_DST_NET,
32 };
33
34 struct 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;
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
50 struct lttng_ht_node_ulong node;
51 };
52
53 struct 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];
69
70 /* Health check of the thread */
71 struct health_state health;
72
73 /* communication lock */
74 pthread_mutex_t lock;
75 };
76
77 /*
78 * Network URIs
79 */
80 struct 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;
98
99 /* Flag if network sockets were sent to the consumer. */
100 unsigned int relayd_socks_sent;
101 };
102
103 /*
104 * Consumer output object describing where and how to send data.
105 */
106 struct consumer_output {
107 /* If the consumer is enabled meaning that should be used */
108 unsigned int enabled;
109 enum consumer_dst_type type;
110
111 /*
112 * The net_seq_index is the index of the network stream on the consumer
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.
115 */
116 int net_seq_index;
117
118 /*
119 * Subdirectory path name used for both local and network consumer.
120 */
121 char subdir[PATH_MAX];
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
130 union {
131 char trace_path[PATH_MAX];
132 struct consumer_net net;
133 } dst;
134 };
135
136 struct consumer_socket *consumer_find_socket(int key,
137 struct consumer_output *consumer);
138 struct consumer_socket *consumer_allocate_socket(int fd);
139 void consumer_add_socket(struct consumer_socket *sock,
140 struct consumer_output *consumer);
141 void consumer_del_socket(struct consumer_socket *sock,
142 struct consumer_output *consumer);
143 void consumer_destroy_socket(struct consumer_socket *sock);
144
145 struct consumer_output *consumer_create_output(enum consumer_dst_type type);
146 struct consumer_output *consumer_copy_output(struct consumer_output *obj);
147 void consumer_destroy_output(struct consumer_output *obj);
148 int consumer_set_network_uri(struct consumer_output *obj,
149 struct lttng_uri *uri);
150 int consumer_send_fds(int sock, int *fds, size_t nb_fd);
151 int consumer_send_stream(int sock, struct consumer_output *dst,
152 struct lttcomm_consumer_msg *msg, int *fds, size_t nb_fd);
153 int consumer_send_channel(int sock, struct lttcomm_consumer_msg *msg);
154 int consumer_send_relayd_socket(int consumer_sock,
155 struct lttcomm_sock *sock, struct consumer_output *consumer,
156 enum lttng_stream_type type);
157 int consumer_send_destroy_relayd(struct consumer_socket *sock,
158 struct consumer_output *consumer);
159 void consumer_output_send_destroy_relayd(struct consumer_output *consumer);
160 int consumer_create_socket(struct consumer_data *data,
161 struct consumer_output *output);
162 int consumer_set_subdir(struct consumer_output *consumer,
163 const char *session_name);
164
165 void 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);
178 void 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
185 #endif /* _CONSUMER_H */
This page took 0.032482 seconds and 4 git commands to generate.