2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef LTTNG_BUFFER_REGISTRY_H
9 #define LTTNG_BUFFER_REGISTRY_H
11 #include "consumer.hpp"
12 #include "lttng-ust-ctl.hpp"
13 #include "ust-registry-session.hpp"
14 #include "ust-registry.hpp"
16 #include <common/hashtable/hashtable.hpp>
18 #include <lttng/lttng.h>
21 #include <urcu/list.h>
23 struct buffer_reg_stream {
24 struct cds_list_head lnode;
26 /* Original object data that MUST be copied over. */
27 struct lttng_ust_abi_object_data *ust;
31 struct buffer_reg_channel {
32 /* This key is the same as a tracing channel key. */
34 /* Key of the channel on the consumer side. */
35 uint64_t consumer_key;
36 /* Stream registry object of this channel registry. */
37 struct cds_list_head streams;
38 /* Total number of stream in the list. */
39 uint64_t stream_count;
40 /* Used to ensure mutual exclusion to the stream's list. */
41 pthread_mutex_t stream_list_lock;
42 /* Node for hash table usage. */
43 struct lttng_ht_node_u64 node;
44 /* Size of subbuffers in this channel. */
46 /* Number of subbuffers per stream. */
49 /* Original object data that MUST be copied over. */
50 struct lttng_ust_abi_object_data *ust;
54 struct buffer_reg_session {
55 /* Registry per domain. */
57 lttng::sessiond::ust::registry_session *ust;
60 /* Contains buffer registry channel indexed by tracing channel key. */
61 struct lttng_ht *channels;
65 * Registry object for per UID buffers.
67 struct buffer_reg_uid {
69 * Keys to match this object in a hash table. The following three variables
70 * identify a unique per UID buffer registry.
72 uint64_t session_id; /* Unique tracing session id. */
73 int bits_per_long; /* ABI */
74 uid_t uid; /* Owner. */
76 enum lttng_domain_type domain;
77 struct buffer_reg_session *registry;
79 /* Indexed by session id. */
80 struct lttng_ht_node_u64 node;
81 /* Node of a linked list used to teardown object at a destroy session. */
82 struct cds_list_head lnode;
84 char root_shm_path[PATH_MAX];
85 char shm_path[PATH_MAX];
89 * Registry object for per PID buffers.
91 struct buffer_reg_pid {
94 struct buffer_reg_session *registry;
96 /* Indexed by session id. */
97 struct lttng_ht_node_u64 node;
99 char root_shm_path[PATH_MAX];
100 char shm_path[PATH_MAX];
103 /* Buffer registry per UID. */
104 void buffer_reg_init_uid_registry();
105 int buffer_reg_uid_create(uint64_t session_id,
106 uint32_t bits_per_long,
108 enum lttng_domain_type domain,
109 struct buffer_reg_uid **regp,
110 const char *root_shm_path,
111 const char *shm_path);
112 void buffer_reg_uid_add(struct buffer_reg_uid *reg);
113 struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, uint32_t bits_per_long, uid_t uid);
114 void buffer_reg_uid_remove(struct buffer_reg_uid *regp);
115 void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, struct consumer_output *consumer);
117 /* Buffer registry per PID. */
118 void buffer_reg_init_pid_registry();
119 int buffer_reg_pid_create(uint64_t session_id,
120 struct buffer_reg_pid **regp,
121 const char *root_shm_path,
122 const char *shm_path);
123 void buffer_reg_pid_add(struct buffer_reg_pid *reg);
124 struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id);
125 void buffer_reg_pid_remove(struct buffer_reg_pid *regp);
126 void buffer_reg_pid_destroy(struct buffer_reg_pid *regp);
129 int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp);
130 void buffer_reg_channel_add(struct buffer_reg_session *session, struct buffer_reg_channel *channel);
131 struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, struct buffer_reg_uid *reg);
132 void buffer_reg_channel_remove(struct buffer_reg_session *session, struct buffer_reg_channel *regp);
133 void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, enum lttng_domain_type domain);
136 int buffer_reg_stream_create(struct buffer_reg_stream **regp);
137 void buffer_reg_stream_add(struct buffer_reg_stream *stream, struct buffer_reg_channel *channel);
138 void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, enum lttng_domain_type domain);
140 /* Global registry. */
141 void buffer_reg_destroy_registries();
143 int buffer_reg_uid_consumer_channel_key(struct cds_list_head *buffer_reg_uid_list,
145 uint64_t *consumer_chan_key);
147 #endif /* LTTNG_BUFFER_REGISTRY_H */