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