Fix: sessiond: assertion fails when getting name of trigger
[lttng-tools.git] / src / bin / lttng-sessiond / buffer-registry.c
index 0ff76defbdcce18ad8aae47b28f9b7a43951af19..32fcbfb5f9ad55276444057e1aa389bd277f8356 100644 (file)
@@ -1,21 +1,10 @@
 /*
- * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <inttypes.h>
 
@@ -25,7 +14,8 @@
 #include "buffer-registry.h"
 #include "fd-limit.h"
 #include "ust-consumer.h"
-#include "ust-ctl.h"
+#include "lttng-ust-ctl.h"
+#include "lttng-ust-error.h"
 #include "utils.h"
 
 /*
@@ -74,10 +64,10 @@ no_match:
  * Hash function for the per UID registry hash table. This XOR the triplet
  * together.
  */
-static unsigned long ht_hash_reg_uid(void *_key, unsigned long seed)
+static unsigned long ht_hash_reg_uid(const void *_key, unsigned long seed)
 {
        uint64_t xored_key;
-       struct buffer_reg_uid *key = _key;
+       const struct buffer_reg_uid *key = _key;
 
        assert(key);
 
@@ -106,7 +96,8 @@ void buffer_reg_init_uid_registry(void)
  * Return 0 on success else a negative value and regp is untouched.
  */
 int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid,
-               enum lttng_domain_type domain, struct buffer_reg_uid **regp)
+               enum lttng_domain_type domain, struct buffer_reg_uid **regp,
+               const char *root_shm_path, const char *shm_path)
 {
        int ret = 0;
        struct buffer_reg_uid *reg = NULL;
@@ -131,7 +122,14 @@ int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid
        reg->bits_per_long = bits_per_long;
        reg->uid = uid;
        reg->domain = domain;
-
+       if (shm_path[0]) {
+               strncpy(reg->root_shm_path, root_shm_path, sizeof(reg->root_shm_path));
+               reg->root_shm_path[sizeof(reg->root_shm_path) - 1] = '\0';
+               strncpy(reg->shm_path, shm_path, sizeof(reg->shm_path));
+               reg->shm_path[sizeof(reg->shm_path) - 1] = '\0';
+               DBG3("shm path '%s' is assigned to uid buffer registry for session id %" PRIu64,
+                       reg->shm_path, session_id);
+       }
        reg->registry->channels = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
        if (!reg->registry->channels) {
                ret = -ENOMEM;
@@ -226,7 +224,8 @@ void buffer_reg_init_pid_registry(void)
  *
  * Return 0 on success else a negative value and regp is untouched.
  */
-int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp)
+int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp,
+               const char *root_shm_path, const char *shm_path)
 {
        int ret = 0;
        struct buffer_reg_pid *reg = NULL;
@@ -249,7 +248,14 @@ int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp)
 
        /* A cast is done here so we can use the session ID as a u64 ht node. */
        reg->session_id = session_id;
-
+       if (shm_path[0]) {
+               strncpy(reg->root_shm_path, root_shm_path, sizeof(reg->root_shm_path));
+               reg->root_shm_path[sizeof(reg->root_shm_path) - 1] = '\0';
+               strncpy(reg->shm_path, shm_path, sizeof(reg->shm_path));
+               reg->shm_path[sizeof(reg->shm_path) - 1] = '\0';
+               DBG3("shm path '%s' is assigned to pid buffer registry for session id %" PRIu64,
+                               reg->shm_path, session_id);
+       }
        reg->registry->channels = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
        if (!reg->registry->channels) {
                ret = -ENOMEM;
@@ -312,6 +318,43 @@ end:
        return reg;
 }
 
+/*
+ * Find the consumer channel key from a UST session per-uid channel key.
+ *
+ * Return the matching key or -1 if not found.
+ */
+int buffer_reg_uid_consumer_channel_key(
+               struct cds_list_head *buffer_reg_uid_list,
+               uint64_t chan_key, 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_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;
+                       }
+               }
+       }
+
+end:
+       rcu_read_unlock();
+       return ret;
+}
+
 /*
  * Allocate and initialize a buffer registry channel with the given key. Set
  * regp with the object pointer.
@@ -451,7 +494,7 @@ void buffer_reg_stream_destroy(struct buffer_reg_stream *regp,
        {
                int ret;
 
-               ret = ust_ctl_release_object(-1, regp->obj.ust);
+               ret = ust_app_release_object(NULL, 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, ret);
@@ -511,7 +554,7 @@ void buffer_reg_channel_destroy(struct buffer_reg_channel *regp,
                }
 
                if (regp->obj.ust) {
-                       ret = ust_ctl_release_object(-1, regp->obj.ust);
+                       ret = ust_app_release_object(NULL, 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, ret);
This page took 0.025215 seconds and 4 git commands to generate.