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.hpp>
15 #include <common/trace-chunk.hpp>
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.
34 struct lttng_trace_chunk_registry *lttng_trace_chunk_registry_create(void);
37 * Destroy an lttng trace chunk registry. The registry must be emptied
38 * (i.e. all references to the trace chunks it contains must be released) before
41 void lttng_trace_chunk_registry_destroy(
42 struct lttng_trace_chunk_registry *registry);
45 * Publish a trace chunk for a given session id.
46 * A reference is acquired on behalf of the caller.
48 * The trace chunk that is returned is the published version of the trace
49 * chunk. The chunk provided should be discarded on success and it's
50 * published version used in its place.
52 * See the documentation of lttng_trace_chunk for more information on
53 * the usage of the various parameters.
55 * Returns an lttng_trace_chunk on success, NULL on error.
57 struct lttng_trace_chunk *lttng_trace_chunk_registry_publish_chunk(
58 struct lttng_trace_chunk_registry *registry,
59 uint64_t session_id, struct lttng_trace_chunk *chunk);
61 * Adds the `previously_published` parameter which allows the caller
62 * to know if a trace chunk equivalent to `chunk` was previously published.
64 * The registry holds a reference to the published trace chunks it contains.
65 * Trace chunks automatically unpublish themselves from their registry on
68 * This information is necessary to drop the reference of newly published
69 * chunks when a user doesn't wish to explicitly maintain all references
70 * to a given trace chunk.
72 * For instance, the relay daemon doesn't need the registry to hold a
73 * reference since it controls the lifetime of its trace chunks.
74 * Conversely, the consumer daemons rely on the session daemon to inform
75 * them of the end of life of a trace chunk and the trace chunks don't
76 * belong to a specific top-level object: they are always retrieved from
77 * the registry by `id`.
79 struct lttng_trace_chunk *lttng_trace_chunk_registry_publish_chunk(
80 struct lttng_trace_chunk_registry *registry,
81 uint64_t session_id, struct lttng_trace_chunk *chunk,
82 bool *previously_published);
85 * Look-up a trace chunk by session_id and chunk_id.
86 * A reference is acquired on behalf of the caller.
88 * Returns an lttng_trace_chunk on success, NULL if the chunk does not exist.
90 struct lttng_trace_chunk *
91 lttng_trace_chunk_registry_find_chunk(
92 const struct lttng_trace_chunk_registry *registry,
93 uint64_t session_id, uint64_t chunk_id);
96 * Query the existence of a trace chunk by session_id and chunk_id.
98 * Returns 0 on success, a negative value on error.
100 int lttng_trace_chunk_registry_chunk_exists(
101 const struct lttng_trace_chunk_registry *registry,
102 uint64_t session_id, uint64_t chunk_id, bool *chunk_exists);
105 * Look-up an anonymous trace chunk by session_id.
106 * A reference is acquired on behalf of the caller.
108 * Returns an lttng_trace_chunk on success, NULL if the chunk does not exist.
110 struct lttng_trace_chunk *
111 lttng_trace_chunk_registry_find_anonymous_chunk(
112 const struct lttng_trace_chunk_registry *registry,
113 uint64_t session_id);
115 unsigned int lttng_trace_chunk_registry_put_each_chunk(
116 const struct lttng_trace_chunk_registry *registry);
118 #endif /* LTTNG_TRACE_CHUNK_REGISTRY_H */