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