* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#define _GNU_SOURCE
+#define _LGPL_SOURCE
#include <inttypes.h>
#include <common/common.h>
* 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);
*
* Return 0 on success else a negative value and regp is untouched.
*/
-int buffer_reg_uid_create(int session_id, uint32_t bits_per_long, uid_t uid,
- enum lttng_domain_type domain, struct buffer_reg_uid **regp)
+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,
+ const char *root_shm_path, const char *shm_path)
{
int ret = 0;
struct buffer_reg_uid *reg = NULL;
}
reg->registry = zmalloc(sizeof(struct buffer_reg_session));
- if (!reg) {
+ if (!reg->registry) {
PERROR("zmalloc buffer registry uid session");
ret = -ENOMEM;
goto error;
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;
cds_lfht_node_init(®->node.node);
*regp = reg;
- DBG3("Buffer registry per UID created id: %d, ABI: %u, uid: %d, domain: %d",
+ DBG3("Buffer registry per UID created id: %" PRIu64 ", ABI: %u, uid: %d, domain: %d",
session_id, bits_per_long, uid, domain);
return 0;
assert(reg);
- DBG3("Buffer registry per UID adding to global registry with id: %d",
+ DBG3("Buffer registry per UID adding to global registry with id: %" PRIu64 ,
reg->session_id);
rcu_read_lock();
*
* Return the object pointer or NULL on error.
*/
-struct buffer_reg_uid *buffer_reg_uid_find(int session_id,
+struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id,
uint32_t bits_per_long, uid_t uid)
{
struct lttng_ht_node_u64 *node;
key.bits_per_long = bits_per_long;
key.uid = uid;
- DBG3("Buffer registry per UID find id: %d, ABI: %u, uid: %d",
+ DBG3("Buffer registry per UID find id: %" PRIu64 ", ABI: %u, uid: %d",
session_id, bits_per_long, uid);
/* Custom lookup function since it's a different key. */
{
/* Should be called once. */
assert(!buffer_registry_pid);
- buffer_registry_pid = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+ buffer_registry_pid = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
assert(buffer_registry_pid);
DBG3("Global buffer per PID registry initialized");
*
* Return 0 on success else a negative value and regp is untouched.
*/
-int buffer_reg_pid_create(int 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;
}
reg->registry = zmalloc(sizeof(struct buffer_reg_session));
- if (!reg) {
+ if (!reg->registry) {
PERROR("zmalloc buffer registry pid session");
ret = -ENOMEM;
goto error;
/* 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;
goto error_session;
}
- lttng_ht_node_init_ulong(®->node, reg->session_id);
+ lttng_ht_node_init_u64(®->node, reg->session_id);
*regp = reg;
- DBG3("Buffer registry per PID created with session id: %d", session_id);
+ DBG3("Buffer registry per PID created with session id: %" PRIu64,
+ session_id);
return 0;
{
assert(reg);
- DBG3("Buffer registry per PID adding to global registry with id: %d",
+ DBG3("Buffer registry per PID adding to global registry with id: %" PRIu64,
reg->session_id);
rcu_read_lock();
- lttng_ht_add_unique_ulong(buffer_registry_pid, ®->node);
+ lttng_ht_add_unique_u64(buffer_registry_pid, ®->node);
rcu_read_unlock();
}
*
* Return the object pointer or NULL on error.
*/
-struct buffer_reg_pid *buffer_reg_pid_find(int session_id)
+struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id)
{
- struct lttng_ht_node_ulong *node;
+ struct lttng_ht_node_u64 *node;
struct lttng_ht_iter iter;
struct buffer_reg_pid *reg = NULL;
struct lttng_ht *ht = buffer_registry_pid;
- DBG3("Buffer registry per PID find id: %d", session_id);
+ DBG3("Buffer registry per PID find id: %" PRIu64, session_id);
- lttng_ht_lookup(ht, (void *)((unsigned long) session_id), &iter);
- node = lttng_ht_iter_get_node_ulong(&iter);
+ lttng_ht_lookup(ht, &session_id, &iter);
+ node = lttng_ht_iter_get_node_u64(&iter);
if (!node) {
goto 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.
pthread_mutex_lock(&channel->stream_list_lock);
cds_list_add_tail(&stream->lnode, &channel->streams);
+ channel->stream_count++;
pthread_mutex_unlock(&channel->stream_list_lock);
}
{
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);
/* Wipe stream */
cds_list_for_each_entry_safe(sreg, stmp, ®p->streams, lnode) {
cds_list_del(&sreg->lnode);
+ regp->stream_count--;
buffer_reg_stream_destroy(sreg, domain);
}
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);
static void rcu_free_buffer_reg_pid(struct rcu_head *head)
{
- struct lttng_ht_node_ulong *node =
- caa_container_of(head, struct lttng_ht_node_ulong, head);
+ struct lttng_ht_node_u64 *node =
+ caa_container_of(head, struct lttng_ht_node_u64, head);
struct buffer_reg_pid *reg =
caa_container_of(node, struct buffer_reg_pid, node);
return;
}
- DBG3("Buffer registry per UID destroy with id: %d, ABI: %u, uid: %d",
+ DBG3("Buffer registry per UID destroy with id: %" PRIu64 ", ABI: %u, uid: %d",
regp->session_id, regp->bits_per_long, regp->uid);
if (!consumer) {
return;
}
- DBG3("Buffer registry per PID destroy with id: %d", regp->session_id);
+ DBG3("Buffer registry per PID destroy with id: %" PRIu64,
+ regp->session_id);
/* This registry is only used by UST. */
call_rcu(®p->node.head, rcu_free_buffer_reg_pid);