0812414e5b4f260253f10f58d5dad2cbf4035e43
[lttng-tools.git] / src / bin / lttng-sessiond / buffer-registry.h
1 /*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef LTTNG_BUFFER_REGISTRY_H
9 #define LTTNG_BUFFER_REGISTRY_H
10
11 #include <stdint.h>
12 #include <urcu/list.h>
13
14 #include <lttng/lttng.h>
15 #include <common/hashtable/hashtable.h>
16
17 #include "consumer.h"
18 #include "lttng-ust-ctl.h"
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. */
25 struct lttng_ust_object_data *ust;
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;
36 /* Total number of stream in the list. */
37 uint64_t stream_count;
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;
42 /* Size of subbuffers in this channel. */
43 size_t subbuf_size;
44 /* Number of subbuffers per stream. */
45 size_t num_subbuf;
46 union {
47 /* Original object data that MUST be copied over. */
48 struct lttng_ust_object_data *ust;
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 */
70 uint64_t session_id; /* Unique tracing session id. */
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;
81
82 char root_shm_path[PATH_MAX];
83 char shm_path[PATH_MAX];
84 };
85
86 /*
87 * Registry object for per PID buffers.
88 */
89 struct buffer_reg_pid {
90 uint64_t session_id;
91
92 struct buffer_reg_session *registry;
93
94 /* Indexed by session id. */
95 struct lttng_ht_node_u64 node;
96
97 char root_shm_path[PATH_MAX];
98 char shm_path[PATH_MAX];
99 };
100
101 /* Buffer registry per UID. */
102 void buffer_reg_init_uid_registry(void);
103 int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid,
104 enum lttng_domain_type domain, struct buffer_reg_uid **regp,
105 const char *root_shm_path, const char *shm_path);
106 void buffer_reg_uid_add(struct buffer_reg_uid *reg);
107 struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id,
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);
115 int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp,
116 const char *root_shm_path, const char *shm_path);
117 void buffer_reg_pid_add(struct buffer_reg_pid *reg);
118 struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id);
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
140 /* Global registry. */
141 void buffer_reg_destroy_registries(void);
142
143 int buffer_reg_uid_consumer_channel_key(
144 struct cds_list_head *buffer_reg_uid_list,
145 uint64_t chan_key, uint64_t *consumer_chan_key);
146
147 #endif /* LTTNG_BUFFER_REGISTRY_H */
This page took 0.052948 seconds and 3 git commands to generate.