Clean-up: sessiond: rename public accessors
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry-session.hpp
CommitLineData
b0f2e8db
JG
1/*
2 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#ifndef LTTNG_UST_REGISTRY_SESSION_H
9#define LTTNG_UST_REGISTRY_SESSION_H
10
11#include "clock-class.hpp"
12#include "session.hpp"
13#include "trace-class.hpp"
14#include "ust-clock-class.hpp"
15#include "ust-registry-channel.hpp"
97f630d4 16#include "ust-registry.hpp"
b0f2e8db
JG
17
18#include <common/make-unique-wrapper.hpp>
19
20#include <cstdint>
21#include <ctime>
22#include <lttng/lttng.h>
23#include <string>
24#include <unistd.h>
25
26namespace lttng {
27namespace sessiond {
28namespace ust {
29
97f630d4 30class registry_enum;
b0f2e8db
JG
31class registry_session;
32
33namespace details {
34void locked_registry_session_release(registry_session *session);
35} /* namespace details */
36
37class registry_session : public lttng::sessiond::trace::trace_class {
38public:
39 using locked_ptr = std::unique_ptr<registry_session,
40 lttng::details::create_unique_class<registry_session,
41 details::locked_registry_session_release>::
42 deleter>;
43
4bcf2294 44 virtual lttng_buffer_type buffering_scheme() const noexcept = 0;
97f630d4 45 locked_ptr lock() noexcept;
b0f2e8db
JG
46
47 void add_channel(uint64_t channel_key);
97f630d4
JG
48
49 /* A channel is protected by its parent registry session's lock. */
4bcf2294 50 lttng::sessiond::ust::registry_channel& channel(uint64_t channel_key) const;
97f630d4 51
b0f2e8db
JG
52 void remove_channel(uint64_t channel_key, bool notify);
53
97f630d4
JG
54 void create_or_find_enum(int session_objd,
55 const char *enum_name,
56 struct lttng_ust_ctl_enum_entry *raw_entries,
57 size_t nr_entries,
58 uint64_t *enum_id);
4bcf2294 59 registry_enum::const_rcu_protected_reference enumeration(
97f630d4
JG
60 const char *enum_name, uint64_t enum_id) const;
61
b0f2e8db
JG
62 void regenerate_metadata();
63 virtual ~registry_session();
64
4bcf2294 65 virtual const lttng::sessiond::trace::type *packet_header() const noexcept override;
24ed18f2 66
b0f2e8db
JG
67 /*
68 * With multiple writers and readers, use this lock to access
69 * the registry. Can nest within the ust app session lock.
70 * Also acts as a registry serialization lock. Used by registry
71 * readers to serialize the registry information sent from the
72 * sessiond to the consumerd.
97f630d4 73 *
b0f2e8db
JG
74 * The consumer socket lock nests within this lock.
75 */
76 mutable pthread_mutex_t _lock;
97f630d4
JG
77
78 /* Generated metadata, not null-terminated. */
79 char *_metadata = nullptr; /* */
80 size_t _metadata_len = 0;
81 /* Length of bytes sent to the consumer. */
82 size_t _metadata_len_sent = 0;
83 /* Current version of the metadata. */
84 uint64_t _metadata_version = 0;
85
86 /*
87 * Unique key to identify the metadata on the consumer side.
88 */
89 uint64_t _metadata_key = 0;
90 /*
91 * Indicates if the metadata is closed on the consumer side. This is to
92 * avoid double close of metadata when an application unregisters AND
93 * deletes its sessions.
94 */
95 bool _metadata_closed = false;
96
97protected:
98 /* Prevent instanciation of this base class. */
99 registry_session(const struct lttng::sessiond::trace::abi& abi,
100 unsigned int app_tracer_version_major,
101 unsigned int app_tracer_version_minor,
102 const char *root_shm_path,
103 const char *shm_path,
104 uid_t euid,
105 gid_t egid,
106 uint64_t tracing_id);
da9dd521
JG
107 virtual void accept(
108 trace::trace_class_environment_visitor& environment_visitor) const override;
97f630d4
JG
109 void _generate_metadata();
110
111private:
112 uint32_t _get_next_channel_id();
113 void _increase_metadata_size(size_t reservation_length);
114 void _append_metadata_fragment(const std::string& fragment);
115 void _reset_metadata();
3691d312 116 void _destroy_enum(registry_enum *reg_enum) noexcept;
97f630d4 117 registry_enum *_lookup_enum(const registry_enum *target_enum) const;
0267b527 118 lttng::sessiond::trace::type::cuptr _create_packet_header() const;
97f630d4
JG
119
120 virtual void _accept_on_clock_classes(
121 lttng::sessiond::trace::trace_class_visitor& trace_class_visitor)
122 const override final;
123 virtual void _accept_on_stream_classes(
124 lttng::sessiond::trace::trace_class_visitor& trace_class_visitor)
125 const override final;
126
b0f2e8db
JG
127 /* Next channel ID available for a newly registered channel. */
128 uint32_t _next_channel_id = 0;
97f630d4 129
b0f2e8db
JG
130 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
131 uint32_t _used_channel_id = 0;
97f630d4 132
b0f2e8db
JG
133 /* Next enumeration ID available. */
134 uint64_t _next_enum_id = 0;
135
97f630d4 136 size_t _metadata_alloc_len = 0;
b0f2e8db
JG
137
138 /*
139 * Those fields are only used when a session is created with
140 * the --shm-path option. In this case, the metadata is output
141 * twice: once to the consumer, as ususal, but a second time
142 * also in the shm path directly. This is done so that a copy
143 * of the metadata that is as fresh as possible is available
144 * on the event of a crash.
145 *
146 * root_shm_path contains the shm-path provided by the user, along with
147 * the session's name and timestamp:
148 * e.g. /tmp/my_shm/my_session-20180612-135822
149 *
150 * shm_path contains the full path of the memory buffers:
151 * e.g. /tmp/my_shm/my_session-20180612-135822/ust/uid/1000/64-bit
152 *
153 * metadata_path contains the full path to the metadata file that
154 * is kept for the "crash buffer" extraction:
155 * e.g.
156 * /tmp/my_shm/my_session-20180612-135822/ust/uid/1000/64-bit/metadata
157 *
158 * Note that this is not the trace's final metadata file. It is
159 * only meant to be used to read the contents of the ring buffers
160 * in the event of a crash.
161 *
162 * metadata_fd is a file descriptor that points to the file at
163 * 'metadata_path'.
164 */
97f630d4
JG
165 const std::string _root_shm_path;
166 const std::string _shm_path;
167 const std::string _metadata_path;
168
b0f2e8db
JG
169 /* File-backed metadata FD */
170 int _metadata_fd = -1;
171
172 /*
173 * Hash table containing channels sent by the UST tracer. MUST
174 * be accessed with a RCU read side lock acquired.
175 */
176 lttng_ht::uptr _channels;
177
b0f2e8db
JG
178 /* Enumerations table. */
179 lttng_ht::uptr _enums;
180
97f630d4
JG
181 /* User and group owning the session. */
182 const uid_t _uid;
183 const gid_t _gid;
184
b0f2e8db
JG
185 /*
186 * Copy of the tracer version when the first app is registered.
187 * It is used if we need to regenerate the metadata.
188 */
97f630d4
JG
189 const struct {
190 uint32_t major, minor;
191 } _app_tracer_version;
b0f2e8db 192
97f630d4
JG
193 /* The id of the parent session. */
194 const ltt_session::id_t _tracing_id;
b0f2e8db 195
042670db 196 lttng::sessiond::ust::clock_class::cuptr _clock;
b0f2e8db 197 const lttng::sessiond::trace::trace_class_visitor::cuptr _metadata_generating_visitor;
0267b527 198 lttng::sessiond::trace::type::cuptr _packet_header;
b0f2e8db
JG
199};
200
201} /* namespace ust */
202} /* namespace sessiond */
203} /* namespace lttng */
204
205#endif /* LTTNG_UST_REGISTRY_SESSION_H */
This page took 0.036276 seconds and 4 git commands to generate.