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 | ||
c9e313bc SM |
11 | #include <common/compat/directory-handle.hpp> |
12 | #include <common/credentials.hpp> | |
13 | #include <common/fd-tracker/fd-tracker.hpp> | |
14 | #include <common/macros.hpp> | |
8bb66c3c | 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 | ||
2c5ff4e4 JG |
73 | struct lttng_trace_chunk *lttng_trace_chunk_create_anonymous(void); |
74 | ||
2c5ff4e4 JG |
75 | struct lttng_trace_chunk *lttng_trace_chunk_create( |
76 | uint64_t chunk_id, | |
a7ceb342 MD |
77 | time_t chunk_creation_time, |
78 | const char *path); | |
2c5ff4e4 | 79 | |
b2621f79 JG |
80 | void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk *chunk, |
81 | struct fd_tracker *fd_tracker); | |
82 | ||
1a414e3a JG |
83 | /* |
84 | * Copy a trace chunk. The copy that is returned is always a _user_ | |
85 | * mode chunk even if the source chunk was an _owner_ as there can never be | |
86 | * two _owners_ of the same trace output. | |
87 | */ | |
1a414e3a JG |
88 | struct lttng_trace_chunk *lttng_trace_chunk_copy( |
89 | struct lttng_trace_chunk *source_chunk); | |
90 | ||
2c5ff4e4 JG |
91 | enum lttng_trace_chunk_status lttng_trace_chunk_get_id( |
92 | struct lttng_trace_chunk *chunk, uint64_t *id); | |
93 | ||
2c5ff4e4 JG |
94 | enum lttng_trace_chunk_status lttng_trace_chunk_get_creation_timestamp( |
95 | struct lttng_trace_chunk *chunk, time_t *creation_ts); | |
96 | ||
2c5ff4e4 JG |
97 | enum lttng_trace_chunk_status lttng_trace_chunk_get_close_timestamp( |
98 | struct lttng_trace_chunk *chunk, time_t *close_ts); | |
99 | ||
2c5ff4e4 JG |
100 | enum lttng_trace_chunk_status lttng_trace_chunk_set_close_timestamp( |
101 | struct lttng_trace_chunk *chunk, time_t close_ts); | |
102 | ||
2c5ff4e4 JG |
103 | enum lttng_trace_chunk_status lttng_trace_chunk_get_name( |
104 | struct lttng_trace_chunk *chunk, const char **name, | |
913a542b | 105 | bool *name_overridden); |
2c5ff4e4 | 106 | |
0e2d816a MD |
107 | bool lttng_trace_chunk_get_name_overridden(struct lttng_trace_chunk *chunk); |
108 | ||
2c5ff4e4 JG |
109 | enum lttng_trace_chunk_status lttng_trace_chunk_override_name( |
110 | struct lttng_trace_chunk *chunk, const char *name); | |
111 | ||
a7ceb342 MD |
112 | enum lttng_trace_chunk_status lttng_trace_chunk_rename_path( |
113 | struct lttng_trace_chunk *chunk, const char *path); | |
114 | ||
2c5ff4e4 JG |
115 | enum lttng_trace_chunk_status lttng_trace_chunk_get_credentials( |
116 | struct lttng_trace_chunk *chunk, | |
117 | struct lttng_credentials *credentials); | |
118 | ||
2c5ff4e4 JG |
119 | enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials( |
120 | struct lttng_trace_chunk *chunk, | |
121 | const struct lttng_credentials *credentials); | |
122 | ||
2c5ff4e4 JG |
123 | enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials_current_user( |
124 | struct lttng_trace_chunk *chunk); | |
125 | ||
2c5ff4e4 JG |
126 | enum lttng_trace_chunk_status lttng_trace_chunk_set_as_owner( |
127 | struct lttng_trace_chunk *chunk, | |
128 | struct lttng_directory_handle *session_output_directory); | |
129 | ||
2c5ff4e4 JG |
130 | enum lttng_trace_chunk_status lttng_trace_chunk_set_as_user( |
131 | struct lttng_trace_chunk *chunk, | |
132 | struct lttng_directory_handle *chunk_directory); | |
133 | ||
7ceefac4 JG |
134 | enum lttng_trace_chunk_status |
135 | lttng_trace_chunk_get_session_output_directory_handle( | |
136 | struct lttng_trace_chunk *chunk, | |
137 | struct lttng_directory_handle **handle); | |
138 | ||
cbf53d23 | 139 | enum lttng_trace_chunk_status lttng_trace_chunk_borrow_chunk_directory_handle( |
2c5ff4e4 JG |
140 | struct lttng_trace_chunk *chunk, |
141 | const struct lttng_directory_handle **handle); | |
142 | ||
2c5ff4e4 JG |
143 | enum lttng_trace_chunk_status lttng_trace_chunk_create_subdirectory( |
144 | struct lttng_trace_chunk *chunk, | |
145 | const char *subdirectory_path); | |
146 | ||
2c5ff4e4 | 147 | enum lttng_trace_chunk_status lttng_trace_chunk_open_file( |
8bb66c3c JG |
148 | struct lttng_trace_chunk *chunk, |
149 | const char *filename, | |
150 | int flags, | |
151 | mode_t mode, | |
152 | int *out_fd, | |
153 | bool expect_no_file); | |
154 | ||
8bb66c3c JG |
155 | enum lttng_trace_chunk_status lttng_trace_chunk_open_fs_handle( |
156 | struct lttng_trace_chunk *chunk, | |
157 | const char *filename, | |
158 | int flags, | |
159 | mode_t mode, | |
160 | struct fs_handle **out_handle, | |
161 | bool expect_no_file); | |
2c5ff4e4 | 162 | |
2c5ff4e4 JG |
163 | int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk *chunk, |
164 | const char *filename); | |
165 | ||
bbc4768c JG |
166 | enum lttng_trace_chunk_status lttng_trace_chunk_get_close_command( |
167 | struct lttng_trace_chunk *chunk, | |
168 | enum lttng_trace_chunk_command_type *command_type); | |
169 | ||
2c5ff4e4 JG |
170 | enum lttng_trace_chunk_status lttng_trace_chunk_set_close_command( |
171 | struct lttng_trace_chunk *chunk, | |
172 | enum lttng_trace_chunk_command_type command_type); | |
173 | ||
bbc4768c JG |
174 | const char *lttng_trace_chunk_command_type_get_name( |
175 | enum lttng_trace_chunk_command_type command); | |
176 | ||
ad8bec24 JG |
177 | bool lttng_trace_chunk_ids_equal(const struct lttng_trace_chunk *chunk_a, |
178 | const struct lttng_trace_chunk *chunk_b); | |
179 | ||
2c5ff4e4 | 180 | /* Returns true on success. */ |
2c5ff4e4 JG |
181 | bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk); |
182 | ||
2c5ff4e4 JG |
183 | void lttng_trace_chunk_put(struct lttng_trace_chunk *chunk); |
184 | ||
185 | #endif /* LTTNG_TRACE_CHUNK_H */ |