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
;
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.
48 unsigned int registered
;
50 struct lttng_ht_node_ulong node
;
53 struct consumer_data
{
54 enum lttng_consumer_type type
;
56 pthread_t thread
; /* Worker thread interacting with the consumer */
59 /* Mutex to control consumerd pid assignation */
60 pthread_mutex_t pid_mutex
;
66 /* consumer error and command Unix socket path */
67 char err_unix_sock_path
[PATH_MAX
];
68 char cmd_unix_sock_path
[PATH_MAX
];
70 /* Health check of the thread */
71 struct health_state health
;
73 /* communication lock */
82 * Indicate if URI type is set. Those flags should only be set when the
83 * created URI is done AND valid.
89 * The following two URIs MUST have the same destination address for
90 * network streaming to work. Network hop are not yet supported.
93 /* Control path for network streaming. */
94 struct lttng_uri control
;
96 /* Data path for network streaming. */
97 struct lttng_uri data
;
99 /* Flag if network sockets were sent to the consumer. */
100 unsigned int relayd_socks_sent
;
104 * Consumer output object describing where and how to send data.
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
;
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.
119 * Subdirectory path name used for both local and network consumer.
121 char subdir
[PATH_MAX
];
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
128 struct lttng_ht
*socks
;
131 char trace_path
[PATH_MAX
];
132 struct consumer_net net
;
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
);
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
);
165 void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
166 enum lttng_consumer_command cmd
,
170 enum lttng_event_output output
,
175 unsigned int metadata_flag
,
177 const char *pathname
);
178 void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
179 enum lttng_consumer_command cmd
,
181 uint64_t max_sb_size
,
185 #endif /* _CONSUMER_H */