2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
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.
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
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.
21 #include <semaphore.h>
23 #include <common/consumer.h>
24 #include <common/hashtable/hashtable.h>
25 #include <lttng/lttng.h>
29 enum consumer_dst_type
{
34 struct consumer_socket
{
38 * To use this socket (send/recv), this lock MUST be acquired.
40 pthread_mutex_t
*lock
;
41 struct lttng_ht_node_ulong node
;
44 struct consumer_data
{
45 enum lttng_consumer_type type
;
47 pthread_t thread
; /* Worker thread interacting with the consumer */
50 /* Mutex to control consumerd pid assignation */
51 pthread_mutex_t pid_mutex
;
57 /* consumer error and command Unix socket path */
58 char err_unix_sock_path
[PATH_MAX
];
59 char cmd_unix_sock_path
[PATH_MAX
];
61 /* Health check of the thread */
62 struct health_state health
;
64 /* communication lock */
73 * Indicate if URI type is set. Those flags should only be set when the
74 * created URI is done AND valid.
80 * The following two URIs MUST have the same destination address for
81 * network streaming to work. Network hop are not yet supported.
84 /* Control path for network streaming. */
85 struct lttng_uri control
;
87 /* Data path for network streaming. */
88 struct lttng_uri data
;
90 /* Flag if network sockets were sent to the consumer. */
91 unsigned int relayd_socks_sent
;
95 * Consumer output object describing where and how to send data.
97 struct consumer_output
{
98 /* If the consumer is enabled meaning that should be used */
100 enum consumer_dst_type type
;
103 * The net_seq_index is the index of the network stream on the consumer
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.
110 * Subdirectory path name used for both local and network consumer.
112 char subdir
[PATH_MAX
];
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
119 struct lttng_ht
*socks
;
122 char trace_path
[PATH_MAX
];
123 struct consumer_net net
;
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
);
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
);
145 int consumer_send_relayd_socket(int consumer_sock
,
146 struct lttcomm_sock
*sock
, struct consumer_output
*consumer
,
147 enum lttng_stream_type type
);
148 int consumer_send_destroy_relayd(struct consumer_socket
*sock
,
149 struct consumer_output
*consumer
);
150 int consumer_create_socket(struct consumer_data
*data
,
151 struct consumer_output
*output
);
153 void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
154 enum lttng_consumer_command cmd
,
158 enum lttng_event_output output
,
163 unsigned int metadata_flag
,
165 const char *pathname
);
166 void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
167 enum lttng_consumer_command cmd
,
169 uint64_t max_sb_size
,
173 #endif /* _CONSUMER_H */