| 1 | /* |
| 2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> |
| 3 | * David Goulet <dgoulet@efficios.com> |
| 4 | * |
| 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. |
| 8 | * |
| 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 |
| 12 | * more details. |
| 13 | * |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #ifndef _STREAM_H |
| 20 | #define _STREAM_H |
| 21 | |
| 22 | #include <limits.h> |
| 23 | #include <inttypes.h> |
| 24 | #include <pthread.h> |
| 25 | #include <urcu/list.h> |
| 26 | |
| 27 | #include <common/hashtable/hashtable.h> |
| 28 | |
| 29 | #include "session.h" |
| 30 | |
| 31 | /* |
| 32 | * Represents a stream in the relay |
| 33 | */ |
| 34 | struct relay_stream { |
| 35 | uint64_t stream_handle; |
| 36 | uint64_t prev_seq; /* previous data sequence number encountered */ |
| 37 | struct lttng_ht_node_u64 node; |
| 38 | /* |
| 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. |
| 42 | */ |
| 43 | struct cds_list_head recv_list; |
| 44 | |
| 45 | /* Added to the corresponding ctf_trace. */ |
| 46 | struct cds_list_head trace_list; |
| 47 | struct rcu_head rcu_node; |
| 48 | uint64_t session_id; |
| 49 | int fd; |
| 50 | /* FD on which to write the index data. */ |
| 51 | int index_fd; |
| 52 | /* FD on which to read the index data for the viewer. */ |
| 53 | int read_index_fd; |
| 54 | |
| 55 | char *path_name; |
| 56 | char *channel_name; |
| 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; |
| 64 | |
| 65 | uint64_t total_index_received; |
| 66 | uint64_t last_net_seq_num; |
| 67 | |
| 68 | /* |
| 69 | * To protect from concurrent read/update. Also used to synchronize the |
| 70 | * closing of this stream. |
| 71 | */ |
| 72 | pthread_mutex_t lock; |
| 73 | |
| 74 | /* |
| 75 | * If the stream is inactive, this field is updated with the live beacon |
| 76 | * timestamp end, when it is active, this field == -1ULL. |
| 77 | */ |
| 78 | uint64_t beacon_ts_end; |
| 79 | /* |
| 80 | * Number of indexes that are supposed to be complete soon. |
| 81 | * Avoid sending the inactivity beacon to the client when data is in |
| 82 | * transit. |
| 83 | */ |
| 84 | int indexes_in_flight; |
| 85 | /* |
| 86 | * CTF stream ID, -1ULL when unset. |
| 87 | */ |
| 88 | uint64_t ctf_stream_id; |
| 89 | /* |
| 90 | * To protect the update of the close_write_flag and the checks of |
| 91 | * the tracefile_count_current. |
| 92 | * It is taken before checking whenever we need to know if the |
| 93 | * writer and reader are working in the same tracefile. |
| 94 | */ |
| 95 | pthread_mutex_t viewer_stream_rotation_lock; |
| 96 | |
| 97 | /* Information telling us when to close the stream */ |
| 98 | unsigned int close_flag:1; |
| 99 | /* |
| 100 | * Indicates if the stream has been effectively closed thus having the |
| 101 | * information in it invalidated but NOT freed. The stream lock MUST be |
| 102 | * held to read/update that value. |
| 103 | */ |
| 104 | unsigned int terminated_flag:1; |
| 105 | /* Indicate if the stream was initialized for a data pending command. */ |
| 106 | unsigned int data_pending_check_done:1; |
| 107 | unsigned int metadata_flag:1; |
| 108 | /* |
| 109 | * To detect when we start overwriting old data, it is used to |
| 110 | * update the oldest_tracefile_id. |
| 111 | */ |
| 112 | unsigned int tracefile_overwrite:1; |
| 113 | /* |
| 114 | * Can this stream be used by a viewer or are we waiting for additional |
| 115 | * information. |
| 116 | */ |
| 117 | unsigned int viewer_ready:1; |
| 118 | }; |
| 119 | |
| 120 | struct relay_stream *stream_find_by_id(struct lttng_ht *ht, |
| 121 | uint64_t stream_id); |
| 122 | int stream_close(struct relay_session *session, struct relay_stream *stream); |
| 123 | void stream_delete(struct lttng_ht *ht, struct relay_stream *stream); |
| 124 | void stream_destroy(struct relay_stream *stream); |
| 125 | |
| 126 | #endif /* _STREAM_H */ |