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
12 #include <urcu/list.h>
14 #include <lttng/lttng.h>
15 #include <common/hashtable/hashtable.hpp>
17 #include "consumer.hpp"
18 #include "lttng-ust-ctl.hpp"
19 #include "ust-registry.hpp"
20 #include "ust-registry-session.hpp"
22 struct buffer_reg_stream {
23 struct cds_list_head lnode;
25 /* Original object data that MUST be copied over. */
26 struct lttng_ust_abi_object_data *ust;
30 struct buffer_reg_channel {
31 /* This key is the same as a tracing channel key. */
33 /* Key of the channel on the consumer side. */
34 uint64_t consumer_key;
35 /* Stream registry object of this channel registry. */
36 struct cds_list_head streams;
37 /* Total number of stream in the list. */
38 uint64_t stream_count;
39 /* Used to ensure mutual exclusion to the stream's list. */
40 pthread_mutex_t stream_list_lock;
41 /* Node for hash table usage. */
42 struct lttng_ht_node_u64 node;
43 /* Size of subbuffers in this channel. */
45 /* Number of subbuffers per stream. */
48 /* Original object data that MUST be copied over. */
49 struct lttng_ust_abi_object_data *ust;
53 struct buffer_reg_session {
54 /* Registry per domain. */
56 lttng::sessiond::ust::registry_session *ust;
59 /* Contains buffer registry channel indexed by tracing channel key. */
60 struct lttng_ht *channels;
64 * Registry object for per UID buffers.
66 struct buffer_reg_uid {
68 * Keys to match this object in a hash table. The following three variables
69 * identify a unique per UID buffer registry.
71 uint64_t session_id; /* Unique tracing session id. */
72 int bits_per_long; /* ABI */
73 uid_t uid; /* Owner. */
75 enum lttng_domain_type domain;
76 struct buffer_reg_session *registry;
78 /* Indexed by session id. */
79 struct lttng_ht_node_u64 node;
80 /* Node of a linked list used to teardown object at a destroy session. */
81 struct cds_list_head lnode;
83 char root_shm_path[PATH_MAX];
84 char shm_path[PATH_MAX];
88 * Registry object for per PID buffers.
90 struct buffer_reg_pid {
93 struct buffer_reg_session *registry;
95 /* Indexed by session id. */
96 struct lttng_ht_node_u64 node;
98 char root_shm_path[PATH_MAX];
99 char shm_path[PATH_MAX];
102 /* Buffer registry per UID. */
103 void buffer_reg_init_uid_registry(void);
104 int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid,
105 enum lttng_domain_type domain, struct buffer_reg_uid **regp,
106 const char *root_shm_path, const char *shm_path);
107 void buffer_reg_uid_add(struct buffer_reg_uid *reg);
108 struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id,
109 uint32_t bits_per_long, uid_t uid);
110 void buffer_reg_uid_remove(struct buffer_reg_uid *regp);
111 void buffer_reg_uid_destroy(struct buffer_reg_uid *regp,
112 struct consumer_output *consumer);
114 /* Buffer registry per PID. */
115 void buffer_reg_init_pid_registry(void);
116 int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp,
117 const char *root_shm_path, const char *shm_path);
118 void buffer_reg_pid_add(struct buffer_reg_pid *reg);
119 struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id);
120 void buffer_reg_pid_remove(struct buffer_reg_pid *regp);
121 void buffer_reg_pid_destroy(struct buffer_reg_pid *regp);
124 int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp);
125 void buffer_reg_channel_add(struct buffer_reg_session *session,
126 struct buffer_reg_channel *channel);
127 struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key,
128 struct buffer_reg_uid *reg);
129 void buffer_reg_channel_remove(struct buffer_reg_session *session,
130 struct buffer_reg_channel *regp);
131 void buffer_reg_channel_destroy(struct buffer_reg_channel *regp,
132 enum lttng_domain_type domain);
135 int buffer_reg_stream_create(struct buffer_reg_stream **regp);
136 void buffer_reg_stream_add(struct buffer_reg_stream *stream,
137 struct buffer_reg_channel *channel);
138 void buffer_reg_stream_destroy(struct buffer_reg_stream *regp,
139 enum lttng_domain_type domain);
141 /* Global registry. */
142 void buffer_reg_destroy_registries(void);
144 int buffer_reg_uid_consumer_channel_key(
145 struct cds_list_head *buffer_reg_uid_list,
146 uint64_t chan_key, uint64_t *consumer_chan_key);
148 #endif /* LTTNG_BUFFER_REGISTRY_H */