2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <urcu/list.h>
27 #include <common/hashtable/hashtable.h>
32 * Represents a stream in the relay
35 uint64_t stream_handle
;
36 uint64_t prev_seq
; /* previous data sequence number encountered */
37 struct lttng_ht_node_u64 node
;
39 * When we receive a stream, it gets stored in a list (on a per connection
40 * basis) until we have all the streams of the same channel and the metadata
41 * associated with it, then it gets flagged with viewer_ready.
43 struct cds_list_head recv_list
;
45 /* Added to the corresponding ctf_trace. */
46 struct cds_list_head trace_list
;
47 struct rcu_head rcu_node
;
50 /* FD on which to write the index data. */
52 /* FD on which to read the index data for the viewer. */
57 /* on-disk circular buffer of tracefiles */
58 uint64_t tracefile_size
;
59 uint64_t tracefile_size_current
;
60 uint64_t tracefile_count
;
61 uint64_t tracefile_count_current
;
62 /* To inform the viewer up to where it can go back in time. */
63 uint64_t oldest_tracefile_id
;
65 uint64_t total_index_received
;
66 uint64_t last_net_seq_num
;
69 * To protect from concurrent read/update. Also used to synchronize the
70 * closing of this stream.
75 * If the stream is inactive, this field is updated with the live beacon
76 * timestamp end, when it is active, this field == -1ULL.
78 uint64_t beacon_ts_end
;
80 * CTF stream ID, -1ULL when unset.
82 uint64_t ctf_stream_id
;
84 * To protect the update of the close_write_flag and the checks of
85 * the tracefile_count_current.
86 * It is taken before checking whenever we need to know if the
87 * writer and reader are working in the same tracefile.
89 pthread_mutex_t viewer_stream_rotation_lock
;
91 /* Information telling us when to close the stream */
92 unsigned int close_flag
:1;
94 * Indicates if the stream has been effectively closed thus having the
95 * information in it invalidated but NOT freed. The stream lock MUST be
96 * held to read/update that value.
98 unsigned int terminated_flag
:1;
99 /* Indicate if the stream was initialized for a data pending command. */
100 unsigned int data_pending_check_done
:1;
101 unsigned int metadata_flag
:1;
103 * To detect when we start overwriting old data, it is used to
104 * update the oldest_tracefile_id.
106 unsigned int tracefile_overwrite
:1;
108 * Can this stream be used by a viewer or are we waiting for additional
111 unsigned int viewer_ready
:1;
114 struct relay_stream
*stream_find_by_id(struct lttng_ht
*ht
,
116 int stream_close(struct relay_session
*session
, struct relay_stream
*stream
);
117 void stream_delete(struct lttng_ht
*ht
, struct relay_stream
*stream
);
118 void stream_destroy(struct relay_stream
*stream
);
120 #endif /* _STREAM_H */