Commit | Line | Data |
---|---|---|
7591bab1 MD |
1 | #ifndef _STREAM_H |
2 | #define _STREAM_H | |
3 | ||
2a174661 DG |
4 | /* |
5 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> | |
6 | * David Goulet <dgoulet@efficios.com> | |
7591bab1 | 7 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
2a174661 DG |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License, version 2 only, as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 | * more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License along with | |
19 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
22 | ||
2a174661 DG |
23 | #include <limits.h> |
24 | #include <inttypes.h> | |
25 | #include <pthread.h> | |
26 | #include <urcu/list.h> | |
27 | ||
28 | #include <common/hashtable/hashtable.h> | |
29 | ||
30 | #include "session.h" | |
7591bab1 | 31 | #include "stream-fd.h" |
a44ca2ca | 32 | #include "tracefile-array.h" |
f465e978 | 33 | #include "index-file.h" |
2a174661 DG |
34 | |
35 | /* | |
36 | * Represents a stream in the relay | |
37 | */ | |
38 | struct relay_stream { | |
39 | uint64_t stream_handle; | |
7591bab1 | 40 | |
2a174661 | 41 | /* |
7591bab1 MD |
42 | * reflock used to synchronize the closing of this stream. |
43 | * stream reflock nests inside viewer stream reflock. | |
44 | * stream reflock nests inside index reflock. | |
2a174661 | 45 | */ |
7591bab1 MD |
46 | pthread_mutex_t reflock; |
47 | struct urcu_ref ref; | |
48 | /* Back reference to trace. Protected by refcount on trace object. */ | |
49 | struct ctf_trace *trace; | |
2a174661 | 50 | |
7591bab1 MD |
51 | /* |
52 | * To protect from concurrent read/update. The viewer stream | |
53 | * lock nests inside the stream lock. The stream lock nests | |
54 | * inside the ctf_trace lock. | |
55 | */ | |
56 | pthread_mutex_t lock; | |
57 | uint64_t prev_seq; /* previous data sequence number encountered. */ | |
58 | uint64_t last_net_seq_num; /* seq num to encounter before closing. */ | |
59 | ||
60 | /* FD on which to write the stream data. */ | |
61 | struct stream_fd *stream_fd; | |
e0547b83 | 62 | /* index file on which to write the index data. */ |
f465e978 | 63 | struct relay_index_file *index_file; |
2a174661 DG |
64 | |
65 | char *path_name; | |
66 | char *channel_name; | |
7591bab1 MD |
67 | |
68 | /* On-disk circular buffer of tracefiles. */ | |
2a174661 DG |
69 | uint64_t tracefile_size; |
70 | uint64_t tracefile_size_current; | |
71 | uint64_t tracefile_count; | |
7591bab1 | 72 | |
a44ca2ca MD |
73 | /* |
74 | * Counts the number of received indexes. The "tag" associated | |
75 | * with an index is taken before incrementing this seqcount. | |
76 | * Therefore, the sequence tag associated with the last index | |
77 | * received is always index_received_seqcount - 1. | |
78 | */ | |
79 | uint64_t index_received_seqcount; | |
2a174661 | 80 | |
a44ca2ca MD |
81 | /* |
82 | * Tracefile array is an index of the stream trace files, | |
83 | * indexed by position. It allows keeping track of the oldest | |
84 | * available indexes when overwriting trace files in tracefile | |
85 | * rotation. | |
86 | */ | |
87 | struct tracefile_array *tfa; | |
2a174661 | 88 | |
bda7c7b9 JG |
89 | bool closed; /* Stream is closed. */ |
90 | bool close_requested; /* Close command has been received. */ | |
2a174661 DG |
91 | |
92 | /* | |
7591bab1 MD |
93 | * Counts number of indexes in indexes_ht. Redundant info. |
94 | * Protected by stream lock. | |
6e7241fe JD |
95 | */ |
96 | int indexes_in_flight; | |
7591bab1 MD |
97 | struct lttng_ht *indexes_ht; |
98 | ||
528f2ffa | 99 | /* |
7591bab1 MD |
100 | * If the stream is inactive, this field is updated with the |
101 | * live beacon timestamp end, when it is active, this | |
102 | * field == -1ULL. | |
528f2ffa | 103 | */ |
7591bab1 MD |
104 | uint64_t beacon_ts_end; |
105 | ||
106 | /* CTF stream ID, -1ULL when unset (first packet not received yet). */ | |
528f2ffa | 107 | uint64_t ctf_stream_id; |
2a174661 | 108 | |
7591bab1 MD |
109 | /* Indicate if the stream was initialized for a data pending command. */ |
110 | bool data_pending_check_done; | |
111 | ||
112 | /* Is this stream a metadata stream ? */ | |
113 | int32_t is_metadata; | |
114 | /* Amount of metadata received (bytes). */ | |
115 | uint64_t metadata_received; | |
116 | ||
2a174661 | 117 | /* |
7591bab1 MD |
118 | * Member of the stream list in struct ctf_trace. |
119 | * Updates are protected by the stream_list_lock. | |
120 | * Traversals are protected by RCU. | |
2a174661 | 121 | */ |
7591bab1 | 122 | struct cds_list_head stream_node; |
2a174661 | 123 | /* |
7591bab1 MD |
124 | * Temporary list belonging to the connection until all streams |
125 | * are received for that connection. | |
126 | * Member of the stream recv list in the connection. | |
127 | * Updates are protected by the stream_recv_list_lock. | |
128 | * Traversals are protected by RCU. | |
2a174661 | 129 | */ |
7591bab1 MD |
130 | bool in_recv_list; |
131 | struct cds_list_head recv_node; | |
132 | bool published; /* Protected by session lock. */ | |
2a174661 | 133 | /* |
7591bab1 | 134 | * Node of stream within global stream hash table. |
2a174661 | 135 | */ |
7591bab1 | 136 | struct lttng_ht_node_u64 node; |
77f7bd85 | 137 | bool in_stream_ht; /* is stream in stream hash table. */ |
7591bab1 | 138 | struct rcu_head rcu_node; /* For call_rcu teardown. */ |
2a174661 DG |
139 | }; |
140 | ||
7591bab1 MD |
141 | struct relay_stream *stream_create(struct ctf_trace *trace, |
142 | uint64_t stream_handle, char *path_name, | |
143 | char *channel_name, uint64_t tracefile_size, | |
144 | uint64_t tracefile_count); | |
145 | ||
146 | struct relay_stream *stream_get_by_id(uint64_t stream_id); | |
147 | bool stream_get(struct relay_stream *stream); | |
148 | void stream_put(struct relay_stream *stream); | |
bda7c7b9 | 149 | void try_stream_close(struct relay_stream *stream); |
7591bab1 MD |
150 | void stream_publish(struct relay_stream *stream); |
151 | void print_relay_streams(void); | |
2a174661 DG |
152 | |
153 | #endif /* _STREAM_H */ |