X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fbuffer-registry.cpp;h=b840a7fa91ef0b69931a0f8c2f59c97389d31073;hp=7d00b435d7e05b10b453783fc61b5c2242ca6ed7;hb=HEAD;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f diff --git a/src/bin/lttng-sessiond/buffer-registry.cpp b/src/bin/lttng-sessiond/buffer-registry.cpp index 7d00b435d..b840a7fa9 100644 --- a/src/bin/lttng-sessiond/buffer-registry.cpp +++ b/src/bin/lttng-sessiond/buffer-registry.cpp @@ -15,6 +15,7 @@ #include #include +#include #include @@ -77,7 +78,7 @@ static unsigned long ht_hash_reg_uid(const void *_key, unsigned long seed) /* * Initialize global buffer per UID registry. Should only be called ONCE!. */ -void buffer_reg_init_uid_registry(void) +void buffer_reg_init_uid_registry() { /* Should be called once. */ LTTNG_ASSERT(!buffer_registry_uid); @@ -103,7 +104,7 @@ int buffer_reg_uid_create(uint64_t session_id, const char *shm_path) { int ret = 0; - struct buffer_reg_uid *reg = NULL; + struct buffer_reg_uid *reg = nullptr; LTTNG_ASSERT(regp); @@ -171,11 +172,10 @@ void buffer_reg_uid_add(struct buffer_reg_uid *reg) DBG3("Buffer registry per UID adding to global registry with id: %" PRIu64, reg->session_id); - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; nodep = cds_lfht_add_unique( ht->ht, ht->hash_fct(reg, lttng_ht_seed), ht->match_fct, reg, ®->node.node); LTTNG_ASSERT(nodep == ®->node.node); - rcu_read_unlock(); } /* @@ -188,7 +188,7 @@ struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, uint32_t bits_pe { struct lttng_ht_node_u64 *node; struct lttng_ht_iter iter; - struct buffer_reg_uid *reg = NULL, key; + struct buffer_reg_uid *reg = nullptr, key; struct lttng_ht *ht = buffer_registry_uid; ASSERT_RCU_READ_LOCKED(); @@ -218,7 +218,7 @@ end: /* * Initialize global buffer per PID registry. Should only be called ONCE!. */ -void buffer_reg_init_pid_registry(void) +void buffer_reg_init_pid_registry() { /* Should be called once. */ LTTNG_ASSERT(!buffer_registry_pid); @@ -239,7 +239,7 @@ int buffer_reg_pid_create(uint64_t session_id, const char *shm_path) { int ret = 0; - struct buffer_reg_pid *reg = NULL; + struct buffer_reg_pid *reg = nullptr; LTTNG_ASSERT(regp); @@ -298,9 +298,8 @@ void buffer_reg_pid_add(struct buffer_reg_pid *reg) DBG3("Buffer registry per PID adding to global registry with id: %" PRIu64, reg->session_id); - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; lttng_ht_add_unique_u64(buffer_registry_pid, ®->node); - rcu_read_unlock(); } /* @@ -313,7 +312,7 @@ struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id) { struct lttng_ht_node_u64 *node; struct lttng_ht_iter iter; - struct buffer_reg_pid *reg = NULL; + struct buffer_reg_pid *reg = nullptr; struct lttng_ht *ht = buffer_registry_pid; DBG3("Buffer registry per PID find id: %" PRIu64, session_id); @@ -339,30 +338,31 @@ int buffer_reg_uid_consumer_channel_key(struct cds_list_head *buffer_reg_uid_lis uint64_t *consumer_chan_key) { struct lttng_ht_iter iter; - struct buffer_reg_uid *uid_reg = NULL; - struct buffer_reg_session *session_reg = NULL; + struct buffer_reg_uid *uid_reg = nullptr; + struct buffer_reg_session *session_reg = nullptr; struct buffer_reg_channel *reg_chan; int ret = -1; - rcu_read_lock(); - /* - * For the per-uid registry, we have to iterate since we don't have the - * uid and bitness key. - */ - cds_list_for_each_entry (uid_reg, buffer_reg_uid_list, lnode) { - session_reg = uid_reg->registry; - cds_lfht_for_each_entry ( - session_reg->channels->ht, &iter.iter, reg_chan, node.node) { - if (reg_chan->key == chan_key) { - *consumer_chan_key = reg_chan->consumer_key; - ret = 0; - goto end; + { + lttng::urcu::read_lock_guard read_lock; + + /* + * For the per-uid registry, we have to iterate since we don't have the + * uid and bitness key. + */ + cds_list_for_each_entry (uid_reg, buffer_reg_uid_list, lnode) { + session_reg = uid_reg->registry; + cds_lfht_for_each_entry ( + session_reg->channels->ht, &iter.iter, reg_chan, node.node) { + if (reg_chan->key == chan_key) { + *consumer_chan_key = reg_chan->consumer_key; + ret = 0; + goto end; + } } } } - end: - rcu_read_unlock(); return ret; } @@ -388,7 +388,7 @@ int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp) reg->key = key; CDS_INIT_LIST_HEAD(®->streams); - pthread_mutex_init(®->stream_list_lock, NULL); + pthread_mutex_init(®->stream_list_lock, nullptr); lttng_ht_node_init_u64(®->node, key); *regp = reg; @@ -443,9 +443,8 @@ void buffer_reg_channel_add(struct buffer_reg_session *session, struct buffer_re LTTNG_ASSERT(session); LTTNG_ASSERT(channel); - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; lttng_ht_add_unique_u64(session->channels, &channel->node); - rcu_read_unlock(); } /* @@ -459,7 +458,7 @@ struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, struct buffer_r { struct lttng_ht_node_u64 *node; struct lttng_ht_iter iter; - struct buffer_reg_channel *chan = NULL; + struct buffer_reg_channel *chan = nullptr; struct lttng_ht *ht; LTTNG_ASSERT(reg); @@ -500,7 +499,7 @@ void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, enum lttng_domain { int ret; - ret = ust_app_release_object(NULL, regp->obj.ust); + ret = ust_app_release_object(nullptr, regp->obj.ust); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Buffer reg stream release obj handle %d failed with ret %d", regp->obj.ust->handle, @@ -559,7 +558,7 @@ void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, enum lttng_doma } if (regp->obj.ust) { - ret = ust_app_release_object(NULL, regp->obj.ust); + ret = ust_app_release_object(nullptr, regp->obj.ust); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Buffer reg channel release obj handle %d failed with ret %d", regp->obj.ust->handle, @@ -591,13 +590,15 @@ static void buffer_reg_session_destroy(struct buffer_reg_session *regp, DBG3("Buffer registry session destroy"); /* Destroy all channels. */ - rcu_read_lock(); - cds_lfht_for_each_entry (regp->channels->ht, &iter.iter, reg_chan, node.node) { - ret = lttng_ht_del(regp->channels, &iter); - LTTNG_ASSERT(!ret); - buffer_reg_channel_destroy(reg_chan, domain); + { + lttng::urcu::read_lock_guard read_lock; + + cds_lfht_for_each_entry (regp->channels->ht, &iter.iter, reg_chan, node.node) { + ret = lttng_ht_del(regp->channels, &iter); + LTTNG_ASSERT(!ret); + buffer_reg_channel_destroy(reg_chan, domain); + } } - rcu_read_unlock(); lttng_ht_destroy(regp->channels); @@ -623,11 +624,10 @@ void buffer_reg_uid_remove(struct buffer_reg_uid *regp) LTTNG_ASSERT(regp); - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; iter.iter.node = ®p->node.node; ret = lttng_ht_del(buffer_registry_uid, &iter); LTTNG_ASSERT(!ret); - rcu_read_unlock(); } static void rcu_free_buffer_reg_uid(struct rcu_head *head) @@ -670,29 +670,28 @@ void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, struct consumer_output goto destroy; } - rcu_read_lock(); - /* Get the right socket from the consumer object. */ - socket = consumer_find_socket_by_bitness(regp->bits_per_long, consumer); - if (!socket) { - goto unlock; - } + { + lttng::urcu::read_lock_guard read_lock; + /* Get the right socket from the consumer object. */ + socket = consumer_find_socket_by_bitness(regp->bits_per_long, consumer); + if (!socket) { + goto destroy; + } - switch (regp->domain) { - case LTTNG_DOMAIN_UST: - if (regp->registry->reg.ust->_metadata_key) { - /* Return value does not matter. This call will print errors. */ - (void) consumer_close_metadata(socket, - regp->registry->reg.ust->_metadata_key); + switch (regp->domain) { + case LTTNG_DOMAIN_UST: + if (regp->registry->reg.ust->_metadata_key) { + /* Return value does not matter. This call will print errors. */ + (void) consumer_close_metadata( + socket, regp->registry->reg.ust->_metadata_key); + } + break; + default: + abort(); + return; } - break; - default: - abort(); - rcu_read_unlock(); - return; } -unlock: - rcu_read_unlock(); destroy: call_rcu(®p->node.head, rcu_free_buffer_reg_uid); } @@ -733,7 +732,7 @@ void buffer_reg_pid_destroy(struct buffer_reg_pid *regp) /* * Destroy per PID and UID registry hash table. */ -void buffer_reg_destroy_registries(void) +void buffer_reg_destroy_registries() { DBG3("Buffer registry destroy all registry"); lttng_ht_destroy(buffer_registry_uid);