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_REGISTRY_H
9 #define LTTNG_TRACE_CHUNK_REGISTRY_H
14 #include <common/macros.h>
15 #include <common/trace-chunk.h>
17 struct lttng_trace_chunk_registry
;
20 * Create an lttng_trace_chunk registry.
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.
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.
30 * Returns a trace chunk registry on success, NULL on error.
32 * Note that a trace chunk registry may only be accessed by an RCU thread.
35 struct lttng_trace_chunk_registry
*lttng_trace_chunk_registry_create(void);
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
43 void lttng_trace_chunk_registry_destroy(
44 struct lttng_trace_chunk_registry
*registry
);
47 * Publish a trace chunk for a given session id.
48 * A reference is acquired on behalf of the caller.
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.
54 * See the documentation of lttng_trace_chunk for more information on
55 * the usage of the various parameters.
57 * Returns an lttng_trace_chunk on success, NULL on error.
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
);
65 * Adds the `previously_published` parameter which allows the caller
66 * to know if a trace chunk equivalent to `chunk` was previously published.
68 * The registry holds a reference to the published trace chunks it contains.
69 * Trace chunks automatically unpublish themselves from their registry on
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.
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`.
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
);
89 * Look-up a trace chunk by session_id and chunk_id.
90 * A reference is acquired on behalf of the caller.
92 * Returns an lttng_trace_chunk on success, NULL if the chunk does not exist.
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
);
101 * Query the existence of a trace chunk by session_id and chunk_id.
103 * Returns 0 on success, a negative value on error.
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
);
111 * Look-up an anonymous trace chunk by session_id.
112 * A reference is acquired on behalf of the caller.
114 * Returns an lttng_trace_chunk on success, NULL if the chunk does not exist.
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
);
123 unsigned int lttng_trace_chunk_registry_put_each_chunk(
124 const struct lttng_trace_chunk_registry
*registry
);
126 #endif /* LTTNG_TRACE_CHUNK_REGISTRY_H */