2 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include "lttng-sessiond.hpp"
10 #include "notification-thread-commands.hpp"
11 #include "session.hpp"
12 #include "trace-class.hpp"
13 #include "tsdl-trace-class-visitor.hpp"
14 #include "ctf2-trace-class-visitor.hpp"
15 #include "ust-app.hpp"
16 #include "ust-field-convert.hpp"
17 #include "ust-registry.hpp"
19 #include <common/compat/directory-handle.hpp>
20 #include <common/error.hpp>
21 #include <common/exception.hpp>
22 #include <common/format.hpp>
23 #include <common/hashtable/utils.hpp>
24 #include <common/macros.hpp>
25 #include <common/make-unique.hpp>
26 #include <common/pthread-lock.hpp>
27 #include <common/runas.hpp>
28 #include <common/time.hpp>
29 #include <common/urcu.hpp>
33 #include <initializer_list>
38 namespace ls
= lttng::sessiond
;
39 namespace lst
= lttng::sessiond::trace
;
40 namespace lsu
= lttng::sessiond::ust
;
43 lttng_uuid
generate_uuid_or_throw()
47 if (lttng_uuid_generate(new_uuid
)) {
48 LTTNG_THROW_POSIX("Failed to generate UST uuid", errno
);
54 int get_count_order(unsigned int count
)
58 order
= lttng_fls(count
) - 1;
59 if (count
& (count
- 1)) {
63 LTTNG_ASSERT(order
>= 0);
67 void clear_metadata_file(int fd
)
69 const auto lseek_ret
= lseek(fd
, 0, SEEK_SET
);
71 LTTNG_THROW_POSIX("Failed to seek to the beginning of the metadata file while clearing it", errno
);
74 const auto ret
= ftruncate(fd
, 0);
76 LTTNG_THROW_POSIX("Failed to truncate the metadata file while clearing it", errno
);
81 * Validate that the id has reached the maximum allowed or not.
83 bool is_max_channel_id(uint32_t id
)
85 return id
== UINT32_MAX
;
88 void destroy_channel_rcu(struct rcu_head
*head
)
91 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
92 lsu::registry_channel
*chan
=
93 lttng::utils::container_of(head
, &lsu::registry_channel::_rcu_head
);
100 * Destroy every element of the registry and free the memory. This does NOT
101 * free the registry pointer since it might not have been allocated before so
102 * it's the caller responsability.
104 * Called from ~registry_session(), must not throw.
106 void destroy_channel(lsu::registry_channel
*chan
, bool notify
) noexcept
108 struct lttng_ht_iter iter
;
109 lttng::sessiond::ust::registry_event
*event
;
110 enum lttng_error_code cmd_ret
;
115 cmd_ret
= notification_thread_command_remove_channel(
116 the_notification_thread_handle
,
117 chan
->_consumer_key
, LTTNG_DOMAIN_UST
);
118 if (cmd_ret
!= LTTNG_OK
) {
119 ERR("Failed to remove channel from notification thread");
124 lttng::urcu::read_lock_guard read_lock_guard
;
126 /* Destroy all event associated with this registry. */
128 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
129 cds_lfht_for_each_entry(
130 chan
->_events
->ht
, &iter
.iter
, event
, _node
) {
131 /* Delete the node from the ht and free it. */
132 ust_registry_channel_destroy_event(chan
, event
);
137 call_rcu(&chan
->_rcu_head
, destroy_channel_rcu
);
140 void destroy_enum(lsu::registry_enum
*reg_enum
)
149 void destroy_enum_rcu(struct rcu_head
*head
)
152 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
153 lsu::registry_enum
*reg_enum
=
154 lttng::utils::container_of(head
, &lsu::registry_enum::rcu_head
);
157 destroy_enum(reg_enum
);
161 * Hash table match function for enumerations in the session. Match is
162 * performed on enumeration name, and confirmed by comparing the enum
165 int ht_match_enum(struct cds_lfht_node
*node
, const void *_key
)
167 lsu::registry_enum
*_enum
;
168 const lsu::registry_enum
*key
;
174 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
175 _enum
= caa_container_of(node
, lsu::registry_enum
,
180 key
= (lsu::registry_enum
*) _key
;
182 return *_enum
== *key
;
186 * Hash table match function for enumerations in the session. Match is
187 * performed by enumeration ID.
189 int ht_match_enum_id(struct cds_lfht_node
*node
, const void *_key
)
191 lsu::registry_enum
*_enum
;
192 const lsu::registry_enum
*key
= (lsu::registry_enum
*) _key
;
198 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
199 _enum
= caa_container_of(node
, lsu::registry_enum
, node
.node
);
204 if (_enum
->id
!= key
->id
) {
216 * Hash table hash function for enumerations in the session. The
217 * enumeration name is used for hashing.
219 unsigned long ht_hash_enum(void *_key
, unsigned long seed
)
221 lsu::registry_enum
*key
= (lsu::registry_enum
*) _key
;
224 return hash_key_str(key
->name
.c_str(), seed
);
228 void lsu::details::locked_registry_session_release(lsu::registry_session
*session
)
230 pthread_mutex_unlock(&session
->_lock
);
233 lttng::sessiond::trace::trace_class_visitor::cuptr
234 lsu::registry_session::trace_class_visitor_factory(
235 const lst::abi
& trace_abi
, const lttng::trace_format_descriptor
& trace_format
)
237 switch (trace_format
.type()) {
238 case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1
:
239 return lttng::make_unique
<ls::tsdl::trace_class_visitor
>(
240 trace_abi
, [this](const std::string
& fragment
) {
241 _append_metadata_fragment(fragment
);
243 case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2
:
244 return lttng::make_unique
<ls::ctf2::trace_class_visitor
>(
245 trace_abi
, [this](const std::string
& fragment
) {
246 _append_metadata_fragment(fragment
);
254 lsu::registry_session::registry_session(const struct lst::abi
& in_abi
,
257 const char *root_shm_path
,
258 const char *shm_path
,
262 const lttng::trace_format_descriptor
& trace_format
) :
263 lst::trace_class(in_abi
, generate_uuid_or_throw()),
264 _root_shm_path
{root_shm_path
? root_shm_path
: ""},
265 _shm_path
{shm_path
? shm_path
: ""},
266 _metadata_path
{_shm_path
.size() > 0 ? fmt::format("{}/metadata", _shm_path
) :
270 _app_tracer_version
{.major
= major
, .minor
= minor
},
271 _tracing_id
{tracing_id
},
272 _metadata_generating_visitor
{trace_class_visitor_factory(abi
, trace_format
)},
273 _packet_header
{_create_packet_header()}
276 pthread_mutex_init(&_lock
, NULL
);
277 if (_shm_path
.size() > 0) {
278 if (run_as_mkdir_recursive(_shm_path
.c_str(), S_IRWXU
| S_IRWXG
, euid
, egid
)) {
279 LTTNG_THROW_POSIX("run_as_mkdir_recursive", errno
);
283 if (_metadata_path
.size() > 0) {
284 /* Create metadata file. */
285 const int ret
= run_as_open(_metadata_path
.c_str(), O_WRONLY
| O_CREAT
| O_EXCL
,
286 S_IRUSR
| S_IWUSR
, euid
, egid
);
288 LTTNG_THROW_POSIX(fmt::format("Failed to open metadata file during registry session creation: path = {}",
289 _metadata_path
), errno
);
295 _enums
.reset(lttng_ht_new(0, LTTNG_HT_TYPE_STRING
));
297 LTTNG_THROW_POSIX("Failed to create enums hash table", ENOMEM
);
300 /* hash/match functions are specified at call site. */
301 _enums
->match_fct
= NULL
;
302 _enums
->hash_fct
= NULL
;
304 _channels
.reset(lttng_ht_new(0, LTTNG_HT_TYPE_U64
));
306 LTTNG_THROW_POSIX("Failed to create channels hash table", ENOMEM
);
310 lst::type::cuptr
lsu::registry_session::_create_packet_header() const
312 lst::structure_type::fields packet_header_fields
;
315 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("magic",
316 lttng::make_unique
<lst::integer_type
>(abi
.uint32_t_alignment
,
317 abi
.byte_order
, 32, lst::integer_type::signedness::UNSIGNED
,
318 lst::integer_type::base::HEXADECIMAL
,
319 std::initializer_list
<lst::integer_type::role
>({lst::integer_type::role::PACKET_MAGIC_NUMBER
}))));
322 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("uuid",
323 lttng::make_unique
<lst::static_length_blob_type
>(0, 16,
324 std::initializer_list
<lst::static_length_blob_type::role
>({lst::static_length_blob_type::role::METADATA_STREAM_UUID
}))));
326 /* uint32_t stream_id */
327 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("stream_id",
328 lttng::make_unique
<lst::integer_type
>(abi
.uint32_t_alignment
,
329 abi
.byte_order
, 32, lst::integer_type::signedness::UNSIGNED
,
330 lst::integer_type::base::DECIMAL
,
331 std::initializer_list
<lst::integer_type::role
>({lst::integer_type::role::DATA_STREAM_CLASS_ID
}))));
333 /* uint64_t stream_instance_id */
334 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("stream_instance_id",
335 lttng::make_unique
<lst::integer_type
>(abi
.uint64_t_alignment
,
336 abi
.byte_order
, 64, lst::integer_type::signedness::UNSIGNED
,
337 lst::integer_type::base::DECIMAL
,
338 std::initializer_list
<lst::integer_type::role
>({lst::integer_type::role::DATA_STREAM_ID
}))));
340 return lttng::make_unique
<lst::structure_type
>(0, std::move(packet_header_fields
));
343 const lst::type
*lsu::registry_session::get_packet_header() const noexcept
345 return _packet_header
.get();
349 * For a given enumeration in a registry, delete the entry and destroy
352 * Note that this is used by ~registry_session() and must not throw.
354 void lsu::registry_session::_destroy_enum(lsu::registry_enum
*reg_enum
) noexcept
357 lttng::urcu::read_lock_guard read_lock_guard
;
359 LTTNG_ASSERT(reg_enum
);
360 ASSERT_RCU_READ_LOCKED();
362 /* Delete the node first. */
363 struct lttng_ht_iter iter
;
364 iter
.iter
.node
= ®_enum
->node
.node
;
365 ret
= lttng_ht_del(_enums
.get(), &iter
);
367 call_rcu(®_enum
->rcu_head
, destroy_enum_rcu
);
370 lsu::registry_session::~registry_session()
373 struct lttng_ht_iter iter
;
374 lsu::registry_channel
*chan
;
375 lsu::registry_enum
*reg_enum
;
377 /* On error, EBUSY can be returned if lock. Code flow error. */
378 ret
= pthread_mutex_destroy(&_lock
);
382 lttng::urcu::read_lock_guard read_lock_guard
;
384 /* Destroy all event associated with this registry. */
386 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
387 cds_lfht_for_each_entry(_channels
->ht
, &iter
.iter
, chan
, _node
.node
) {
388 /* Delete the node from the ht and free it. */
389 ret
= lttng_ht_del(_channels
.get(), &iter
);
391 destroy_channel(chan
, true);
397 if (_metadata_fd
>= 0) {
398 ret
= close(_metadata_fd
);
403 ret
= run_as_unlink(_metadata_path
.c_str(), _uid
, _gid
);
409 if (_root_shm_path
[0]) {
410 /* Try to delete the directory hierarchy. */
411 (void) run_as_rmdir_recursive(_root_shm_path
.c_str(), _uid
, _gid
,
412 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG
);
415 /* Destroy the enum hash table */
417 lttng::urcu::read_lock_guard read_lock_guard
;
419 /* Destroy all enum entries associated with this registry. */
421 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
422 cds_lfht_for_each_entry (_enums
->ht
, &iter
.iter
, reg_enum
, node
.node
) {
423 _destroy_enum(reg_enum
);
429 lsu::registry_session::locked_ptr
lsu::registry_session::lock() noexcept
431 pthread_mutex_lock(&_lock
);
432 return locked_ptr(this);
436 * Initialize registry with default values.
438 void lsu::registry_session::add_channel(uint64_t key
)
440 lttng::pthread::lock_guard
session_lock_guard(_lock
);
443 * Assign a channel ID right now since the event notification comes
444 * *before* the channel notify so the ID needs to be set at this point so
445 * the metadata can be dumped for that event.
447 if (is_max_channel_id(_used_channel_id
)) {
448 LTTNG_THROW_ERROR(fmt::format("Failed to allocate unique id for channel under session while adding channel"));
451 auto chan
= new lsu::registry_channel(
452 _get_next_channel_id(), abi
, _clock
.name
,
453 /* Registered channel listener. */
454 [this](const lsu::registry_channel
& registered_channel
) {
456 * Channel registration completed, serialize it's layout's
459 registered_channel
.accept(*_metadata_generating_visitor
);
461 /* Added event listener. */
462 [this](const lsu::registry_channel
& channel
,
463 const lsu::registry_event
& added_event
) {
465 * The channel and its event classes will be dumped at once when
466 * it is registered. This check prevents event classes from being
467 * declared before their stream class.
469 if (channel
.is_registered()) {
470 added_event
.accept(*_metadata_generating_visitor
);
474 lttng::urcu::read_lock_guard rcu_read_lock_guard
;
475 lttng_ht_node_init_u64(&chan
->_node
, key
);
476 lttng_ht_add_unique_u64(_channels
.get(), &chan
->_node
);
479 lttng::sessiond::ust::registry_channel
& lsu::registry_session::get_channel(
480 uint64_t channel_key
) const
482 lttng::urcu::read_lock_guard read_lock_guard
;
483 struct lttng_ht_node_u64
*node
;
484 struct lttng_ht_iter iter
;
486 ASSERT_LOCKED(_lock
);
488 lttng_ht_lookup(_channels
.get(), &channel_key
, &iter
);
489 node
= lttng_ht_iter_get_node_u64(&iter
);
491 LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
492 "Invalid channel key provided: channel key = {}", channel_key
));
496 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
497 auto chan
= lttng::utils::container_of(node
, &lsu::registry_channel::_node
);
502 void lsu::registry_session::remove_channel(uint64_t channel_key
, bool notify
)
504 struct lttng_ht_iter iter
;
506 lttng::urcu::read_lock_guard read_lock_guard
;
508 ASSERT_LOCKED(_lock
);
509 auto& channel
= get_channel(channel_key
);
511 iter
.iter
.node
= &channel
._node
.node
;
512 ret
= lttng_ht_del(_channels
.get(), &iter
);
514 destroy_channel(&channel
, notify
);
517 void lsu::registry_session::accept(
518 lttng::sessiond::trace::trace_class_environment_visitor
& visitor
) const
520 ASSERT_LOCKED(_lock
);
522 visitor
.visit(lst::environment_field
<const char *>("domain", "ust"));
523 visitor
.visit(lst::environment_field
<const char *>("tracer_name", "lttng-ust"));
524 visitor
.visit(lst::environment_field
<int64_t>("tracer_major", _app_tracer_version
.major
));
525 visitor
.visit(lst::environment_field
<int64_t>("tracer_minor", _app_tracer_version
.minor
));
526 visitor
.visit(lst::environment_field
<const char *>("tracer_buffering_scheme",
527 get_buffering_scheme() == LTTNG_BUFFER_PER_PID
? "pid" : "uid"));
528 visitor
.visit(lst::environment_field
<int64_t>("architecture_bit_width", abi
.bits_per_long
));
531 /* The caller already holds the session and session list locks. */
532 ASSERT_SESSION_LIST_LOCKED();
533 const auto session
= lttng::sessiond::find_session_by_id(_tracing_id
);
535 LTTNG_ASSERT(session
);
536 ASSERT_LOCKED(session
->lock
);
538 visitor
.visit(lst::environment_field
<const char *>("trace_name",
539 session
->has_auto_generated_name
? DEFAULT_SESSION_NAME
:
541 visitor
.visit(lst::environment_field
<std::string
>("trace_creation_datetime",
542 lttng::utils::time_to_iso8601_str(session
->creation_time
)));
543 visitor
.visit(lst::environment_field
<const char *>("hostname", session
->hostname
));
547 void lsu::registry_session::_accept_on_clock_classes(lst::trace_class_visitor
& visitor
) const
549 ASSERT_LOCKED(_lock
);
550 _clock
.accept(visitor
);
553 void lsu::registry_session::_accept_on_stream_classes(lst::trace_class_visitor
& visitor
) const
555 ASSERT_LOCKED(_lock
);
557 std::vector
<const lttng::sessiond::ust::registry_channel
*> sorted_stream_classes
;
560 lttng::urcu::read_lock_guard rcu_lock_guard
;
561 const lsu::registry_channel
*channel
;
562 lttng_ht_iter channel_it
;
565 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
566 cds_lfht_for_each_entry(_channels
->ht
, &channel_it
.iter
, channel
, _node
.node
) {
567 sorted_stream_classes
.emplace_back(channel
);
572 std::sort(sorted_stream_classes
.begin(), sorted_stream_classes
.end(),
573 [](const lttng::sessiond::ust::registry_channel
*a
,
574 const lttng::sessiond::ust::registry_channel
*b
) {
575 return a
->id
< b
->id
;
578 for (const auto stream_class
: sorted_stream_classes
) {
579 stream_class
->accept(visitor
);
584 * Return next available channel id and increment the used counter. The
585 * is_max_channel_id function MUST be called before in order to validate
586 * if the maximum number of IDs have been reached. If not, it is safe to call
589 * Return a unique channel ID. If max is reached, the used_channel_id counter
592 uint32_t lsu::registry_session::_get_next_channel_id()
594 if (is_max_channel_id(_used_channel_id
)) {
595 return _used_channel_id
;
599 return _next_channel_id
++;
602 void lsu::registry_session::_increase_metadata_size(size_t reservation_length
)
604 const auto new_len
= _metadata_len
+ reservation_length
;
605 auto new_alloc_len
= new_len
;
606 const auto old_alloc_len
= _metadata_alloc_len
;
608 /* Rounding the new allocation length to the next power of 2 would overflow. */
609 if (new_alloc_len
> (UINT32_MAX
>> 1)) {
610 LTTNG_THROW_ERROR("Failed to reserve trace metadata storage as the new size would overflow");
613 /* The current allocation length is already the largest we can afford. */
614 if ((old_alloc_len
<< 1) > (UINT32_MAX
>> 1)) {
615 LTTNG_THROW_ERROR("Failed to reserve trace metadata storage as the max size was already reached");
618 if (new_alloc_len
> old_alloc_len
) {
619 new_alloc_len
= std::max
<size_t>(
620 1U << get_count_order(new_alloc_len
), old_alloc_len
<< 1);
622 auto newptr
= (char *) realloc(_metadata
, new_alloc_len
);
624 LTTNG_THROW_POSIX("Failed to allocate trace metadata storage", errno
);
629 /* We zero directly the memory from start of allocation. */
630 memset(&_metadata
[old_alloc_len
], 0, new_alloc_len
- old_alloc_len
);
631 _metadata_alloc_len
= new_alloc_len
;
634 _metadata_len
+= reservation_length
;
637 void lsu::registry_session::_append_metadata_fragment(const std::string
& fragment
)
639 const auto offset
= _metadata_len
;
641 _increase_metadata_size(fragment
.size());
642 memcpy(&_metadata
[offset
], fragment
.c_str(), fragment
.size());
644 if (_metadata_fd
>= 0) {
645 const auto bytes_written
=
646 lttng_write(_metadata_fd
, fragment
.c_str(), fragment
.size());
648 if (bytes_written
!= fragment
.size()) {
649 LTTNG_THROW_POSIX("Failed to write trace metadata fragment to file",
655 void lsu::registry_session::_reset_metadata()
657 _metadata_len_sent
= 0;
658 memset(_metadata
, 0, _metadata_alloc_len
);
661 if (_metadata_fd
> 0) {
662 /* Clear the metadata file's content. */
663 clear_metadata_file(_metadata_fd
);
667 void lsu::registry_session::_generate_metadata()
669 trace_class::accept(*_metadata_generating_visitor
);
672 void lsu::registry_session::regenerate_metadata()
674 lttng::pthread::lock_guard
registry_lock(_lock
);
678 _generate_metadata();
682 * Lookup enumeration by enum ID.
684 * Note that there is no need to lock the registry session as this only
685 * performs an RCU-protected look-up. The function also return an rcu-protected
686 * reference, which ensures that the caller keeps the RCU read lock until it
687 * disposes of the object.
689 lsu::registry_enum::const_rcu_protected_reference
690 lsu::registry_session::get_enumeration(const char *enum_name
, uint64_t enum_id
) const
692 lsu::registry_enum
*reg_enum
= NULL
;
693 struct lttng_ht_node_str
*node
;
694 struct lttng_ht_iter iter
;
695 lttng::urcu::unique_read_lock rcu_lock
;
697 * Hack: only the name is used for hashing; the rest of the attributes
700 lsu::registry_signed_enum
reg_enum_lookup(enum_name
, nullptr, 0);
702 ASSERT_RCU_READ_LOCKED();
704 reg_enum_lookup
.id
= enum_id
;
705 cds_lfht_lookup(_enums
->ht
,
706 ht_hash_enum((void *) ®_enum_lookup
, lttng_ht_seed
),
707 ht_match_enum_id
, ®_enum_lookup
, &iter
.iter
);
708 node
= lttng_ht_iter_get_node_str(&iter
);
710 LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
711 "Unknown enumeration referenced by application event field: enum name = `{}`, enum id = {}",
712 enum_name
, enum_id
));
716 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
717 reg_enum
= lttng::utils::container_of(node
, &lsu::registry_enum::node
);
720 return lsu::registry_enum::const_rcu_protected_reference
{*reg_enum
, std::move(rcu_lock
)};
724 * Lookup enumeration by name and comparing enumeration entries.
725 * Needs to be called from RCU read-side critical section.
727 lsu::registry_enum
*lsu::registry_session::_lookup_enum(
728 const lsu::registry_enum
*reg_enum_lookup
) const
730 lsu::registry_enum
*reg_enum
= NULL
;
731 struct lttng_ht_node_str
*node
;
732 struct lttng_ht_iter iter
;
734 ASSERT_RCU_READ_LOCKED();
736 cds_lfht_lookup(_enums
->ht
, ht_hash_enum((void *) reg_enum_lookup
, lttng_ht_seed
),
737 ht_match_enum
, reg_enum_lookup
, &iter
.iter
);
738 node
= lttng_ht_iter_get_node_str(&iter
);
744 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
745 reg_enum
= lttng::utils::container_of(node
, &lsu::registry_enum::node
);
753 * Create a lsu::registry_enum from the given parameters and add it to the
754 * registry hash table, or find it if already there.
756 * Should be called with session registry mutex held.
758 * We receive ownership of entries.
760 void lsu::registry_session::create_or_find_enum(
761 int session_objd
, const char *enum_name
,
762 struct lttng_ust_ctl_enum_entry
*raw_entries
, size_t nr_entries
,
765 struct cds_lfht_node
*nodep
;
766 lsu::registry_enum
*reg_enum
= NULL
, *old_reg_enum
;
767 lttng::urcu::read_lock_guard read_lock_guard
;
768 auto entries
= lttng::make_unique_wrapper
<lttng_ust_ctl_enum_entry
, lttng::free
>(raw_entries
);
770 LTTNG_ASSERT(enum_name
);
773 * This should not happen but since it comes from the UST tracer, an
774 * external party, don't assert and simply validate values.
776 if (session_objd
< 0) {
777 LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
778 "Invalid parameters used to create or look-up enumeration from registry session: session_objd = {}",
781 if (nr_entries
== 0) {
782 LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
783 "Invalid parameters used to create or look-up enumeration from registry session: nr_entries = {}",
786 if (lttng_strnlen(enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
) ==
787 LTTNG_UST_ABI_SYM_NAME_LEN
) {
788 LTTNG_THROW_INVALID_ARGUMENT_ERROR(
789 "Invalid parameters used to create or look-up enumeration from registry session: enumeration name is not null terminated");
792 if (entries
->start
.signedness
) {
793 reg_enum
= new lsu::registry_signed_enum(
794 enum_name
, entries
.get(), nr_entries
);
796 reg_enum
= new lsu::registry_unsigned_enum(
797 enum_name
, entries
.get(), nr_entries
);
800 old_reg_enum
= _lookup_enum(reg_enum
);
802 DBG("enum %s already in sess_objd: %u", enum_name
, session_objd
);
803 /* Fall through. Use prior enum. */
804 destroy_enum(reg_enum
);
805 reg_enum
= old_reg_enum
;
807 DBG("UST registry creating enum: %s, sess_objd: %u",
808 enum_name
, session_objd
);
809 if (_next_enum_id
== -1ULL) {
810 destroy_enum(reg_enum
);
811 LTTNG_THROW_ERROR("Failed to allocate unique enumeration ID as it would overflow");
814 reg_enum
->id
= _next_enum_id
++;
815 nodep
= cds_lfht_add_unique(_enums
->ht
,
816 ht_hash_enum(reg_enum
, lttng_ht_seed
),
817 ht_match_enum_id
, reg_enum
,
818 ®_enum
->node
.node
);
819 LTTNG_ASSERT(nodep
== ®_enum
->node
.node
);
822 DBG("UST registry reply with enum %s with id %" PRIu64
" in sess_objd: %u",
823 enum_name
, reg_enum
->id
, session_objd
);
824 *enum_id
= reg_enum
->id
;