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
,
73 struct lttng_trace_chunk
*lttng_trace_chunk_create_anonymous(void);
75 struct lttng_trace_chunk
*lttng_trace_chunk_create(
77 time_t chunk_creation_time
,
80 void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk
*chunk
,
81 struct fd_tracker
*fd_tracker
);
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.
88 struct lttng_trace_chunk
*lttng_trace_chunk_copy(
89 struct lttng_trace_chunk
*source_chunk
);
91 enum lttng_trace_chunk_status
lttng_trace_chunk_get_id(
92 struct lttng_trace_chunk
*chunk
, uint64_t *id
);
94 enum lttng_trace_chunk_status
lttng_trace_chunk_get_creation_timestamp(
95 struct lttng_trace_chunk
*chunk
, time_t *creation_ts
);
97 enum lttng_trace_chunk_status
lttng_trace_chunk_get_close_timestamp(
98 struct lttng_trace_chunk
*chunk
, time_t *close_ts
);
100 enum lttng_trace_chunk_status
lttng_trace_chunk_set_close_timestamp(
101 struct lttng_trace_chunk
*chunk
, time_t close_ts
);
103 enum lttng_trace_chunk_status
lttng_trace_chunk_get_name(
104 struct lttng_trace_chunk
*chunk
, const char **name
,
105 bool *name_overridden
);
107 bool lttng_trace_chunk_get_name_overridden(struct lttng_trace_chunk
*chunk
);
109 enum lttng_trace_chunk_status
lttng_trace_chunk_override_name(
110 struct lttng_trace_chunk
*chunk
, const char *name
);
112 enum lttng_trace_chunk_status
lttng_trace_chunk_rename_path(
113 struct lttng_trace_chunk
*chunk
, const char *path
);
115 enum lttng_trace_chunk_status
lttng_trace_chunk_get_credentials(
116 struct lttng_trace_chunk
*chunk
,
117 struct lttng_credentials
*credentials
);
119 enum lttng_trace_chunk_status
lttng_trace_chunk_set_credentials(
120 struct lttng_trace_chunk
*chunk
,
121 const struct lttng_credentials
*credentials
);
123 enum lttng_trace_chunk_status
lttng_trace_chunk_set_credentials_current_user(
124 struct lttng_trace_chunk
*chunk
);
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
);
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
);
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
);
139 enum lttng_trace_chunk_status
lttng_trace_chunk_borrow_chunk_directory_handle(
140 struct lttng_trace_chunk
*chunk
,
141 const struct lttng_directory_handle
**handle
);
143 enum lttng_trace_chunk_status
lttng_trace_chunk_create_subdirectory(
144 struct lttng_trace_chunk
*chunk
,
145 const char *subdirectory_path
);
147 enum lttng_trace_chunk_status
lttng_trace_chunk_open_file(
148 struct lttng_trace_chunk
*chunk
,
149 const char *filename
,
153 bool expect_no_file
);
155 enum lttng_trace_chunk_status
lttng_trace_chunk_open_fs_handle(
156 struct lttng_trace_chunk
*chunk
,
157 const char *filename
,
160 struct fs_handle
**out_handle
,
161 bool expect_no_file
);
163 int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk
*chunk
,
164 const char *filename
);
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
);
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
);
174 const char *lttng_trace_chunk_command_type_get_name(
175 enum lttng_trace_chunk_command_type command
);
177 bool lttng_trace_chunk_ids_equal(const struct lttng_trace_chunk
*chunk_a
,
178 const struct lttng_trace_chunk
*chunk_b
);
180 /* Returns true on success. */
181 bool lttng_trace_chunk_get(struct lttng_trace_chunk
*chunk
);
183 void lttng_trace_chunk_put(struct lttng_trace_chunk
*chunk
);
185 #endif /* LTTNG_TRACE_CHUNK_H */