Commit | Line | Data |
---|---|---|
7972aab2 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
7972aab2 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
7972aab2 | 5 | * |
7972aab2 DG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_BUFFER_REGISTRY_H | |
9 | #define LTTNG_BUFFER_REGISTRY_H | |
10 | ||
c9e313bc SM |
11 | #include "consumer.hpp" |
12 | #include "lttng-ust-ctl.hpp" | |
b0f2e8db | 13 | #include "ust-registry-session.hpp" |
28f23191 JG |
14 | #include "ust-registry.hpp" |
15 | ||
16 | #include <common/hashtable/hashtable.hpp> | |
17 | ||
18 | #include <lttng/lttng.h> | |
19 | ||
20 | #include <stdint.h> | |
21 | #include <urcu/list.h> | |
7972aab2 DG |
22 | |
23 | struct buffer_reg_stream { | |
24 | struct cds_list_head lnode; | |
25 | union { | |
26 | /* Original object data that MUST be copied over. */ | |
fc4b93fa | 27 | struct lttng_ust_abi_object_data *ust; |
7972aab2 DG |
28 | } obj; |
29 | }; | |
30 | ||
31 | struct buffer_reg_channel { | |
32 | /* This key is the same as a tracing channel key. */ | |
33 | uint32_t 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; | |
5c786ded JD |
38 | /* Total number of stream in the list. */ |
39 | uint64_t stream_count; | |
7972aab2 DG |
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; | |
8c924c7b MD |
44 | /* Size of subbuffers in this channel. */ |
45 | size_t subbuf_size; | |
d07ceecd MD |
46 | /* Number of subbuffers per stream. */ |
47 | size_t num_subbuf; | |
7972aab2 DG |
48 | union { |
49 | /* Original object data that MUST be copied over. */ | |
fc4b93fa | 50 | struct lttng_ust_abi_object_data *ust; |
7972aab2 DG |
51 | } obj; |
52 | }; | |
53 | ||
54 | struct buffer_reg_session { | |
55 | /* Registry per domain. */ | |
56 | union { | |
b0f2e8db | 57 | lttng::sessiond::ust::registry_session *ust; |
7972aab2 DG |
58 | } reg; |
59 | ||
60 | /* Contains buffer registry channel indexed by tracing channel key. */ | |
61 | struct lttng_ht *channels; | |
62 | }; | |
63 | ||
64 | /* | |
65 | * Registry object for per UID buffers. | |
66 | */ | |
67 | struct buffer_reg_uid { | |
68 | /* | |
69 | * Keys to match this object in a hash table. The following three variables | |
70 | * identify a unique per UID buffer registry. | |
71 | */ | |
28f23191 JG |
72 | uint64_t session_id; /* Unique tracing session id. */ |
73 | int bits_per_long; /* ABI */ | |
74 | uid_t uid; /* Owner. */ | |
7972aab2 DG |
75 | |
76 | enum lttng_domain_type domain; | |
77 | struct buffer_reg_session *registry; | |
78 | ||
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; | |
d7ba1388 | 83 | |
3d071855 | 84 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 85 | char shm_path[PATH_MAX]; |
7972aab2 DG |
86 | }; |
87 | ||
88 | /* | |
89 | * Registry object for per PID buffers. | |
90 | */ | |
91 | struct buffer_reg_pid { | |
d9bf3ca4 | 92 | uint64_t session_id; |
7972aab2 DG |
93 | |
94 | struct buffer_reg_session *registry; | |
95 | ||
96 | /* Indexed by session id. */ | |
d9bf3ca4 | 97 | struct lttng_ht_node_u64 node; |
d7ba1388 | 98 | |
3d071855 | 99 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 100 | char shm_path[PATH_MAX]; |
7972aab2 DG |
101 | }; |
102 | ||
103 | /* Buffer registry per UID. */ | |
104 | void buffer_reg_init_uid_registry(void); | |
28f23191 JG |
105 | int buffer_reg_uid_create(uint64_t session_id, |
106 | uint32_t bits_per_long, | |
107 | uid_t uid, | |
108 | enum lttng_domain_type domain, | |
109 | struct buffer_reg_uid **regp, | |
110 | const char *root_shm_path, | |
111 | const char *shm_path); | |
7972aab2 | 112 | void buffer_reg_uid_add(struct buffer_reg_uid *reg); |
28f23191 | 113 | struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, uint32_t bits_per_long, uid_t uid); |
7972aab2 | 114 | void buffer_reg_uid_remove(struct buffer_reg_uid *regp); |
28f23191 | 115 | void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, struct consumer_output *consumer); |
7972aab2 DG |
116 | |
117 | /* Buffer registry per PID. */ | |
118 | void buffer_reg_init_pid_registry(void); | |
28f23191 JG |
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); | |
7972aab2 | 123 | void buffer_reg_pid_add(struct buffer_reg_pid *reg); |
d9bf3ca4 | 124 | struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id); |
7972aab2 DG |
125 | void buffer_reg_pid_remove(struct buffer_reg_pid *regp); |
126 | void buffer_reg_pid_destroy(struct buffer_reg_pid *regp); | |
127 | ||
128 | /* Channel */ | |
129 | int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp); | |
28f23191 JG |
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); | |
7972aab2 DG |
134 | |
135 | /* Stream */ | |
136 | int buffer_reg_stream_create(struct buffer_reg_stream **regp); | |
28f23191 JG |
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); | |
7972aab2 | 139 | |
7972aab2 DG |
140 | /* Global registry. */ |
141 | void buffer_reg_destroy_registries(void); | |
142 | ||
28f23191 JG |
143 | int buffer_reg_uid_consumer_channel_key(struct cds_list_head *buffer_reg_uid_list, |
144 | uint64_t chan_key, | |
145 | uint64_t *consumer_chan_key); | |
fb83fe64 | 146 | |
7972aab2 | 147 | #endif /* LTTNG_BUFFER_REGISTRY_H */ |