Fix: lttng-snapshot: use after free of max size argument
[lttng-tools.git] / src / bin / lttng-relayd / tracefile-array.h
1 #ifndef _TRACEFILE_ARRAY_H
2 #define _TRACEFILE_ARRAY_H
3
4 /*
5 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0-only
8 *
9 */
10
11 #include <limits.h>
12 #include <inttypes.h>
13 #include <pthread.h>
14 #include <stdbool.h>
15
16 struct tracefile {
17 /* Per-tracefile head/tail seq. */
18 uint64_t seq_head; /* Newest seqcount. Inclusive. */
19 uint64_t seq_tail; /* Oldest seqcount. Inclusive. */
20 };
21
22 enum tracefile_rotate_type {
23 TRACEFILE_ROTATE_READ,
24 TRACEFILE_ROTATE_WRITE,
25 };
26
27 /*
28 * Represents an array of trace files in a stream.
29 * head is the most recent file/trace packet.
30 * tail is the oldest file/trace packet.
31 *
32 * There are two heads: a "read" head and a "write" head. The "write" head is
33 * the position of the newest data file. The "read" head position is only moved
34 * forward when the index is received.
35 *
36 * The viewer uses the "read" head position as upper bound, which
37 * ensures it never attempts to open a non-existing index file.
38 */
39 struct tracefile_array {
40 struct tracefile *tf;
41 size_t count;
42
43 /* Current head/tail files. */
44 uint64_t file_head_read;
45 uint64_t file_head_write;
46 uint64_t file_tail;
47
48 /* Overall head/tail seq for the entire array. Inclusive. */
49 uint64_t seq_head;
50 uint64_t seq_tail;
51 };
52
53 struct tracefile_array *tracefile_array_create(size_t count);
54 void tracefile_array_destroy(struct tracefile_array *tfa);
55
56 void tracefile_array_file_rotate(struct tracefile_array *tfa, enum tracefile_rotate_type type);
57 void tracefile_array_commit_seq(struct tracefile_array *tfa,
58 uint64_t new_seq_head);
59 void tracefile_array_reset(struct tracefile_array *tfa);
60
61 uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa);
62 /* May return -1ULL in the case where we have not received any indexes yet. */
63 uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa);
64
65 uint64_t tracefile_array_get_file_index_tail(struct tracefile_array *tfa);
66 /* May return -1ULL in the case where we have not received any indexes yet. */
67 uint64_t tracefile_array_get_seq_tail(struct tracefile_array *tfa);
68
69 bool tracefile_array_seq_in_file(struct tracefile_array *tfa,
70 uint64_t file_index, uint64_t seq);
71
72 #endif /* _STREAM_H */
This page took 0.041227 seconds and 4 git commands to generate.