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.h>
18 #include "lttng-ust-ctl.h"
19 #include "ust-registry.h"
21 struct buffer_reg_stream
{
22 struct cds_list_head lnode
;
24 /* Original object data that MUST be copied over. */
25 struct lttng_ust_abi_object_data
*ust
;
29 struct buffer_reg_channel
{
30 /* This key is the same as a tracing channel 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. */
44 /* Number of subbuffers per stream. */
47 /* Original object data that MUST be copied over. */
48 struct lttng_ust_abi_object_data
*ust
;
52 struct buffer_reg_session
{
53 /* Registry per domain. */
55 struct ust_registry_session
*ust
;
58 /* Contains buffer registry channel indexed by tracing channel key. */
59 struct lttng_ht
*channels
;
63 * Registry object for per UID buffers.
65 struct buffer_reg_uid
{
67 * Keys to match this object in a hash table. The following three variables
68 * identify a unique per UID buffer registry.
70 uint64_t session_id
; /* Unique tracing session id. */
71 int bits_per_long
; /* ABI */
72 uid_t uid
; /* Owner. */
74 enum lttng_domain_type domain
;
75 struct buffer_reg_session
*registry
;
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
;
82 char root_shm_path
[PATH_MAX
];
83 char shm_path
[PATH_MAX
];
87 * Registry object for per PID buffers.
89 struct buffer_reg_pid
{
92 struct buffer_reg_session
*registry
;
94 /* Indexed by session id. */
95 struct lttng_ht_node_u64 node
;
97 char root_shm_path
[PATH_MAX
];
98 char shm_path
[PATH_MAX
];
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
);
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
);
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
);
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
);
140 /* Global registry. */
141 void buffer_reg_destroy_registries(void);
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
);
147 #endif /* LTTNG_BUFFER_REGISTRY_H */