Commit | Line | Data |
---|---|---|
7591bab1 MD |
1 | #ifndef _STREAM_H |
2 | #define _STREAM_H | |
3 | ||
2a174661 | 4 | /* |
ab5be9fa MJ |
5 | * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com> |
6 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> | |
7 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
2a174661 | 8 | * |
ab5be9fa | 9 | * SPDX-License-Identifier: GPL-2.0-only |
2a174661 | 10 | * |
2a174661 DG |
11 | */ |
12 | ||
28f23191 JG |
13 | #include "session.hpp" |
14 | #include "tracefile-array.hpp" | |
2a174661 | 15 | |
28f23191 | 16 | #include <common/buffer-view.hpp> |
c9e313bc | 17 | #include <common/hashtable/hashtable.hpp> |
c9e313bc | 18 | #include <common/optional.hpp> |
28f23191 | 19 | #include <common/trace-chunk.hpp> |
2a174661 | 20 | |
28f23191 JG |
21 | #include <inttypes.h> |
22 | #include <limits.h> | |
23 | #include <pthread.h> | |
24 | #include <urcu/list.h> | |
2a174661 | 25 | |
c35f9726 JG |
26 | struct lttcomm_relayd_index; |
27 | ||
28 | struct relay_stream_rotation { | |
29 | /* | |
30 | * Indicates if the stream's data and index have been rotated. A | |
31 | * rotation is considered completed when both rotations have occurred. | |
32 | */ | |
33 | bool data_rotated; | |
34 | bool index_rotated; | |
35 | /* | |
0f83d1cc MD |
36 | * Packet sequence number of the first packet of the new trace chunk to |
37 | * which the stream is rotating. | |
c35f9726 | 38 | */ |
0f83d1cc MD |
39 | uint64_t packet_seq_num; |
40 | /* | |
41 | * Monotonically increasing previous network sequence number of first | |
42 | * data packet of the new trace chunk to which the stream is rotating. | |
43 | */ | |
44 | uint64_t prev_data_net_seq; | |
c35f9726 JG |
45 | struct lttng_trace_chunk *next_trace_chunk; |
46 | }; | |
47 | ||
2a174661 DG |
48 | /* |
49 | * Represents a stream in the relay | |
50 | */ | |
51 | struct relay_stream { | |
52 | uint64_t stream_handle; | |
7591bab1 | 53 | |
7591bab1 MD |
54 | struct urcu_ref ref; |
55 | /* Back reference to trace. Protected by refcount on trace object. */ | |
56 | struct ctf_trace *trace; | |
2a174661 | 57 | |
7591bab1 | 58 | /* |
c56468d0 | 59 | * To protect from concurrent read/update.The stream lock nests |
7591bab1 MD |
60 | * inside the ctf_trace lock. |
61 | */ | |
62 | pthread_mutex_t lock; | |
a8f9f353 JG |
63 | /* previous data sequence number written to disk. */ |
64 | uint64_t prev_data_seq; | |
7a45c7e6 JG |
65 | /* previous index sequence number written to disk. */ |
66 | uint64_t prev_index_seq; | |
a8f9f353 JG |
67 | /* seq num to encounter before closing. */ |
68 | uint64_t last_net_seq_num; | |
7591bab1 | 69 | |
8bb66c3c | 70 | struct fs_handle *file; |
f8f3885c MD |
71 | /* index file on which to write the index data. */ |
72 | struct lttng_index_file *index_file; | |
2a174661 DG |
73 | |
74 | char *path_name; | |
75 | char *channel_name; | |
7591bab1 MD |
76 | |
77 | /* On-disk circular buffer of tracefiles. */ | |
2a174661 DG |
78 | uint64_t tracefile_size; |
79 | uint64_t tracefile_size_current; | |
c35f9726 | 80 | /* Max number of trace files for this stream. */ |
2a174661 | 81 | uint64_t tracefile_count; |
c35f9726 JG |
82 | /* |
83 | * Index of the currently active file for this stream's on-disk | |
84 | * ring buffer. | |
85 | */ | |
86 | uint64_t tracefile_current_index; | |
87 | /* | |
88 | * Indicates that the on-disk buffer has wrapped around. Stream | |
89 | * files shall be unlinked before being opened after this has occurred. | |
90 | */ | |
91 | bool tracefile_wrapped_around; | |
7591bab1 | 92 | |
d3ecc550 JD |
93 | /* |
94 | * Position in the tracefile where we have the full index also on disk. | |
95 | */ | |
96 | uint64_t pos_after_last_complete_data_index; | |
97 | ||
a44ca2ca MD |
98 | /* |
99 | * Counts the number of received indexes. The "tag" associated | |
100 | * with an index is taken before incrementing this seqcount. | |
101 | * Therefore, the sequence tag associated with the last index | |
102 | * received is always index_received_seqcount - 1. | |
103 | */ | |
104 | uint64_t index_received_seqcount; | |
2a174661 | 105 | |
0f83d1cc MD |
106 | /* |
107 | * Packet sequence number of the last received packet index. | |
108 | * Only populated when interacting with CTF_INDEX 1.1+. | |
109 | */ | |
110 | LTTNG_OPTIONAL(uint64_t) received_packet_seq_num; | |
111 | ||
a44ca2ca MD |
112 | /* |
113 | * Tracefile array is an index of the stream trace files, | |
114 | * indexed by position. It allows keeping track of the oldest | |
115 | * available indexes when overwriting trace files in tracefile | |
116 | * rotation. | |
117 | */ | |
118 | struct tracefile_array *tfa; | |
2a174661 | 119 | |
28f23191 JG |
120 | bool closed; /* Stream is closed. */ |
121 | bool close_requested; /* Close command has been received. */ | |
2a174661 DG |
122 | |
123 | /* | |
7591bab1 MD |
124 | * Counts number of indexes in indexes_ht. Redundant info. |
125 | * Protected by stream lock. | |
6e7241fe JD |
126 | */ |
127 | int indexes_in_flight; | |
7591bab1 MD |
128 | struct lttng_ht *indexes_ht; |
129 | ||
528f2ffa | 130 | /* |
7591bab1 MD |
131 | * If the stream is inactive, this field is updated with the |
132 | * live beacon timestamp end, when it is active, this | |
133 | * field == -1ULL. | |
528f2ffa | 134 | */ |
7591bab1 MD |
135 | uint64_t beacon_ts_end; |
136 | ||
137 | /* CTF stream ID, -1ULL when unset (first packet not received yet). */ | |
528f2ffa | 138 | uint64_t ctf_stream_id; |
2a174661 | 139 | |
7591bab1 MD |
140 | /* Indicate if the stream was initialized for a data pending command. */ |
141 | bool data_pending_check_done; | |
142 | ||
143 | /* Is this stream a metadata stream ? */ | |
819cb727 | 144 | bool is_metadata; |
7591bab1 MD |
145 | /* Amount of metadata received (bytes). */ |
146 | uint64_t metadata_received; | |
147 | ||
2a174661 | 148 | /* |
7591bab1 MD |
149 | * Member of the stream list in struct ctf_trace. |
150 | * Updates are protected by the stream_list_lock. | |
151 | * Traversals are protected by RCU. | |
2a174661 | 152 | */ |
7591bab1 | 153 | struct cds_list_head stream_node; |
2a174661 | 154 | /* |
7591bab1 MD |
155 | * Temporary list belonging to the connection until all streams |
156 | * are received for that connection. | |
157 | * Member of the stream recv list in the connection. | |
158 | * Updates are protected by the stream_recv_list_lock. | |
159 | * Traversals are protected by RCU. | |
2a174661 | 160 | */ |
7591bab1 MD |
161 | bool in_recv_list; |
162 | struct cds_list_head recv_node; | |
c35f9726 JG |
163 | /* Protected by session lock. */ |
164 | bool published; | |
2a174661 | 165 | /* |
7591bab1 | 166 | * Node of stream within global stream hash table. |
2a174661 | 167 | */ |
7591bab1 | 168 | struct lttng_ht_node_u64 node; |
28f23191 JG |
169 | bool in_stream_ht; /* is stream in stream hash table. */ |
170 | struct rcu_head rcu_node; /* For call_rcu teardown. */ | |
d3ecc550 | 171 | /* |
c35f9726 JG |
172 | * The trace chunk to which the file currently being produced (if any) |
173 | * belongs. | |
87250ba1 JG |
174 | * |
175 | * Note that a relay stream can have no output trace chunk. For | |
176 | * instance, after a session stop followed by a session clear, | |
177 | * streams will not have an output trace chunk until the session | |
178 | * is resumed. | |
d3ecc550 | 179 | */ |
348a81dc | 180 | struct lttng_trace_chunk *trace_chunk; |
c35f9726 | 181 | LTTNG_OPTIONAL(struct relay_stream_rotation) ongoing_rotation; |
80516611 | 182 | uint64_t completed_rotation_count; |
2a174661 DG |
183 | }; |
184 | ||
7591bab1 | 185 | struct relay_stream *stream_create(struct ctf_trace *trace, |
28f23191 JG |
186 | uint64_t stream_handle, |
187 | char *path_name, | |
188 | char *channel_name, | |
189 | uint64_t tracefile_size, | |
190 | uint64_t tracefile_count); | |
7591bab1 MD |
191 | |
192 | struct relay_stream *stream_get_by_id(uint64_t stream_id); | |
193 | bool stream_get(struct relay_stream *stream); | |
194 | void stream_put(struct relay_stream *stream); | |
28f23191 | 195 | int stream_rotate_output_files(struct relay_session *session, struct relay_stream *stream); |
c35f9726 | 196 | int stream_set_pending_rotation(struct relay_stream *stream, |
28f23191 JG |
197 | struct lttng_trace_chunk *next_trace_chunk, |
198 | uint64_t rotation_sequence_number); | |
bda7c7b9 | 199 | void try_stream_close(struct relay_stream *stream); |
7591bab1 | 200 | void stream_publish(struct relay_stream *stream); |
28f23191 | 201 | int stream_init_packet(struct relay_stream *stream, size_t packet_size, bool *file_rotated); |
c35f9726 | 202 | int stream_write(struct relay_stream *stream, |
28f23191 JG |
203 | const struct lttng_buffer_view *packet, |
204 | size_t padding_len); | |
c35f9726 | 205 | /* Called after the reception of a complete data packet. */ |
28f23191 JG |
206 | int stream_update_index(struct relay_stream *stream, |
207 | uint64_t net_seq_num, | |
208 | bool rotate_index, | |
209 | bool *flushed, | |
210 | uint64_t total_size); | |
c35f9726 | 211 | int stream_complete_packet(struct relay_stream *stream, |
28f23191 JG |
212 | size_t packet_total_size, |
213 | uint64_t sequence_number, | |
214 | bool index_flushed); | |
c35f9726 | 215 | /* Index info is in host endianness. */ |
28f23191 | 216 | int stream_add_index(struct relay_stream *stream, const struct lttcomm_relayd_index *index_info); |
c35f9726 JG |
217 | int stream_reset_file(struct relay_stream *stream); |
218 | ||
0f4aa1a8 | 219 | void print_relay_streams(); |
2a174661 DG |
220 | |
221 | #endif /* _STREAM_H */ |