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 lttng_ust_ctl_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_ABI_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 lttng_ust_ctl_field
*field
,
205 const char *event_name
,
210 switch(field
->type
.atype
) {
211 case lttng_ust_ctl_atype_integer
:
212 case lttng_ust_ctl_atype_enum
:
213 case lttng_ust_ctl_atype_array
:
214 case lttng_ust_ctl_atype_sequence
:
215 case lttng_ust_ctl_atype_string
:
216 case lttng_ust_ctl_atype_variant
:
217 case lttng_ust_ctl_atype_array_nestable
:
218 case lttng_ust_ctl_atype_sequence_nestable
:
219 case lttng_ust_ctl_atype_enum_nestable
:
220 case lttng_ust_ctl_atype_variant_nestable
:
222 case lttng_ust_ctl_atype_struct
:
223 if (field
->type
.u
.legacy
._struct
.nr_fields
!= 0) {
224 WARN("Unsupported non-empty struct field.");
229 case lttng_ust_ctl_atype_struct_nestable
:
230 if (field
->type
.u
.struct_nestable
.nr_fields
!= 0) {
231 WARN("Unsupported non-empty struct field.");
237 case lttng_ust_ctl_atype_float
:
238 switch (field
->type
.u
._float
.mant_dig
) {
240 WARN("UST application '%s' (pid: %d) has unknown float mantissa '%u' "
241 "in field '%s', rejecting event '%s'",
243 field
->type
.u
._float
.mant_dig
,
262 int validate_event_fields(size_t nr_fields
, struct lttng_ust_ctl_field
*fields
,
263 const char *event_name
, struct ust_app
*app
)
267 for (i
= 0; i
< nr_fields
; i
++) {
268 if (validate_event_field(&fields
[i
], event_name
, app
) < 0)
275 * Allocate event and initialize it. This does NOT set a valid event id from a
278 static struct ust_registry_event
*alloc_event(int session_objd
,
279 int channel_objd
, char *name
, char *sig
, size_t nr_fields
,
280 struct lttng_ust_ctl_field
*fields
, int loglevel_value
,
281 char *model_emf_uri
, struct ust_app
*app
)
283 struct ust_registry_event
*event
= NULL
;
286 * Ensure that the field content is valid.
288 if (validate_event_fields(nr_fields
, fields
, name
, app
) < 0) {
292 event
= zmalloc(sizeof(*event
));
294 PERROR("zmalloc ust registry event");
298 event
->session_objd
= session_objd
;
299 event
->channel_objd
= channel_objd
;
300 /* Allocated by ustctl. */
301 event
->signature
= sig
;
302 event
->nr_fields
= nr_fields
;
303 event
->fields
= fields
;
304 event
->loglevel_value
= loglevel_value
;
305 event
->model_emf_uri
= model_emf_uri
;
307 /* Copy event name and force NULL byte. */
308 strncpy(event
->name
, name
, sizeof(event
->name
));
309 event
->name
[sizeof(event
->name
) - 1] = '\0';
311 cds_lfht_node_init(&event
->node
.node
);
318 * Free event data structure. This does NOT delete it from any hash table. It's
319 * safe to pass a NULL pointer. This shoudl be called inside a call RCU if the
320 * event is previously deleted from a rcu hash table.
322 static void destroy_event(struct ust_registry_event
*event
)
329 free(event
->model_emf_uri
);
330 free(event
->signature
);
335 * Destroy event function call of the call RCU.
337 static void destroy_event_rcu(struct rcu_head
*head
)
339 struct lttng_ht_node_u64
*node
=
340 caa_container_of(head
, struct lttng_ht_node_u64
, head
);
341 struct ust_registry_event
*event
=
342 caa_container_of(node
, struct ust_registry_event
, node
);
344 destroy_event(event
);
348 * Find an event using the name and signature in the given registry. RCU read
349 * side lock MUST be acquired before calling this function and as long as the
350 * event reference is kept by the caller.
352 * On success, the event pointer is returned else NULL.
354 struct ust_registry_event
*ust_registry_find_event(
355 struct ust_registry_channel
*chan
, char *name
, char *sig
)
357 struct lttng_ht_node_u64
*node
;
358 struct lttng_ht_iter iter
;
359 struct ust_registry_event
*event
= NULL
;
360 struct ust_registry_event key
;
366 /* Setup key for the match function. */
367 strncpy(key
.name
, name
, sizeof(key
.name
));
368 key
.name
[sizeof(key
.name
) - 1] = '\0';
371 cds_lfht_lookup(chan
->ht
->ht
, chan
->ht
->hash_fct(&key
, lttng_ht_seed
),
372 chan
->ht
->match_fct
, &key
, &iter
.iter
);
373 node
= lttng_ht_iter_get_node_u64(&iter
);
377 event
= caa_container_of(node
, struct ust_registry_event
, node
);
384 * Create a ust_registry_event from the given parameters and add it to the
385 * registry hash table. If event_id is valid, it is set with the newly created
388 * On success, return 0 else a negative value. The created event MUST be unique
389 * so on duplicate entry -EINVAL is returned. On error, event_id is untouched.
391 * Should be called with session registry mutex held.
393 int ust_registry_create_event(struct ust_registry_session
*session
,
394 uint64_t chan_key
, int session_objd
, int channel_objd
, char *name
,
395 char *sig
, size_t nr_fields
, struct lttng_ust_ctl_field
*fields
,
396 int loglevel_value
, char *model_emf_uri
, int buffer_type
,
397 uint32_t *event_id_p
, struct ust_app
*app
)
401 struct cds_lfht_node
*nptr
;
402 struct ust_registry_event
*event
= NULL
;
403 struct ust_registry_channel
*chan
;
413 * This should not happen but since it comes from the UST tracer, an
414 * external party, don't assert and simply validate values.
416 if (session_objd
< 0 || channel_objd
< 0) {
421 chan
= ust_registry_channel_find(session
, chan_key
);
427 /* Check if we've reached the maximum possible id. */
428 if (ust_registry_is_max_id(chan
->used_event_id
)) {
433 event
= alloc_event(session_objd
, channel_objd
, name
, sig
, nr_fields
,
434 fields
, loglevel_value
, model_emf_uri
, app
);
440 DBG3("UST registry creating event with event: %s, sig: %s, id: %u, "
441 "chan_objd: %u, sess_objd: %u, chan_id: %u", event
->name
,
442 event
->signature
, event
->id
, event
->channel_objd
,
443 event
->session_objd
, chan
->chan_id
);
446 * This is an add unique with a custom match function for event. The node
447 * are matched using the event name and signature.
449 nptr
= cds_lfht_add_unique(chan
->ht
->ht
, chan
->ht
->hash_fct(event
,
450 lttng_ht_seed
), chan
->ht
->match_fct
, event
, &event
->node
.node
);
451 if (nptr
!= &event
->node
.node
) {
452 if (buffer_type
== LTTNG_BUFFER_PER_UID
) {
454 * This is normal, we just have to send the event id of the
455 * returned node and make sure we destroy the previously allocated
458 destroy_event(event
);
459 event
= caa_container_of(nptr
, struct ust_registry_event
,
462 event_id
= event
->id
;
464 ERR("UST registry create event add unique failed for event: %s, "
465 "sig: %s, id: %u, chan_objd: %u, sess_objd: %u",
466 event
->name
, event
->signature
, event
->id
,
467 event
->channel_objd
, event
->session_objd
);
472 /* Request next event id if the node was successfully added. */
473 event_id
= event
->id
= ust_registry_get_next_event_id(chan
);
476 *event_id_p
= event_id
;
478 if (!event
->metadata_dumped
) {
479 /* Append to metadata */
480 ret
= ust_metadata_event_statedump(session
, chan
, event
);
482 ERR("Error appending event metadata (errno = %d)", ret
);
497 destroy_event(event
);
502 * For a given event in a registry, delete the entry and destroy the event.
503 * This MUST be called within a RCU read side lock section.
505 void ust_registry_destroy_event(struct ust_registry_channel
*chan
,
506 struct ust_registry_event
*event
)
509 struct lttng_ht_iter iter
;
514 /* Delete the node first. */
515 iter
.iter
.node
= &event
->node
.node
;
516 ret
= lttng_ht_del(chan
->ht
, &iter
);
519 call_rcu(&event
->node
.head
, destroy_event_rcu
);
524 static void destroy_enum(struct ust_registry_enum
*reg_enum
)
529 free(reg_enum
->entries
);
533 static void destroy_enum_rcu(struct rcu_head
*head
)
535 struct ust_registry_enum
*reg_enum
=
536 caa_container_of(head
, struct ust_registry_enum
, rcu_head
);
538 destroy_enum(reg_enum
);
542 * Lookup enumeration by name and comparing enumeration entries.
543 * Needs to be called from RCU read-side critical section.
545 static struct ust_registry_enum
*ust_registry_lookup_enum(
546 struct ust_registry_session
*session
,
547 const struct ust_registry_enum
*reg_enum_lookup
)
549 struct ust_registry_enum
*reg_enum
= NULL
;
550 struct lttng_ht_node_str
*node
;
551 struct lttng_ht_iter iter
;
553 cds_lfht_lookup(session
->enums
->ht
,
554 ht_hash_enum((void *) reg_enum_lookup
, lttng_ht_seed
),
555 ht_match_enum
, reg_enum_lookup
, &iter
.iter
);
556 node
= lttng_ht_iter_get_node_str(&iter
);
560 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
566 * Lookup enumeration by enum ID.
567 * Needs to be called from RCU read-side critical section.
569 struct ust_registry_enum
*
570 ust_registry_lookup_enum_by_id(struct ust_registry_session
*session
,
571 const char *enum_name
, uint64_t enum_id
)
573 struct ust_registry_enum
*reg_enum
= NULL
;
574 struct lttng_ht_node_str
*node
;
575 struct lttng_ht_iter iter
;
576 struct ust_registry_enum reg_enum_lookup
;
578 memset(®_enum_lookup
, 0, sizeof(reg_enum_lookup
));
579 strncpy(reg_enum_lookup
.name
, enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
580 reg_enum_lookup
.name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
581 reg_enum_lookup
.id
= enum_id
;
582 cds_lfht_lookup(session
->enums
->ht
,
583 ht_hash_enum((void *) ®_enum_lookup
, lttng_ht_seed
),
584 ht_match_enum_id
, ®_enum_lookup
, &iter
.iter
);
585 node
= lttng_ht_iter_get_node_str(&iter
);
589 reg_enum
= caa_container_of(node
, struct ust_registry_enum
, node
);
595 * Create a ust_registry_enum from the given parameters and add it to the
596 * registry hash table, or find it if already there.
598 * On success, return 0 else a negative value.
600 * Should be called with session registry mutex held.
602 * We receive ownership of entries.
604 int ust_registry_create_or_find_enum(struct ust_registry_session
*session
,
605 int session_objd
, char *enum_name
,
606 struct lttng_ust_ctl_enum_entry
*entries
, size_t nr_entries
,
610 struct cds_lfht_node
*nodep
;
611 struct ust_registry_enum
*reg_enum
= NULL
, *old_reg_enum
;
619 * This should not happen but since it comes from the UST tracer, an
620 * external party, don't assert and simply validate values.
622 if (session_objd
< 0) {
627 /* Check if the enumeration was already dumped */
628 reg_enum
= zmalloc(sizeof(*reg_enum
));
630 PERROR("zmalloc ust registry enumeration");
634 strncpy(reg_enum
->name
, enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
635 reg_enum
->name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
636 /* entries will be owned by reg_enum. */
637 reg_enum
->entries
= entries
;
638 reg_enum
->nr_entries
= nr_entries
;
641 old_reg_enum
= ust_registry_lookup_enum(session
, reg_enum
);
643 DBG("enum %s already in sess_objd: %u", enum_name
, session_objd
);
644 /* Fall through. Use prior enum. */
645 destroy_enum(reg_enum
);
646 reg_enum
= old_reg_enum
;
648 DBG("UST registry creating enum: %s, sess_objd: %u",
649 enum_name
, session_objd
);
650 if (session
->next_enum_id
== -1ULL) {
652 destroy_enum(reg_enum
);
655 reg_enum
->id
= session
->next_enum_id
++;
656 cds_lfht_node_init(®_enum
->node
.node
);
657 nodep
= cds_lfht_add_unique(session
->enums
->ht
,
658 ht_hash_enum(reg_enum
, lttng_ht_seed
),
659 ht_match_enum_id
, reg_enum
,
660 ®_enum
->node
.node
);
661 assert(nodep
== ®_enum
->node
.node
);
663 DBG("UST registry reply with enum %s with id %" PRIu64
" in sess_objd: %u",
664 enum_name
, reg_enum
->id
, session_objd
);
665 *enum_id
= reg_enum
->id
;
673 * For a given enumeration in a registry, delete the entry and destroy
675 * This MUST be called within a RCU read side lock section.
677 static void ust_registry_destroy_enum(struct ust_registry_session
*reg_session
,
678 struct ust_registry_enum
*reg_enum
)
681 struct lttng_ht_iter iter
;
686 /* Delete the node first. */
687 iter
.iter
.node
= ®_enum
->node
.node
;
688 ret
= lttng_ht_del(reg_session
->enums
, &iter
);
690 call_rcu(®_enum
->rcu_head
, destroy_enum_rcu
);
694 * We need to execute ht_destroy outside of RCU read-side critical
695 * section and outside of call_rcu thread, so we postpone its execution
696 * using ht_cleanup_push. It is simpler than to change the semantic of
697 * the many callers of delete_ust_app_session().
700 void destroy_channel_rcu(struct rcu_head
*head
)
702 struct ust_registry_channel
*chan
=
703 caa_container_of(head
, struct ust_registry_channel
, rcu_head
);
706 ht_cleanup_push(chan
->ht
);
708 free(chan
->ctx_fields
);
713 * Destroy every element of the registry and free the memory. This does NOT
714 * free the registry pointer since it might not have been allocated before so
715 * it's the caller responsability.
717 static void destroy_channel(struct ust_registry_channel
*chan
, bool notif
)
719 struct lttng_ht_iter iter
;
720 struct ust_registry_event
*event
;
721 enum lttng_error_code cmd_ret
;
726 cmd_ret
= notification_thread_command_remove_channel(
727 the_notification_thread_handle
,
728 chan
->consumer_key
, LTTNG_DOMAIN_UST
);
729 if (cmd_ret
!= LTTNG_OK
) {
730 ERR("Failed to remove channel from notification thread");
736 /* Destroy all event associated with this registry. */
737 cds_lfht_for_each_entry(
738 chan
->ht
->ht
, &iter
.iter
, event
, node
.node
) {
739 /* Delete the node from the ht and free it. */
740 ust_registry_destroy_event(chan
, event
);
744 call_rcu(&chan
->rcu_head
, destroy_channel_rcu
);
748 * Initialize registry with default values.
750 int ust_registry_channel_add(struct ust_registry_session
*session
,
754 struct ust_registry_channel
*chan
;
758 chan
= zmalloc(sizeof(*chan
));
760 PERROR("zmalloc ust registry channel");
765 chan
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
771 /* Set custom match function. */
772 chan
->ht
->match_fct
= ht_match_event
;
773 chan
->ht
->hash_fct
= ht_hash_event
;
776 * Assign a channel ID right now since the event notification comes
777 * *before* the channel notify so the ID needs to be set at this point so
778 * the metadata can be dumped for that event.
780 if (ust_registry_is_max_id(session
->used_channel_id
)) {
784 chan
->chan_id
= ust_registry_get_next_chan_id(session
);
787 lttng_ht_node_init_u64(&chan
->node
, key
);
788 lttng_ht_add_unique_u64(session
->channels
, &chan
->node
);
794 destroy_channel(chan
, false);
800 * Find a channel in the given registry. RCU read side lock MUST be acquired
801 * before calling this function and as long as the event reference is kept by
804 * On success, the pointer is returned else NULL.
806 struct ust_registry_channel
*ust_registry_channel_find(
807 struct ust_registry_session
*session
, uint64_t key
)
809 struct lttng_ht_node_u64
*node
;
810 struct lttng_ht_iter iter
;
811 struct ust_registry_channel
*chan
= NULL
;
814 assert(session
->channels
);
816 DBG3("UST registry channel finding key %" PRIu64
, key
);
818 lttng_ht_lookup(session
->channels
, &key
, &iter
);
819 node
= lttng_ht_iter_get_node_u64(&iter
);
823 chan
= caa_container_of(node
, struct ust_registry_channel
, node
);
830 * Remove channel using key from registry and free memory.
832 void ust_registry_channel_del_free(struct ust_registry_session
*session
,
833 uint64_t key
, bool notif
)
835 struct lttng_ht_iter iter
;
836 struct ust_registry_channel
*chan
;
842 chan
= ust_registry_channel_find(session
, key
);
848 iter
.iter
.node
= &chan
->node
.node
;
849 ret
= lttng_ht_del(session
->channels
, &iter
);
852 destroy_channel(chan
, notif
);
859 * Initialize registry with default values and set the newly allocated session
860 * pointer to sessionp.
862 * Return 0 on success and sessionp is set or else return -1 and sessionp is
865 int ust_registry_session_init(struct ust_registry_session
**sessionp
,
867 uint32_t bits_per_long
,
868 uint32_t uint8_t_alignment
,
869 uint32_t uint16_t_alignment
,
870 uint32_t uint32_t_alignment
,
871 uint32_t uint64_t_alignment
,
872 uint32_t long_alignment
,
876 const char *root_shm_path
,
877 const char *shm_path
,
884 struct ust_registry_session
*session
;
888 session
= zmalloc(sizeof(*session
));
890 PERROR("zmalloc ust registry session");
894 pthread_mutex_init(&session
->lock
, NULL
);
895 session
->bits_per_long
= bits_per_long
;
896 session
->uint8_t_alignment
= uint8_t_alignment
;
897 session
->uint16_t_alignment
= uint16_t_alignment
;
898 session
->uint32_t_alignment
= uint32_t_alignment
;
899 session
->uint64_t_alignment
= uint64_t_alignment
;
900 session
->long_alignment
= long_alignment
;
901 session
->byte_order
= byte_order
;
902 session
->metadata_fd
= -1;
905 session
->next_enum_id
= 0;
906 session
->major
= major
;
907 session
->minor
= minor
;
908 strncpy(session
->root_shm_path
, root_shm_path
,
909 sizeof(session
->root_shm_path
));
910 session
->root_shm_path
[sizeof(session
->root_shm_path
) - 1] = '\0';
912 strncpy(session
->shm_path
, shm_path
,
913 sizeof(session
->shm_path
));
914 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
915 strncpy(session
->metadata_path
, shm_path
,
916 sizeof(session
->metadata_path
));
917 session
->metadata_path
[sizeof(session
->metadata_path
) - 1] = '\0';
918 strncat(session
->metadata_path
, "/metadata",
919 sizeof(session
->metadata_path
)
920 - strlen(session
->metadata_path
) - 1);
922 if (session
->shm_path
[0]) {
923 ret
= run_as_mkdir_recursive(session
->shm_path
,
927 PERROR("run_as_mkdir_recursive");
931 if (session
->metadata_path
[0]) {
932 /* Create metadata file */
933 ret
= run_as_open(session
->metadata_path
,
934 O_WRONLY
| O_CREAT
| O_EXCL
,
935 S_IRUSR
| S_IWUSR
, euid
, egid
);
937 PERROR("Opening metadata file");
940 session
->metadata_fd
= ret
;
943 session
->enums
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
944 if (!session
->enums
) {
945 ERR("Failed to create enums hash table");
948 /* hash/match functions are specified at call site. */
949 session
->enums
->match_fct
= NULL
;
950 session
->enums
->hash_fct
= NULL
;
952 session
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
953 if (!session
->channels
) {
957 ret
= lttng_uuid_generate(session
->uuid
);
959 ERR("Failed to generate UST uuid (errno = %d)", ret
);
963 session
->tracing_id
= tracing_id
;
964 session
->tracing_uid
= tracing_uid
;
966 pthread_mutex_lock(&session
->lock
);
967 ret
= ust_metadata_session_statedump(session
, app
, major
, minor
);
968 pthread_mutex_unlock(&session
->lock
);
970 ERR("Failed to generate session metadata (errno = %d)", ret
);
979 ust_registry_session_destroy(session
);
986 * Destroy session registry. This does NOT free the given pointer since it
987 * might get passed as a reference. The registry lock should NOT be acquired.
989 void ust_registry_session_destroy(struct ust_registry_session
*reg
)
992 struct lttng_ht_iter iter
;
993 struct ust_registry_channel
*chan
;
994 struct ust_registry_enum
*reg_enum
;
1000 /* On error, EBUSY can be returned if lock. Code flow error. */
1001 ret
= pthread_mutex_destroy(®
->lock
);
1004 if (reg
->channels
) {
1006 /* Destroy all event associated with this registry. */
1007 cds_lfht_for_each_entry(reg
->channels
->ht
, &iter
.iter
, chan
,
1009 /* Delete the node from the ht and free it. */
1010 ret
= lttng_ht_del(reg
->channels
, &iter
);
1012 destroy_channel(chan
, true);
1015 ht_cleanup_push(reg
->channels
);
1018 free(reg
->metadata
);
1019 if (reg
->metadata_fd
>= 0) {
1020 ret
= close(reg
->metadata_fd
);
1024 ret
= run_as_unlink(reg
->metadata_path
,
1025 reg
->uid
, reg
->gid
);
1030 if (reg
->root_shm_path
[0]) {
1032 * Try deleting the directory hierarchy.
1034 (void) run_as_rmdir_recursive(reg
->root_shm_path
,
1036 LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG
);
1038 /* Destroy the enum hash table */
1041 /* Destroy all enum entries associated with this registry. */
1042 cds_lfht_for_each_entry(reg
->enums
->ht
, &iter
.iter
, reg_enum
,
1044 ust_registry_destroy_enum(reg
, reg_enum
);
1047 ht_cleanup_push(reg
->enums
);