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