Fix: Relay daemon ownership and reference counting
[lttng-tools.git] / src / bin / lttng-relayd / stream.h
1 #ifndef _STREAM_H
2 #define _STREAM_H
3
4 /*
5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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
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"
31 #include "stream-fd.h"
32
33 /*
34 * Represents a stream in the relay
35 */
36 struct relay_stream {
37 uint64_t stream_handle;
38
39 /*
40 * reflock used to synchronize the closing of this stream.
41 * stream reflock nests inside viewer stream reflock.
42 * stream reflock nests inside index reflock.
43 */
44 pthread_mutex_t reflock;
45 struct urcu_ref ref;
46 /* Back reference to trace. Protected by refcount on trace object. */
47 struct ctf_trace *trace;
48
49 /*
50 * To protect from concurrent read/update. The viewer stream
51 * lock nests inside the stream lock. The stream lock nests
52 * inside the ctf_trace lock.
53 */
54 pthread_mutex_t lock;
55 uint64_t prev_seq; /* previous data sequence number encountered. */
56 uint64_t last_net_seq_num; /* seq num to encounter before closing. */
57
58 /* FD on which to write the stream data. */
59 struct stream_fd *stream_fd;
60 /* FD on which to write the index data. */
61 struct stream_fd *index_fd;
62
63 char *path_name;
64 char *channel_name;
65
66 /* On-disk circular buffer of tracefiles. */
67 uint64_t tracefile_size;
68 uint64_t tracefile_size_current;
69 uint64_t tracefile_count;
70 uint64_t current_tracefile_id;
71
72 uint64_t current_tracefile_seq; /* Free-running counter. */
73 uint64_t oldest_tracefile_seq; /* Free-running counter. */
74
75 /* To inform the viewer up to where it can go back in time. */
76 uint64_t oldest_tracefile_id;
77
78 uint64_t total_index_received;
79
80 bool closed; /* Stream is closed. */
81
82 /*
83 * Counts number of indexes in indexes_ht. Redundant info.
84 * Protected by stream lock.
85 */
86 int indexes_in_flight;
87 struct lttng_ht *indexes_ht;
88
89 /*
90 * If the stream is inactive, this field is updated with the
91 * live beacon timestamp end, when it is active, this
92 * field == -1ULL.
93 */
94 uint64_t beacon_ts_end;
95
96 /* CTF stream ID, -1ULL when unset (first packet not received yet). */
97 uint64_t ctf_stream_id;
98
99 /* Indicate if the stream was initialized for a data pending command. */
100 bool data_pending_check_done;
101
102 /* Is this stream a metadata stream ? */
103 int32_t is_metadata;
104 /* Amount of metadata received (bytes). */
105 uint64_t metadata_received;
106
107 /*
108 * Member of the stream list in struct ctf_trace.
109 * Updates are protected by the stream_list_lock.
110 * Traversals are protected by RCU.
111 */
112 struct cds_list_head stream_node;
113 /*
114 * Temporary list belonging to the connection until all streams
115 * are received for that connection.
116 * Member of the stream recv list in the connection.
117 * Updates are protected by the stream_recv_list_lock.
118 * Traversals are protected by RCU.
119 */
120 bool in_recv_list;
121 struct cds_list_head recv_node;
122 bool published; /* Protected by session lock. */
123 /*
124 * Node of stream within global stream hash table.
125 */
126 struct lttng_ht_node_u64 node;
127 struct rcu_head rcu_node; /* For call_rcu teardown. */
128 };
129
130 struct relay_stream *stream_create(struct ctf_trace *trace,
131 uint64_t stream_handle, char *path_name,
132 char *channel_name, uint64_t tracefile_size,
133 uint64_t tracefile_count);
134
135 struct relay_stream *stream_get_by_id(uint64_t stream_id);
136 bool stream_get(struct relay_stream *stream);
137 void stream_put(struct relay_stream *stream);
138 void stream_close(struct relay_stream *stream);
139 void stream_publish(struct relay_stream *stream);
140 void print_relay_streams(void);
141
142 #endif /* _STREAM_H */
This page took 0.032725 seconds and 5 git commands to generate.