Extend API and remove lttng_uri from lttng.h
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.h
CommitLineData
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
29enum consumer_dst_type {
30 CONSUMER_DST_LOCAL,
31 CONSUMER_DST_NET,
32};
f1e16794 33
173af62f
DG
34struct 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
44struct 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 */
71struct 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 */
94struct consumer_output {
00e2e675
DG
95 /* If the consumer is enabled meaning that should be used */
96 unsigned int enabled;
97 enum consumer_dst_type type;
173af62f 98
00e2e675
DG
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;
173af62f 105
00e2e675
DG
106 /*
107 * Subdirectory path name used for both local and network consumer.
108 */
109 char subdir[PATH_MAX];
173af62f
DG
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
00e2e675
DG
118 union {
119 char trace_path[PATH_MAX];
120 struct consumer_net net;
121 } dst;
122};
123
173af62f
DG
124struct consumer_socket *consumer_find_socket(int key,
125 struct consumer_output *consumer);
126struct consumer_socket *consumer_allocate_socket(int fd);
127void consumer_add_socket(struct consumer_socket *sock,
128 struct consumer_output *consumer);
129void consumer_del_socket(struct consumer_socket *sock,
130 struct consumer_output *consumer);
131void consumer_destroy_socket(struct consumer_socket *sock);
132
00e2e675
DG
133struct consumer_output *consumer_create_output(enum consumer_dst_type type);
134struct consumer_output *consumer_copy_output(struct consumer_output *obj);
135void consumer_destroy_output(struct consumer_output *obj);
136int consumer_set_network_uri(struct consumer_output *obj,
137 struct lttng_uri *uri);
138int consumer_send_fds(int sock, int *fds, size_t nb_fd);
139int consumer_send_stream(int sock, struct consumer_output *dst,
140 struct lttcomm_consumer_msg *msg, int *fds, size_t nb_fd);
141int consumer_send_channel(int sock, struct lttcomm_consumer_msg *msg);
37278a1e
DG
142int consumer_send_relayd_socket(int consumer_sock,
143 struct lttcomm_sock *sock, struct consumer_output *consumer,
144 enum lttng_stream_type type);
173af62f
DG
145int consumer_send_destroy_relayd(struct consumer_socket *sock,
146 struct consumer_output *consumer);
a4b92340
DG
147int consumer_create_socket(struct consumer_data *data,
148 struct consumer_output *output);
37278a1e 149
00e2e675
DG
150void 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);
163void 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
f1e16794 170#endif /* _CONSUMER_H */
This page took 0.029436 seconds and 4 git commands to generate.