Fix: relayd: rotation failure for multi-domain session
[lttng-tools.git] / src / common / trace-chunk-registry.h
1 /*
2 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_TRACE_CHUNK_REGISTRY_H
9 #define LTTNG_TRACE_CHUNK_REGISTRY_H
10
11 #include <stddef.h>
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <common/macros.h>
15 #include <common/trace-chunk.h>
16
17 struct lttng_trace_chunk_registry;
18
19 /*
20 * Create an lttng_trace_chunk registry.
21 *
22 * A trace chunk registry maintains an association between a
23 * (session_id, chunk_id) tuple and a trace chunk object. The chunk_id can
24 * be "unset" in the case of an anonymous trace chunk.
25 *
26 * Note that a trace chunk registry holds no ownership of its trace
27 * chunks. Trace chunks are unpublished when their last reference is released.
28 * See the documentation of lttng_trace_chunk.
29 *
30 * Returns a trace chunk registry on success, NULL on error.
31 *
32 * Note that a trace chunk registry may only be accessed by an RCU thread.
33 */
34 LTTNG_HIDDEN
35 struct lttng_trace_chunk_registry *lttng_trace_chunk_registry_create(void);
36
37 /*
38 * Destroy an lttng trace chunk registry. The registry must be emptied
39 * (i.e. all references to the trace chunks it contains must be released) before
40 * it is destroyed.
41 */
42 LTTNG_HIDDEN
43 void lttng_trace_chunk_registry_destroy(
44 struct lttng_trace_chunk_registry *registry);
45
46 /*
47 * Publish a trace chunk for a given session id.
48 * A reference is acquired on behalf of the caller.
49 *
50 * The trace chunk that is returned is the published version of the trace
51 * chunk. The chunk provided should be discarded on success and it's
52 * published version used in its place.
53 *
54 * See the documentation of lttng_trace_chunk for more information on
55 * the usage of the various parameters.
56 *
57 * Returns an lttng_trace_chunk on success, NULL on error.
58 */
59 LTTNG_HIDDEN
60 struct lttng_trace_chunk *lttng_trace_chunk_registry_publish_chunk(
61 struct lttng_trace_chunk_registry *registry,
62 uint64_t session_id, struct lttng_trace_chunk *chunk);
63
64 /*
65 * Adds the `previously_published` parameter which allows the caller
66 * to know if a trace chunk equivalent to `chunk` was previously published.
67 *
68 * The registry holds a reference to the published trace chunks it contains.
69 * Trace chunks automatically unpublish themselves from their registry on
70 * destruction.
71 *
72 * This information is necessary to drop the reference of newly published
73 * chunks when a user doesn't wish to explicitly maintain all references
74 * to a given trace chunk.
75 *
76 * For instance, the relay daemon doesn't need the registry to hold a
77 * reference since it controls the lifetime of its trace chunks.
78 * Conversely, the consumer daemons rely on the session daemon to inform
79 * them of the end of life of a trace chunk and the trace chunks don't
80 * belong to a specific top-level object: they are always retrieved from
81 * the registry by `id`.
82 */
83 struct lttng_trace_chunk *lttng_trace_chunk_registry_publish_chunk_published(
84 struct lttng_trace_chunk_registry *registry,
85 uint64_t session_id, struct lttng_trace_chunk *chunk,
86 bool *previously_published);
87
88 /*
89 * Look-up a trace chunk by session_id and chunk_id.
90 * A reference is acquired on behalf of the caller.
91 *
92 * Returns an lttng_trace_chunk on success, NULL if the chunk does not exist.
93 */
94 LTTNG_HIDDEN
95 struct lttng_trace_chunk *
96 lttng_trace_chunk_registry_find_chunk(
97 const struct lttng_trace_chunk_registry *registry,
98 uint64_t session_id, uint64_t chunk_id);
99
100 /*
101 * Query the existence of a trace chunk by session_id and chunk_id.
102 *
103 * Returns 0 on success, a negative value on error.
104 */
105 LTTNG_HIDDEN
106 int lttng_trace_chunk_registry_chunk_exists(
107 const struct lttng_trace_chunk_registry *registry,
108 uint64_t session_id, uint64_t chunk_id, bool *chunk_exists);
109
110 /*
111 * Look-up an anonymous trace chunk by session_id.
112 * A reference is acquired on behalf of the caller.
113 *
114 * Returns an lttng_trace_chunk on success, NULL if the chunk does not exist.
115 */
116 LTTNG_HIDDEN
117 struct lttng_trace_chunk *
118 lttng_trace_chunk_registry_find_anonymous_chunk(
119 const struct lttng_trace_chunk_registry *registry,
120 uint64_t session_id);
121
122 LTTNG_HIDDEN
123 unsigned int lttng_trace_chunk_registry_put_each_chunk(
124 const struct lttng_trace_chunk_registry *registry);
125
126 #endif /* LTTNG_TRACE_CHUNK_REGISTRY_H */
This page took 0.032931 seconds and 5 git commands to generate.