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 | ||
11 | #include <stdint.h> | |
7972aab2 DG |
12 | #include <urcu/list.h> |
13 | ||
14 | #include <lttng/lttng.h> | |
15 | #include <common/hashtable/hashtable.h> | |
16 | ||
17 | #include "consumer.h" | |
75018ab6 | 18 | #include "lttng-ust-ctl.h" |
7972aab2 DG |
19 | #include "ust-registry.h" |
20 | ||
21 | struct buffer_reg_stream { | |
22 | struct cds_list_head lnode; | |
23 | union { | |
24 | /* Original object data that MUST be copied over. */ | |
fc4b93fa | 25 | struct lttng_ust_abi_object_data *ust; |
7972aab2 DG |
26 | } obj; |
27 | }; | |
28 | ||
29 | struct buffer_reg_channel { | |
30 | /* This key is the same as a tracing channel key. */ | |
31 | uint32_t key; | |
32 | /* Key of the channel on the consumer side. */ | |
33 | uint64_t consumer_key; | |
34 | /* Stream registry object of this channel registry. */ | |
35 | struct cds_list_head streams; | |
5c786ded JD |
36 | /* Total number of stream in the list. */ |
37 | uint64_t stream_count; | |
7972aab2 DG |
38 | /* Used to ensure mutual exclusion to the stream's list. */ |
39 | pthread_mutex_t stream_list_lock; | |
40 | /* Node for hash table usage. */ | |
41 | struct lttng_ht_node_u64 node; | |
8c924c7b MD |
42 | /* Size of subbuffers in this channel. */ |
43 | size_t subbuf_size; | |
d07ceecd MD |
44 | /* Number of subbuffers per stream. */ |
45 | size_t num_subbuf; | |
7972aab2 DG |
46 | union { |
47 | /* Original object data that MUST be copied over. */ | |
fc4b93fa | 48 | struct lttng_ust_abi_object_data *ust; |
7972aab2 DG |
49 | } obj; |
50 | }; | |
51 | ||
52 | struct buffer_reg_session { | |
53 | /* Registry per domain. */ | |
54 | union { | |
55 | struct ust_registry_session *ust; | |
56 | } reg; | |
57 | ||
58 | /* Contains buffer registry channel indexed by tracing channel key. */ | |
59 | struct lttng_ht *channels; | |
60 | }; | |
61 | ||
62 | /* | |
63 | * Registry object for per UID buffers. | |
64 | */ | |
65 | struct buffer_reg_uid { | |
66 | /* | |
67 | * Keys to match this object in a hash table. The following three variables | |
68 | * identify a unique per UID buffer registry. | |
69 | */ | |
d9bf3ca4 | 70 | uint64_t session_id; /* Unique tracing session id. */ |
7972aab2 DG |
71 | int bits_per_long; /* ABI */ |
72 | uid_t uid; /* Owner. */ | |
73 | ||
74 | enum lttng_domain_type domain; | |
75 | struct buffer_reg_session *registry; | |
76 | ||
77 | /* Indexed by session id. */ | |
78 | struct lttng_ht_node_u64 node; | |
79 | /* Node of a linked list used to teardown object at a destroy session. */ | |
80 | struct cds_list_head lnode; | |
d7ba1388 | 81 | |
3d071855 | 82 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 83 | char shm_path[PATH_MAX]; |
7972aab2 DG |
84 | }; |
85 | ||
86 | /* | |
87 | * Registry object for per PID buffers. | |
88 | */ | |
89 | struct buffer_reg_pid { | |
d9bf3ca4 | 90 | uint64_t session_id; |
7972aab2 DG |
91 | |
92 | struct buffer_reg_session *registry; | |
93 | ||
94 | /* Indexed by session id. */ | |
d9bf3ca4 | 95 | struct lttng_ht_node_u64 node; |
d7ba1388 | 96 | |
3d071855 | 97 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 98 | char shm_path[PATH_MAX]; |
7972aab2 DG |
99 | }; |
100 | ||
101 | /* Buffer registry per UID. */ | |
102 | void buffer_reg_init_uid_registry(void); | |
d9bf3ca4 | 103 | int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid, |
d7ba1388 | 104 | enum lttng_domain_type domain, struct buffer_reg_uid **regp, |
3d071855 | 105 | const char *root_shm_path, const char *shm_path); |
7972aab2 | 106 | void buffer_reg_uid_add(struct buffer_reg_uid *reg); |
d9bf3ca4 | 107 | struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, |
7972aab2 DG |
108 | uint32_t bits_per_long, uid_t uid); |
109 | void buffer_reg_uid_remove(struct buffer_reg_uid *regp); | |
110 | void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, | |
111 | struct consumer_output *consumer); | |
112 | ||
113 | /* Buffer registry per PID. */ | |
114 | void buffer_reg_init_pid_registry(void); | |
d7ba1388 | 115 | int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp, |
3d071855 | 116 | const char *root_shm_path, const char *shm_path); |
7972aab2 | 117 | void buffer_reg_pid_add(struct buffer_reg_pid *reg); |
d9bf3ca4 | 118 | struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id); |
7972aab2 DG |
119 | void buffer_reg_pid_remove(struct buffer_reg_pid *regp); |
120 | void buffer_reg_pid_destroy(struct buffer_reg_pid *regp); | |
121 | ||
122 | /* Channel */ | |
123 | int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp); | |
124 | void buffer_reg_channel_add(struct buffer_reg_session *session, | |
125 | struct buffer_reg_channel *channel); | |
126 | struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, | |
127 | struct buffer_reg_uid *reg); | |
128 | void buffer_reg_channel_remove(struct buffer_reg_session *session, | |
129 | struct buffer_reg_channel *regp); | |
130 | void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, | |
131 | enum lttng_domain_type domain); | |
132 | ||
133 | /* Stream */ | |
134 | int buffer_reg_stream_create(struct buffer_reg_stream **regp); | |
135 | void buffer_reg_stream_add(struct buffer_reg_stream *stream, | |
136 | struct buffer_reg_channel *channel); | |
137 | void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, | |
138 | enum lttng_domain_type domain); | |
139 | ||
7972aab2 DG |
140 | /* Global registry. */ |
141 | void buffer_reg_destroy_registries(void); | |
142 | ||
fb83fe64 JD |
143 | int buffer_reg_uid_consumer_channel_key( |
144 | struct cds_list_head *buffer_reg_uid_list, | |
76604852 | 145 | uint64_t chan_key, uint64_t *consumer_chan_key); |
fb83fe64 | 146 | |
7972aab2 | 147 | #endif /* LTTNG_BUFFER_REGISTRY_H */ |