Extend API and remove lttng_uri from lttng.h
[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 struct lttng_ht_node_ulong node;
42 };
43
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];
60
61 /* Health check of the thread */
62 struct health_state health;
63
64 /* communication lock */
65 pthread_mutex_t lock;
66 };
67
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;
89 };
90
91 /*
92 * Consumer output object describing where and how to send data.
93 */
94 struct consumer_output {
95 /* If the consumer is enabled meaning that should be used */
96 unsigned int enabled;
97 enum consumer_dst_type type;
98
99 /*
100 * The net_seq_index is the index of the network stream on the consumer
101 * side. It's basically the relayd socket file descriptor value so the
102 * consumer can identify which streams goes with which socket.
103 */
104 int net_seq_index;
105
106 /*
107 * Subdirectory path name used for both local and network consumer.
108 */
109 char subdir[PATH_MAX];
110
111 /*
112 * Hashtable of consumer_socket index by the file descriptor value. For
113 * multiarch consumer support, we can have more than one consumer (ex: 32
114 * and 64 bit).
115 */
116 struct lttng_ht *socks;
117
118 union {
119 char trace_path[PATH_MAX];
120 struct consumer_net net;
121 } dst;
122 };
123
124 struct consumer_socket *consumer_find_socket(int key,
125 struct consumer_output *consumer);
126 struct consumer_socket *consumer_allocate_socket(int fd);
127 void consumer_add_socket(struct consumer_socket *sock,
128 struct consumer_output *consumer);
129 void consumer_del_socket(struct consumer_socket *sock,
130 struct consumer_output *consumer);
131 void consumer_destroy_socket(struct consumer_socket *sock);
132
133 struct consumer_output *consumer_create_output(enum consumer_dst_type type);
134 struct consumer_output *consumer_copy_output(struct consumer_output *obj);
135 void consumer_destroy_output(struct consumer_output *obj);
136 int consumer_set_network_uri(struct consumer_output *obj,
137 struct lttng_uri *uri);
138 int consumer_send_fds(int sock, int *fds, size_t nb_fd);
139 int consumer_send_stream(int sock, struct consumer_output *dst,
140 struct lttcomm_consumer_msg *msg, int *fds, size_t nb_fd);
141 int consumer_send_channel(int sock, struct lttcomm_consumer_msg *msg);
142 int consumer_send_relayd_socket(int consumer_sock,
143 struct lttcomm_sock *sock, struct consumer_output *consumer,
144 enum lttng_stream_type type);
145 int consumer_send_destroy_relayd(struct consumer_socket *sock,
146 struct consumer_output *consumer);
147 int consumer_create_socket(struct consumer_data *data,
148 struct consumer_output *output);
149
150 void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg *msg,
151 enum lttng_consumer_command cmd,
152 int channel_key,
153 int stream_key,
154 uint32_t state,
155 enum lttng_event_output output,
156 uint64_t mmap_len,
157 uid_t uid,
158 gid_t gid,
159 int net_index,
160 unsigned int metadata_flag,
161 const char *name,
162 const char *pathname);
163 void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg,
164 enum lttng_consumer_command cmd,
165 int channel_key,
166 uint64_t max_sb_size,
167 uint64_t mmap_len,
168 const char *name);
169
170 #endif /* _CONSUMER_H */
This page took 0.034708 seconds and 5 git commands to generate.