Commit | Line | Data |
---|---|---|
7972aab2 DG |
1 | /* |
2 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License, version 2 only, as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
16 | */ | |
17 | ||
18 | #ifndef LTTNG_BUFFER_REGISTRY_H | |
19 | #define LTTNG_BUFFER_REGISTRY_H | |
20 | ||
21 | #include <stdint.h> | |
7972aab2 DG |
22 | #include <urcu/list.h> |
23 | ||
24 | #include <lttng/lttng.h> | |
25 | #include <common/hashtable/hashtable.h> | |
26 | ||
27 | #include "consumer.h" | |
534b3ed8 | 28 | #include "ust-ctl.h" |
7972aab2 DG |
29 | #include "ust-registry.h" |
30 | ||
31 | struct buffer_reg_stream { | |
32 | struct cds_list_head lnode; | |
33 | union { | |
34 | /* Original object data that MUST be copied over. */ | |
35 | struct lttng_ust_object_data *ust; | |
36 | } obj; | |
37 | }; | |
38 | ||
39 | struct buffer_reg_channel { | |
40 | /* This key is the same as a tracing channel key. */ | |
41 | uint32_t key; | |
42 | /* Key of the channel on the consumer side. */ | |
43 | uint64_t consumer_key; | |
44 | /* Stream registry object of this channel registry. */ | |
45 | struct cds_list_head streams; | |
5c786ded JD |
46 | /* Total number of stream in the list. */ |
47 | uint64_t stream_count; | |
7972aab2 DG |
48 | /* Used to ensure mutual exclusion to the stream's list. */ |
49 | pthread_mutex_t stream_list_lock; | |
50 | /* Node for hash table usage. */ | |
51 | struct lttng_ht_node_u64 node; | |
52 | union { | |
53 | /* Original object data that MUST be copied over. */ | |
54 | struct lttng_ust_object_data *ust; | |
55 | } obj; | |
56 | }; | |
57 | ||
58 | struct buffer_reg_session { | |
59 | /* Registry per domain. */ | |
60 | union { | |
61 | struct ust_registry_session *ust; | |
62 | } reg; | |
63 | ||
64 | /* Contains buffer registry channel indexed by tracing channel key. */ | |
65 | struct lttng_ht *channels; | |
66 | }; | |
67 | ||
68 | /* | |
69 | * Registry object for per UID buffers. | |
70 | */ | |
71 | struct buffer_reg_uid { | |
72 | /* | |
73 | * Keys to match this object in a hash table. The following three variables | |
74 | * identify a unique per UID buffer registry. | |
75 | */ | |
d9bf3ca4 | 76 | uint64_t session_id; /* Unique tracing session id. */ |
7972aab2 DG |
77 | int bits_per_long; /* ABI */ |
78 | uid_t uid; /* Owner. */ | |
79 | ||
80 | enum lttng_domain_type domain; | |
81 | struct buffer_reg_session *registry; | |
82 | ||
83 | /* Indexed by session id. */ | |
84 | struct lttng_ht_node_u64 node; | |
85 | /* Node of a linked list used to teardown object at a destroy session. */ | |
86 | struct cds_list_head lnode; | |
87 | }; | |
88 | ||
89 | /* | |
90 | * Registry object for per PID buffers. | |
91 | */ | |
92 | struct buffer_reg_pid { | |
d9bf3ca4 | 93 | uint64_t session_id; |
7972aab2 DG |
94 | |
95 | struct buffer_reg_session *registry; | |
96 | ||
97 | /* Indexed by session id. */ | |
d9bf3ca4 | 98 | struct lttng_ht_node_u64 node; |
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, |
7972aab2 DG |
104 | enum lttng_domain_type domain, struct buffer_reg_uid **regp); |
105 | void buffer_reg_uid_add(struct buffer_reg_uid *reg); | |
d9bf3ca4 | 106 | struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, |
7972aab2 DG |
107 | uint32_t bits_per_long, uid_t uid); |
108 | void buffer_reg_uid_remove(struct buffer_reg_uid *regp); | |
109 | void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, | |
110 | struct consumer_output *consumer); | |
111 | ||
112 | /* Buffer registry per PID. */ | |
113 | void buffer_reg_init_pid_registry(void); | |
d9bf3ca4 | 114 | int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp); |
7972aab2 | 115 | void buffer_reg_pid_add(struct buffer_reg_pid *reg); |
d9bf3ca4 | 116 | struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id); |
7972aab2 DG |
117 | void buffer_reg_pid_remove(struct buffer_reg_pid *regp); |
118 | void buffer_reg_pid_destroy(struct buffer_reg_pid *regp); | |
119 | ||
120 | /* Channel */ | |
121 | int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp); | |
122 | void buffer_reg_channel_add(struct buffer_reg_session *session, | |
123 | struct buffer_reg_channel *channel); | |
124 | struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, | |
125 | struct buffer_reg_uid *reg); | |
126 | void buffer_reg_channel_remove(struct buffer_reg_session *session, | |
127 | struct buffer_reg_channel *regp); | |
128 | void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, | |
129 | enum lttng_domain_type domain); | |
130 | ||
131 | /* Stream */ | |
132 | int buffer_reg_stream_create(struct buffer_reg_stream **regp); | |
133 | void buffer_reg_stream_add(struct buffer_reg_stream *stream, | |
134 | struct buffer_reg_channel *channel); | |
135 | void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, | |
136 | enum lttng_domain_type domain); | |
137 | ||
7972aab2 DG |
138 | /* Global registry. */ |
139 | void buffer_reg_destroy_registries(void); | |
140 | ||
141 | #endif /* LTTNG_BUFFER_REGISTRY_H */ |