Commit | Line | Data |
---|---|---|
2c5ff4e4 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
2c5ff4e4 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
2c5ff4e4 | 5 | * |
2c5ff4e4 JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_TRACE_CHUNK_H | |
9 | #define LTTNG_TRACE_CHUNK_H | |
10 | ||
2c5ff4e4 | 11 | #include <common/compat/directory-handle.h> |
8bb66c3c JG |
12 | #include <common/credentials.h> |
13 | #include <common/fd-tracker/fd-tracker.h> | |
14 | #include <common/macros.h> | |
15 | #include <stdbool.h> | |
2c5ff4e4 JG |
16 | #include <stddef.h> |
17 | #include <stdint.h> | |
2c5ff4e4 JG |
18 | |
19 | /* | |
20 | * A trace chunk is a group of directories and files forming a (or a set of) | |
21 | * complete and independant trace(s). For instance, a trace archive chunk, | |
22 | * a snapshot, or a regular LTTng trace are all instances of a trace archive. | |
23 | * | |
24 | * A trace chunk is always contained within a session output directory. | |
25 | * | |
26 | * This facility is used by the session daemon, consumer daemon(s), and relay | |
27 | * daemon to: | |
28 | * - Control file (data stream, metadata, and index) creation relative to | |
29 | * a given output directory, | |
30 | * - Track the use of an output directory by other objects in order to | |
31 | * know if/when an output directory can be safely consumed, renamed, | |
32 | * deleted, etc. | |
33 | * | |
34 | * | |
35 | * OWNER VS USER | |
36 | * --- | |
37 | * | |
38 | * A trace chunk can either be a owner or a user of its | |
39 | * "chunk output directory". | |
40 | * | |
41 | * A "user" trace chunk is provided with a handle to the chunk output directory | |
42 | * which can then be used to create subdirectories and files. | |
43 | * | |
44 | * An "owner" chunk, on top of being able to perform the operations of a "user" | |
45 | * chunk can perform operations on its chunk output directory, such as renaming | |
46 | * or deleting it. | |
47 | * | |
48 | * A trace chunk becomes an "owner" or "user" chunk based on which of | |
49 | * 'lttng_trace_chunk_set_as_owner()' or 'lttng_trace_chunk_set_as_user()' is | |
50 | * used. These methods are _exclusive_ and must only be used once on a | |
51 | * trace chunk. | |
52 | */ | |
53 | ||
54 | struct lttng_trace_chunk; | |
b2621f79 | 55 | struct fd_tracker; |
2c5ff4e4 JG |
56 | |
57 | enum lttng_trace_chunk_status { | |
420acd90 | 58 | LTTNG_TRACE_CHUNK_STATUS_OK, |
2c5ff4e4 JG |
59 | LTTNG_TRACE_CHUNK_STATUS_NONE, |
60 | LTTNG_TRACE_CHUNK_STATUS_INVALID_ARGUMENT, | |
61 | LTTNG_TRACE_CHUNK_STATUS_INVALID_OPERATION, | |
62 | LTTNG_TRACE_CHUNK_STATUS_ERROR, | |
3ff5c5db | 63 | LTTNG_TRACE_CHUNK_STATUS_NO_FILE, |
2c5ff4e4 JG |
64 | }; |
65 | ||
66 | enum lttng_trace_chunk_command_type { | |
67 | LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED = 0, | |
343defc2 MD |
68 | LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION = 1, |
69 | LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE = 2, | |
70 | LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX, | |
2c5ff4e4 JG |
71 | }; |
72 | ||
73 | LTTNG_HIDDEN | |
74 | struct lttng_trace_chunk *lttng_trace_chunk_create_anonymous(void); | |
75 | ||
76 | LTTNG_HIDDEN | |
77 | struct lttng_trace_chunk *lttng_trace_chunk_create( | |
78 | uint64_t chunk_id, | |
a7ceb342 MD |
79 | time_t chunk_creation_time, |
80 | const char *path); | |
2c5ff4e4 | 81 | |
b2621f79 JG |
82 | LTTNG_HIDDEN |
83 | void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk *chunk, | |
84 | struct fd_tracker *fd_tracker); | |
85 | ||
1a414e3a JG |
86 | /* |
87 | * Copy a trace chunk. The copy that is returned is always a _user_ | |
88 | * mode chunk even if the source chunk was an _owner_ as there can never be | |
89 | * two _owners_ of the same trace output. | |
90 | */ | |
91 | LTTNG_HIDDEN | |
92 | struct lttng_trace_chunk *lttng_trace_chunk_copy( | |
93 | struct lttng_trace_chunk *source_chunk); | |
94 | ||
2c5ff4e4 JG |
95 | LTTNG_HIDDEN |
96 | enum lttng_trace_chunk_status lttng_trace_chunk_get_id( | |
97 | struct lttng_trace_chunk *chunk, uint64_t *id); | |
98 | ||
99 | LTTNG_HIDDEN | |
100 | enum lttng_trace_chunk_status lttng_trace_chunk_get_creation_timestamp( | |
101 | struct lttng_trace_chunk *chunk, time_t *creation_ts); | |
102 | ||
103 | LTTNG_HIDDEN | |
104 | enum lttng_trace_chunk_status lttng_trace_chunk_get_close_timestamp( | |
105 | struct lttng_trace_chunk *chunk, time_t *close_ts); | |
106 | ||
107 | LTTNG_HIDDEN | |
108 | enum lttng_trace_chunk_status lttng_trace_chunk_set_close_timestamp( | |
109 | struct lttng_trace_chunk *chunk, time_t close_ts); | |
110 | ||
111 | LTTNG_HIDDEN | |
112 | enum lttng_trace_chunk_status lttng_trace_chunk_get_name( | |
113 | struct lttng_trace_chunk *chunk, const char **name, | |
913a542b | 114 | bool *name_overridden); |
2c5ff4e4 | 115 | |
0e2d816a MD |
116 | LTTNG_HIDDEN |
117 | bool lttng_trace_chunk_get_name_overridden(struct lttng_trace_chunk *chunk); | |
118 | ||
2c5ff4e4 JG |
119 | LTTNG_HIDDEN |
120 | enum lttng_trace_chunk_status lttng_trace_chunk_override_name( | |
121 | struct lttng_trace_chunk *chunk, const char *name); | |
122 | ||
a7ceb342 MD |
123 | LTTNG_HIDDEN |
124 | enum lttng_trace_chunk_status lttng_trace_chunk_rename_path( | |
125 | struct lttng_trace_chunk *chunk, const char *path); | |
126 | ||
2c5ff4e4 JG |
127 | LTTNG_HIDDEN |
128 | enum lttng_trace_chunk_status lttng_trace_chunk_get_credentials( | |
129 | struct lttng_trace_chunk *chunk, | |
130 | struct lttng_credentials *credentials); | |
131 | ||
132 | LTTNG_HIDDEN | |
133 | enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials( | |
134 | struct lttng_trace_chunk *chunk, | |
135 | const struct lttng_credentials *credentials); | |
136 | ||
137 | LTTNG_HIDDEN | |
138 | enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials_current_user( | |
139 | struct lttng_trace_chunk *chunk); | |
140 | ||
2c5ff4e4 JG |
141 | LTTNG_HIDDEN |
142 | enum lttng_trace_chunk_status lttng_trace_chunk_set_as_owner( | |
143 | struct lttng_trace_chunk *chunk, | |
144 | struct lttng_directory_handle *session_output_directory); | |
145 | ||
2c5ff4e4 JG |
146 | LTTNG_HIDDEN |
147 | enum lttng_trace_chunk_status lttng_trace_chunk_set_as_user( | |
148 | struct lttng_trace_chunk *chunk, | |
149 | struct lttng_directory_handle *chunk_directory); | |
150 | ||
7ceefac4 JG |
151 | LTTNG_HIDDEN |
152 | enum lttng_trace_chunk_status | |
153 | lttng_trace_chunk_get_session_output_directory_handle( | |
154 | struct lttng_trace_chunk *chunk, | |
155 | struct lttng_directory_handle **handle); | |
156 | ||
2c5ff4e4 | 157 | LTTNG_HIDDEN |
cbf53d23 | 158 | enum lttng_trace_chunk_status lttng_trace_chunk_borrow_chunk_directory_handle( |
2c5ff4e4 JG |
159 | struct lttng_trace_chunk *chunk, |
160 | const struct lttng_directory_handle **handle); | |
161 | ||
162 | LTTNG_HIDDEN | |
163 | enum lttng_trace_chunk_status lttng_trace_chunk_create_subdirectory( | |
164 | struct lttng_trace_chunk *chunk, | |
165 | const char *subdirectory_path); | |
166 | ||
167 | LTTNG_HIDDEN | |
168 | enum lttng_trace_chunk_status lttng_trace_chunk_open_file( | |
8bb66c3c JG |
169 | struct lttng_trace_chunk *chunk, |
170 | const char *filename, | |
171 | int flags, | |
172 | mode_t mode, | |
173 | int *out_fd, | |
174 | bool expect_no_file); | |
175 | ||
176 | LTTNG_HIDDEN | |
177 | enum lttng_trace_chunk_status lttng_trace_chunk_open_fs_handle( | |
178 | struct lttng_trace_chunk *chunk, | |
179 | const char *filename, | |
180 | int flags, | |
181 | mode_t mode, | |
182 | struct fs_handle **out_handle, | |
183 | bool expect_no_file); | |
2c5ff4e4 JG |
184 | |
185 | LTTNG_HIDDEN | |
186 | int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk *chunk, | |
187 | const char *filename); | |
188 | ||
bbc4768c JG |
189 | LTTNG_HIDDEN |
190 | enum lttng_trace_chunk_status lttng_trace_chunk_get_close_command( | |
191 | struct lttng_trace_chunk *chunk, | |
192 | enum lttng_trace_chunk_command_type *command_type); | |
193 | ||
2c5ff4e4 JG |
194 | LTTNG_HIDDEN |
195 | enum lttng_trace_chunk_status lttng_trace_chunk_set_close_command( | |
196 | struct lttng_trace_chunk *chunk, | |
197 | enum lttng_trace_chunk_command_type command_type); | |
198 | ||
bbc4768c JG |
199 | LTTNG_HIDDEN |
200 | const char *lttng_trace_chunk_command_type_get_name( | |
201 | enum lttng_trace_chunk_command_type command); | |
202 | ||
ad8bec24 JG |
203 | LTTNG_HIDDEN |
204 | bool lttng_trace_chunk_ids_equal(const struct lttng_trace_chunk *chunk_a, | |
205 | const struct lttng_trace_chunk *chunk_b); | |
206 | ||
2c5ff4e4 JG |
207 | /* Returns true on success. */ |
208 | LTTNG_HIDDEN | |
209 | bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk); | |
210 | ||
211 | LTTNG_HIDDEN | |
212 | void lttng_trace_chunk_put(struct lttng_trace_chunk *chunk); | |
213 | ||
214 | #endif /* LTTNG_TRACE_CHUNK_H */ |