Commit | Line | Data |
---|---|---|
51230d70 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
51230d70 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
51230d70 | 5 | * |
51230d70 DG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_CONSUMER_STREAM_H | |
9 | #define LTTNG_CONSUMER_STREAM_H | |
10 | ||
11 | #include "consumer.h" | |
12 | ||
97535efa SM |
13 | #ifdef __cplusplus |
14 | extern "C" { | |
15 | #endif | |
16 | ||
503fefca JG |
17 | enum consumer_stream_open_packet_status { |
18 | CONSUMER_STREAM_OPEN_PACKET_STATUS_OPENED, | |
19 | CONSUMER_STREAM_OPEN_PACKET_STATUS_NO_SPACE, | |
20 | CONSUMER_STREAM_OPEN_PACKET_STATUS_ERROR, | |
21 | }; | |
22 | ||
6f9449c2 JG |
23 | /* |
24 | * Create a consumer stream. | |
25 | * | |
26 | * The channel lock MUST be acquired. | |
27 | */ | |
28 | struct lttng_consumer_stream *consumer_stream_create( | |
29 | struct lttng_consumer_channel *channel, | |
30 | uint64_t channel_key, | |
31 | uint64_t stream_key, | |
32 | const char *channel_name, | |
33 | uint64_t relayd_id, | |
34 | uint64_t session_id, | |
35 | struct lttng_trace_chunk *trace_chunk, | |
36 | int cpu, | |
37 | int *alloc_ret, | |
38 | enum consumer_channel_type type, | |
39 | unsigned int monitor); | |
40 | ||
51230d70 DG |
41 | /* |
42 | * Close stream's file descriptors and, if needed, close stream also on the | |
43 | * relayd side. | |
44 | * | |
45 | * The stream lock MUST be acquired. | |
46 | * The consumer data lock MUST be acquired. | |
47 | */ | |
48 | void consumer_stream_close(struct lttng_consumer_stream *stream); | |
49 | ||
50 | /* | |
51 | * Close stream on the relayd side. This call can destroy a relayd if the | |
52 | * conditions are met. | |
53 | * | |
54 | * A RCU read side lock MUST be acquired if the relayd object was looked up in | |
55 | * a hash table before calling this. | |
56 | */ | |
57 | void consumer_stream_relayd_close(struct lttng_consumer_stream *stream, | |
58 | struct consumer_relayd_sock_pair *relayd); | |
59 | ||
60 | /* | |
61 | * Delete the stream from all possible hash tables. | |
62 | * | |
63 | * The consumer data lock MUST be acquired. | |
64 | */ | |
65 | void consumer_stream_delete(struct lttng_consumer_stream *stream, | |
66 | struct lttng_ht *ht); | |
67 | ||
68 | /* | |
69 | * Free the given stream within a RCU call. | |
70 | */ | |
71 | void consumer_stream_free(struct lttng_consumer_stream *stream); | |
72 | ||
73 | /* | |
74 | * Destroy a stream completely. This will delete, close and free the stream. | |
75 | * Once return, the stream is NO longer usable. Its channel may get destroyed | |
76 | * if conditions are met. | |
77 | * | |
78 | * This MUST be called WITHOUT the consumer data and stream lock acquired. | |
79 | */ | |
80 | void consumer_stream_destroy(struct lttng_consumer_stream *stream, | |
81 | struct lttng_ht *ht); | |
82 | ||
10a50311 JD |
83 | /* |
84 | * Destroy the stream's buffers on the tracer side. This is also called in a | |
85 | * stream destroy. | |
86 | */ | |
87 | void consumer_stream_destroy_buffers(struct lttng_consumer_stream *stream); | |
88 | ||
1c20f0e2 JD |
89 | /* |
90 | * Write index of a specific stream either on the relayd or local disk. | |
91 | */ | |
92 | int consumer_stream_write_index(struct lttng_consumer_stream *stream, | |
50adc264 | 93 | struct ctf_packet_index *index); |
1c20f0e2 | 94 | |
94d49140 JD |
95 | int consumer_stream_sync_metadata(struct lttng_consumer_local_data *ctx, |
96 | uint64_t session_id); | |
97 | ||
d2956687 | 98 | /* |
c35f9726 | 99 | * Create the output files of a local stream. |
d2956687 JG |
100 | * |
101 | * This must be called with the channel's and the stream's lock held. | |
102 | */ | |
103 | int consumer_stream_create_output_files(struct lttng_consumer_stream *stream, | |
104 | bool create_index); | |
105 | ||
106 | /* | |
107 | * Rotate the output files of a local stream. This will change the | |
108 | * active output files of both the binary and index in accordance | |
109 | * with the stream's configuration (stream file count). | |
110 | * | |
111 | * This must be called with the channel's and the stream's lock held. | |
112 | */ | |
113 | int consumer_stream_rotate_output_files(struct lttng_consumer_stream *stream); | |
114 | ||
cdb72e4e JG |
115 | /* |
116 | * Indicates whether or not a stream is logically deleted. A deleted stream | |
117 | * should no longer be used; its existence is only garanteed by the RCU lock | |
118 | * held by the caller. | |
119 | * | |
120 | * This function must be called with the RCU read side lock held. | |
121 | */ | |
122 | bool consumer_stream_is_deleted(struct lttng_consumer_stream *stream); | |
123 | ||
f5ba75b4 JG |
124 | /* |
125 | * Enable metadata bucketization. This must only be enabled if the tracer | |
126 | * provides a reliable metadata `coherent` flag. | |
127 | * | |
128 | * This must be called on initialization before any subbuffer is consumed. | |
129 | */ | |
130 | int consumer_stream_enable_metadata_bucketization( | |
131 | struct lttng_consumer_stream *stream); | |
132 | ||
55954e07 JG |
133 | /* |
134 | * Set the version of a metadata stream (i.e. following a metadata | |
135 | * regeneration). | |
136 | * | |
137 | * Changing the version of a metadata stream will cause any bucketized metadata | |
138 | * to be discarded and will mark the metadata stream for future `reset`. | |
139 | */ | |
140 | void consumer_stream_metadata_set_version( | |
141 | struct lttng_consumer_stream *stream, uint64_t new_version); | |
142 | ||
503fefca JG |
143 | /* |
144 | * Set the version of a metadata stream (i.e. following a metadata | |
145 | * regeneration). | |
146 | * | |
147 | * Changing the version of a metadata stream will cause any bucketized metadata | |
148 | * to be discarded and will mark the metadata stream for future `reset`. | |
149 | */ | |
150 | void consumer_stream_metadata_set_version( | |
151 | struct lttng_consumer_stream *stream, uint64_t new_version); | |
152 | ||
153 | /* | |
154 | * Attempt to open a packet in a stream. | |
155 | * | |
156 | * This function must be called with the stream and channel locks held. | |
157 | */ | |
158 | enum consumer_stream_open_packet_status consumer_stream_open_packet( | |
159 | struct lttng_consumer_stream *stream); | |
160 | ||
161 | /* | |
162 | * Flush a stream's buffer. | |
163 | * | |
164 | * producer_active: if true, causes a flush to occur only if there is | |
165 | * content present in the current sub-buffer. If false, forces a flush to take | |
166 | * place (otherwise known as "flush_empty"). | |
167 | * | |
168 | * This function must be called with the stream and channel locks held. | |
169 | */ | |
170 | int consumer_stream_flush_buffer(struct lttng_consumer_stream *stream, | |
171 | bool producer_active); | |
172 | ||
97535efa SM |
173 | #ifdef __cplusplus |
174 | } | |
175 | #endif | |
176 | ||
51230d70 | 177 | #endif /* LTTNG_CONSUMER_STREAM_H */ |