liblttng-ctl: hide MI trigger command variables
[lttng-tools.git] / src / common / trace-chunk.h
CommitLineData
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
54struct lttng_trace_chunk;
b2621f79 55struct fd_tracker;
2c5ff4e4
JG
56
57enum 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
66enum 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
73LTTNG_HIDDEN
74struct lttng_trace_chunk *lttng_trace_chunk_create_anonymous(void);
75
76LTTNG_HIDDEN
77struct 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
82LTTNG_HIDDEN
83void 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 */
91LTTNG_HIDDEN
92struct lttng_trace_chunk *lttng_trace_chunk_copy(
93 struct lttng_trace_chunk *source_chunk);
94
2c5ff4e4
JG
95LTTNG_HIDDEN
96enum lttng_trace_chunk_status lttng_trace_chunk_get_id(
97 struct lttng_trace_chunk *chunk, uint64_t *id);
98
99LTTNG_HIDDEN
100enum lttng_trace_chunk_status lttng_trace_chunk_get_creation_timestamp(
101 struct lttng_trace_chunk *chunk, time_t *creation_ts);
102
103LTTNG_HIDDEN
104enum lttng_trace_chunk_status lttng_trace_chunk_get_close_timestamp(
105 struct lttng_trace_chunk *chunk, time_t *close_ts);
106
107LTTNG_HIDDEN
108enum lttng_trace_chunk_status lttng_trace_chunk_set_close_timestamp(
109 struct lttng_trace_chunk *chunk, time_t close_ts);
110
111LTTNG_HIDDEN
112enum 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
116LTTNG_HIDDEN
117bool lttng_trace_chunk_get_name_overridden(struct lttng_trace_chunk *chunk);
118
2c5ff4e4
JG
119LTTNG_HIDDEN
120enum lttng_trace_chunk_status lttng_trace_chunk_override_name(
121 struct lttng_trace_chunk *chunk, const char *name);
122
a7ceb342
MD
123LTTNG_HIDDEN
124enum lttng_trace_chunk_status lttng_trace_chunk_rename_path(
125 struct lttng_trace_chunk *chunk, const char *path);
126
2c5ff4e4
JG
127LTTNG_HIDDEN
128enum lttng_trace_chunk_status lttng_trace_chunk_get_credentials(
129 struct lttng_trace_chunk *chunk,
130 struct lttng_credentials *credentials);
131
132LTTNG_HIDDEN
133enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials(
134 struct lttng_trace_chunk *chunk,
135 const struct lttng_credentials *credentials);
136
137LTTNG_HIDDEN
138enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials_current_user(
139 struct lttng_trace_chunk *chunk);
140
2c5ff4e4
JG
141LTTNG_HIDDEN
142enum 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
146LTTNG_HIDDEN
147enum 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
151LTTNG_HIDDEN
152enum lttng_trace_chunk_status
153lttng_trace_chunk_get_session_output_directory_handle(
154 struct lttng_trace_chunk *chunk,
155 struct lttng_directory_handle **handle);
156
2c5ff4e4 157LTTNG_HIDDEN
cbf53d23 158enum 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
162LTTNG_HIDDEN
163enum lttng_trace_chunk_status lttng_trace_chunk_create_subdirectory(
164 struct lttng_trace_chunk *chunk,
165 const char *subdirectory_path);
166
167LTTNG_HIDDEN
168enum 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
176LTTNG_HIDDEN
177enum 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
185LTTNG_HIDDEN
186int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk *chunk,
187 const char *filename);
188
bbc4768c
JG
189LTTNG_HIDDEN
190enum 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
194LTTNG_HIDDEN
195enum 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
199LTTNG_HIDDEN
200const char *lttng_trace_chunk_command_type_get_name(
201 enum lttng_trace_chunk_command_type command);
202
ad8bec24
JG
203LTTNG_HIDDEN
204bool 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. */
208LTTNG_HIDDEN
209bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk);
210
211LTTNG_HIDDEN
212void lttng_trace_chunk_put(struct lttng_trace_chunk *chunk);
213
214#endif /* LTTNG_TRACE_CHUNK_H */
This page took 0.05148 seconds and 5 git commands to generate.