Fix: put ctf trace ht ref. inside stream
[lttng-tools.git] / src / bin / lttng-relayd / lttng-relayd.h
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
19 #ifndef LTTNG_RELAYD_H
20 #define LTTNG_RELAYD_H
21
22 #define _LGPL_SOURCE
23 #include <limits.h>
24 #include <urcu.h>
25 #include <urcu/wfqueue.h>
26
27 #include <common/hashtable/hashtable.h>
28 #include <common/index/lttng-index.h>
29
30 #include "ctf-trace.h"
31
32 /*
33 * Queue used to enqueue relay requests
34 */
35 struct relay_cmd_queue {
36 struct cds_wfq_queue queue;
37 int32_t futex;
38 };
39
40 enum connection_type {
41 RELAY_DATA = 1,
42 RELAY_CONTROL = 2,
43 RELAY_VIEWER_COMMAND = 3,
44 RELAY_VIEWER_NOTIFICATION = 4,
45 };
46
47 /*
48 * Represents a session for the relay point of view
49 */
50 struct relay_session {
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 */
56 uint64_t id;
57 struct lttcomm_sock *sock;
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;
65 /* Tell if this session is for a snapshot or not. */
66 unsigned int snapshot:1;
67
68 /*
69 * Indicate version protocol for this session. This is especially useful
70 * for the data thread that has no idea which version it operates on since
71 * linking control/data sockets is non trivial.
72 */
73 uint64_t minor;
74 uint64_t major;
75 };
76
77 /*
78 * Represents a stream in the relay
79 */
80 struct relay_stream {
81 uint64_t stream_handle;
82 uint64_t prev_seq; /* previous data sequence number encountered */
83 struct lttng_ht_node_ulong stream_n;
84 struct relay_session *session;
85 struct rcu_head rcu_node;
86 int fd;
87 /* FD on which to write the index data. */
88 int index_fd;
89 /* FD on which to read the index data for the viewer. */
90 int read_index_fd;
91
92 char *path_name;
93 char *channel_name;
94 /* on-disk circular buffer of tracefiles */
95 uint64_t tracefile_size;
96 uint64_t tracefile_size_current;
97 uint64_t tracefile_count;
98 uint64_t tracefile_count_current;
99
100 uint64_t total_index_received;
101 struct relay_viewer_stream *viewer_stream;
102 uint64_t last_net_seq_num;
103
104 /*
105 * This node is added to the *control* connection hash table and the
106 * pointer is copied in here so we can access it when deleting this object.
107 * When deleting this, the ctf trace ht MUST NOT be destroyed. This happens
108 * at connection deletion.
109 */
110 struct lttng_ht_node_str ctf_trace_node;
111 struct lttng_ht *ctf_traces_ht;
112
113 /*
114 * To protect from concurrent read/update between the
115 * streaming-side and the viewer-side.
116 * This lock must be held, we reading/updating the
117 * ctf_trace pointer.
118 */
119 pthread_mutex_t lock;
120
121 struct ctf_trace *ctf_trace;
122 /*
123 * If the stream is inactive, this field is updated with the live beacon
124 * timestamp end, when it is active, this field == -1ULL.
125 */
126 uint64_t beacon_ts_end;
127
128 /* Information telling us when to close the stream */
129 unsigned int close_flag:1;
130 /* Indicate if the stream was initialized for a data pending command. */
131 unsigned int data_pending_check_done:1;
132 unsigned int metadata_flag:1;
133 };
134
135 /*
136 * Shadow copy of the relay_stream structure for the viewer side. The only
137 * fields updated by the writer (streaming side) after allocation are :
138 * total_index_received and close_flag. Everything else is updated by the
139 * reader (viewer side).
140 */
141 struct relay_viewer_stream {
142 uint64_t stream_handle;
143 uint64_t session_id;
144 int read_fd;
145 int index_read_fd;
146 char *path_name;
147 char *channel_name;
148 uint64_t last_sent_index;
149 uint64_t total_index_received;
150 uint64_t tracefile_size;
151 uint64_t tracefile_size_current;
152 uint64_t tracefile_count;
153 uint64_t tracefile_count_current;
154 struct lttng_ht_node_u64 stream_n;
155 struct rcu_head rcu_node;
156 struct ctf_trace *ctf_trace;
157 /* Information telling us if the stream is a metadata stream. */
158 unsigned int metadata_flag:1;
159 };
160
161 /*
162 * Internal structure to map a socket with the corresponding session.
163 * A hashtable indexed on the socket FD is used for the lookups.
164 */
165 struct relay_command {
166 struct lttcomm_sock *sock;
167 struct relay_session *session;
168 struct cds_wfq_node node;
169 struct lttng_ht_node_ulong sock_n;
170 struct rcu_head rcu_node;
171 enum connection_type type;
172 unsigned int version_check_done:1;
173 /* protocol version to use for this session */
174 uint32_t major;
175 uint32_t minor;
176 struct lttng_ht *ctf_traces_ht; /* indexed by path name */
177 uint64_t session_id;
178 };
179
180 struct relay_local_data {
181 struct lttng_ht *sessions_ht;
182 };
183
184 extern char *opt_output_path;
185
186 extern struct lttng_ht *relay_streams_ht;
187 extern struct lttng_ht *viewer_streams_ht;
188 extern struct lttng_ht *indexes_ht;
189
190 extern const char *tracing_group_name;
191
192 struct relay_stream *relay_stream_find_by_id(uint64_t stream_id);
193
194 #endif /* LTTNG_RELAYD_H */
This page took 0.03403 seconds and 5 git commands to generate.