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> | |
a4baae1b | 26 | #include <urcu/list.h> |
d3e2ba59 | 27 | |
0f907de1 | 28 | #include <common/hashtable/hashtable.h> |
50adc264 | 29 | #include <common/index/ctf-index.h> |
b8aa1682 | 30 | |
d3e2ba59 | 31 | #include "ctf-trace.h" |
2f8f53af | 32 | #include "session.h" |
d3e2ba59 | 33 | |
b8aa1682 JD |
34 | /* |
35 | * Queue used to enqueue relay requests | |
36 | */ | |
37 | struct relay_cmd_queue { | |
b8aa1682 | 38 | struct cds_wfq_queue queue; |
7717e361 | 39 | int32_t futex; |
b8aa1682 JD |
40 | }; |
41 | ||
42 | enum connection_type { | |
d5200de1 DG |
43 | RELAY_DATA = 1, |
44 | RELAY_CONTROL = 2, | |
45 | RELAY_VIEWER_COMMAND = 3, | |
46 | RELAY_VIEWER_NOTIFICATION = 4, | |
b8aa1682 JD |
47 | }; |
48 | ||
a4baae1b JD |
49 | /* |
50 | * When we receive a stream, it gets stored in a list (on a per connection | |
51 | * basis) until we have all the streams of the same channel and the metadata | |
52 | * associated with it, then it gets flagged with viewer_ready. | |
53 | */ | |
54 | struct relay_stream_recv_handle { | |
55 | uint64_t id; /* stream handle */ | |
56 | struct cds_list_head node; | |
57 | }; | |
58 | ||
b8aa1682 JD |
59 | /* |
60 | * Represents a stream in the relay | |
61 | */ | |
62 | struct relay_stream { | |
63 | uint64_t stream_handle; | |
173af62f | 64 | uint64_t prev_seq; /* previous data sequence number encountered */ |
7717e361 | 65 | struct lttng_ht_node_ulong stream_n; |
b8aa1682 | 66 | struct relay_session *session; |
9d1bbf21 | 67 | struct rcu_head rcu_node; |
7717e361 | 68 | int fd; |
1c20f0e2 | 69 | /* FD on which to write the index data. */ |
309167d2 | 70 | int index_fd; |
d3e2ba59 JD |
71 | /* FD on which to read the index data for the viewer. */ |
72 | int read_index_fd; | |
173af62f | 73 | |
0f907de1 JD |
74 | char *path_name; |
75 | char *channel_name; | |
76 | /* on-disk circular buffer of tracefiles */ | |
77 | uint64_t tracefile_size; | |
78 | uint64_t tracefile_size_current; | |
79 | uint64_t tracefile_count; | |
80 | uint64_t tracefile_count_current; | |
6b6b9a5a JD |
81 | /* To inform the viewer up to where it can go back in time. */ |
82 | uint64_t oldest_tracefile_id; | |
0f907de1 | 83 | |
d3e2ba59 | 84 | uint64_t total_index_received; |
d3e2ba59 | 85 | uint64_t last_net_seq_num; |
c07d8a78 DG |
86 | |
87 | /* | |
88 | * This node is added to the *control* connection hash table and the | |
89 | * pointer is copied in here so we can access it when deleting this object. | |
90 | * When deleting this, the ctf trace ht MUST NOT be destroyed. This happens | |
91 | * at connection deletion. | |
92 | */ | |
d3e2ba59 | 93 | struct lttng_ht_node_str ctf_trace_node; |
c07d8a78 | 94 | struct lttng_ht *ctf_traces_ht; |
d3e2ba59 JD |
95 | |
96 | /* | |
97 | * To protect from concurrent read/update between the | |
98 | * streaming-side and the viewer-side. | |
99 | * This lock must be held, we reading/updating the | |
100 | * ctf_trace pointer. | |
101 | */ | |
102 | pthread_mutex_t lock; | |
103 | ||
104 | struct ctf_trace *ctf_trace; | |
105 | /* | |
106 | * If the stream is inactive, this field is updated with the live beacon | |
107 | * timestamp end, when it is active, this field == -1ULL. | |
108 | */ | |
109 | uint64_t beacon_ts_end; | |
6b6b9a5a JD |
110 | /* |
111 | * To protect the update of the close_write_flag and the checks of | |
112 | * the tracefile_count_current. | |
113 | * It is taken before checking whenever we need to know if the | |
114 | * writer and reader are working in the same tracefile. | |
115 | */ | |
116 | pthread_mutex_t viewer_stream_rotation_lock; | |
d3e2ba59 | 117 | |
173af62f DG |
118 | /* Information telling us when to close the stream */ |
119 | unsigned int close_flag:1; | |
f7079f67 DG |
120 | /* Indicate if the stream was initialized for a data pending command. */ |
121 | unsigned int data_pending_check_done:1; | |
d3e2ba59 | 122 | unsigned int metadata_flag:1; |
6b6b9a5a JD |
123 | /* |
124 | * To detect when we start overwriting old data, it is used to | |
125 | * update the oldest_tracefile_id. | |
126 | */ | |
127 | unsigned int tracefile_overwrite:1; | |
a4baae1b JD |
128 | /* |
129 | * Can this stream be used by a viewer or are we waiting for additional | |
130 | * information. | |
131 | */ | |
132 | unsigned int viewer_ready:1; | |
d3e2ba59 JD |
133 | }; |
134 | ||
b8aa1682 JD |
135 | /* |
136 | * Internal structure to map a socket with the corresponding session. | |
137 | * A hashtable indexed on the socket FD is used for the lookups. | |
138 | */ | |
139 | struct relay_command { | |
140 | struct lttcomm_sock *sock; | |
7717e361 | 141 | struct relay_session *session; |
b8aa1682 JD |
142 | struct cds_wfq_node node; |
143 | struct lttng_ht_node_ulong sock_n; | |
9d1bbf21 | 144 | struct rcu_head rcu_node; |
b8aa1682 | 145 | enum connection_type type; |
0f907de1 JD |
146 | /* protocol version to use for this session */ |
147 | uint32_t major; | |
148 | uint32_t minor; | |
d3e2ba59 | 149 | struct lttng_ht *ctf_traces_ht; /* indexed by path name */ |
b92fdc2b | 150 | uint64_t session_id; |
a4baae1b JD |
151 | struct cds_list_head recv_head; |
152 | unsigned int version_check_done:1; | |
d3e2ba59 JD |
153 | }; |
154 | ||
155 | struct relay_local_data { | |
156 | struct lttng_ht *sessions_ht; | |
b8aa1682 JD |
157 | }; |
158 | ||
0f907de1 JD |
159 | extern char *opt_output_path; |
160 | ||
d3e2ba59 | 161 | extern struct lttng_ht *relay_streams_ht; |
92c6ca54 | 162 | extern struct lttng_ht *viewer_streams_ht; |
0a6518b0 | 163 | extern struct lttng_ht *indexes_ht; |
d3e2ba59 | 164 | |
65931c8b MD |
165 | extern const char *tracing_group_name; |
166 | ||
cd60b05a JG |
167 | extern const char * const config_section_name; |
168 | ||
0b242f62 MD |
169 | extern int thread_quit_pipe[2]; |
170 | ||
d3e2ba59 | 171 | struct relay_stream *relay_stream_find_by_id(uint64_t stream_id); |
3fd27398 | 172 | void lttng_relay_notify_ready(void); |
d3e2ba59 | 173 | |
7717e361 | 174 | #endif /* LTTNG_RELAYD_H */ |