2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef LTTNG_TRACE_CHUNK_H
19 #define LTTNG_TRACE_CHUNK_H
21 #include <common/macros.h>
22 #include <common/credentials.h>
23 #include <common/compat/directory-handle.h>
29 * A trace chunk is a group of directories and files forming a (or a set of)
30 * complete and independant trace(s). For instance, a trace archive chunk,
31 * a snapshot, or a regular LTTng trace are all instances of a trace archive.
33 * A trace chunk is always contained within a session output directory.
35 * This facility is used by the session daemon, consumer daemon(s), and relay
37 * - Control file (data stream, metadata, and index) creation relative to
38 * a given output directory,
39 * - Track the use of an output directory by other objects in order to
40 * know if/when an output directory can be safely consumed, renamed,
47 * A trace chunk can either be a owner or a user of its
48 * "chunk output directory".
50 * A "user" trace chunk is provided with a handle to the chunk output directory
51 * which can then be used to create subdirectories and files.
53 * An "owner" chunk, on top of being able to perform the operations of a "user"
54 * chunk can perform operations on its chunk output directory, such as renaming
57 * A trace chunk becomes an "owner" or "user" chunk based on which of
58 * 'lttng_trace_chunk_set_as_owner()' or 'lttng_trace_chunk_set_as_user()' is
59 * used. These methods are _exclusive_ and must only be used once on a
63 struct lttng_trace_chunk
;
65 enum lttng_trace_chunk_status
{
66 LTTNG_TRACE_CHUNK_STATUS_OK
,
67 LTTNG_TRACE_CHUNK_STATUS_NONE
,
68 LTTNG_TRACE_CHUNK_STATUS_INVALID_ARGUMENT
,
69 LTTNG_TRACE_CHUNK_STATUS_INVALID_OPERATION
,
70 LTTNG_TRACE_CHUNK_STATUS_ERROR
,
73 enum lttng_trace_chunk_command_type
{
74 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED
= 0,
75 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX
79 struct lttng_trace_chunk
*lttng_trace_chunk_create_anonymous(void);
82 struct lttng_trace_chunk
*lttng_trace_chunk_create(
84 time_t chunk_creation_time
);
87 enum lttng_trace_chunk_status
lttng_trace_chunk_get_id(
88 struct lttng_trace_chunk
*chunk
, uint64_t *id
);
91 enum lttng_trace_chunk_status
lttng_trace_chunk_get_creation_timestamp(
92 struct lttng_trace_chunk
*chunk
, time_t *creation_ts
);
95 enum lttng_trace_chunk_status
lttng_trace_chunk_get_close_timestamp(
96 struct lttng_trace_chunk
*chunk
, time_t *close_ts
);
99 enum lttng_trace_chunk_status
lttng_trace_chunk_set_close_timestamp(
100 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
);
108 enum lttng_trace_chunk_status
lttng_trace_chunk_override_name(
109 struct lttng_trace_chunk
*chunk
, const char *name
);
112 enum lttng_trace_chunk_status
lttng_trace_chunk_get_credentials(
113 struct lttng_trace_chunk
*chunk
,
114 struct lttng_credentials
*credentials
);
117 enum lttng_trace_chunk_status
lttng_trace_chunk_set_credentials(
118 struct lttng_trace_chunk
*chunk
,
119 const struct lttng_credentials
*credentials
);
122 enum lttng_trace_chunk_status
lttng_trace_chunk_set_credentials_current_user(
123 struct lttng_trace_chunk
*chunk
);
125 /* session_output_directory ownership is transferred to the chunk on success. */
127 enum lttng_trace_chunk_status
lttng_trace_chunk_set_as_owner(
128 struct lttng_trace_chunk
*chunk
,
129 struct lttng_directory_handle
*session_output_directory
);
131 /* chunk_output_directory ownership is transferred to the chunk on success. */
133 enum lttng_trace_chunk_status
lttng_trace_chunk_set_as_user(
134 struct lttng_trace_chunk
*chunk
,
135 struct lttng_directory_handle
*chunk_directory
);
138 enum lttng_trace_chunk_status
lttng_trace_chunk_get_chunk_directory_handle(
139 struct lttng_trace_chunk
*chunk
,
140 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
);
148 enum lttng_trace_chunk_status
lttng_trace_chunk_open_file(
149 struct lttng_trace_chunk
*chunk
, const char *filename
,
150 int flags
, mode_t mode
, int *out_fd
);
153 int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk
*chunk
,
154 const char *filename
);
157 enum lttng_trace_chunk_status
lttng_trace_chunk_get_close_command(
158 struct lttng_trace_chunk
*chunk
,
159 enum lttng_trace_chunk_command_type
*command_type
);
162 enum lttng_trace_chunk_status
lttng_trace_chunk_set_close_command(
163 struct lttng_trace_chunk
*chunk
,
164 enum lttng_trace_chunk_command_type command_type
);
167 const char *lttng_trace_chunk_command_type_get_name(
168 enum lttng_trace_chunk_command_type command
);
170 /* Returns true on success. */
172 bool lttng_trace_chunk_get(struct lttng_trace_chunk
*chunk
);
175 void lttng_trace_chunk_put(struct lttng_trace_chunk
*chunk
);
177 #endif /* LTTNG_TRACE_CHUNK_H */