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
;
92 * Consumer output object describing where and how to send data.
94 struct consumer_output
{
95 /* If the consumer is enabled meaning that should be used */
97 enum consumer_dst_type type
;
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.
107 * Subdirectory path name used for both local and network consumer.
109 char subdir
[PATH_MAX
];
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
116 struct lttng_ht
*socks
;
119 char trace_path
[PATH_MAX
];
120 struct consumer_net net
;
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
);
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
);
148 void consumer_init_stream_comm_msg(struct lttcomm_consumer_msg
*msg
,
149 enum lttng_consumer_command cmd
,
153 enum lttng_event_output output
,
158 unsigned int metadata_flag
,
160 const char *pathname
);
161 void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg
*msg
,
162 enum lttng_consumer_command cmd
,
164 uint64_t max_sb_size
,
168 #endif /* _CONSUMER_H */