Fix: lttng-ctl: _handle can be NULL
[lttng-tools.git] / src / common / trace-chunk.h
1 /*
2 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_TRACE_CHUNK_H
9 #define LTTNG_TRACE_CHUNK_H
10
11 #include <common/compat/directory-handle.h>
12 #include <common/credentials.h>
13 #include <common/fd-tracker/fd-tracker.h>
14 #include <common/macros.h>
15 #include <stdbool.h>
16 #include <stddef.h>
17 #include <stdint.h>
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;
55 struct fd_tracker;
56
57 enum lttng_trace_chunk_status {
58 LTTNG_TRACE_CHUNK_STATUS_OK,
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,
63 LTTNG_TRACE_CHUNK_STATUS_NO_FILE,
64 };
65
66 enum lttng_trace_chunk_command_type {
67 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED = 0,
68 LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION = 1,
69 LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE = 2,
70 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX,
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,
79 time_t chunk_creation_time,
80 const char *path);
81
82 LTTNG_HIDDEN
83 void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk *chunk,
84 struct fd_tracker *fd_tracker);
85
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
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,
114 bool *name_overridden);
115
116 LTTNG_HIDDEN
117 bool lttng_trace_chunk_get_name_overridden(struct lttng_trace_chunk *chunk);
118
119 LTTNG_HIDDEN
120 enum lttng_trace_chunk_status lttng_trace_chunk_override_name(
121 struct lttng_trace_chunk *chunk, const char *name);
122
123 LTTNG_HIDDEN
124 enum lttng_trace_chunk_status lttng_trace_chunk_rename_path(
125 struct lttng_trace_chunk *chunk, const char *path);
126
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
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
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
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
157 LTTNG_HIDDEN
158 enum lttng_trace_chunk_status lttng_trace_chunk_borrow_chunk_directory_handle(
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(
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);
184
185 LTTNG_HIDDEN
186 int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk *chunk,
187 const char *filename);
188
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
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
199 LTTNG_HIDDEN
200 const char *lttng_trace_chunk_command_type_get_name(
201 enum lttng_trace_chunk_command_type command);
202
203 /* Returns true on success. */
204 LTTNG_HIDDEN
205 bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk);
206
207 LTTNG_HIDDEN
208 void lttng_trace_chunk_put(struct lttng_trace_chunk *chunk);
209
210 #endif /* LTTNG_TRACE_CHUNK_H */
This page took 0.035128 seconds and 4 git commands to generate.