Commit | Line | Data |
---|---|---|
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 |
29 | enum consumer_dst_type { |
30 | CONSUMER_DST_LOCAL, | |
31 | CONSUMER_DST_NET, | |
32 | }; | |
f1e16794 | 33 | |
173af62f DG |
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 | struct lttng_ht_node_ulong node; | |
42 | }; | |
43 | ||
f1e16794 DG |
44 | struct consumer_data { |
45 | enum lttng_consumer_type type; | |
46 | ||
47 | pthread_t thread; /* Worker thread interacting with the consumer */ | |
48 | sem_t sem; | |
49 | ||
50 | /* Mutex to control consumerd pid assignation */ | |
51 | pthread_mutex_t pid_mutex; | |
52 | pid_t pid; | |
53 | ||
54 | int err_sock; | |
55 | int cmd_sock; | |
56 | ||
57 | /* consumer error and command Unix socket path */ | |
58 | char err_unix_sock_path[PATH_MAX]; | |
59 | char cmd_unix_sock_path[PATH_MAX]; | |
44a5e5eb DG |
60 | |
61 | /* Health check of the thread */ | |
62 | struct health_state health; | |
173af62f DG |
63 | |
64 | /* communication lock */ | |
65 | pthread_mutex_t lock; | |
f1e16794 DG |
66 | }; |
67 | ||
00e2e675 DG |
68 | /* |
69 | * Network URIs | |
70 | */ | |
71 | struct consumer_net { | |
72 | /* | |
73 | * Indicate if URI type is set. Those flags should only be set when the | |
74 | * created URI is done AND valid. | |
75 | */ | |
76 | int control_isset; | |
77 | int data_isset; | |
78 | ||
79 | /* | |
80 | * The following two URIs MUST have the same destination address for | |
81 | * network streaming to work. Network hop are not yet supported. | |
82 | */ | |
83 | ||
84 | /* Control path for network streaming. */ | |
85 | struct lttng_uri control; | |
86 | ||
87 | /* Data path for network streaming. */ | |
88 | struct lttng_uri data; | |
3f8e211f DG |
89 | |
90 | /* Flag if network sockets were sent to the consumer. */ | |
91 | unsigned int relayd_socks_sent; | |
00e2e675 DG |
92 | }; |
93 | ||
94 | /* | |
95 | * Consumer output object describing where and how to send data. | |
96 | */ | |
97 | struct consumer_output { | |
00e2e675 DG |
98 | /* If the consumer is enabled meaning that should be used */ |
99 | unsigned int enabled; | |
100 | enum consumer_dst_type type; | |
173af62f | 101 | |
00e2e675 DG |
102 | /* |
103 | * The net_seq_index is the index of the network stream on the consumer | |
3f8e211f DG |
104 | * side. It tells the consumer which streams goes to which relayd with this |
105 | * index. The relayd sockets are index with it on the consumer side. | |
00e2e675 DG |
106 | */ |
107 | int net_seq_index; | |
173af62f | 108 | |
00e2e675 DG |
109 | /* |
110 | * Subdirectory path name used for both local and network consumer. | |
111 | */ | |
112 | char subdir[PATH_MAX]; | |
173af62f DG |
113 | |
114 | /* | |
115 | * Hashtable of consumer_socket index by the file descriptor value. For | |
116 | * multiarch consumer support, we can have more than one consumer (ex: 32 | |
117 | * and 64 bit). | |
118 | */ | |
119 | struct lttng_ht *socks; | |
120 | ||
00e2e675 DG |
121 | union { |
122 | char trace_path[PATH_MAX]; | |
123 | struct consumer_net net; | |
124 | } dst; | |
125 | }; | |
126 | ||
173af62f DG |
127 | struct consumer_socket *consumer_find_socket(int key, |
128 | struct consumer_output *consumer); | |
129 | struct consumer_socket *consumer_allocate_socket(int fd); | |
130 | void consumer_add_socket(struct consumer_socket *sock, | |
131 | struct consumer_output *consumer); | |
132 | void consumer_del_socket(struct consumer_socket *sock, | |
133 | struct consumer_output *consumer); | |
134 | void consumer_destroy_socket(struct consumer_socket *sock); | |
135 | ||
00e2e675 DG |
136 | struct consumer_output *consumer_create_output(enum consumer_dst_type type); |
137 | struct consumer_output *consumer_copy_output(struct consumer_output *obj); | |
138 | void consumer_destroy_output(struct consumer_output *obj); | |
139 | int consumer_set_network_uri(struct consumer_output *obj, | |
140 | struct lttng_uri *uri); | |
141 | int consumer_send_fds(int sock, int *fds, size_t nb_fd); | |
142 | int consumer_send_stream(int sock, struct consumer_output *dst, | |
143 | struct lttcomm_consumer_msg *msg, int *fds, size_t nb_fd); | |
144 | int consumer_send_channel(int sock, struct lttcomm_consumer_msg *msg); | |
37278a1e DG |
145 | int consumer_send_relayd_socket(int consumer_sock, |
146 | struct lttcomm_sock *sock, struct consumer_output *consumer, | |
147 | enum lttng_stream_type type); | |
173af62f DG |
148 | int consumer_send_destroy_relayd(struct consumer_socket *sock, |
149 | struct consumer_output *consumer); | |
a4b92340 DG |
150 | int consumer_create_socket(struct consumer_data *data, |
151 | struct consumer_output *output); | |
37278a1e | 152 | |
00e2e675 DG |
153 | void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg *msg, |
154 | enum lttng_consumer_command cmd, | |
155 | int channel_key, | |
156 | int stream_key, | |
157 | uint32_t state, | |
158 | enum lttng_event_output output, | |
159 | uint64_t mmap_len, | |
160 | uid_t uid, | |
161 | gid_t gid, | |
162 | int net_index, | |
163 | unsigned int metadata_flag, | |
164 | const char *name, | |
165 | const char *pathname); | |
166 | void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg, | |
167 | enum lttng_consumer_command cmd, | |
168 | int channel_key, | |
169 | uint64_t max_sb_size, | |
170 | uint64_t mmap_len, | |
171 | const char *name); | |
172 | ||
f1e16794 | 173 | #endif /* _CONSUMER_H */ |