Commit | Line | Data |
---|---|---|
b8aa1682 JD |
1 | /* |
2 | * Copyright (C) 2012 - Julien Desfossez <jdesfossez@efficios.com> | |
3 | * David Goulet <dgoulet@efficios.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License, version 2 only, | |
7 | * as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
7717e361 MD |
19 | #ifndef LTTNG_RELAYD_H |
20 | #define LTTNG_RELAYD_H | |
b8aa1682 JD |
21 | |
22 | #define _LGPL_SOURCE | |
d3e2ba59 | 23 | #include <limits.h> |
b8aa1682 JD |
24 | #include <urcu.h> |
25 | #include <urcu/wfqueue.h> | |
d3e2ba59 | 26 | |
0f907de1 | 27 | #include <common/hashtable/hashtable.h> |
1c20f0e2 | 28 | #include <common/index/lttng-index.h> |
b8aa1682 | 29 | |
d3e2ba59 JD |
30 | #include "ctf-trace.h" |
31 | ||
b8aa1682 JD |
32 | /* |
33 | * Queue used to enqueue relay requests | |
34 | */ | |
35 | struct relay_cmd_queue { | |
b8aa1682 | 36 | struct cds_wfq_queue queue; |
7717e361 | 37 | int32_t futex; |
b8aa1682 JD |
38 | }; |
39 | ||
40 | enum connection_type { | |
d5200de1 DG |
41 | RELAY_DATA = 1, |
42 | RELAY_CONTROL = 2, | |
43 | RELAY_VIEWER_COMMAND = 3, | |
44 | RELAY_VIEWER_NOTIFICATION = 4, | |
b8aa1682 JD |
45 | }; |
46 | ||
47 | /* | |
48 | * Represents a session for the relay point of view | |
49 | */ | |
50 | struct relay_session { | |
f7079f67 DG |
51 | /* |
52 | * This session id is used to identify a set of stream to a tracing session | |
53 | * but also make sure we have a unique session id associated with a session | |
54 | * daemon which can provide multiple data source. | |
55 | */ | |
b8aa1682 JD |
56 | uint64_t id; |
57 | struct lttcomm_sock *sock; | |
d3e2ba59 JD |
58 | char session_name[NAME_MAX]; |
59 | char hostname[HOST_NAME_MAX]; | |
60 | uint32_t live_timer; | |
61 | struct lttng_ht_node_ulong session_n; | |
62 | struct rcu_head rcu_node; | |
63 | uint32_t viewer_attached; | |
64 | uint32_t stream_count; | |
b8aa1682 JD |
65 | }; |
66 | ||
67 | /* | |
68 | * Represents a stream in the relay | |
69 | */ | |
70 | struct relay_stream { | |
71 | uint64_t stream_handle; | |
173af62f | 72 | uint64_t prev_seq; /* previous data sequence number encountered */ |
7717e361 | 73 | struct lttng_ht_node_ulong stream_n; |
b8aa1682 | 74 | struct relay_session *session; |
9d1bbf21 | 75 | struct rcu_head rcu_node; |
7717e361 | 76 | int fd; |
1c20f0e2 | 77 | /* FD on which to write the index data. */ |
309167d2 | 78 | int index_fd; |
d3e2ba59 JD |
79 | /* FD on which to read the index data for the viewer. */ |
80 | int read_index_fd; | |
173af62f | 81 | |
0f907de1 JD |
82 | char *path_name; |
83 | char *channel_name; | |
84 | /* on-disk circular buffer of tracefiles */ | |
85 | uint64_t tracefile_size; | |
86 | uint64_t tracefile_size_current; | |
87 | uint64_t tracefile_count; | |
88 | uint64_t tracefile_count_current; | |
89 | ||
d3e2ba59 JD |
90 | uint64_t total_index_received; |
91 | struct relay_viewer_stream *viewer_stream; | |
92 | uint64_t last_net_seq_num; | |
93 | struct lttng_ht_node_str ctf_trace_node; | |
94 | ||
95 | /* | |
96 | * To protect from concurrent read/update between the | |
97 | * streaming-side and the viewer-side. | |
98 | * This lock must be held, we reading/updating the | |
99 | * ctf_trace pointer. | |
100 | */ | |
101 | pthread_mutex_t lock; | |
102 | ||
103 | struct ctf_trace *ctf_trace; | |
104 | /* | |
105 | * If the stream is inactive, this field is updated with the live beacon | |
106 | * timestamp end, when it is active, this field == -1ULL. | |
107 | */ | |
108 | uint64_t beacon_ts_end; | |
109 | ||
173af62f DG |
110 | /* Information telling us when to close the stream */ |
111 | unsigned int close_flag:1; | |
f7079f67 DG |
112 | /* Indicate if the stream was initialized for a data pending command. */ |
113 | unsigned int data_pending_check_done:1; | |
d3e2ba59 JD |
114 | unsigned int metadata_flag:1; |
115 | }; | |
116 | ||
117 | /* | |
118 | * Shadow copy of the relay_stream structure for the viewer side. The only | |
119 | * fields updated by the writer (streaming side) after allocation are : | |
120 | * total_index_received and close_flag. Everything else is updated by the | |
121 | * reader (viewer side). | |
122 | */ | |
123 | struct relay_viewer_stream { | |
124 | uint64_t stream_handle; | |
125 | uint64_t session_id; | |
126 | int read_fd; | |
127 | int index_read_fd; | |
128 | char *path_name; | |
129 | char *channel_name; | |
130 | uint64_t last_sent_index; | |
131 | uint64_t total_index_received; | |
132 | uint64_t tracefile_size; | |
133 | uint64_t tracefile_size_current; | |
134 | uint64_t tracefile_count; | |
135 | uint64_t tracefile_count_current; | |
136 | struct lttng_ht_node_u64 stream_n; | |
137 | struct rcu_head rcu_node; | |
138 | struct ctf_trace *ctf_trace; | |
139 | /* Information telling us if the stream is a metadata stream. */ | |
140 | unsigned int metadata_flag:1; | |
b8aa1682 JD |
141 | }; |
142 | ||
143 | /* | |
144 | * Internal structure to map a socket with the corresponding session. | |
145 | * A hashtable indexed on the socket FD is used for the lookups. | |
146 | */ | |
147 | struct relay_command { | |
148 | struct lttcomm_sock *sock; | |
7717e361 | 149 | struct relay_session *session; |
b8aa1682 JD |
150 | struct cds_wfq_node node; |
151 | struct lttng_ht_node_ulong sock_n; | |
9d1bbf21 | 152 | struct rcu_head rcu_node; |
b8aa1682 | 153 | enum connection_type type; |
c5b6f4f0 | 154 | unsigned int version_check_done:1; |
0f907de1 JD |
155 | /* protocol version to use for this session */ |
156 | uint32_t major; | |
157 | uint32_t minor; | |
d3e2ba59 JD |
158 | struct lttng_ht *ctf_traces_ht; /* indexed by path name */ |
159 | }; | |
160 | ||
161 | struct relay_local_data { | |
162 | struct lttng_ht *sessions_ht; | |
b8aa1682 JD |
163 | }; |
164 | ||
0f907de1 JD |
165 | extern char *opt_output_path; |
166 | ||
d3e2ba59 | 167 | extern struct lttng_ht *relay_streams_ht; |
92c6ca54 | 168 | extern struct lttng_ht *viewer_streams_ht; |
0a6518b0 | 169 | extern struct lttng_ht *indexes_ht; |
d3e2ba59 JD |
170 | |
171 | struct relay_stream *relay_stream_find_by_id(uint64_t stream_id); | |
172 | ||
7717e361 | 173 | #endif /* LTTNG_RELAYD_H */ |