2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
12 #include <common/common.h>
13 #include <common/hashtable/utils.h>
14 #include <lttng/lttng.h>
16 #include "ust-registry.h"
18 #include "ust-field-utils.h"
20 #include "lttng-sessiond.h"
21 #include "notification-thread-commands.h"
25 * Hash table match function for event in the registry.
27 static int ht_match_event(struct cds_lfht_node
*node
, const void *_key
)
29 const struct ust_registry_event
*key
;
30 struct ust_registry_event
*event
;
36 event
= caa_container_of(node
, struct ust_registry_event
, node
.node
);
40 /* It has to be a perfect match. First, compare the event names. */
41 if (strncmp(event
->name
, key
->name
, sizeof(event
->name
))) {
45 /* Compare log levels. */
46 if (event
->loglevel_value
!= key
->loglevel_value
) {
50 /* Compare the number of fields. */
51 if (event
->nr_fields
!= key
->nr_fields
) {
55 /* Compare each field individually. */
56 for (i
= 0; i
< event
->nr_fields
; i
++) {
57 if (!match_ustctl_field(&event
->fields
[i
], &key
->fields
[i
])) {
62 /* Compare model URI. */
63 if (event
->model_emf_uri
!= NULL
&& key
->model_emf_uri
== NULL
) {
65 } else if(event
->model_emf_uri
== NULL
&& key
->model_emf_uri
!= NULL
) {
67 } else if (event
->model_emf_uri
!= NULL
&& key
->model_emf_uri
!= NULL
) {
68 if (strcmp(event
->model_emf_uri
, key
->model_emf_uri
)) {
80 static unsigned long ht_hash_event(const void *_key
, unsigned long seed
)
83 const struct ust_registry_event
*key
= _key
;
87 hashed_key
= (uint64_t) hash_key_str(key
->name
, seed
);
89 return hash_key_u64(&hashed_key
, seed
);
92 static int compare_enums(const struct ust_registry_enum
*reg_enum_a
,
93 const struct ust_registry_enum
*reg_enum_b
)
98 assert(strcmp(reg_enum_a
->name
, reg_enum_b
->name
) == 0);
99 if (reg_enum_a
->nr_entries
!= reg_enum_b
->nr_entries
) {
103 for (i
= 0; i
< reg_enum_a
->nr_entries
; i
++) {
104 const struct ustctl_enum_entry
*entries_a
, *entries_b
;
106 entries_a
= ®_enum_a
->entries
[i
];
107 entries_b
= ®_enum_b
->entries
[i
];
108 if (entries_a
->start
.value
!= entries_b
->start
.value
) {
112 if (entries_a
->end
.value
!= entries_b
->end
.value
) {
116 if (entries_a
->start
.signedness
!= entries_b
->start
.signedness
) {
120 if (entries_a
->end
.signedness
!= entries_b
->end
.signedness
) {
125 if (strcmp(entries_a
->string
, entries_b
->string
)) {
135 * Hash table match function for enumerations in the session. Match is
136 * performed on enumeration name, and confirmed by comparing the enum
139 static int ht_match_enum(struct cds_lfht_node
*node
, const void *_key
)
141 struct ust_registry_enum
*_enum
;
142 const struct ust_registry_enum
*key
;
147 _enum
= caa_container_of(node
, struct ust_registry_enum
,
152 if (strncmp(_enum
->name
, key
->name
, LTTNG_UST_ABI_SYM_NAME_LEN
)) {
155 if (compare_enums(_enum
, key
)) {
167 * Hash table match function for enumerations in the session. Match is
168 * performed by enumeration ID.
170 static int ht_match_enum_id(struct cds_lfht_node
*node
, const void *_key
)
172 struct ust_registry_enum
*_enum
;
173 const struct ust_registry_enum
*key
= _key
;
178 _enum
= caa_container_of(node
, struct ust_registry_enum
, node
.node
);
181 if (_enum
->id
!= key
->id
) {
193 * Hash table hash function for enumerations in the session. The
194 * enumeration name is used for hashing.
196 static unsigned long ht_hash_enum(void *_key
, unsigned long seed
)
198 struct ust_registry_enum
*key
= _key
;
201 return hash_key_str(key
->name
, seed
);
205 * Return negative value on error, 0 if OK.
207 * TODO: we could add stricter verification of more types to catch
208 * errors in liblttng-ust implementation earlier than consumption by the
212 int validate_event_field(struct ustctl_field
*field
,
213 const char *event_name
,
218 switch(field
->type
.atype
) {
219 case ustctl_atype_integer
:
220 case ustctl_atype_enum
:
221 case ustctl_atype_array
:
222 case ustctl_atype_sequence
:
223 case ustctl_atype_string
:
224 case ustctl_atype_variant
:
225 case ustctl_atype_array_nestable
:
226 case ustctl_atype_sequence_nestable
:
227 case ustctl_atype_enum_nestable
:
228 case ustctl_atype_variant_nestable
:
230 case ustctl_atype_struct
:
231 if (field
->type
.u
.legacy
._struct
.nr_fields
!= 0) {
232 WARN("Unsupported non-empty struct field.");
237 case ustctl_atype_struct_nestable
:
238 if (field
->type
.u
.struct_nestable
.nr_fields
!= 0) {
239 WARN("Unsupported non-empty struct field.");
245 case ustctl_atype_float
:
246 switch (field
->type
.u
._float
.mant_dig
) {
248 WARN("UST application '%s' (pid: %d) has unknown float mantissa '%u' "
249 "in field '%s', rejecting event '%s'",
251 field
->type
.u
._float
.mant_dig
,
270 int validate_event_fields(size_t nr_fields
, struct ustctl_field
*fields
,
271 const char *event_name
, struct ust_app
*app
)
275 for (i
= 0; i
< nr_fields
; i
++) {
276 if (validate_event_field(&fields
[i
], event_name
, app
) < 0)
283 * Allocate event and initialize it. This does NOT set a valid event id from a
286 static struct ust_registry_event
*alloc_event(int session_objd
,
287 int channel_objd
, char *name
, char *sig
, size_t nr_fields
,
288 struct ustctl_field
*fields
, int loglevel_value
,
289 char *model_emf_uri
, struct ust_app
*app
)
291 struct ust_registry_event
*event
= NULL
;
294 * Ensure that the field content is valid.
296 if (validate_event_fields(nr_fields
, fields
, name
, app
) < 0) {
300 event
= zmalloc(sizeof(*event
));
302 PERROR("zmalloc ust registry event");
306 event
->session_objd
= session_objd
;
307 event
->channel_objd
= channel_objd
;
308 /* Allocated by ustctl. */
309 event
->signature
= sig
;
310 event
->nr_fields
= nr_fields
;
311 event
->fields
= fields
;
312 event
->loglevel_value
= loglevel_value
;
313 event
->model_emf_uri
= model_emf_uri
;
315 /* Copy event name and force NULL byte. */
316 strncpy(event
->name
, name
, sizeof(event
->name
));
317 event
->name
[sizeof(event
->name
) - 1] = '\0';
319 cds_lfht_node_init(&event
->node
.node
);
326 * Free event data structure. This does NOT delete it from any hash table. It's
327 * safe to pass a NULL pointer. This shoudl be called inside a call RCU if the
328 * event is previously deleted from a rcu hash table.
330 static void destroy_event(struct ust_registry_event
*event
)
337 free(event
->model_emf_uri
);
338 free(event
->signature
);
343 * Destroy event function call of the call RCU.
345 static void destroy_event_rcu(struct rcu_head
*head
)
347 struct lttng_ht_node_u64
*node
=
348 caa_container_of(head
, struct lttng_ht_node_u64
, head
);
349 struct ust_registry_event
*event
=
350 caa_container_of(node
, struct ust_registry_event
, node
);
352 destroy_event(event
);
356 * Find an event using the name and signature in the given registry. RCU read
357 * side lock MUST be acquired before calling this function and as long as the
358 * event reference is kept by the caller.
360 * On success, the event pointer is returned else NULL.
362 struct ust_registry_event
*ust_registry_find_event(
363 struct ust_registry_channel
*chan
, char *name
, char *sig
)
365 struct lttng_ht_node_u64
*node
;
366 struct lttng_ht_iter iter
;
367 struct ust_registry_event
*event
= NULL
;
368 struct ust_registry_event key
;
374 /* Setup key for the match function. */
375 strncpy(key
.name
, name
, sizeof(key
.name
));
376 key
.name
[sizeof(key
.name
) - 1] = '\0';
379 cds_lfht_lookup(chan
->ht
->ht
, chan
->ht
->hash_fct(&key
, lttng_ht_seed
),
380 chan
->ht
->match_fct
, &key
, &iter
.iter
);
381 node
= lttng_ht_iter_get_node_u64(&iter
);
385 event
= caa_container_of(node
, struct ust_registry_event
, node
);
392 * Create a ust_registry_event from the given parameters and add it to the
393 * registry hash table. If event_id is valid, it is set with the newly created
396 * On success, return 0 else a negative value. The created event MUST be unique
397 * so on duplicate entry -EINVAL is returned. On error, event_id is untouched.
399 * Should be called with session registry mutex held.
401 int ust_registry_create_event(struct ust_registry_session
*session
,
402 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
403 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
,
404 int loglevel_value
, char *model_emf_uri
, int buffer_type
,
405 uint32_t *event_id_p
, struct ust_app
*app
)
409 struct cds_lfht_node
*nptr
;
410 struct ust_registry_event
*event
= NULL
;
411 struct ust_registry_channel
*chan
;
421 * This should not happen but since it comes from the UST tracer, an
422 * external party, don't assert and simply validate values.
424 if (session_objd
< 0 || channel_objd
< 0) {
429 chan
= ust_registry_channel_find(session
, chan_key
);
435 /* Check if we've reached the maximum possible id. */
436 if (ust_registry_is_max_id(chan
->used_event_id
)) {
441 event
= alloc_event(session_objd
, channel_objd
, name
, sig
, nr_fields
,
442 fields
, loglevel_value
, model_emf_uri
, app
);
448 DBG3("UST registry creating event with event: %s, sig: %s, id: %u, "
449 "chan_objd: %u, sess_objd: %u, chan_id: %u", event
->name
,
450 event
->signature
, event
->id
, event
->channel_objd
,
451 event
->session_objd
, chan
->chan_id
);
454 * This is an add unique with a custom match function for event. The node
455 * are matched using the event name and signature.
457 nptr
= cds_lfht_add_unique(chan
->ht
->ht
, chan
->ht
->hash_fct(event
,
458 lttng_ht_seed
), chan
->ht
->match_fct
, event
, &event
->node
.node
);
459 if (nptr
!= &event
->node
.node
) {
460 if (buffer_type
== LTTNG_BUFFER_PER_UID
) {
462 * This is normal, we just have to send the event id of the
463 * returned node and make sure we destroy the previously allocated
466 destroy_event(event
);
467 event
= caa_container_of(nptr
, struct ust_registry_event
,
470 event_id
= event
->id
;
472 ERR("UST registry create event add unique failed for event: %s, "
473 "sig: %s, id: %u, chan_objd: %u, sess_objd: %u",
474 event
->name
, event
->signature
, event
->id
,
475 event
->channel_objd
, event
->session_objd
);
480 /* Request next event id if the node was successfully added. */
481 event_id
= event
->id
= ust_registry_get_next_event_id(chan
);
484 *event_id_p
= event_id
;
486 if (!event
->metadata_dumped
) {
487 /* Append to metadata */
488 ret
= ust_metadata_event_statedump(session
, chan
, event
);
490 ERR("Error appending event metadata (errno = %d)", ret
);
505 destroy_event(event
);
510 * For a given event in a registry, delete the entry and destroy the event.
511 * This MUST be called within a RCU read side lock section.
513 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
514 struct ust_registry_event
*event
)
517 struct lttng_ht_iter iter
;
522 /* Delete the node first. */
523 iter
.iter
.node
= &event
->node
.node
;
524 ret
= lttng_ht_del(chan
->ht
, &iter
);
527 call_rcu(&event
->node
.head
, destroy_event_rcu
);
532 static void destroy_enum(struct ust_registry_enum
*reg_enum
)
537 free(reg_enum
->entries
);
541 static void destroy_enum_rcu(struct rcu_head
*head
)
543 struct ust_registry_enum
*reg_enum
=
544 caa_container_of(head
, struct ust_registry_enum
, rcu_head
);
546 destroy_enum(reg_enum
);
550 * Lookup enumeration by name and comparing enumeration entries.
551 * Needs to be called from RCU read-side critical section.
553 static struct ust_registry_enum
*ust_registry_lookup_enum(
554 struct ust_registry_session
*session
,
555 const struct ust_registry_enum
*reg_enum_lookup
)
557 struct ust_registry_enum
*reg_enum
= NULL
;
558 struct lttng_ht_node_str
*node
;
559 struct lttng_ht_iter iter
;
561 cds_lfht_lookup(session
->enums
->ht
,
562 ht_hash_enum((void *) reg_enum_lookup
, lttng_ht_seed
),
563 ht_match_enum
, reg_enum_lookup
, &iter
.iter
);
564 node
= lttng_ht_iter_get_node_str(&iter
);
568 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
574 * Lookup enumeration by enum ID.
575 * Needs to be called from RCU read-side critical section.
577 struct ust_registry_enum
*
578 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
579 const char *enum_name
, uint64_t enum_id
)
581 struct ust_registry_enum
*reg_enum
= NULL
;
582 struct lttng_ht_node_str
*node
;
583 struct lttng_ht_iter iter
;
584 struct ust_registry_enum reg_enum_lookup
;
586 memset(®_enum_lookup
, 0, sizeof(reg_enum_lookup
));
587 strncpy(reg_enum_lookup
.name
, enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
588 reg_enum_lookup
.name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
589 reg_enum_lookup
.id
= enum_id
;
590 cds_lfht_lookup(session
->enums
->ht
,
591 ht_hash_enum((void *) ®_enum_lookup
, lttng_ht_seed
),
592 ht_match_enum_id
, ®_enum_lookup
, &iter
.iter
);
593 node
= lttng_ht_iter_get_node_str(&iter
);
597 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
603 * Create a ust_registry_enum from the given parameters and add it to the
604 * registry hash table, or find it if already there.
606 * On success, return 0 else a negative value.
608 * Should be called with session registry mutex held.
610 * We receive ownership of entries.
612 int ust_registry_create_or_find_enum(struct ust_registry_session
*session
,
613 int session_objd
, char *enum_name
,
614 struct ustctl_enum_entry
*entries
, size_t nr_entries
,
618 struct cds_lfht_node
*nodep
;
619 struct ust_registry_enum
*reg_enum
= NULL
, *old_reg_enum
;
627 * This should not happen but since it comes from the UST tracer, an
628 * external party, don't assert and simply validate values.
630 if (session_objd
< 0) {
635 /* Check if the enumeration was already dumped */
636 reg_enum
= zmalloc(sizeof(*reg_enum
));
638 PERROR("zmalloc ust registry enumeration");
642 strncpy(reg_enum
->name
, enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
643 reg_enum
->name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
644 /* entries will be owned by reg_enum. */
645 reg_enum
->entries
= entries
;
646 reg_enum
->nr_entries
= nr_entries
;
649 old_reg_enum
= ust_registry_lookup_enum(session
, reg_enum
);
651 DBG("enum %s already in sess_objd: %u", enum_name
, session_objd
);
652 /* Fall through. Use prior enum. */
653 destroy_enum(reg_enum
);
654 reg_enum
= old_reg_enum
;
656 DBG("UST registry creating enum: %s, sess_objd: %u",
657 enum_name
, session_objd
);
658 if (session
->next_enum_id
== -1ULL) {
660 destroy_enum(reg_enum
);
663 reg_enum
->id
= session
->next_enum_id
++;
664 cds_lfht_node_init(®_enum
->node
.node
);
665 nodep
= cds_lfht_add_unique(session
->enums
->ht
,
666 ht_hash_enum(reg_enum
, lttng_ht_seed
),
667 ht_match_enum_id
, reg_enum
,
668 ®_enum
->node
.node
);
669 assert(nodep
== ®_enum
->node
.node
);
671 DBG("UST registry reply with enum %s with id %" PRIu64
" in sess_objd: %u",
672 enum_name
, reg_enum
->id
, session_objd
);
673 *enum_id
= reg_enum
->id
;
681 * For a given enumeration in a registry, delete the entry and destroy
683 * This MUST be called within a RCU read side lock section.
685 static void ust_registry_destroy_enum(struct ust_registry_session
*reg_session
,
686 struct ust_registry_enum
*reg_enum
)
689 struct lttng_ht_iter iter
;
694 /* Delete the node first. */
695 iter
.iter
.node
= ®_enum
->node
.node
;
696 ret
= lttng_ht_del(reg_session
->enums
, &iter
);
698 call_rcu(®_enum
->rcu_head
, destroy_enum_rcu
);
702 * We need to execute ht_destroy outside of RCU read-side critical
703 * section and outside of call_rcu thread, so we postpone its execution
704 * using ht_cleanup_push. It is simpler than to change the semantic of
705 * the many callers of delete_ust_app_session().
708 void destroy_channel_rcu(struct rcu_head
*head
)
710 struct ust_registry_channel
*chan
=
711 caa_container_of(head
, struct ust_registry_channel
, rcu_head
);
714 ht_cleanup_push(chan
->ht
);
716 free(chan
->ctx_fields
);
721 * Destroy every element of the registry and free the memory. This does NOT
722 * free the registry pointer since it might not have been allocated before so
723 * it's the caller responsability.
725 static void destroy_channel(struct ust_registry_channel
*chan
, bool notif
)
727 struct lttng_ht_iter iter
;
728 struct ust_registry_event
*event
;
729 enum lttng_error_code cmd_ret
;
734 cmd_ret
= notification_thread_command_remove_channel(
735 the_notification_thread_handle
,
736 chan
->consumer_key
, LTTNG_DOMAIN_UST
);
737 if (cmd_ret
!= LTTNG_OK
) {
738 ERR("Failed to remove channel from notification thread");
744 /* Destroy all event associated with this registry. */
745 cds_lfht_for_each_entry(
746 chan
->ht
->ht
, &iter
.iter
, event
, node
.node
) {
747 /* Delete the node from the ht and free it. */
748 ust_registry_destroy_event(chan
, event
);
752 call_rcu(&chan
->rcu_head
, destroy_channel_rcu
);
756 * Initialize registry with default values.
758 int ust_registry_channel_add(struct ust_registry_session
*session
,
762 struct ust_registry_channel
*chan
;
766 chan
= zmalloc(sizeof(*chan
));
768 PERROR("zmalloc ust registry channel");
773 chan
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
779 /* Set custom match function. */
780 chan
->ht
->match_fct
= ht_match_event
;
781 chan
->ht
->hash_fct
= ht_hash_event
;
784 * Assign a channel ID right now since the event notification comes
785 * *before* the channel notify so the ID needs to be set at this point so
786 * the metadata can be dumped for that event.
788 if (ust_registry_is_max_id(session
->used_channel_id
)) {
792 chan
->chan_id
= ust_registry_get_next_chan_id(session
);
795 lttng_ht_node_init_u64(&chan
->node
, key
);
796 lttng_ht_add_unique_u64(session
->channels
, &chan
->node
);
802 destroy_channel(chan
, false);
808 * Find a channel in the given registry. RCU read side lock MUST be acquired
809 * before calling this function and as long as the event reference is kept by
812 * On success, the pointer is returned else NULL.
814 struct ust_registry_channel
*ust_registry_channel_find(
815 struct ust_registry_session
*session
, uint64_t key
)
817 struct lttng_ht_node_u64
*node
;
818 struct lttng_ht_iter iter
;
819 struct ust_registry_channel
*chan
= NULL
;
822 assert(session
->channels
);
824 DBG3("UST registry channel finding key %" PRIu64
, key
);
826 lttng_ht_lookup(session
->channels
, &key
, &iter
);
827 node
= lttng_ht_iter_get_node_u64(&iter
);
831 chan
= caa_container_of(node
, struct ust_registry_channel
, node
);
838 * Remove channel using key from registry and free memory.
840 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
841 uint64_t key
, bool notif
)
843 struct lttng_ht_iter iter
;
844 struct ust_registry_channel
*chan
;
850 chan
= ust_registry_channel_find(session
, key
);
856 iter
.iter
.node
= &chan
->node
.node
;
857 ret
= lttng_ht_del(session
->channels
, &iter
);
860 destroy_channel(chan
, notif
);
867 * Initialize registry with default values and set the newly allocated session
868 * pointer to sessionp.
870 * Return 0 on success and sessionp is set or else return -1 and sessionp is
873 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
875 uint32_t bits_per_long
,
876 uint32_t uint8_t_alignment
,
877 uint32_t uint16_t_alignment
,
878 uint32_t uint32_t_alignment
,
879 uint32_t uint64_t_alignment
,
880 uint32_t long_alignment
,
884 const char *root_shm_path
,
885 const char *shm_path
,
892 struct ust_registry_session
*session
;
896 session
= zmalloc(sizeof(*session
));
898 PERROR("zmalloc ust registry session");
902 pthread_mutex_init(&session
->lock
, NULL
);
903 session
->bits_per_long
= bits_per_long
;
904 session
->uint8_t_alignment
= uint8_t_alignment
;
905 session
->uint16_t_alignment
= uint16_t_alignment
;
906 session
->uint32_t_alignment
= uint32_t_alignment
;
907 session
->uint64_t_alignment
= uint64_t_alignment
;
908 session
->long_alignment
= long_alignment
;
909 session
->byte_order
= byte_order
;
910 session
->metadata_fd
= -1;
913 session
->next_enum_id
= 0;
914 session
->major
= major
;
915 session
->minor
= minor
;
916 strncpy(session
->root_shm_path
, root_shm_path
,
917 sizeof(session
->root_shm_path
));
918 session
->root_shm_path
[sizeof(session
->root_shm_path
) - 1] = '\0';
920 strncpy(session
->shm_path
, shm_path
,
921 sizeof(session
->shm_path
));
922 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
923 strncpy(session
->metadata_path
, shm_path
,
924 sizeof(session
->metadata_path
));
925 session
->metadata_path
[sizeof(session
->metadata_path
) - 1] = '\0';
926 strncat(session
->metadata_path
, "/metadata",
927 sizeof(session
->metadata_path
)
928 - strlen(session
->metadata_path
) - 1);
930 if (session
->shm_path
[0]) {
931 ret
= run_as_mkdir_recursive(session
->shm_path
,
935 PERROR("run_as_mkdir_recursive");
939 if (session
->metadata_path
[0]) {
940 /* Create metadata file */
941 ret
= run_as_open(session
->metadata_path
,
942 O_WRONLY
| O_CREAT
| O_EXCL
,
943 S_IRUSR
| S_IWUSR
, euid
, egid
);
945 PERROR("Opening metadata file");
948 session
->metadata_fd
= ret
;
951 session
->enums
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
952 if (!session
->enums
) {
953 ERR("Failed to create enums hash table");
956 /* hash/match functions are specified at call site. */
957 session
->enums
->match_fct
= NULL
;
958 session
->enums
->hash_fct
= NULL
;
960 session
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
961 if (!session
->channels
) {
965 ret
= lttng_uuid_generate(session
->uuid
);
967 ERR("Failed to generate UST uuid (errno = %d)", ret
);
971 session
->tracing_id
= tracing_id
;
972 session
->tracing_uid
= tracing_uid
;
974 pthread_mutex_lock(&session
->lock
);
975 ret
= ust_metadata_session_statedump(session
, app
, major
, minor
);
976 pthread_mutex_unlock(&session
->lock
);
978 ERR("Failed to generate session metadata (errno = %d)", ret
);
987 ust_registry_session_destroy(session
);
994 * Destroy session registry. This does NOT free the given pointer since it
995 * might get passed as a reference. The registry lock should NOT be acquired.
997 void ust_registry_session_destroy(struct ust_registry_session
*reg
)
1000 struct lttng_ht_iter iter
;
1001 struct ust_registry_channel
*chan
;
1002 struct ust_registry_enum
*reg_enum
;
1008 /* On error, EBUSY can be returned if lock. Code flow error. */
1009 ret
= pthread_mutex_destroy(®
->lock
);
1012 if (reg
->channels
) {
1014 /* Destroy all event associated with this registry. */
1015 cds_lfht_for_each_entry(reg
->channels
->ht
, &iter
.iter
, chan
,
1017 /* Delete the node from the ht and free it. */
1018 ret
= lttng_ht_del(reg
->channels
, &iter
);
1020 destroy_channel(chan
, true);
1023 ht_cleanup_push(reg
->channels
);
1026 free(reg
->metadata
);
1027 if (reg
->metadata_fd
>= 0) {
1028 ret
= close(reg
->metadata_fd
);
1032 ret
= run_as_unlink(reg
->metadata_path
,
1033 reg
->uid
, reg
->gid
);
1038 if (reg
->root_shm_path
[0]) {
1040 * Try deleting the directory hierarchy.
1042 (void) run_as_rmdir_recursive(reg
->root_shm_path
,
1044 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG
);
1046 /* Destroy the enum hash table */
1049 /* Destroy all enum entries associated with this registry. */
1050 cds_lfht_for_each_entry(reg
->enums
->ht
, &iter
.iter
, reg_enum
,
1052 ust_registry_destroy_enum(reg
, reg_enum
);
1055 ht_cleanup_push(reg
->enums
);