Fix: ust-consumer.c: Double unlock of channel lock
[lttng-tools.git] / src / common / trace-chunk.h
CommitLineData
1545fd17
JG
1/*
2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
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.
7 *
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
11 * for more details.
12 *
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
16 */
17
18#ifndef LTTNG_TRACE_CHUNK_H
19#define LTTNG_TRACE_CHUNK_H
20
21#include <common/macros.h>
22#include <common/credentials.h>
23#include <common/compat/directory-handle.h>
24#include <stddef.h>
25#include <stdint.h>
26#include <stdbool.h>
27
28/*
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.
32 *
33 * A trace chunk is always contained within a session output directory.
34 *
35 * This facility is used by the session daemon, consumer daemon(s), and relay
36 * daemon to:
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,
41 * deleted, etc.
42 *
43 *
44 * OWNER VS USER
45 * ---
46 *
47 * A trace chunk can either be a owner or a user of its
48 * "chunk output directory".
49 *
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.
52 *
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
55 * or deleting it.
56 *
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
60 * trace chunk.
61 */
62
63struct lttng_trace_chunk;
64
65enum 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,
71};
72
73enum lttng_trace_chunk_command_type {
74 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED = 0,
75 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX
76};
77
78LTTNG_HIDDEN
79struct lttng_trace_chunk *lttng_trace_chunk_create_anonymous(void);
80
81LTTNG_HIDDEN
82struct lttng_trace_chunk *lttng_trace_chunk_create(
83 uint64_t chunk_id,
84 time_t chunk_creation_time);
85
6b65aac1
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
1545fd17
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,
d83dccf5 114 bool *name_overridden);
1545fd17
JG
115
116LTTNG_HIDDEN
117enum lttng_trace_chunk_status lttng_trace_chunk_override_name(
118 struct lttng_trace_chunk *chunk, const char *name);
119
120LTTNG_HIDDEN
121enum lttng_trace_chunk_status lttng_trace_chunk_get_credentials(
122 struct lttng_trace_chunk *chunk,
123 struct lttng_credentials *credentials);
124
125LTTNG_HIDDEN
126enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials(
127 struct lttng_trace_chunk *chunk,
128 const struct lttng_credentials *credentials);
129
130LTTNG_HIDDEN
131enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials_current_user(
132 struct lttng_trace_chunk *chunk);
133
134/* session_output_directory ownership is transferred to the chunk on success. */
135LTTNG_HIDDEN
136enum lttng_trace_chunk_status lttng_trace_chunk_set_as_owner(
137 struct lttng_trace_chunk *chunk,
138 struct lttng_directory_handle *session_output_directory);
139
140/* chunk_output_directory ownership is transferred to the chunk on success. */
141LTTNG_HIDDEN
142enum lttng_trace_chunk_status lttng_trace_chunk_set_as_user(
143 struct lttng_trace_chunk *chunk,
144 struct lttng_directory_handle *chunk_directory);
145
146LTTNG_HIDDEN
147enum lttng_trace_chunk_status lttng_trace_chunk_get_chunk_directory_handle(
148 struct lttng_trace_chunk *chunk,
149 const struct lttng_directory_handle **handle);
150
151LTTNG_HIDDEN
152enum lttng_trace_chunk_status lttng_trace_chunk_create_subdirectory(
153 struct lttng_trace_chunk *chunk,
154 const char *subdirectory_path);
155
156LTTNG_HIDDEN
157enum lttng_trace_chunk_status lttng_trace_chunk_open_file(
158 struct lttng_trace_chunk *chunk, const char *filename,
159 int flags, mode_t mode, int *out_fd);
160
161LTTNG_HIDDEN
162int lttng_trace_chunk_unlink_file(struct lttng_trace_chunk *chunk,
163 const char *filename);
164
6bbcff33
JG
165LTTNG_HIDDEN
166enum 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);
169
1545fd17
JG
170LTTNG_HIDDEN
171enum lttng_trace_chunk_status lttng_trace_chunk_set_close_command(
172 struct lttng_trace_chunk *chunk,
173 enum lttng_trace_chunk_command_type command_type);
174
6bbcff33
JG
175LTTNG_HIDDEN
176const char *lttng_trace_chunk_command_type_get_name(
177 enum lttng_trace_chunk_command_type command);
178
1545fd17
JG
179/* Returns true on success. */
180LTTNG_HIDDEN
181bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk);
182
183LTTNG_HIDDEN
184void lttng_trace_chunk_put(struct lttng_trace_chunk *chunk);
185
186#endif /* LTTNG_TRACE_CHUNK_H */
This page took 0.048367 seconds and 4 git commands to generate.