Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / bin / lttng-relayd / session.h
1 #ifndef _SESSION_H
2 #define _SESSION_H
3
4 /*
5 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * SPDX-License-Identifier: GPL-2.0-only
10 *
11 */
12
13 #include <limits.h>
14 #include <inttypes.h>
15 #include <pthread.h>
16 #include <urcu/list.h>
17 #include <urcu/ref.h>
18
19 #include <lttng/constant.h>
20 #include <common/hashtable/hashtable.h>
21 #include <common/uuid.h>
22 #include <common/trace-chunk.h>
23 #include <common/optional.h>
24
25 /*
26 * Represents a session for the relay point of view
27 */
28 struct relay_session {
29 /*
30 * This session id is generated by the relay daemon to guarantee
31 * its uniqueness even when serving multiple session daemons.
32 * It is used to match a set of streams to their session.
33 */
34 uint64_t id;
35 /*
36 * ID of the session in the session daemon's domain.
37 * This information is only provided by 2.11+ peers.
38 */
39 LTTNG_OPTIONAL(uint64_t) id_sessiond;
40 /*
41 * Only provided by 2.11+ peers. However, the UUID is set to 'nil' in
42 * the other cases.
43 */
44 lttng_uuid sessiond_uuid;
45 LTTNG_OPTIONAL(time_t) creation_time;
46 /* Must _not_ be empty for 2.4+ peers. */
47 char session_name[LTTNG_NAME_MAX];
48 char hostname[LTTNG_HOST_NAME_MAX];
49 char base_path[LTTNG_PATH_MAX];
50 /*
51 * Session output path relative to relayd's output path.
52 * Will be empty when interacting with peers < 2.11 since their
53 * streams' path are expressed relative to the relay daemon's
54 * output path.
55 */
56 char output_path[LTTNG_PATH_MAX];
57 uint32_t live_timer;
58
59 /* Session in snapshot mode. */
60 bool snapshot;
61
62 /*
63 * Session has no back reference to its connection because it
64 * has a life-time that can be longer than the consumer connection's
65 * life-time; a reference can still be held by the viewer
66 * connection through the viewer streams.
67 */
68
69 struct urcu_ref ref;
70
71 pthread_mutex_t lock;
72
73 /* major/minor version used for this session. */
74 uint32_t major;
75 uint32_t minor;
76
77 bool viewer_attached;
78 /* Tell if the session connection has been closed on the streaming side. */
79 bool connection_closed;
80
81 /*
82 * Tell if the session is currently living in a exiting relayd and
83 * should be cleaned forcefully without waiting for pending data or
84 * pending ctrl data.
85 */
86 bool aborted;
87
88 bool session_name_contains_creation_time;
89 /* Whether session has performed an explicit rotation. */
90 bool has_rotated;
91
92 /* Contains ctf_trace object of that session indexed by path name. */
93 struct lttng_ht *ctf_traces_ht;
94
95 /*
96 * This contains streams that are received on that connection.
97 * It's used to store them until we get the streams sent
98 * command. When this is received, we remove those streams from
99 * the list and publish them.
100 *
101 * Updates are protected by the recv_list_lock.
102 * Traversals are protected by RCU.
103 * recv_list_lock also protects stream_count.
104 */
105 struct cds_list_head recv_list; /* RCU list. */
106 uint32_t stream_count;
107 pthread_mutex_t recv_list_lock;
108
109 /*
110 * Flag checked and exchanged with uatomic_cmpxchg to tell the
111 * viewer-side if new streams got added since the last check.
112 */
113 unsigned long new_streams;
114
115 /*
116 * Node in the global session hash table.
117 */
118 struct lttng_ht_node_u64 session_n;
119 /*
120 * Member of the session list in struct relay_viewer_session.
121 * Updates are protected by the relay_viewer_session
122 * session_list_lock. Traversals are protected by RCU.
123 */
124 struct cds_list_head viewer_session_node;
125 struct lttng_trace_chunk *current_trace_chunk;
126 struct lttng_trace_chunk *pending_closure_trace_chunk;
127 /*
128 * Prevent live viewers from taking of copy of the chunk
129 * while new chunk has a temporary directory name.
130 */
131 bool ongoing_rotation;
132 struct lttng_directory_handle *output_directory;
133 struct rcu_head rcu_node; /* For call_rcu teardown. */
134 };
135
136 struct relay_session *session_create(const char *session_name,
137 const char *hostname, const char *base_path,
138 uint32_t live_timer,
139 bool snapshot,
140 const lttng_uuid sessiond_uuid,
141 const uint64_t *id_sessiond,
142 const uint64_t *current_chunk_id,
143 const time_t *creation_time,
144 uint32_t major,
145 uint32_t minor,
146 bool session_name_contains_creation_timestamp);
147 struct relay_session *session_get_by_id(uint64_t id);
148 bool session_get(struct relay_session *session);
149 void session_put(struct relay_session *session);
150
151 int session_close(struct relay_session *session);
152 int session_abort(struct relay_session *session);
153
154 void print_sessions(void);
155
156 #endif /* _SESSION_H */
This page took 0.0477959999999999 seconds and 5 git commands to generate.