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"
24 * Hash table match function for event in the registry.
26 static int ht_match_event(struct cds_lfht_node
*node
, const void *_key
)
28 const struct ust_registry_event
*key
;
29 struct ust_registry_event
*event
;
34 event
= caa_container_of(node
, struct ust_registry_event
, node
.node
);
38 /* It has to be a perfect match. First, compare the event names. */
39 if (strncmp(event
->name
, key
->name
, sizeof(event
->name
))) {
43 /* Compare log levels. */
44 if (event
->loglevel_value
!= key
->loglevel_value
) {
48 /* Compare the arrays of fields. */
49 if (!match_lttng_ust_ctl_field_array(event
->fields
, event
->nr_fields
,
50 key
->fields
, key
->nr_fields
)) {
54 /* Compare model URI. */
55 if (event
->model_emf_uri
!= NULL
&& key
->model_emf_uri
== NULL
) {
57 } else if(event
->model_emf_uri
== NULL
&& key
->model_emf_uri
!= NULL
) {
59 } else if (event
->model_emf_uri
!= NULL
&& key
->model_emf_uri
!= NULL
) {
60 if (strcmp(event
->model_emf_uri
, key
->model_emf_uri
)) {
72 static unsigned long ht_hash_event(const void *_key
, unsigned long seed
)
75 const struct ust_registry_event
*key
= _key
;
79 hashed_key
= (uint64_t) hash_key_str(key
->name
, seed
);
81 return hash_key_u64(&hashed_key
, seed
);
84 static int compare_enums(const struct ust_registry_enum
*reg_enum_a
,
85 const struct ust_registry_enum
*reg_enum_b
)
90 assert(strcmp(reg_enum_a
->name
, reg_enum_b
->name
) == 0);
91 if (reg_enum_a
->nr_entries
!= reg_enum_b
->nr_entries
) {
95 for (i
= 0; i
< reg_enum_a
->nr_entries
; i
++) {
96 const struct ustctl_enum_entry
*entries_a
, *entries_b
;
98 entries_a
= ®_enum_a
->entries
[i
];
99 entries_b
= ®_enum_b
->entries
[i
];
100 if (entries_a
->start
.value
!= entries_b
->start
.value
) {
104 if (entries_a
->end
.value
!= entries_b
->end
.value
) {
108 if (entries_a
->start
.signedness
!= entries_b
->start
.signedness
) {
112 if (entries_a
->end
.signedness
!= entries_b
->end
.signedness
) {
117 if (strcmp(entries_a
->string
, entries_b
->string
)) {
127 * Hash table match function for enumerations in the session. Match is
128 * performed on enumeration name, and confirmed by comparing the enum
131 static int ht_match_enum(struct cds_lfht_node
*node
, const void *_key
)
133 struct ust_registry_enum
*_enum
;
134 const struct ust_registry_enum
*key
;
139 _enum
= caa_container_of(node
, struct ust_registry_enum
,
144 if (strncmp(_enum
->name
, key
->name
, LTTNG_UST_SYM_NAME_LEN
)) {
147 if (compare_enums(_enum
, key
)) {
159 * Hash table match function for enumerations in the session. Match is
160 * performed by enumeration ID.
162 static int ht_match_enum_id(struct cds_lfht_node
*node
, const void *_key
)
164 struct ust_registry_enum
*_enum
;
165 const struct ust_registry_enum
*key
= _key
;
170 _enum
= caa_container_of(node
, struct ust_registry_enum
, node
.node
);
173 if (_enum
->id
!= key
->id
) {
185 * Hash table hash function for enumerations in the session. The
186 * enumeration name is used for hashing.
188 static unsigned long ht_hash_enum(void *_key
, unsigned long seed
)
190 struct ust_registry_enum
*key
= _key
;
193 return hash_key_str(key
->name
, seed
);
197 * Return negative value on error, 0 if OK.
199 * TODO: we could add stricter verification of more types to catch
200 * errors in liblttng-ust implementation earlier than consumption by the
204 int validate_event_field(struct ustctl_field
*field
,
205 const char *event_name
,
210 switch(field
->type
.atype
) {
211 case ustctl_atype_integer
:
212 case ustctl_atype_enum
:
213 case ustctl_atype_array
:
214 case ustctl_atype_sequence
:
215 case ustctl_atype_string
:
216 case ustctl_atype_variant
:
218 case ustctl_atype_struct
:
219 if (field
->type
.u
._struct
.nr_fields
!= 0) {
220 WARN("Unsupported non-empty struct field.");
226 case ustctl_atype_float
:
227 switch (field
->type
.u
.basic
._float
.mant_dig
) {
229 WARN("UST application '%s' (pid: %d) has unknown float mantissa '%u' "
230 "in field '%s', rejecting event '%s'",
232 field
->type
.u
.basic
._float
.mant_dig
,
251 int validate_event_fields(size_t nr_fields
, struct ustctl_field
*fields
,
252 const char *event_name
, struct ust_app
*app
)
256 for (i
= 0; i
< nr_fields
; i
++) {
257 if (validate_event_field(&fields
[i
], event_name
, app
) < 0)
264 * Allocate event and initialize it. This does NOT set a valid event id from a
267 static struct ust_registry_event
*alloc_event(int session_objd
,
268 int channel_objd
, char *name
, char *sig
, size_t nr_fields
,
269 struct ustctl_field
*fields
, int loglevel_value
,
270 char *model_emf_uri
, struct ust_app
*app
)
272 struct ust_registry_event
*event
= NULL
;
275 * Ensure that the field content is valid.
277 if (validate_event_fields(nr_fields
, fields
, name
, app
) < 0) {
281 event
= zmalloc(sizeof(*event
));
283 PERROR("zmalloc ust registry event");
287 event
->session_objd
= session_objd
;
288 event
->channel_objd
= channel_objd
;
289 /* Allocated by ustctl. */
290 event
->signature
= sig
;
291 event
->nr_fields
= nr_fields
;
292 event
->fields
= fields
;
293 event
->loglevel_value
= loglevel_value
;
294 event
->model_emf_uri
= model_emf_uri
;
296 /* Copy event name and force NULL byte. */
297 strncpy(event
->name
, name
, sizeof(event
->name
));
298 event
->name
[sizeof(event
->name
) - 1] = '\0';
300 cds_lfht_node_init(&event
->node
.node
);
307 * Free event data structure. This does NOT delete it from any hash table. It's
308 * safe to pass a NULL pointer. This shoudl be called inside a call RCU if the
309 * event is previously deleted from a rcu hash table.
311 static void destroy_event(struct ust_registry_event
*event
)
318 free(event
->model_emf_uri
);
319 free(event
->signature
);
324 * Destroy event function call of the call RCU.
326 static void destroy_event_rcu(struct rcu_head
*head
)
328 struct lttng_ht_node_u64
*node
=
329 caa_container_of(head
, struct lttng_ht_node_u64
, head
);
330 struct ust_registry_event
*event
=
331 caa_container_of(node
, struct ust_registry_event
, node
);
333 destroy_event(event
);
337 * Find an event using the name and signature in the given registry. RCU read
338 * side lock MUST be acquired before calling this function and as long as the
339 * event reference is kept by the caller.
341 * On success, the event pointer is returned else NULL.
343 struct ust_registry_event
*ust_registry_find_event(
344 struct ust_registry_channel
*chan
, char *name
, char *sig
)
346 struct lttng_ht_node_u64
*node
;
347 struct lttng_ht_iter iter
;
348 struct ust_registry_event
*event
= NULL
;
349 struct ust_registry_event key
;
355 /* Setup key for the match function. */
356 strncpy(key
.name
, name
, sizeof(key
.name
));
357 key
.name
[sizeof(key
.name
) - 1] = '\0';
360 cds_lfht_lookup(chan
->ht
->ht
, chan
->ht
->hash_fct(&key
, lttng_ht_seed
),
361 chan
->ht
->match_fct
, &key
, &iter
.iter
);
362 node
= lttng_ht_iter_get_node_u64(&iter
);
366 event
= caa_container_of(node
, struct ust_registry_event
, node
);
373 * Create a ust_registry_event from the given parameters and add it to the
374 * registry hash table. If event_id is valid, it is set with the newly created
377 * On success, return 0 else a negative value. The created event MUST be unique
378 * so on duplicate entry -EINVAL is returned. On error, event_id is untouched.
380 * Should be called with session registry mutex held.
382 int ust_registry_create_event(struct ust_registry_session
*session
,
383 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
384 char *sig
, size_t nr_fields
, struct ustctl_field
*fields
,
385 int loglevel_value
, char *model_emf_uri
, int buffer_type
,
386 uint32_t *event_id_p
, struct ust_app
*app
)
390 struct cds_lfht_node
*nptr
;
391 struct ust_registry_event
*event
= NULL
;
392 struct ust_registry_channel
*chan
;
402 * This should not happen but since it comes from the UST tracer, an
403 * external party, don't assert and simply validate values.
405 if (session_objd
< 0 || channel_objd
< 0) {
410 chan
= ust_registry_channel_find(session
, chan_key
);
416 /* Check if we've reached the maximum possible id. */
417 if (ust_registry_is_max_id(chan
->used_event_id
)) {
422 event
= alloc_event(session_objd
, channel_objd
, name
, sig
, nr_fields
,
423 fields
, loglevel_value
, model_emf_uri
, app
);
429 DBG3("UST registry creating event with event: %s, sig: %s, id: %u, "
430 "chan_objd: %u, sess_objd: %u, chan_id: %u", event
->name
,
431 event
->signature
, event
->id
, event
->channel_objd
,
432 event
->session_objd
, chan
->chan_id
);
435 * This is an add unique with a custom match function for event. The node
436 * are matched using the event name and signature.
438 nptr
= cds_lfht_add_unique(chan
->ht
->ht
, chan
->ht
->hash_fct(event
,
439 lttng_ht_seed
), chan
->ht
->match_fct
, event
, &event
->node
.node
);
440 if (nptr
!= &event
->node
.node
) {
441 if (buffer_type
== LTTNG_BUFFER_PER_UID
) {
443 * This is normal, we just have to send the event id of the
444 * returned node and make sure we destroy the previously allocated
447 destroy_event(event
);
448 event
= caa_container_of(nptr
, struct ust_registry_event
,
451 event_id
= event
->id
;
453 ERR("UST registry create event add unique failed for event: %s, "
454 "sig: %s, id: %u, chan_objd: %u, sess_objd: %u",
455 event
->name
, event
->signature
, event
->id
,
456 event
->channel_objd
, event
->session_objd
);
461 /* Request next event id if the node was successfully added. */
462 event_id
= event
->id
= ust_registry_get_next_event_id(chan
);
465 *event_id_p
= event_id
;
467 if (!event
->metadata_dumped
) {
468 /* Append to metadata */
469 ret
= ust_metadata_event_statedump(session
, chan
, event
);
471 ERR("Error appending event metadata (errno = %d)", ret
);
486 destroy_event(event
);
491 * For a given event in a registry, delete the entry and destroy the event.
492 * This MUST be called within a RCU read side lock section.
494 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
495 struct ust_registry_event
*event
)
498 struct lttng_ht_iter iter
;
503 /* Delete the node first. */
504 iter
.iter
.node
= &event
->node
.node
;
505 ret
= lttng_ht_del(chan
->ht
, &iter
);
508 call_rcu(&event
->node
.head
, destroy_event_rcu
);
513 static void destroy_enum(struct ust_registry_enum
*reg_enum
)
518 free(reg_enum
->entries
);
522 static void destroy_enum_rcu(struct rcu_head
*head
)
524 struct ust_registry_enum
*reg_enum
=
525 caa_container_of(head
, struct ust_registry_enum
, rcu_head
);
527 destroy_enum(reg_enum
);
531 * Lookup enumeration by name and comparing enumeration entries.
532 * Needs to be called from RCU read-side critical section.
534 static struct ust_registry_enum
*ust_registry_lookup_enum(
535 struct ust_registry_session
*session
,
536 const struct ust_registry_enum
*reg_enum_lookup
)
538 struct ust_registry_enum
*reg_enum
= NULL
;
539 struct lttng_ht_node_str
*node
;
540 struct lttng_ht_iter iter
;
542 cds_lfht_lookup(session
->enums
->ht
,
543 ht_hash_enum((void *) reg_enum_lookup
, lttng_ht_seed
),
544 ht_match_enum
, reg_enum_lookup
, &iter
.iter
);
545 node
= lttng_ht_iter_get_node_str(&iter
);
549 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
555 * Lookup enumeration by enum ID.
556 * Needs to be called from RCU read-side critical section.
558 struct ust_registry_enum
*
559 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
560 const char *enum_name
, uint64_t enum_id
)
562 struct ust_registry_enum
*reg_enum
= NULL
;
563 struct lttng_ht_node_str
*node
;
564 struct lttng_ht_iter iter
;
565 struct ust_registry_enum reg_enum_lookup
;
567 memset(®_enum_lookup
, 0, sizeof(reg_enum_lookup
));
568 strncpy(reg_enum_lookup
.name
, enum_name
, LTTNG_UST_SYM_NAME_LEN
);
569 reg_enum_lookup
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
570 reg_enum_lookup
.id
= enum_id
;
571 cds_lfht_lookup(session
->enums
->ht
,
572 ht_hash_enum((void *) ®_enum_lookup
, lttng_ht_seed
),
573 ht_match_enum_id
, ®_enum_lookup
, &iter
.iter
);
574 node
= lttng_ht_iter_get_node_str(&iter
);
578 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
584 * Create a ust_registry_enum from the given parameters and add it to the
585 * registry hash table, or find it if already there.
587 * On success, return 0 else a negative value.
589 * Should be called with session registry mutex held.
591 * We receive ownership of entries.
593 int ust_registry_create_or_find_enum(struct ust_registry_session
*session
,
594 int session_objd
, char *enum_name
,
595 struct ustctl_enum_entry
*entries
, size_t nr_entries
,
599 struct cds_lfht_node
*nodep
;
600 struct ust_registry_enum
*reg_enum
= NULL
, *old_reg_enum
;
608 * This should not happen but since it comes from the UST tracer, an
609 * external party, don't assert and simply validate values.
611 if (session_objd
< 0) {
616 /* Check if the enumeration was already dumped */
617 reg_enum
= zmalloc(sizeof(*reg_enum
));
619 PERROR("zmalloc ust registry enumeration");
623 strncpy(reg_enum
->name
, enum_name
, LTTNG_UST_SYM_NAME_LEN
);
624 reg_enum
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
625 /* entries will be owned by reg_enum. */
626 reg_enum
->entries
= entries
;
627 reg_enum
->nr_entries
= nr_entries
;
630 old_reg_enum
= ust_registry_lookup_enum(session
, reg_enum
);
632 DBG("enum %s already in sess_objd: %u", enum_name
, session_objd
);
633 /* Fall through. Use prior enum. */
634 destroy_enum(reg_enum
);
635 reg_enum
= old_reg_enum
;
637 DBG("UST registry creating enum: %s, sess_objd: %u",
638 enum_name
, session_objd
);
639 if (session
->next_enum_id
== -1ULL) {
641 destroy_enum(reg_enum
);
644 reg_enum
->id
= session
->next_enum_id
++;
645 cds_lfht_node_init(®_enum
->node
.node
);
646 nodep
= cds_lfht_add_unique(session
->enums
->ht
,
647 ht_hash_enum(reg_enum
, lttng_ht_seed
),
648 ht_match_enum_id
, reg_enum
,
649 ®_enum
->node
.node
);
650 assert(nodep
== ®_enum
->node
.node
);
652 DBG("UST registry reply with enum %s with id %" PRIu64
" in sess_objd: %u",
653 enum_name
, reg_enum
->id
, session_objd
);
654 *enum_id
= reg_enum
->id
;
662 * For a given enumeration in a registry, delete the entry and destroy
664 * This MUST be called within a RCU read side lock section.
666 static void ust_registry_destroy_enum(struct ust_registry_session
*reg_session
,
667 struct ust_registry_enum
*reg_enum
)
670 struct lttng_ht_iter iter
;
675 /* Delete the node first. */
676 iter
.iter
.node
= ®_enum
->node
.node
;
677 ret
= lttng_ht_del(reg_session
->enums
, &iter
);
679 call_rcu(®_enum
->rcu_head
, destroy_enum_rcu
);
683 * We need to execute ht_destroy outside of RCU read-side critical
684 * section and outside of call_rcu thread, so we postpone its execution
685 * using ht_cleanup_push. It is simpler than to change the semantic of
686 * the many callers of delete_ust_app_session().
689 void destroy_channel_rcu(struct rcu_head
*head
)
691 struct ust_registry_channel
*chan
=
692 caa_container_of(head
, struct ust_registry_channel
, rcu_head
);
695 ht_cleanup_push(chan
->ht
);
697 free(chan
->ctx_fields
);
702 * Destroy every element of the registry and free the memory. This does NOT
703 * free the registry pointer since it might not have been allocated before so
704 * it's the caller responsability.
706 static void destroy_channel(struct ust_registry_channel
*chan
, bool notif
)
708 struct lttng_ht_iter iter
;
709 struct ust_registry_event
*event
;
710 enum lttng_error_code cmd_ret
;
715 cmd_ret
= notification_thread_command_remove_channel(
716 notification_thread_handle
, chan
->consumer_key
,
718 if (cmd_ret
!= LTTNG_OK
) {
719 ERR("Failed to remove channel from notification thread");
725 /* Destroy all event associated with this registry. */
726 cds_lfht_for_each_entry(
727 chan
->ht
->ht
, &iter
.iter
, event
, node
.node
) {
728 /* Delete the node from the ht and free it. */
729 ust_registry_destroy_event(chan
, event
);
733 call_rcu(&chan
->rcu_head
, destroy_channel_rcu
);
737 * Initialize registry with default values.
739 int ust_registry_channel_add(struct ust_registry_session
*session
,
743 struct ust_registry_channel
*chan
;
747 chan
= zmalloc(sizeof(*chan
));
749 PERROR("zmalloc ust registry channel");
754 chan
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
760 /* Set custom match function. */
761 chan
->ht
->match_fct
= ht_match_event
;
762 chan
->ht
->hash_fct
= ht_hash_event
;
765 * Assign a channel ID right now since the event notification comes
766 * *before* the channel notify so the ID needs to be set at this point so
767 * the metadata can be dumped for that event.
769 if (ust_registry_is_max_id(session
->used_channel_id
)) {
773 chan
->chan_id
= ust_registry_get_next_chan_id(session
);
776 lttng_ht_node_init_u64(&chan
->node
, key
);
777 lttng_ht_add_unique_u64(session
->channels
, &chan
->node
);
783 destroy_channel(chan
, false);
789 * Find a channel in the given registry. RCU read side lock MUST be acquired
790 * before calling this function and as long as the event reference is kept by
793 * On success, the pointer is returned else NULL.
795 struct ust_registry_channel
*ust_registry_channel_find(
796 struct ust_registry_session
*session
, uint64_t key
)
798 struct lttng_ht_node_u64
*node
;
799 struct lttng_ht_iter iter
;
800 struct ust_registry_channel
*chan
= NULL
;
803 assert(session
->channels
);
805 DBG3("UST registry channel finding key %" PRIu64
, key
);
807 lttng_ht_lookup(session
->channels
, &key
, &iter
);
808 node
= lttng_ht_iter_get_node_u64(&iter
);
812 chan
= caa_container_of(node
, struct ust_registry_channel
, node
);
819 * Remove channel using key from registry and free memory.
821 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
822 uint64_t key
, bool notif
)
824 struct lttng_ht_iter iter
;
825 struct ust_registry_channel
*chan
;
831 chan
= ust_registry_channel_find(session
, key
);
837 iter
.iter
.node
= &chan
->node
.node
;
838 ret
= lttng_ht_del(session
->channels
, &iter
);
841 destroy_channel(chan
, notif
);
848 * Initialize registry with default values and set the newly allocated session
849 * pointer to sessionp.
851 * Return 0 on success and sessionp is set or else return -1 and sessionp is
854 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
856 uint32_t bits_per_long
,
857 uint32_t uint8_t_alignment
,
858 uint32_t uint16_t_alignment
,
859 uint32_t uint32_t_alignment
,
860 uint32_t uint64_t_alignment
,
861 uint32_t long_alignment
,
865 const char *root_shm_path
,
866 const char *shm_path
,
873 struct ust_registry_session
*session
;
877 session
= zmalloc(sizeof(*session
));
879 PERROR("zmalloc ust registry session");
883 pthread_mutex_init(&session
->lock
, NULL
);
884 session
->bits_per_long
= bits_per_long
;
885 session
->uint8_t_alignment
= uint8_t_alignment
;
886 session
->uint16_t_alignment
= uint16_t_alignment
;
887 session
->uint32_t_alignment
= uint32_t_alignment
;
888 session
->uint64_t_alignment
= uint64_t_alignment
;
889 session
->long_alignment
= long_alignment
;
890 session
->byte_order
= byte_order
;
891 session
->metadata_fd
= -1;
894 session
->next_enum_id
= 0;
895 session
->major
= major
;
896 session
->minor
= minor
;
897 strncpy(session
->root_shm_path
, root_shm_path
,
898 sizeof(session
->root_shm_path
));
899 session
->root_shm_path
[sizeof(session
->root_shm_path
) - 1] = '\0';
901 strncpy(session
->shm_path
, shm_path
,
902 sizeof(session
->shm_path
));
903 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
904 strncpy(session
->metadata_path
, shm_path
,
905 sizeof(session
->metadata_path
));
906 session
->metadata_path
[sizeof(session
->metadata_path
) - 1] = '\0';
907 strncat(session
->metadata_path
, "/metadata",
908 sizeof(session
->metadata_path
)
909 - strlen(session
->metadata_path
) - 1);
911 if (session
->shm_path
[0]) {
912 ret
= run_as_mkdir_recursive(session
->shm_path
,
916 PERROR("run_as_mkdir_recursive");
920 if (session
->metadata_path
[0]) {
921 /* Create metadata file */
922 ret
= run_as_open(session
->metadata_path
,
923 O_WRONLY
| O_CREAT
| O_EXCL
,
924 S_IRUSR
| S_IWUSR
, euid
, egid
);
926 PERROR("Opening metadata file");
929 session
->metadata_fd
= ret
;
932 session
->enums
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
933 if (!session
->enums
) {
934 ERR("Failed to create enums hash table");
937 /* hash/match functions are specified at call site. */
938 session
->enums
->match_fct
= NULL
;
939 session
->enums
->hash_fct
= NULL
;
941 session
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
942 if (!session
->channels
) {
946 ret
= lttng_uuid_generate(session
->uuid
);
948 ERR("Failed to generate UST uuid (errno = %d)", ret
);
952 session
->tracing_id
= tracing_id
;
953 session
->tracing_uid
= tracing_uid
;
955 pthread_mutex_lock(&session
->lock
);
956 ret
= ust_metadata_session_statedump(session
, app
, major
, minor
);
957 pthread_mutex_unlock(&session
->lock
);
959 ERR("Failed to generate session metadata (errno = %d)", ret
);
968 ust_registry_session_destroy(session
);
975 * Destroy session registry. This does NOT free the given pointer since it
976 * might get passed as a reference. The registry lock should NOT be acquired.
978 void ust_registry_session_destroy(struct ust_registry_session
*reg
)
981 struct lttng_ht_iter iter
;
982 struct ust_registry_channel
*chan
;
983 struct ust_registry_enum
*reg_enum
;
989 /* On error, EBUSY can be returned if lock. Code flow error. */
990 ret
= pthread_mutex_destroy(®
->lock
);
995 /* Destroy all event associated with this registry. */
996 cds_lfht_for_each_entry(reg
->channels
->ht
, &iter
.iter
, chan
,
998 /* Delete the node from the ht and free it. */
999 ret
= lttng_ht_del(reg
->channels
, &iter
);
1001 destroy_channel(chan
, true);
1004 ht_cleanup_push(reg
->channels
);
1007 free(reg
->metadata
);
1008 if (reg
->metadata_fd
>= 0) {
1009 ret
= close(reg
->metadata_fd
);
1013 ret
= run_as_unlink(reg
->metadata_path
,
1014 reg
->uid
, reg
->gid
);
1019 if (reg
->root_shm_path
[0]) {
1021 * Try deleting the directory hierarchy.
1023 (void) run_as_rmdir_recursive(reg
->root_shm_path
,
1025 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG
);
1027 /* Destroy the enum hash table */
1030 /* Destroy all enum entries associated with this registry. */
1031 cds_lfht_for_each_entry(reg
->enums
->ht
, &iter
.iter
, reg_enum
,
1033 ust_registry_destroy_enum(reg
, reg_enum
);
1036 ht_cleanup_push(reg
->enums
);