2 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRACE_CHUNK_H
9 #define LTTNG_TRACE_CHUNK_H
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>
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.
24 * A trace chunk is always contained within a session output directory.
26 * This facility is used by the session daemon, consumer daemon(s), and relay
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,
38 * A trace chunk can either be a owner or a user of its
39 * "chunk output directory".
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.
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
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
54 struct lttng_trace_chunk
;
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
,
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
,
74 struct lttng_trace_chunk
*lttng_trace_chunk_create_anonymous(void);
77 struct lttng_trace_chunk
*lttng_trace_chunk_create(
79 time_t chunk_creation_time
,
83 void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk
*chunk
,
84 struct fd_tracker
*fd_tracker
);
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.
92 struct lttng_trace_chunk
*lttng_trace_chunk_copy(
93 struct lttng_trace_chunk
*source_chunk
);
96 enum lttng_trace_chunk_status
lttng_trace_chunk_get_id(
97 struct lttng_trace_chunk
*chunk
, uint64_t *id
);
100 enum lttng_trace_chunk_status
lttng_trace_chunk_get_creation_timestamp(
101 struct lttng_trace_chunk
*chunk
, time_t *creation_ts
);
104 enum lttng_trace_chunk_status
lttng_trace_chunk_get_close_timestamp(
105 struct lttng_trace_chunk
*chunk
, time_t *close_ts
);
108 enum lttng_trace_chunk_status
lttng_trace_chunk_set_close_timestamp(
109 struct lttng_trace_chunk
*chunk
, time_t close_ts
);
112 enum lttng_trace_chunk_status
lttng_trace_chunk_get_name(
113 struct lttng_trace_chunk
*chunk
, const char **name
,
114 bool *name_overridden
);
117 bool lttng_trace_chunk_get_name_overridden(struct lttng_trace_chunk
*chunk
);
120 enum lttng_trace_chunk_status
lttng_trace_chunk_override_name(
121 struct lttng_trace_chunk
*chunk
, const char *name
);
124 enum lttng_trace_chunk_status
lttng_trace_chunk_rename_path(
125 struct lttng_trace_chunk
*chunk
, const char *path
);
128 enum lttng_trace_chunk_status
lttng_trace_chunk_get_credentials(
129 struct lttng_trace_chunk
*chunk
,
130 struct lttng_credentials
*credentials
);
133 enum lttng_trace_chunk_status
lttng_trace_chunk_set_credentials(
134 struct lttng_trace_chunk
*chunk
,
135 const struct lttng_credentials
*credentials
);
138 enum lttng_trace_chunk_status
lttng_trace_chunk_set_credentials_current_user(
139 struct lttng_trace_chunk
*chunk
);
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
);
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
);
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
);
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
);
163 enum lttng_trace_chunk_status
lttng_trace_chunk_create_subdirectory(
164 struct lttng_trace_chunk
*chunk
,
165 const char *subdirectory_path
);
168 enum lttng_trace_chunk_status
lttng_trace_chunk_open_file(
169 struct lttng_trace_chunk
*chunk
,
170 const char *filename
,
174 bool expect_no_file
);
177 enum lttng_trace_chunk_status
lttng_trace_chunk_open_fs_handle(
178 struct lttng_trace_chunk
*chunk
,
179 const char *filename
,
182 struct fs_handle
**out_handle
,
183 bool expect_no_file
);
186 int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk
*chunk
,
187 const char *filename
);
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
);
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
);
200 const char *lttng_trace_chunk_command_type_get_name(
201 enum lttng_trace_chunk_command_type command
);
204 bool lttng_trace_chunk_ids_equal(const struct lttng_trace_chunk
*chunk_a
,
205 const struct lttng_trace_chunk
*chunk_b
);
207 /* Returns true on success. */
209 bool lttng_trace_chunk_get(struct lttng_trace_chunk
*chunk
);
212 void lttng_trace_chunk_put(struct lttng_trace_chunk
*chunk
);
214 #endif /* LTTNG_TRACE_CHUNK_H */