X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-registry.cpp;h=b327fdf32c449dfc082af8a55eebd9dd8b99c145;hb=64803277bbdbe0a943360d918298a48157d9da55;hp=088e8d64fedfd36e6aa7cba44ecdc74e68df553a;hpb=fb2772932d3207bd9d340f34f41d822d9c0ff0a9;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-registry.cpp b/src/bin/lttng-sessiond/ust-registry.cpp index 088e8d64f..b327fdf32 100644 --- a/src/bin/lttng-sessiond/ust-registry.cpp +++ b/src/bin/lttng-sessiond/ust-registry.cpp @@ -8,16 +8,16 @@ #define _LGPL_SOURCE #include -#include -#include +#include +#include #include -#include "ust-registry.h" -#include "ust-app.h" -#include "ust-field-utils.h" -#include "utils.h" -#include "lttng-sessiond.h" -#include "notification-thread-commands.h" +#include "ust-registry.hpp" +#include "ust-app.hpp" +#include "ust-field-utils.hpp" +#include "utils.hpp" +#include "lttng-sessiond.hpp" +#include "notification-thread-commands.hpp" /* * Hash table match function for event in the registry. @@ -288,7 +288,7 @@ static struct ust_registry_event *alloc_event(int session_objd, return NULL; } - event = (ust_registry_event *) zmalloc(sizeof(*event)); + event = zmalloc(); if (!event) { PERROR("zmalloc ust registry event"); goto error; @@ -315,7 +315,7 @@ error: /* * Free event data structure. This does NOT delete it from any hash table. It's - * safe to pass a NULL pointer. This shoudl be called inside a call RCU if the + * safe to pass a NULL pointer. This should be called inside a call RCU if the * event is previously deleted from a rcu hash table. */ static void destroy_event(struct ust_registry_event *event) @@ -361,14 +361,15 @@ struct ust_registry_event *ust_registry_find_event( LTTNG_ASSERT(chan); LTTNG_ASSERT(name); LTTNG_ASSERT(sig); + ASSERT_RCU_READ_LOCKED(); /* Setup key for the match function. */ strncpy(key.name, name, sizeof(key.name)); key.name[sizeof(key.name) - 1] = '\0'; key.signature = sig; - cds_lfht_lookup(chan->ht->ht, chan->ht->hash_fct(&key, lttng_ht_seed), - chan->ht->match_fct, &key, &iter.iter); + cds_lfht_lookup(chan->events->ht, chan->events->hash_fct(&key, lttng_ht_seed), + chan->events->match_fct, &key, &iter.iter); node = lttng_ht_iter_get_node_u64(&iter); if (!node) { goto end; @@ -445,8 +446,8 @@ int ust_registry_create_event(struct ust_registry_session *session, * This is an add unique with a custom match function for event. The node * are matched using the event name and signature. */ - nptr = cds_lfht_add_unique(chan->ht->ht, chan->ht->hash_fct(event, - lttng_ht_seed), chan->ht->match_fct, event, &event->node.node); + nptr = cds_lfht_add_unique(chan->events->ht, chan->events->hash_fct(event, + lttng_ht_seed), chan->events->match_fct, event, &event->node.node); if (nptr != &event->node.node) { if (buffer_type == LTTNG_BUFFER_PER_UID) { /* @@ -509,10 +510,11 @@ void ust_registry_destroy_event(struct ust_registry_channel *chan, LTTNG_ASSERT(chan); LTTNG_ASSERT(event); + ASSERT_RCU_READ_LOCKED(); /* Delete the node first. */ iter.iter.node = &event->node.node; - ret = lttng_ht_del(chan->ht, &iter); + ret = lttng_ht_del(chan->events, &iter); LTTNG_ASSERT(!ret); call_rcu(&event->node.head, destroy_event_rcu); @@ -549,6 +551,8 @@ static struct ust_registry_enum *ust_registry_lookup_enum( struct lttng_ht_node_str *node; struct lttng_ht_iter iter; + ASSERT_RCU_READ_LOCKED(); + cds_lfht_lookup(session->enums->ht, ht_hash_enum((void *) reg_enum_lookup, lttng_ht_seed), ht_match_enum, reg_enum_lookup, &iter.iter); @@ -574,6 +578,8 @@ struct ust_registry_enum * struct lttng_ht_iter iter; struct ust_registry_enum reg_enum_lookup; + ASSERT_RCU_READ_LOCKED(); + memset(®_enum_lookup, 0, sizeof(reg_enum_lookup)); strncpy(reg_enum_lookup.name, enum_name, LTTNG_UST_ABI_SYM_NAME_LEN); reg_enum_lookup.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; @@ -624,7 +630,7 @@ int ust_registry_create_or_find_enum(struct ust_registry_session *session, } /* Check if the enumeration was already dumped */ - reg_enum = (ust_registry_enum *) zmalloc(sizeof(*reg_enum)); + reg_enum = zmalloc(); if (!reg_enum) { PERROR("zmalloc ust registry enumeration"); ret = -ENOMEM; @@ -681,6 +687,7 @@ static void ust_registry_destroy_enum(struct ust_registry_session *reg_session, LTTNG_ASSERT(reg_session); LTTNG_ASSERT(reg_enum); + ASSERT_RCU_READ_LOCKED(); /* Delete the node first. */ iter.iter.node = ®_enum->node.node; @@ -689,21 +696,16 @@ static void ust_registry_destroy_enum(struct ust_registry_session *reg_session, call_rcu(®_enum->rcu_head, destroy_enum_rcu); } -/* - * We need to execute ht_destroy outside of RCU read-side critical - * section and outside of call_rcu thread, so we postpone its execution - * using ht_cleanup_push. It is simpler than to change the semantic of - * the many callers of delete_ust_app_session(). - */ static void destroy_channel_rcu(struct rcu_head *head) { struct ust_registry_channel *chan = caa_container_of(head, struct ust_registry_channel, rcu_head); - if (chan->ht) { - ht_cleanup_push(chan->ht); + if (chan->events) { + lttng_ht_destroy(chan->events); } + free(chan->ctx_fields); free(chan); } @@ -730,11 +732,11 @@ static void destroy_channel(struct ust_registry_channel *chan, bool notif) } } - if (chan->ht) { + if (chan->events) { rcu_read_lock(); /* Destroy all event associated with this registry. */ cds_lfht_for_each_entry( - chan->ht->ht, &iter.iter, event, node.node) { + chan->events->ht, &iter.iter, event, node.node) { /* Delete the node from the ht and free it. */ ust_registry_destroy_event(chan, event); } @@ -754,22 +756,22 @@ int ust_registry_channel_add(struct ust_registry_session *session, LTTNG_ASSERT(session); - chan = (ust_registry_channel *) zmalloc(sizeof(*chan)); + chan = zmalloc(); if (!chan) { PERROR("zmalloc ust registry channel"); ret = -ENOMEM; goto error_alloc; } - chan->ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); - if (!chan->ht) { + chan->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); + if (!chan->events) { ret = -ENOMEM; goto error; } /* Set custom match function. */ - chan->ht->match_fct = ht_match_event; - chan->ht->hash_fct = ht_hash_event; + chan->events->match_fct = ht_match_event; + chan->events->hash_fct = ht_hash_event; /* * Assign a channel ID right now since the event notification comes @@ -811,6 +813,7 @@ struct ust_registry_channel *ust_registry_channel_find( LTTNG_ASSERT(session); LTTNG_ASSERT(session->channels); + ASSERT_RCU_READ_LOCKED(); DBG3("UST registry channel finding key %" PRIu64, key); @@ -884,7 +887,7 @@ int ust_registry_session_init(struct ust_registry_session **sessionp, LTTNG_ASSERT(sessionp); - session = (ust_registry_session *) zmalloc(sizeof(*session)); + session = zmalloc(); if (!session) { PERROR("zmalloc ust registry session"); goto error_alloc; @@ -1011,7 +1014,7 @@ void ust_registry_session_destroy(struct ust_registry_session *reg) destroy_channel(chan, true); } rcu_read_unlock(); - ht_cleanup_push(reg->channels); + lttng_ht_destroy(reg->channels); } free(reg->metadata); @@ -1043,6 +1046,6 @@ void ust_registry_session_destroy(struct ust_registry_session *reg) ust_registry_destroy_enum(reg, reg_enum); } rcu_read_unlock(); - ht_cleanup_push(reg->enums); + lttng_ht_destroy(reg->enums); } }