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 "ust-app.hpp"
15 #include "ust-field-convert.hpp"
16 #include "ust-registry.hpp"
18 #include <common/compat/directory-handle.hpp>
19 #include <common/error.hpp>
20 #include <common/exception.hpp>
21 #include <common/format.hpp>
22 #include <common/hashtable/utils.hpp>
23 #include <common/macros.hpp>
24 #include <common/make-unique.hpp>
25 #include <common/pthread-lock.hpp>
26 #include <common/runas.hpp>
27 #include <common/time.hpp>
28 #include <common/urcu.hpp>
32 #include <initializer_list>
37 namespace ls
= lttng::sessiond
;
38 namespace lst
= lttng::sessiond::trace
;
39 namespace lsu
= lttng::sessiond::ust
;
42 lttng_uuid
generate_uuid_or_throw()
46 if (lttng_uuid_generate(new_uuid
)) {
47 LTTNG_THROW_POSIX("Failed to generate UST uuid", errno
);
53 int get_count_order(unsigned int count
)
57 order
= lttng_fls(count
) - 1;
58 if (count
& (count
- 1)) {
62 LTTNG_ASSERT(order
>= 0);
66 void clear_metadata_file(int fd
)
68 const auto lseek_ret
= lseek(fd
, 0, SEEK_SET
);
70 LTTNG_THROW_POSIX("Failed to seek to the beginning of the metadata file while clearing it", errno
);
73 const auto ret
= ftruncate(fd
, 0);
75 LTTNG_THROW_POSIX("Failed to truncate the metadata file while clearing it", errno
);
80 * Validate that the id has reached the maximum allowed or not.
82 bool is_max_channel_id(uint32_t id
)
84 return id
== UINT32_MAX
;
87 void destroy_channel_rcu(struct rcu_head
*head
)
90 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
91 lsu::registry_channel
*chan
=
92 lttng::utils::container_of(head
, &lsu::registry_channel::_rcu_head
);
99 * Destroy every element of the registry and free the memory. This does NOT
100 * free the registry pointer since it might not have been allocated before so
101 * it's the caller responsability.
103 * Called from ~registry_session(), must not throw.
105 void destroy_channel(lsu::registry_channel
*chan
, bool notify
) noexcept
107 struct lttng_ht_iter iter
;
108 lttng::sessiond::ust::registry_event
*event
;
109 enum lttng_error_code cmd_ret
;
114 cmd_ret
= notification_thread_command_remove_channel(
115 the_notification_thread_handle
,
116 chan
->_consumer_key
, LTTNG_DOMAIN_UST
);
117 if (cmd_ret
!= LTTNG_OK
) {
118 ERR("Failed to remove channel from notification thread");
123 lttng::urcu::read_lock_guard read_lock_guard
;
125 /* Destroy all event associated with this registry. */
127 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
128 cds_lfht_for_each_entry(
129 chan
->_events
->ht
, &iter
.iter
, event
, _node
) {
130 /* Delete the node from the ht and free it. */
131 ust_registry_channel_destroy_event(chan
, event
);
136 call_rcu(&chan
->_rcu_head
, destroy_channel_rcu
);
139 void destroy_enum(lsu::registry_enum
*reg_enum
)
148 void destroy_enum_rcu(struct rcu_head
*head
)
151 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
152 lsu::registry_enum
*reg_enum
=
153 lttng::utils::container_of(head
, &lsu::registry_enum::rcu_head
);
156 destroy_enum(reg_enum
);
160 * Hash table match function for enumerations in the session. Match is
161 * performed on enumeration name, and confirmed by comparing the enum
164 int ht_match_enum(struct cds_lfht_node
*node
, const void *_key
)
166 lsu::registry_enum
*_enum
;
167 const lsu::registry_enum
*key
;
173 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
174 _enum
= caa_container_of(node
, lsu::registry_enum
,
179 key
= (lsu::registry_enum
*) _key
;
181 return *_enum
== *key
;
185 * Hash table match function for enumerations in the session. Match is
186 * performed by enumeration ID.
188 int ht_match_enum_id(struct cds_lfht_node
*node
, const void *_key
)
190 lsu::registry_enum
*_enum
;
191 const lsu::registry_enum
*key
= (lsu::registry_enum
*) _key
;
197 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
198 _enum
= caa_container_of(node
, lsu::registry_enum
, node
.node
);
203 if (_enum
->id
!= key
->id
) {
215 * Hash table hash function for enumerations in the session. The
216 * enumeration name is used for hashing.
218 unsigned long ht_hash_enum(void *_key
, unsigned long seed
)
220 lsu::registry_enum
*key
= (lsu::registry_enum
*) _key
;
223 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 lsu::registry_session::registry_session(const struct lst::abi
& in_abi
,
236 const char *root_shm_path
,
237 const char *shm_path
,
240 uint64_t tracing_id
) :
241 lst::trace_class(in_abi
, generate_uuid_or_throw()),
242 _root_shm_path
{root_shm_path
? root_shm_path
: ""},
243 _shm_path
{shm_path
? shm_path
: ""},
244 _metadata_path
{_shm_path
.size() > 0 ? fmt::format("{}/metadata", _shm_path
) :
248 _app_tracer_version
{.major
= major
, .minor
= minor
},
249 _tracing_id
{tracing_id
},
250 _metadata_generating_visitor
{lttng::make_unique
<ls::tsdl::trace_class_visitor
>(
251 abi
, [this](const std::string
& fragment
) {
252 _append_metadata_fragment(fragment
);
254 _packet_header
{_create_packet_header()}
256 pthread_mutex_init(&_lock
, NULL
);
257 if (_shm_path
.size() > 0) {
258 if (run_as_mkdir_recursive(_shm_path
.c_str(), S_IRWXU
| S_IRWXG
, euid
, egid
)) {
259 LTTNG_THROW_POSIX("run_as_mkdir_recursive", errno
);
263 if (_metadata_path
.size() > 0) {
264 /* Create metadata file. */
265 const int ret
= run_as_open(_metadata_path
.c_str(), O_WRONLY
| O_CREAT
| O_EXCL
,
266 S_IRUSR
| S_IWUSR
, euid
, egid
);
268 LTTNG_THROW_POSIX(fmt::format("Failed to open metadata file during registry session creation: path = {}",
269 _metadata_path
), errno
);
275 _enums
.reset(lttng_ht_new(0, LTTNG_HT_TYPE_STRING
));
277 LTTNG_THROW_POSIX("Failed to create enums hash table", ENOMEM
);
280 /* hash/match functions are specified at call site. */
281 _enums
->match_fct
= NULL
;
282 _enums
->hash_fct
= NULL
;
284 _channels
.reset(lttng_ht_new(0, LTTNG_HT_TYPE_U64
));
286 LTTNG_THROW_POSIX("Failed to create channels hash table", ENOMEM
);
290 lst::type::cuptr
lsu::registry_session::_create_packet_header() const
292 lst::structure_type::fields packet_header_fields
;
295 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("magic",
296 lttng::make_unique
<lst::integer_type
>(abi
.uint32_t_alignment
,
297 abi
.byte_order
, 32, lst::integer_type::signedness::UNSIGNED
,
298 lst::integer_type::base::HEXADECIMAL
,
299 std::initializer_list
<lst::integer_type::role
>({lst::integer_type::role::PACKET_MAGIC_NUMBER
}))));
302 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("uuid",
303 lttng::make_unique
<lst::static_length_blob_type
>(0, 16,
304 std::initializer_list
<lst::static_length_blob_type::role
>({lst::static_length_blob_type::role::TRACE_CLASS_UUID
}))));
306 /* uint32_t stream_id */
307 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("stream_id",
308 lttng::make_unique
<lst::integer_type
>(abi
.uint32_t_alignment
,
309 abi
.byte_order
, 32, lst::integer_type::signedness::UNSIGNED
,
310 lst::integer_type::base::DECIMAL
,
311 std::initializer_list
<lst::integer_type::role
>({lst::integer_type::role::DATA_STREAM_CLASS_ID
}))));
313 /* uint64_t stream_instance_id */
314 packet_header_fields
.emplace_back(lttng::make_unique
<lst::field
>("stream_instance_id",
315 lttng::make_unique
<lst::integer_type
>(abi
.uint64_t_alignment
,
316 abi
.byte_order
, 64, lst::integer_type::signedness::UNSIGNED
,
317 lst::integer_type::base::DECIMAL
,
318 std::initializer_list
<lst::integer_type::role
>({lst::integer_type::role::DATA_STREAM_ID
}))));
320 return lttng::make_unique
<lst::structure_type
>(0, std::move(packet_header_fields
));
323 const lst::type
*lsu::registry_session::get_packet_header() const noexcept
325 return _packet_header
.get();
329 * For a given enumeration in a registry, delete the entry and destroy
332 * Note that this is used by ~registry_session() and must not throw.
334 void lsu::registry_session::_destroy_enum(lsu::registry_enum
*reg_enum
) noexcept
337 lttng::urcu::read_lock_guard read_lock_guard
;
339 LTTNG_ASSERT(reg_enum
);
340 ASSERT_RCU_READ_LOCKED();
342 /* Delete the node first. */
343 struct lttng_ht_iter iter
;
344 iter
.iter
.node
= ®_enum
->node
.node
;
345 ret
= lttng_ht_del(_enums
.get(), &iter
);
347 call_rcu(®_enum
->rcu_head
, destroy_enum_rcu
);
350 lsu::registry_session::~registry_session()
353 struct lttng_ht_iter iter
;
354 lsu::registry_channel
*chan
;
355 lsu::registry_enum
*reg_enum
;
357 /* On error, EBUSY can be returned if lock. Code flow error. */
358 ret
= pthread_mutex_destroy(&_lock
);
362 lttng::urcu::read_lock_guard read_lock_guard
;
364 /* Destroy all event associated with this registry. */
366 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
367 cds_lfht_for_each_entry(_channels
->ht
, &iter
.iter
, chan
, _node
.node
) {
368 /* Delete the node from the ht and free it. */
369 ret
= lttng_ht_del(_channels
.get(), &iter
);
371 destroy_channel(chan
, true);
377 if (_metadata_fd
>= 0) {
378 ret
= close(_metadata_fd
);
383 ret
= run_as_unlink(_metadata_path
.c_str(), _uid
, _gid
);
389 if (_root_shm_path
[0]) {
390 /* Try to delete the directory hierarchy. */
391 (void) run_as_rmdir_recursive(_root_shm_path
.c_str(), _uid
, _gid
,
392 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG
);
395 /* Destroy the enum hash table */
397 lttng::urcu::read_lock_guard read_lock_guard
;
399 /* Destroy all enum entries associated with this registry. */
401 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
402 cds_lfht_for_each_entry (_enums
->ht
, &iter
.iter
, reg_enum
, node
.node
) {
403 _destroy_enum(reg_enum
);
409 lsu::registry_session::locked_ptr
lsu::registry_session::lock() noexcept
411 pthread_mutex_lock(&_lock
);
412 return locked_ptr(this);
416 * Initialize registry with default values.
418 void lsu::registry_session::add_channel(uint64_t key
)
420 lttng::pthread::lock_guard
session_lock_guard(_lock
);
423 * Assign a channel ID right now since the event notification comes
424 * *before* the channel notify so the ID needs to be set at this point so
425 * the metadata can be dumped for that event.
427 if (is_max_channel_id(_used_channel_id
)) {
428 LTTNG_THROW_ERROR(fmt::format("Failed to allocate unique id for channel under session while adding channel"));
431 auto chan
= new lsu::registry_channel(
432 _get_next_channel_id(), abi
, _clock
.name
,
433 /* Registered channel listener. */
434 [this](const lsu::registry_channel
& registered_channel
) {
436 * Channel registration completed, serialize it's layout's
439 registered_channel
.accept(*_metadata_generating_visitor
);
441 /* Added event listener. */
442 [this](const lsu::registry_channel
& channel
,
443 const lsu::registry_event
& added_event
) {
445 * The channel and its event classes will be dumped at once when
446 * it is registered. This check prevents event classes from being
447 * declared before their stream class.
449 if (channel
.is_registered()) {
450 added_event
.accept(*_metadata_generating_visitor
);
454 lttng::urcu::read_lock_guard rcu_read_lock_guard
;
455 lttng_ht_node_init_u64(&chan
->_node
, key
);
456 lttng_ht_add_unique_u64(_channels
.get(), &chan
->_node
);
459 lttng::sessiond::ust::registry_channel
& lsu::registry_session::get_channel(
460 uint64_t channel_key
) const
462 lttng::urcu::read_lock_guard read_lock_guard
;
463 struct lttng_ht_node_u64
*node
;
464 struct lttng_ht_iter iter
;
466 ASSERT_LOCKED(_lock
);
468 lttng_ht_lookup(_channels
.get(), &channel_key
, &iter
);
469 node
= lttng_ht_iter_get_node_u64(&iter
);
471 LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
472 "Invalid channel key provided: channel key = {}", channel_key
));
476 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
477 auto chan
= lttng::utils::container_of(node
, &lsu::registry_channel::_node
);
482 void lsu::registry_session::remove_channel(uint64_t channel_key
, bool notify
)
484 struct lttng_ht_iter iter
;
486 lttng::urcu::read_lock_guard read_lock_guard
;
488 ASSERT_LOCKED(_lock
);
489 auto& channel
= get_channel(channel_key
);
491 iter
.iter
.node
= &channel
._node
.node
;
492 ret
= lttng_ht_del(_channels
.get(), &iter
);
494 destroy_channel(&channel
, notify
);
497 void lsu::registry_session::_visit_environment(
498 lttng::sessiond::trace::trace_class_visitor
& visitor
) const
500 ASSERT_LOCKED(_lock
);
502 visitor
.visit(lst::environment_field
<const char *>("domain", "ust"));
503 visitor
.visit(lst::environment_field
<const char *>("tracer_name", "lttng-ust"));
504 visitor
.visit(lst::environment_field
<int64_t>("tracer_major", _app_tracer_version
.major
));
505 visitor
.visit(lst::environment_field
<int64_t>("tracer_minor", _app_tracer_version
.minor
));
506 visitor
.visit(lst::environment_field
<const char *>("tracer_buffering_scheme",
507 get_buffering_scheme() == LTTNG_BUFFER_PER_PID
? "pid" : "uid"));
508 visitor
.visit(lst::environment_field
<int64_t>("architecture_bit_width", abi
.bits_per_long
));
511 /* The caller already holds the session and session list locks. */
512 ASSERT_SESSION_LIST_LOCKED();
513 const auto session
= lttng::sessiond::find_session_by_id(_tracing_id
);
515 LTTNG_ASSERT(session
);
516 ASSERT_LOCKED(session
->lock
);
518 visitor
.visit(lst::environment_field
<const char *>("trace_name",
519 session
->has_auto_generated_name
? DEFAULT_SESSION_NAME
:
521 visitor
.visit(lst::environment_field
<std::string
>("trace_creation_datetime",
522 lttng::utils::time_to_iso8601_str(session
->creation_time
)));
523 visitor
.visit(lst::environment_field
<const char *>("hostname", session
->hostname
));
527 void lsu::registry_session::_accept_on_clock_classes(lst::trace_class_visitor
& visitor
) const
529 ASSERT_LOCKED(_lock
);
530 _clock
.accept(visitor
);
533 void lsu::registry_session::_accept_on_stream_classes(lst::trace_class_visitor
& visitor
) const
535 ASSERT_LOCKED(_lock
);
537 std::vector
<const lttng::sessiond::ust::registry_channel
*> sorted_stream_classes
;
540 lttng::urcu::read_lock_guard rcu_lock_guard
;
541 const lsu::registry_channel
*channel
;
542 lttng_ht_iter channel_it
;
545 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
546 cds_lfht_for_each_entry(_channels
->ht
, &channel_it
.iter
, channel
, _node
.node
) {
547 sorted_stream_classes
.emplace_back(channel
);
552 std::sort(sorted_stream_classes
.begin(), sorted_stream_classes
.end(),
553 [](const lttng::sessiond::ust::registry_channel
*a
,
554 const lttng::sessiond::ust::registry_channel
*b
) {
555 return a
->id
< b
->id
;
558 for (const auto stream_class
: sorted_stream_classes
) {
559 stream_class
->accept(visitor
);
564 * Return next available channel id and increment the used counter. The
565 * is_max_channel_id function MUST be called before in order to validate
566 * if the maximum number of IDs have been reached. If not, it is safe to call
569 * Return a unique channel ID. If max is reached, the used_channel_id counter
572 uint32_t lsu::registry_session::_get_next_channel_id()
574 if (is_max_channel_id(_used_channel_id
)) {
575 return _used_channel_id
;
579 return _next_channel_id
++;
582 void lsu::registry_session::_increase_metadata_size(size_t reservation_length
)
584 const auto new_len
= _metadata_len
+ reservation_length
;
585 auto new_alloc_len
= new_len
;
586 const auto old_alloc_len
= _metadata_alloc_len
;
588 /* Rounding the new allocation length to the next power of 2 would overflow. */
589 if (new_alloc_len
> (UINT32_MAX
>> 1)) {
590 LTTNG_THROW_ERROR("Failed to reserve trace metadata storage as the new size would overflow");
593 /* The current allocation length is already the largest we can afford. */
594 if ((old_alloc_len
<< 1) > (UINT32_MAX
>> 1)) {
595 LTTNG_THROW_ERROR("Failed to reserve trace metadata storage as the max size was already reached");
598 if (new_alloc_len
> old_alloc_len
) {
599 new_alloc_len
= std::max
<size_t>(
600 1U << get_count_order(new_alloc_len
), old_alloc_len
<< 1);
602 auto newptr
= (char *) realloc(_metadata
, new_alloc_len
);
604 LTTNG_THROW_POSIX("Failed to allocate trace metadata storage", errno
);
609 /* We zero directly the memory from start of allocation. */
610 memset(&_metadata
[old_alloc_len
], 0, new_alloc_len
- old_alloc_len
);
611 _metadata_alloc_len
= new_alloc_len
;
614 _metadata_len
+= reservation_length
;
617 void lsu::registry_session::_append_metadata_fragment(const std::string
& fragment
)
619 const auto offset
= _metadata_len
;
621 _increase_metadata_size(fragment
.size());
622 memcpy(&_metadata
[offset
], fragment
.c_str(), fragment
.size());
624 if (_metadata_fd
>= 0) {
625 const auto bytes_written
=
626 lttng_write(_metadata_fd
, fragment
.c_str(), fragment
.size());
628 if (bytes_written
!= fragment
.size()) {
629 LTTNG_THROW_POSIX("Failed to write trace metadata fragment to file",
635 void lsu::registry_session::_reset_metadata()
637 _metadata_len_sent
= 0;
638 memset(_metadata
, 0, _metadata_alloc_len
);
641 if (_metadata_fd
> 0) {
642 /* Clear the metadata file's content. */
643 clear_metadata_file(_metadata_fd
);
647 void lsu::registry_session::_generate_metadata()
649 accept(*_metadata_generating_visitor
);
652 void lsu::registry_session::regenerate_metadata()
654 lttng::pthread::lock_guard
registry_lock(_lock
);
658 _generate_metadata();
662 * Lookup enumeration by enum ID.
664 * Note that there is no need to lock the registry session as this only
665 * performs an RCU-protected look-up. The function also return an rcu-protected
666 * reference, which ensures that the caller keeps the RCU read lock until it
667 * disposes of the object.
669 lsu::registry_enum::const_rcu_protected_reference
670 lsu::registry_session::get_enumeration(const char *enum_name
, uint64_t enum_id
) const
672 lsu::registry_enum
*reg_enum
= NULL
;
673 struct lttng_ht_node_str
*node
;
674 struct lttng_ht_iter iter
;
675 lttng::urcu::unique_read_lock rcu_lock
;
677 * Hack: only the name is used for hashing; the rest of the attributes
680 lsu::registry_signed_enum
reg_enum_lookup(enum_name
, nullptr, 0);
682 ASSERT_RCU_READ_LOCKED();
684 reg_enum_lookup
.id
= enum_id
;
685 cds_lfht_lookup(_enums
->ht
,
686 ht_hash_enum((void *) ®_enum_lookup
, lttng_ht_seed
),
687 ht_match_enum_id
, ®_enum_lookup
, &iter
.iter
);
688 node
= lttng_ht_iter_get_node_str(&iter
);
690 LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
691 "Unknown enumeration referenced by application event field: enum name = `{}`, enum id = {}",
692 enum_name
, enum_id
));
696 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
697 reg_enum
= lttng::utils::container_of(node
, &lsu::registry_enum::node
);
700 return lsu::registry_enum::const_rcu_protected_reference
{*reg_enum
, std::move(rcu_lock
)};
704 * Lookup enumeration by name and comparing enumeration entries.
705 * Needs to be called from RCU read-side critical section.
707 lsu::registry_enum
*lsu::registry_session::_lookup_enum(
708 const lsu::registry_enum
*reg_enum_lookup
) const
710 lsu::registry_enum
*reg_enum
= NULL
;
711 struct lttng_ht_node_str
*node
;
712 struct lttng_ht_iter iter
;
714 ASSERT_RCU_READ_LOCKED();
716 cds_lfht_lookup(_enums
->ht
, ht_hash_enum((void *) reg_enum_lookup
, lttng_ht_seed
),
717 ht_match_enum
, reg_enum_lookup
, &iter
.iter
);
718 node
= lttng_ht_iter_get_node_str(&iter
);
724 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
725 reg_enum
= lttng::utils::container_of(node
, &lsu::registry_enum::node
);
733 * Create a lsu::registry_enum from the given parameters and add it to the
734 * registry hash table, or find it if already there.
736 * Should be called with session registry mutex held.
738 * We receive ownership of entries.
740 void lsu::registry_session::create_or_find_enum(
741 int session_objd
, const char *enum_name
,
742 struct lttng_ust_ctl_enum_entry
*raw_entries
, size_t nr_entries
,
745 struct cds_lfht_node
*nodep
;
746 lsu::registry_enum
*reg_enum
= NULL
, *old_reg_enum
;
747 lttng::urcu::read_lock_guard read_lock_guard
;
748 auto entries
= lttng::make_unique_wrapper
<lttng_ust_ctl_enum_entry
, lttng::free
>(raw_entries
);
750 LTTNG_ASSERT(enum_name
);
753 * This should not happen but since it comes from the UST tracer, an
754 * external party, don't assert and simply validate values.
756 if (session_objd
< 0) {
757 LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
758 "Invalid parameters used to create or look-up enumeration from registry session: session_objd = {}",
761 if (nr_entries
== 0) {
762 LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
763 "Invalid parameters used to create or look-up enumeration from registry session: nr_entries = {}",
766 if (lttng_strnlen(enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
) ==
767 LTTNG_UST_ABI_SYM_NAME_LEN
) {
768 LTTNG_THROW_INVALID_ARGUMENT_ERROR(
769 "Invalid parameters used to create or look-up enumeration from registry session: enumeration name is not null terminated");
772 if (entries
->start
.signedness
) {
773 reg_enum
= new lsu::registry_signed_enum(
774 enum_name
, entries
.get(), nr_entries
);
776 reg_enum
= new lsu::registry_unsigned_enum(
777 enum_name
, entries
.get(), nr_entries
);
780 old_reg_enum
= _lookup_enum(reg_enum
);
782 DBG("enum %s already in sess_objd: %u", enum_name
, session_objd
);
783 /* Fall through. Use prior enum. */
784 destroy_enum(reg_enum
);
785 reg_enum
= old_reg_enum
;
787 DBG("UST registry creating enum: %s, sess_objd: %u",
788 enum_name
, session_objd
);
789 if (_next_enum_id
== -1ULL) {
790 destroy_enum(reg_enum
);
791 LTTNG_THROW_ERROR("Failed to allocate unique enumeration ID as it would overflow");
794 reg_enum
->id
= _next_enum_id
++;
795 nodep
= cds_lfht_add_unique(_enums
->ht
,
796 ht_hash_enum(reg_enum
, lttng_ht_seed
),
797 ht_match_enum_id
, reg_enum
,
798 ®_enum
->node
.node
);
799 LTTNG_ASSERT(nodep
== ®_enum
->node
.node
);
802 DBG("UST registry reply with enum %s with id %" PRIu64
" in sess_objd: %u",
803 enum_name
, reg_enum
->id
, session_objd
);
804 *enum_id
= reg_enum
->id
;